@Test public void testFilterAllRecords() throws IOException { Scan scan = new Scan(); scan.setBatch(1); scan.setCaching(1); // Filter out any records scan.setFilter(new FilterList(new FirstKeyOnlyFilter(), new InclusiveStopFilter(new byte[0]))); try (Table table = TEST_UTIL.getConnection().getTable(TableName.META_TABLE_NAME)) { try (ResultScanner s = table.getScanner(scan)) { assertNull(s.next()); } } }
@Test public void testFirstKeyOnlyFilter() throws Exception { FirstKeyOnlyFilter firstKeyOnlyFilter = new FirstKeyOnlyFilter(); assertTrue(firstKeyOnlyFilter.areSerializedFieldsEqual( ProtobufUtil.toFilter(ProtobufUtil.toFilter(firstKeyOnlyFilter)))); }
@Deprecated @Override public ReturnCode filterKeyValue(final Cell c) { return filterCell(c); }
@Test public void testAddFilter() throws Exception { Filter filter1 = new FirstKeyOnlyFilter(); Filter filter2 = new FirstKeyOnlyFilter(); FilterList filterList = new FilterList(filter1, filter2); filterList.addFilter(new FirstKeyOnlyFilter()); filterList = new FilterList(Arrays.asList(filter1, filter2)); filterList.addFilter(new FirstKeyOnlyFilter()); filterList = new FilterList(Operator.MUST_PASS_ALL, filter1, filter2); filterList.addFilter(new FirstKeyOnlyFilter()); filterList = new FilterList(Operator.MUST_PASS_ALL, Arrays.asList(filter1, filter2)); filterList.addFilter(new FirstKeyOnlyFilter()); filterList.setReversed(false); FirstKeyOnlyFilter f = new FirstKeyOnlyFilter(); f.setReversed(true); try { filterList.addFilter(f); fail("The IllegalArgumentException should be thrown because the added filter is reversed"); } catch (IllegalArgumentException e) { } }
Scan scan = new Scan(); scan.setCacheBlocks(false); if (startKey != null && !startKey.equals("")) { scan.setStartRow(Bytes.toBytes(startKey)); scan.setStopRow(Bytes.toBytes(endKey)); scan.setFilter(new FirstKeyOnlyFilter()); if (sb.length() > 0) { for (String columnName : sb.toString().trim().split(" ")) { throw new IOException("must specify qualifier to read themis table"); } else { scan.addColumn(Bytes.toBytes(family), Bytes.toBytes(qualifier));
Scan scan = new Scan(); boolean empty = true; scan.addFamily(colMap.familyNameBytes); addedFamilies.add(colMap.familyName); } else { if(!addedFamilies.contains(colMap.familyName)){ scan.addColumn(colMap.familyNameBytes, colMap.qualifierNameBytes); scan.setFilter(new FilterList(new FirstKeyOnlyFilter(), new KeyOnlyFilter()));
@Test public void testReverseScanWithoutPadding() throws Exception { byte[] row1 = Bytes.toBytes("a"); byte[] row2 = Bytes.toBytes("ab"); byte[] row3 = Bytes.toBytes("b"); region.put(put3); region.flush(true); Scan scan = new Scan(); scan.setCacheBlocks(false); scan.setReversed(true); scan.setFilter(new FirstKeyOnlyFilter()); scan.addFamily(cfName); RegionScanner scanner = region.getScanner(scan);
PTable table = tableRef.getTable(); Map<byte [], NavigableSet<byte []>> familyMap = scan.getFamilyMap(); scan.setMaxVersions(); scan.setFilter(null); // Remove any filter scan.setRaw(true); // Traverse (and subsequently clone) all KeyValues ScanUtil.andFilterAtBeginning(scan, new FirstKeyOnlyFilter()); scan.setAttribute(BaseScannerRegionObserver.IMMUTABLE_STORAGE_ENCODING_SCHEME, new byte[]{table.getImmutableStorageScheme().getSerializedMetadataValue()}); scan.setAttribute(BaseScannerRegionObserver.USE_NEW_VALUE_COLUMN_QUALIFIER, Bytes.toBytes(true));
@Test public void testReverseScanWithPadding() throws Exception { byte[] terminator = new byte[] { -1 }; byte[] row1 = Bytes.add(invert(Bytes.toBytes("a")), terminator); byte[] row2 = Bytes.add(invert(Bytes.toBytes("ab")), terminator); byte[] row3 = Bytes.add(invert(Bytes.toBytes("b")), terminator); Put put1 = new Put(row1); put1.addColumn(cfName, cqName, HConstants.EMPTY_BYTE_ARRAY); Put put2 = new Put(row2); put2.addColumn(cfName, cqName, HConstants.EMPTY_BYTE_ARRAY); Put put3 = new Put(row3); put3.addColumn(cfName, cqName, HConstants.EMPTY_BYTE_ARRAY); region.put(put1); region.put(put2); region.put(put3); region.flush(true); Scan scan = new Scan(); scan.setCacheBlocks(false); scan.setReversed(true); scan.setFilter(new FirstKeyOnlyFilter()); scan.addFamily(cfName); RegionScanner scanner = region.getScanner(scan); List<Cell> res = new ArrayList<>(); int count = 1; while (scanner.next(res)) { count++; } assertEquals(3, count); }
List<WorkflowInstanceExecutionData> executionData(WorkflowId workflowId, String offset, int limit) throws IOException { try (final Table eventsTable = connection.getTable(EVENTS_TABLE_NAME)) { final Scan scan = new Scan() .setRowPrefixFilter(Bytes.toBytes(workflowId.toKey() + '#')) .setFilter(new FirstKeyOnlyFilter()); if (!Strings.isNullOrEmpty(offset)) { final WorkflowInstance offsetInstance = WorkflowInstance.create(workflowId, offset); scan.setStartRow(Bytes.toBytes(offsetInstance.toKey() + '#')); } final Set<WorkflowInstance> workflowInstancesSet = Sets.newHashSet(); try (ResultScanner scanner = eventsTable.getScanner(scan)) { Result result = scanner.next(); while (result != null) { final String key = new String(result.getRow()); final int lastHash = key.lastIndexOf('#'); final WorkflowInstance wfi = WorkflowInstance.parseKey(key.substring(0, lastHash)); workflowInstancesSet.add(wfi); if (workflowInstancesSet.size() == limit) { break; } result = scanner.next(); } } return executionData(workflowInstancesSet); } }
@Override public Map<String, Object> count(String task) { MappingConfig config = hbaseMapping.get(task); String hbaseTable = config.getHbaseMapping().getHbaseTable(); long rowCount = 0L; try { HTable table = (HTable) hbaseTemplate.getConnection().getTable(TableName.valueOf(hbaseTable)); Scan scan = new Scan(); scan.setFilter(new FirstKeyOnlyFilter()); ResultScanner resultScanner = table.getScanner(scan); for (Result result : resultScanner) { rowCount += result.size(); } } catch (IOException e) { logger.error(e.getMessage(), e); } Map<String, Object> res = new LinkedHashMap<>(); res.put("hbaseTable", hbaseTable); res.put("count", rowCount); return res; }
Bytes.toStringBinary(startKey)); if (startKey.length > 0) { get = new Get(startKey); get.setCacheBlocks(false); get.setFilter(new FirstKeyOnlyFilter()); stopWatch.start(); table.get(get); stopWatch.stop(); } else { scan = new Scan(); scan.setCacheBlocks(false); scan.setFilter(new FirstKeyOnlyFilter()); scan.setCaching(1); scan.setMaxResultSize(1L);
Scan scan = new Scan(); scan.setCacheBlocks(false); scan.setFilter(new FirstKeyOnlyFilter()); if (sb.length() > 0) { for (String columnName : sb.toString().trim().split(" ")) { throw new IOException("must specify qualifier to read themis table"); } else { scan.addColumn(Bytes.toBytes(family), Bytes.toBytes(qualifier)); for (String tableName : tableNames) { Scan thisScan = new Scan(scan); thisScan.setAttribute(Scan.SCAN_ATTRIBUTES_TABLE_NAME, Bytes.toBytes(tableName)); scans.add(thisScan);
/** * Test partial Result re-assembly in the presence of different filters. The Results from the * partial scanner should match the Results returned from a scanner that receives all of the * results in one RPC to the server. The partial scanner is tested with a variety of different * result sizes (all of which are less than the size necessary to fetch an entire row) * @throws Exception */ @Test public void testPartialResultsWithColumnFilter() throws Exception { testPartialResultsWithColumnFilter(new FirstKeyOnlyFilter()); testPartialResultsWithColumnFilter(new ColumnPrefixFilter(Bytes.toBytes("testQualifier5"))); testPartialResultsWithColumnFilter(new ColumnRangeFilter(Bytes.toBytes("testQualifer1"), true, Bytes.toBytes("testQualifier7"), true)); Set<byte[]> qualifiers = new LinkedHashSet<>(); qualifiers.add(Bytes.toBytes("testQualifier5")); testPartialResultsWithColumnFilter(new FirstKeyValueMatchingQualifiersFilter(qualifiers)); }
Preconditions.checkNotNull(subScanSpec, "HBase reader needs a sub-scan spec").getNamespace(), Preconditions.checkNotNull(subScanSpec, "HBase reader needs a sub-scan spec").getTableName()); hbaseScan = new Scan( subScanSpec.getStartRow() == null ? HConstants.EMPTY_START_ROW : subScanSpec.getStartRow(), subScanSpec.getStopRow() == null ? HConstants.EMPTY_END_ROW : subScanSpec.getStopRow()); this.sample = sample; hbaseScan .setFilter(subScanSpec.asScanFilter()) .setCaching((int) numRowsPerBatch); hbaseScan.setFilter( HBaseUtils.andFilterAtIndex(hbaseScan.getFilter(), HBaseUtils.LAST_FILTER, new FirstKeyOnlyFilter()));
@After public void tearDown() throws IOException { try (Table table = UTIL.getConnection().getTable(TableName.META_TABLE_NAME); ResultScanner scanner = table.getScanner(new Scan().addFamily(HConstants.CATALOG_FAMILY) .addFamily(HConstants.REPLICATION_BARRIER_FAMILY).setFilter(new FirstKeyOnlyFilter()))) { for (;;) { Result result = scanner.next(); if (result == null) { break; } TableName tableName = RegionInfo.getTable(result.getRow()); if (!tableName.isSystemTable()) { table.delete(new Delete(result.getRow())); } } } }
/** * Tries to scan a row from passed region */ private void isSuccessfulScan(RegionInfo region) throws IOException { Scan scan = new Scan().withStartRow(region.getStartKey()).setRaw(true).setOneRowLimit() .setMaxResultSize(1L).setCaching(1).setFilter(new FirstKeyOnlyFilter()) .setCacheBlocks(false); try (Table table = conn.getTable(region.getTable()); ResultScanner scanner = table.getScanner(scan)) { scanner.next(); } catch (IOException e) { LOG.error("Could not scan region:" + region.getEncodedName(), e); throw e; } }
public void getRowCount(RpcController controller, ExampleProtos.CountRequest request, RpcCallback<ExampleProtos.CountResponse> done) { Scan scan = new Scan(); scan.setFilter(new FirstKeyOnlyFilter()); ExampleProtos.CountResponse response = null; InternalScanner scanner = null; for (Cell kv : results) { byte[] currentRow = CellUtil.cloneRow(kv); if (lastRow == null || !Bytes.equals(lastRow, currentRow)) { lastRow = currentRow; count++;
if (child != null && child.isNamed()) { byte[] qualifier = child.getNameSegment().getPath().getBytes(); hbaseScanColumnsOnly.addColumn(family, qualifier); if (!completeFamilies.contains(root.getPath())) { hbaseScan.addColumn(family, qualifier); hbaseScan.addFamily(family); completeFamilies.add(root.getPath()); hbaseScan.setFilter( HBaseUtils.andFilterAtIndex(hbaseScan.getFilter(), HBaseUtils.LAST_FILTER, new FirstKeyOnlyFilter()));
/** * Sets filter {@link FilterBase} to the {@link Scan} instance. * If provided rowRangeList contains more than one element, * method sets filter which is instance of {@link MultiRowRangeFilter}. * Otherwise, method sets filter which is instance of {@link FirstKeyOnlyFilter}. * If rowRangeList contains exactly one element, startRow and stopRow are set to the scan. * @param scan * @param rowRangeList */ private static void setScanFilter(Scan scan, List<MultiRowRangeFilter.RowRange> rowRangeList) { final int size = rowRangeList == null ? 0 : rowRangeList.size(); if (size <= 1) { scan.setFilter(new FirstKeyOnlyFilter()); } if (size == 1) { MultiRowRangeFilter.RowRange range = rowRangeList.get(0); scan.setStartRow(range.getStartRow()); //inclusive scan.setStopRow(range.getStopRow()); //exclusive } else if (size > 1) { scan.setFilter(new MultiRowRangeFilter(rowRangeList)); } }