Refine search
/** * Create a Scan operation for the range of rows specified. * @param startRow row to start scanner at or after (inclusive) * @param stopRow row to stop scanner before (exclusive) * @deprecated use {@code new Scan().withStartRow(startRow).withStopRow(stopRow)} instead. */ @Deprecated public Scan(byte[] startRow, byte[] stopRow) { setStartRow(startRow); setStopRow(stopRow); }
/** * Creates Scan operation to load backup set list * @return scan operation */ private Scan createScanForBackupSetList() { Scan scan = new Scan(); byte[] startRow = Bytes.toBytes(SET_KEY_PREFIX); byte[] stopRow = Arrays.copyOf(startRow, startRow.length); stopRow[stopRow.length - 1] = (byte) (stopRow[stopRow.length - 1] + 1); scan.setStartRow(startRow); scan.setStopRow(stopRow); scan.addFamily(BackupSystemTable.META_FAMILY); return scan; }
private Result getReverseScanResult(byte[] tableName, byte[] row, byte[] family) throws IOException { Scan scan = new Scan(row); scan.setReversed(true); scan.addFamily(family); scan.setStartRow(row); try (Table table = getTable(tableName); ResultScanner scanner = table.getScanner(scan)) { return scanner.next(); } }
/** * Creates Scan operation to load WALs * @param backupRoot path to backup destination * @return scan operation */ private Scan createScanForGetWALs(String backupRoot) { // TODO: support for backupRoot Scan scan = new Scan(); byte[] startRow = Bytes.toBytes(WALS_PREFIX); byte[] stopRow = Arrays.copyOf(startRow, startRow.length); stopRow[stopRow.length - 1] = (byte) (stopRow[stopRow.length - 1] + 1); scan.setStartRow(startRow); scan.setStopRow(stopRow); scan.addFamily(BackupSystemTable.META_FAMILY); return scan; }
protected static CINode findStartNode(Table table, byte[] startKey) throws IOException { Scan scan = new Scan(); scan.setStartRow(startKey); scan.setBatch(1); scan.addColumn(FAMILY_NAME, COLUMN_PREV); long t1 = System.currentTimeMillis(); ResultScanner scanner = table.getScanner(scan); Result result = scanner.next(); long t2 = System.currentTimeMillis(); scanner.close(); if ( result != null) { CINode node = getCINode(result, new CINode()); System.out.printf("FSR %d %s\n", t2 - t1, Bytes.toStringBinary(node.key)); return node; } System.out.println("FSR " + (t2 - t1)); return null; } protected CINode getNode(byte[] row, Table table, CINode node) throws IOException {
/** * <p>Set a filter (using stopRow and startRow) so the result set only contains rows where the * rowKey starts with the specified prefix.</p> * <p>This is a utility method that converts the desired rowPrefix into the appropriate values * for the startRow and stopRow to achieve the desired result.</p> * <p>This can safely be used in combination with setFilter.</p> * <p><b>NOTE: Doing a {@link #setStartRow(byte[])} and/or {@link #setStopRow(byte[])} * after this method will yield undefined results.</b></p> * @param rowPrefix the prefix all rows must start with. (Set <i>null</i> to remove the filter.) * @return this */ public Scan setRowPrefixFilter(byte[] rowPrefix) { if (rowPrefix == null) { setStartRow(HConstants.EMPTY_START_ROW); setStopRow(HConstants.EMPTY_END_ROW); } else { this.setStartRow(rowPrefix); this.setStopRow(calculateTheClosestNextRowKeyForPrefix(rowPrefix)); } return this; }
/** * Creates Scan to load table-> { RS -> ts} map of maps * @return scan operation */ private Scan createScanForReadLogTimestampMap(String backupRoot) { Scan scan = new Scan(); byte[] startRow = rowkey(TABLE_RS_LOG_MAP_PREFIX, backupRoot); byte[] stopRow = Arrays.copyOf(startRow, startRow.length); stopRow[stopRow.length - 1] = (byte) (stopRow[stopRow.length - 1] + 1); scan.setStartRow(startRow); scan.setStopRow(stopRow); scan.addFamily(BackupSystemTable.META_FAMILY); return scan; }
Scan scan2 = new Scan(scan); scan2.setStartRow(startRow);
private static void setStartAndStopRows(Scan scan, byte[] startPrefixRow, byte[] lastPrefixRow) { scan.setStartRow(startPrefixRow); byte[] stopRow = Bytes.add(Bytes.head(lastPrefixRow, lastPrefixRow.length - 1), new byte[]{(byte) (lastPrefixRow[lastPrefixRow.length - 1] + 1)}); scan.setStopRow(stopRow); }
/** * Creates Scan operation to load backup history * @return scan operation */ private Scan createScanForBackupHistory() { Scan scan = new Scan(); byte[] startRow = Bytes.toBytes(BACKUP_INFO_PREFIX); byte[] stopRow = Arrays.copyOf(startRow, startRow.length); stopRow[stopRow.length - 1] = (byte) (stopRow[stopRow.length - 1] + 1); scan.setStartRow(startRow); scan.setStopRow(stopRow); scan.addFamily(BackupSystemTable.SESSIONS_FAMILY); scan.setMaxVersions(1); return scan; }
@Override public void run() { ResultScanner rs = null; TraceUtil.addSampler(Sampler.ALWAYS); try (TraceScope scope = TraceUtil.createTrace("Scan")){ Table ht = util.getConnection().getTable(tableName); Scan s = new Scan(); s.setStartRow(Bytes.toBytes(rowKeyQueue.take())); s.setBatch(7); rs = ht.getScanner(s); // Something to keep the jvm from removing the loop. long accum = 0; for(int x = 0; x < 1000; x++) { Result r = rs.next(); accum |= Bytes.toLong(r.getRow()); } TraceUtil.addTimelineAnnotation("Accum result = " + accum); ht.close(); ht = null; } catch (IOException e) { e.printStackTrace(); TraceUtil.addKVAnnotation("exception", e.getClass().getSimpleName()); } catch (Exception e) { } finally { if (rs != null) rs.close(); } } };
@Override public void open(TableInputSplit split) throws IOException { if (table == null) { throw new IOException("The HBase table has not been opened! " + "This needs to be done in configure()."); } if (scan == null) { throw new IOException("Scan has not been initialized! " + "This needs to be done in configure()."); } if (split == null) { throw new IOException("Input split is null!"); } logSplitInfo("opening", split); // set scan range currentRow = split.getStartRow(); scan.setStartRow(currentRow); scan.setStopRow(split.getEndRow()); resultScanner = table.getScanner(scan); endReached = false; scannedRows = 0; }
static Scan createScanForBulkLoadedFiles(String backupId) { Scan scan = new Scan(); byte[] startRow = backupId == null ? BULK_LOAD_PREFIX_BYTES : rowkey(BULK_LOAD_PREFIX, backupId + BLK_LD_DELIM); byte[] stopRow = Arrays.copyOf(startRow, startRow.length); stopRow[stopRow.length - 1] = (byte) (stopRow[stopRow.length - 1] + 1); scan.setStartRow(startRow); scan.setStopRow(stopRow); scan.addFamily(BackupSystemTable.META_FAMILY); scan.setMaxVersions(1); return scan; }
Scan s = new Scan(); s.setStartRow(ROWS_FOUR[1]); RegionScanner scanner = region.getScanner(s);
/** * This method creates a Scan object that will only scan catalog rows that * belong to the specified table. It doesn't specify any columns. * This is a better alternative to just using a start row and scan until * it hits a new table since that requires parsing the HRI to get the table * name. * @param tableName bytes of table's name * @return configured Scan object */ @Deprecated public static Scan getScanForTableName(Connection connection, TableName tableName) { // Start key is just the table name with delimiters byte[] startKey = getTableStartRowForMeta(tableName, QueryType.REGION); // Stop key appends the smallest possible char to the table name byte[] stopKey = getTableStopRowForMeta(tableName, QueryType.REGION); Scan scan = getMetaScan(connection, -1); scan.setStartRow(startKey); scan.setStopRow(stopKey); return scan; }
/** * Creates Scan operation to load last RS log roll results * @return scan operation */ private Scan createScanForReadRegionServerLastLogRollResult(String backupRoot) { Scan scan = new Scan(); byte[] startRow = rowkey(RS_LOG_TS_PREFIX, backupRoot); byte[] stopRow = Arrays.copyOf(startRow, startRow.length); stopRow[stopRow.length - 1] = (byte) (stopRow[stopRow.length - 1] + 1); scan.setStartRow(startRow); scan.setStopRow(stopRow); scan.addFamily(BackupSystemTable.META_FAMILY); scan.setMaxVersions(1); return scan; }
table.increment(increment); TestCoprocessorForTags.checkTagPresence = true; scanner = table.getScanner(new Scan().setStartRow(row2)); result = scanner.next(); kv = KeyValueUtil.ensureKeyValue(result.getColumnLatestCell(f, q)); table.append(append); TestCoprocessorForTags.checkTagPresence = true; scanner = table.getScanner(new Scan().setStartRow(row3)); result = scanner.next(); kv = KeyValueUtil.ensureKeyValue(result.getColumnLatestCell(f, q)); table.append(append); TestCoprocessorForTags.checkTagPresence = true; scanner = table.getScanner(new Scan().setStartRow(row3)); result = scanner.next(); kv = KeyValueUtil.ensureKeyValue(result.getColumnLatestCell(f, q)); table.append(append); TestCoprocessorForTags.checkTagPresence = true; scanner = table.getScanner(new Scan().setStartRow(row4)); result = scanner.next(); kv = KeyValueUtil.ensureKeyValue(result.getColumnLatestCell(f, q));
public void setup(Scan scan, Configuration conf, boolean filterOnly) throws Exception { if (!filterOnly) { // Set the start and stop rows only if asked to if (startRow != null) { scan.setStartRow(startRow); } if (stopRow != null) { scan.setStopRow(stopRow); } } if (filterDescs.isEmpty()) { return; } if (filterDescs.size() == 1) { scan.setFilter(filterDescs.get(0).toFilter(conf)); return; } List<Filter> filters = new ArrayList<Filter>(); for (FilterDesc filter : filterDescs) { filters.add(filter.toFilter(conf)); } scan.setFilter(new FilterList(filters)); }
Scan scan = new Scan(); scan.setStartRow(Bytes.toBytesBinary(conf.get(SCAN_ROW_START))); scan.setStopRow(Bytes.toBytesBinary(conf.get(SCAN_ROW_STOP)));
public static void main(String[] args) throws IOException { Configuration conf = HBaseConfiguration.create(); HBaseHelper helper = HBaseHelper.getHelper(conf); helper.dropTable("testtable"); helper.createTable("testtable", "colfam1"); System.out.println("Adding rows to table..."); helper.fillTable("testtable", 1, 100, 1, "colfam1"); Connection connection = ConnectionFactory.createConnection(conf); Table table = connection.getTable(TableName.valueOf("testtable")); // vv InclusiveStopFilterExample Filter filter = new InclusiveStopFilter(Bytes.toBytes("row-5")); Scan scan = new Scan(); scan.setStartRow(Bytes.toBytes("row-3")); scan.setFilter(filter); ResultScanner scanner = table.getScanner(scan); // ^^ InclusiveStopFilterExample System.out.println("Results of scan:"); // vv InclusiveStopFilterExample for (Result result : scanner) { System.out.println(result); } scanner.close(); // ^^ InclusiveStopFilterExample } }