/** * Creates a {@link Scan} which returns only {@link SpaceQuotaSnapshot} from the quota table for a * specific table. * @param tn Optionally, a table name to limit the scan's rowkey space. Can be null. */ public static Scan makeQuotaSnapshotScanForTable(TableName tn) { Scan s = new Scan(); // Limit to "u:v" column s.addColumn(QUOTA_FAMILY_USAGE, QUOTA_QUALIFIER_POLICY); if (null == tn) { s.setRowPrefixFilter(QUOTA_TABLE_ROW_KEY_PREFIX); } else { byte[] row = getTableRowKey(tn); // Limit rowspace to the "t:" prefix s.withStartRow(row, true).withStopRow(row, true); } return s; }
static Scan createScanForSpaceSnapshotSizes(TableName table) { Scan s = new Scan(); if (null == table) { // Read all tables, just look at the row prefix s.setRowPrefixFilter(QUOTA_TABLE_ROW_KEY_PREFIX); } else { // Fetch the exact row for the table byte[] rowkey = getTableRowKey(table); // Fetch just this one row s.withStartRow(rowkey).withStopRow(rowkey, true); } // Just the usage family and only the snapshot size qualifiers return s.addFamily(QUOTA_FAMILY_USAGE).setFilter( new ColumnPrefixFilter(QUOTA_SNAPSHOT_SIZE_QUALIFIER)); }
scan.setRowPrefixFilter(prefix0); verifyScanResult(table, scan, expected0, "Scan empty prefix failed"); scan.setRowPrefixFilter(prefix1); verifyScanResult(table, scan, expected1, "Scan normal prefix failed"); scan.setRowPrefixFilter(null); verifyScanResult(table, scan, expected0, "Scan after prefix reset failed"); scan.setRowPrefixFilter(prefix2); verifyScanResult(table, scan, expected2, "Scan edge 0xFF prefix failed"); scan.setRowPrefixFilter(null); verifyScanResult(table, scan, expected0, "Scan after prefix reset failed"); scan.setRowPrefixFilter(prefix3); verifyScanResult(table, scan, expected3, "Scan normal with 0x00 ends failed"); scan.setRowPrefixFilter(null); verifyScanResult(table, scan, expected0, "Scan after prefix reset failed"); scan.setRowPrefixFilter(prefix4); verifyScanResult(table, scan, expected4, "Scan end prefix failed"); scan.setRowPrefixFilter(null); verifyScanResult(table, scan, expected0, "Scan after prefix reset failed"); scan.setRowPrefixFilter(prefix1); verifyScanResult(table, scan, expected1, "Prefix filter failed");
/** * Creates a {@link Scan} which returns only {@link SpaceQuotaSnapshot} from the quota table for a * specific table. * @param tn Optionally, a table name to limit the scan's rowkey space. Can be null. */ public static Scan makeQuotaSnapshotScanForTable(TableName tn) { Scan s = new Scan(); // Limit to "u:v" column s.addColumn(QUOTA_FAMILY_USAGE, QUOTA_QUALIFIER_POLICY); if (null == tn) { s.setRowPrefixFilter(QUOTA_TABLE_ROW_KEY_PREFIX); } else { byte[] row = getTableRowKey(tn); // Limit rowspace to the "t:" prefix s.withStartRow(row, true).withStopRow(row, true); } return s; }
.setRowPrefixFilter(Bytes.toBytes("row-1")) // co MultipleColumnPrefixFilterExample-1-Row Limit to rows starting with a specific prefix. .setFilter(filter); ResultScanner scanner = table.getScanner(scan);
static Scan createScanForSpaceSnapshotSizes(TableName table) { Scan s = new Scan(); if (null == table) { // Read all tables, just look at the row prefix s.setRowPrefixFilter(QUOTA_TABLE_ROW_KEY_PREFIX); } else { // Fetch the exact row for the table byte[] rowkey = getTableRowKey(table); // Fetch just this one row s.withStartRow(rowkey).withStopRow(rowkey, true); } // Just the usage family and only the snapshot size qualifiers return s.addFamily(QUOTA_FAMILY_USAGE).setFilter( new ColumnPrefixFilter(QUOTA_SNAPSHOT_SIZE_QUALIFIER)); }
.setReversed(true) .setRowOffsetPerColumnFamily(5) .setRowPrefixFilter(Bytes.toBytes("row_")) .setScanMetricsEnabled(true) .setSmall(true)
private Scan getVertexIndexScan(String label, boolean isUnique, String key, Object value) { byte[] startRow = serializeForRead(label, isUnique, key, value); Scan scan = new Scan(startRow); scan.setRowPrefixFilter(startRow); return scan; }
private Scan getEdgesScan(Vertex vertex, Direction direction, boolean isUnique, String key, String label, Object value) { LOGGER.trace("Executing Scan, type: {}, id: {}", "key-value", vertex.id()); byte[] startRow = serializeForRead(vertex, direction, isUnique, key, label, value); Scan scan = new Scan(startRow); scan.setRowPrefixFilter(startRow); return scan; }
SortedSet<SequenceEvent> readEvents(WorkflowInstance workflowInstance) throws IOException { try (final Table eventsTable = connection.getTable(EVENTS_TABLE_NAME)) { final Scan scan = new Scan() .setRowPrefixFilter(Bytes.toBytes(workflowInstance.toKey() + '#')); final SortedSet<SequenceEvent> set = newSortedEventSet(); for (Result result : eventsTable.getScanner(scan)) { set.add(parseEventResult(result)); } return set; } }
private Scan getEdgeEndpointsScan(Vertex vertex, Direction direction, String... labels) { LOGGER.trace("Executing Scan, type: {}, id: {}", "key", vertex.id()); final String key = Constants.CREATED_AT; byte[] startRow = serializeForRead(vertex, direction != Direction.BOTH ? direction : null, false, key, labels.length == 1 ? labels[0] : null, null); Scan scan = new Scan(startRow); scan.setRowPrefixFilter(startRow); scan.setFilter(applyEdgeLabelsRowFilter(vertex, direction, key, labels)); return scan; }
@ProcessElement public void processElement(ProcessContext c) throws IOException { Scan scan = new Scan() .setRowPrefixFilter(c.element().getBytes()) .setFilter(new KeyOnlyFilter()); Table table = getConnection().getTable(TableName.valueOf(tableId)); for (Result result : table.getScanner(scan)) { c.output(result.getRow()); } } }
/** * Creates a {@link Scan} which returns only {@link SpaceQuotaSnapshot} from the quota table for a * specific table. * @param tn Optionally, a table name to limit the scan's rowkey space. Can be null. */ public static Scan makeQuotaSnapshotScanForTable(TableName tn) { Scan s = new Scan(); // Limit to "u:v" column s.addColumn(QUOTA_FAMILY_USAGE, QUOTA_QUALIFIER_POLICY); if (null == tn) { s.setRowPrefixFilter(QUOTA_TABLE_ROW_KEY_PREFIX); } else { byte[] row = getTableRowKey(tn); // Limit rowspace to the "t:" prefix s.withStartRow(row, true).withStopRow(row, true); } return s; }
@Override protected Scan getInputScan(final HBaseGraph graph, final IndexMetadata index) { if (index.type() == ElementType.EDGE) { return new Scan(); } else { // optimization for vertex index scans byte[] startRow = graph.getVertexIndexModel().serializeForRead( index.label(), index.isUnique(), index.propertyKey(), null); Scan scan = new Scan(startRow); scan.setRowPrefixFilter(startRow); return scan; } }
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); } }
public Iterator<Map<String, List<Variant>>> rawIterator(int study, int sample) throws IOException { String tableName = tableNameGenerator.getSampleIndexTableName(study); return hBaseManager.act(tableName, table -> { Scan scan = new Scan(); scan.setRowPrefixFilter(SampleIndexConverter.toRowKey(sample)); SampleIndexConverter converter = new SampleIndexConverter(); try { ResultScanner scanner = table.getScanner(scan); Iterator<Result> resultIterator = scanner.iterator(); Iterator<Map<String, List<Variant>>> iterator = Iterators.transform(resultIterator, converter::convertToMap); return iterator; } catch (IOException e) { throw VariantQueryException.internalException(e); } }); }
static Scan createScanForSpaceSnapshotSizes(TableName table) { Scan s = new Scan(); if (null == table) { // Read all tables, just look at the row prefix s.setRowPrefixFilter(QUOTA_TABLE_ROW_KEY_PREFIX); } else { // Fetch the exact row for the table byte[] rowkey = getTableRowKey(table); // Fetch just this one row s.withStartRow(rowkey).withStopRow(rowkey, true); } // Just the usage family and only the snapshot size qualifiers return s.addFamily(QUOTA_FAMILY_USAGE).setFilter( new ColumnPrefixFilter(QUOTA_SNAPSHOT_SIZE_QUALIFIER)); }
private static Map<String, Long> getResult(SingleColumnValueFilter filter) throws IOException { Scan scan = new Scan(); scan.setRowPrefixFilter(Bytes.toBytes(PREFIX)); scan.setFilter(filter); Map<String, Long> rowKeys = new HashMap<>(); try (ResultScanner scanner = table.getScanner(scan)) { for (Result result : scanner) { String key = Bytes.toString(result.getRow()); if (!key.startsWith(PREFIX)) { Assert.fail(String.format("Found key %s which does not start with %s", key, PREFIX)); } else if (key.startsWith(NOT_STRICT_KEY)) { long randomValue = (long) ((Math.random() * 30) - 15); rowKeys.put(key, randomValue); } else { Assert.assertEquals(2, result.size()); byte[] val = CellUtil.cloneValue(result.getColumnLatestCell(COLUMN_FAMILY, QUALIFIER)); rowKeys.put(key, Bytes.toLong(val)); } } } return rowKeys; }
public Set<Integer> getLoadedFiles(int studyId) throws IOException { if (!hBaseManager.tableExists(tableName)) { return new HashSet<>(); } else { return hBaseManager.act(tableName, table -> { Set<Integer> set = new TreeSet<>(); Scan scan = new Scan(); scan.addColumn(family, getStatusColumn()); scan.addColumn(family, getTypeColumn()); scan.setRowPrefixFilter(getVariantFileMetadataRowKeyPrefix(studyId)); scan.setFilter(new FilterList(FilterList.Operator.MUST_PASS_ALL, new SingleColumnValueFilter(family, getStatusColumn(), CompareOp.EQUAL, Status.READY.bytes()), new SingleColumnValueFilter(family, getTypeColumn(), CompareOp.EQUAL, Type.VARIANT_FILE_METADATA.bytes()))); for (Result result : table.getScanner(scan)) { Pair<Integer, Integer> pair = parseVariantFileMetadataRowKey(result.getRow()); Integer fileId = pair.getValue(); set.add(fileId); } return set; }); } }
.setReversed(true) .setRowOffsetPerColumnFamily(5) .setRowPrefixFilter(Bytes.toBytes("row_")) .setScanMetricsEnabled(true) .setSmall(true)