/** * @return True if this Scan is in "raw" mode. */ public boolean isRaw() { byte[] attr = getAttribute(RAW_ATTR); return attr == null ? false : Bytes.toBoolean(attr); }
@Test public void testAttributesSerialization() throws IOException { Scan scan = new Scan(); scan.setAttribute("attribute1", Bytes.toBytes("value1")); scan.setAttribute("attribute2", Bytes.toBytes("value2")); scan.setAttribute("attribute3", Bytes.toBytes("value3")); ClientProtos.Scan scanProto = ProtobufUtil.toScan(scan); Scan scan2 = ProtobufUtil.toScan(scanProto); Assert.assertNull(scan2.getAttribute("absent")); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value1"), scan2.getAttribute("attribute1"))); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value2"), scan2.getAttribute("attribute2"))); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value3"), scan2.getAttribute("attribute3"))); Assert.assertEquals(3, scan2.getAttributesMap().size()); }
assertEquals(scan.getAttribute("test_key"), scanCopy.getAttribute("test_key")); assertEquals(scan.getAttributeSize(), scanCopy.getAttributeSize()); assertEquals(scan.getAttributesMap(), scanCopy.getAttributesMap());
/** * @return True if collection of scan metrics is enabled. For advanced users. */ public boolean isScanMetricsEnabled() { byte[] attr = getAttribute(Scan.SCAN_ATTRIBUTES_METRICS_ENABLE); return attr == null ? false : Bytes.toBoolean(attr); }
Scan scan = new Scan(); Assert.assertTrue(scan.getAttributesMap().isEmpty()); Assert.assertNull(scan.getAttribute("absent")); Assert.assertNull(scan.getAttribute("absent")); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value1"), scan.getAttribute("attribute1"))); Assert.assertEquals(1, scan.getAttributesMap().size()); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value1"), scan.getAttributesMap().get("attribute1"))); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value12"), scan.getAttribute("attribute1"))); Assert.assertEquals(1, scan.getAttributesMap().size()); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value12"), scan.getAttributesMap().get("attribute1"))); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value2"), scan.getAttribute("attribute2"))); Assert.assertEquals(2, scan.getAttributesMap().size()); Assert.assertTrue(Arrays.equals(Bytes.toBytes("value2"), scan.getAttributesMap().get("attribute2"))); Assert.assertNull(scan.getAttribute("attribute2")); Assert.assertEquals(1, scan.getAttributesMap().size()); Assert.assertNull(scan.getAttributesMap().get("attribute2")); Assert.assertNull(scan.getAttribute("attribute2")); Assert.assertEquals(1, scan.getAttributesMap().size()); Assert.assertNull(scan.getAttributesMap().get("attribute2")); Assert.assertNull(scan.getAttribute("attribute1")); Assert.assertTrue(scan.getAttributesMap().isEmpty()); Assert.assertNull(scan.getAttributesMap().get("attribute1"));
/** * @return Metrics on this Scan, if metrics were enabled. * @see #setScanMetricsEnabled(boolean) * @deprecated Use {@link ResultScanner#getScanMetrics()} instead. And notice that, please do not * use this method and {@link ResultScanner#getScanMetrics()} together, the metrics * will be messed up. */ @Deprecated public ScanMetrics getScanMetrics() { byte[] bytes = getAttribute(Scan.SCAN_ATTRIBUTES_METRICS_DATA); if (bytes == null) return null; return ProtobufUtil.toScanMetrics(bytes); }
/** * Indicates whether the scan contains the information of caching blocks. * The information is set in the attribute "hbase.mob.cache.blocks" of scan. * @param scan The current scan. * @return True when the Scan attribute specifies to cache the MOB blocks. */ public static boolean isCacheMobBlocks(Scan scan) { byte[] cache = scan.getAttribute(MobConstants.MOB_CACHE_BLOCKS); try { return cache != null && Bytes.toBoolean(cache); } catch (IllegalArgumentException e) { return false; } }
/** * Indicates whether return null value when the mob file is missing or corrupt. * The information is set in the attribute "empty.value.on.mobcell.miss" of scan. * @param scan The current scan. * @return True if the readEmptyValueOnMobCellMiss is enabled. */ public static boolean isReadEmptyValueOnMobCellMiss(Scan scan) { byte[] readEmptyValueOnMobCellMiss = scan.getAttribute(MobConstants.EMPTY_VALUE_ON_MOBCELL_MISS); try { return readEmptyValueOnMobCellMiss != null && Bytes.toBoolean(readEmptyValueOnMobCellMiss); } catch (IllegalArgumentException e) { return false; } }
/** * Indicates whether it's a reference only scan. * The information is set in the attribute "hbase.mob.scan.ref.only" of scan. * If it's a ref only scan, only the cells with ref tag are returned. * @param scan The current scan. * @return True if it's a ref only scan. */ public static boolean isRefOnlyScan(Scan scan) { byte[] refOnly = scan.getAttribute(MobConstants.MOB_SCAN_REF_ONLY); try { return refOnly != null && Bytes.toBoolean(refOnly); } catch (IllegalArgumentException e) { return false; } }
/** * Indicates whether it's a raw scan. * The information is set in the attribute "hbase.mob.scan.raw" of scan. * For a mob cell, in a normal scan the scanners retrieves the mob cell from the mob file. * In a raw scan, the scanner directly returns cell in HBase without retrieve the one in * the mob file. * @param scan The current scan. * @return True if it's a raw scan. */ public static boolean isRawMobScan(Scan scan) { byte[] raw = scan.getAttribute(MobConstants.MOB_SCAN_RAW); try { return raw != null && Bytes.toBoolean(raw); } catch (IllegalArgumentException e) { return false; } }
private ScanMetrics getScanMetrics(Scan scan) throws Exception { byte[] serializedMetrics = scan.getAttribute(Scan.SCAN_ATTRIBUTES_METRICS_DATA); assertTrue("Serialized metrics were not found.", serializedMetrics != null); ScanMetrics scanMetrics = ProtobufUtil.toScanMetrics(serializedMetrics); return scanMetrics; }
@Nullable @Override public String apply(Scan input) { return snapshotNameForTable( Bytes.toStringBinary(input.getAttribute(Scan.SCAN_ATTRIBUTES_TABLE_NAME))); } }).asMap();
byte[] tableNameBytes = scan.getAttribute(Scan.SCAN_ATTRIBUTES_TABLE_NAME); if (tableNameBytes == null) throw new IOException("A scan object did not have a table name");
@Override protected boolean isRegionObserverFor(Scan scan) { return scan.getAttribute(BaseScannerRegionObserver.UNORDERED_GROUP_BY_EXPRESSIONS) != null || scan.getAttribute(BaseScannerRegionObserver.KEY_ORDERED_GROUP_BY_EXPRESSIONS) != null; } }
tScan.setAttributes(attributes); Scan scan = scanFromThrift(tScan); assertArrayEquals(scan.getAttribute("attribute1"), attributeValue);
public static boolean isReversed(Scan scan) { byte[] reversed = scan.getAttribute(REVERSED_ATTR); return (PDataType.TRUE_BYTES.equals(reversed)); } }
public static boolean isSimpleScan(Scan scan) { return ScanUtil.isNonAggregateScan(scan) && scan.getAttribute(BaseScannerRegionObserver.TOPN) == null && scan.getAttribute(BaseScannerRegionObserver.SCAN_OFFSET) == null; }
public static int getClientVersion(Scan scan) { int clientVersion = UNKNOWN_CLIENT_VERSION; byte[] clientVersionBytes = scan.getAttribute(BaseScannerRegionObserver.CLIENT_VERSION); if (clientVersionBytes != null) { clientVersion = Bytes.toInt(clientVersionBytes); } return clientVersion; }
assertEquals(get.getTimeRange().getMin(), scan.getTimeRange().getMin()); assertEquals(get.getTimeRange().getMax(), scan.getTimeRange().getMax()); assertTrue(Bytes.equals(get.getAttribute("att_v0"), scan.getAttribute("att_v0"))); assertEquals(get.getColumnFamilyTimeRange().get(Bytes.toBytes("cf")).getMin(), scan.getColumnFamilyTimeRange().get(Bytes.toBytes("cf")).getMin());
public static byte[] getActualStartRow(Scan localIndexScan, RegionInfo regionInfo) { return localIndexScan.getAttribute(SCAN_START_ROW_SUFFIX) == null ? localIndexScan .getStartRow() : ScanRanges.prefixKey(localIndexScan.getAttribute(SCAN_START_ROW_SUFFIX), 0 , regionInfo.getStartKey().length == 0 ? new byte[regionInfo.getEndKey().length] : regionInfo.getStartKey(), regionInfo.getStartKey().length == 0 ? regionInfo.getEndKey().length : regionInfo .getStartKey().length); }