org.apache.hadoop.hbase.client.Table.getScanner()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(305)

本文整理了Java中org.apache.hadoop.hbase.client.Table.getScanner()方法的一些代码示例,展示了Table.getScanner()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Table.getScanner()方法的具体详情如下:
包路径:org.apache.hadoop.hbase.client.Table
类名称:Table
方法名:getScanner

Table.getScanner介绍

[英]Returns a scanner on the current table as specified by the Scanobject. Note that the passed Scan's start row and caching properties maybe changed.
[中]按Scanobject的指定返回当前表上的扫描程序。请注意,传递的扫描的开始行和缓存属性可能会更改。

代码示例

代码示例来源:origin: apache/hbase

  1. /**
  2. * Tests that scan on a table throws {@link RetriesExhaustedException} when the operation takes
  3. * longer than 'hbase.client.scanner.timeout.period'.
  4. */
  5. @Test(expected = RetriesExhaustedException.class)
  6. public void testScanTimeout() throws Exception {
  7. DELAY_SCAN = 600;
  8. ResultScanner scanner = table.getScanner(new Scan());
  9. scanner.next();
  10. }

代码示例来源:origin: apache/hbase

  1. private static Result [] getResult(Table table, Scan scan) throws IOException {
  2. ResultScanner scanner = table.getScanner(scan);
  3. Result[] next = scanner.next(1);
  4. assertTrue(next.length == 1);
  5. return next;
  6. }

代码示例来源:origin: apache/hbase

  1. private Result getReverseScanResult(byte[] tableName, byte[] row, byte[] family)
  2. throws IOException {
  3. Scan scan = new Scan(row);
  4. scan.setReversed(true);
  5. scan.addFamily(family);
  6. scan.setStartRow(row);
  7. try (Table table = getTable(tableName);
  8. ResultScanner scanner = table.getScanner(scan)) {
  9. return scanner.next();
  10. }
  11. }

代码示例来源:origin: apache/hbase

  1. @Test
  2. public void testReadRequestsCountWithTTLExpiration() throws Exception {
  3. putTTLExpiredData();
  4. Scan scan = new Scan();
  5. scan.addFamily(CF2);
  6. try (ResultScanner scanner = table.getScanner(scan)) {
  7. int resultCount = 0;
  8. for (Result ignore : scanner) {
  9. resultCount++;
  10. }
  11. testReadRequests(resultCount, 2, 1);
  12. }
  13. }

代码示例来源:origin: apache/hbase

  1. private static void assertRowCount(Table t, int expected) throws IOException {
  2. try (ResultScanner scanner = t.getScanner(new Scan())) {
  3. int i = 0;
  4. for (Result r: scanner) {
  5. LOG.info(r.toString());
  6. i++;
  7. }
  8. assertEquals(expected, i);
  9. }
  10. }

代码示例来源:origin: apache/hbase

  1. /**
  2. * Return an md5 digest of the entire contents of a table.
  3. */
  4. public String checksumRows(final Table table) throws Exception {
  5. Scan scan = new Scan();
  6. ResultScanner results = table.getScanner(scan);
  7. MessageDigest digest = MessageDigest.getInstance("MD5");
  8. for (Result res : results) {
  9. digest.update(res.getRow());
  10. }
  11. results.close();
  12. return digest.toString();
  13. }

代码示例来源:origin: apache/kylin

  1. private void convertToResourceStore(KylinConfig kylinConfig, String tableName, ResourceStore store,
  2. ResultConverter converter) throws IOException {
  3. Table table = null;
  4. ResultScanner rs = null;
  5. Scan scan = new Scan();
  6. try {
  7. table = HBaseConnection.get(kylinConfig.getStorageUrl()).getTable(TableName.valueOf(tableName));
  8. rs = table.getScanner(scan);
  9. converter.convertResult(rs, store);
  10. store.checkAndPutResource(MIGRATE_OK_PREFIX + tableName, new StringEntity(tableName + " migrated"),
  11. StringEntity.serializer);
  12. } finally {
  13. IOUtils.closeQuietly(rs);
  14. IOUtils.closeQuietly(table);
  15. }
  16. }

代码示例来源:origin: apache/hbase

  1. private List<Result> doScan(Scan scan) throws IOException {
  2. List<Result> results = new ArrayList<>();
  3. try (Table table = TEST_UTIL.getConnection().getTable(TABLE_NAME);
  4. ResultScanner scanner = table.getScanner(scan)) {
  5. for (Result r; (r = scanner.next()) != null;) {
  6. results.add(r);
  7. }
  8. }
  9. return assertAndCreateCompleteResults(results);
  10. }

代码示例来源:origin: apache/hbase

  1. private void verifyRowCount(Table table, int expectedRegionNum)
  2. throws IOException {
  3. ResultScanner scanner = table.getScanner(new Scan());
  4. int rowCount = 0;
  5. while (scanner.next() != null) {
  6. rowCount++;
  7. }
  8. assertEquals(expectedRegionNum, rowCount);
  9. scanner.close();
  10. }

代码示例来源:origin: apache/hbase

  1. /**
  2. * Provide an existing table name to truncate.
  3. * Scans the table and issues a delete for each row read.
  4. * @param tableName existing table
  5. * @return HTable to that new table
  6. * @throws IOException
  7. */
  8. public Table deleteTableData(TableName tableName) throws IOException {
  9. Table table = getConnection().getTable(tableName);
  10. Scan scan = new Scan();
  11. ResultScanner resScan = table.getScanner(scan);
  12. for(Result res : resScan) {
  13. Delete del = new Delete(res.getRow());
  14. table.delete(del);
  15. }
  16. resScan = table.getScanner(scan);
  17. resScan.close();
  18. return table;
  19. }

代码示例来源:origin: apache/hbase

  1. private boolean peerHasAllNormalRows() throws IOException {
  2. try (ResultScanner scanner = htable2.getScanner(new Scan())) {
  3. Result[] results = scanner.next(ROWS_COUNT);
  4. if (results.length != ROWS_COUNT) {
  5. return false;
  6. }
  7. for (int i = 0; i < results.length; i++) {
  8. Assert.assertArrayEquals(generateRowKey(i), results[i].getRow());
  9. }
  10. return true;
  11. }
  12. }

代码示例来源:origin: apache/hbase

  1. public void testEquivalenceOfScanResults(Table table, Scan scan1, Scan scan2) throws Exception {
  2. ResultScanner scanner1 = table.getScanner(scan1);
  3. ResultScanner scanner2 = table.getScanner(scan2);
  4. Result r1 = null;
  5. Result r2 = null;
  6. int count = 0;
  7. while ((r1 = scanner1.next()) != null) {
  8. r2 = scanner2.next();
  9. assertTrue(r2 != null);
  10. compareResults(r1, r2, "Comparing result #" + count);
  11. count++;
  12. }
  13. r2 = scanner2.next();
  14. assertTrue("r2: " + r2 + " Should be null", r2 == null);
  15. scanner1.close();
  16. scanner2.close();
  17. }

代码示例来源:origin: apache/hbase

  1. /**
  2. * Gets the number of cells in the given table.
  3. * @param table to get the scanner
  4. * @return the number of cells
  5. */
  6. private int countMobCells(final Table table) throws IOException {
  7. Scan scan = new Scan();
  8. // Do not retrieve the mob data when scanning
  9. scan.setAttribute(MobConstants.MOB_SCAN_RAW, Bytes.toBytes(Boolean.TRUE));
  10. ResultScanner results = table.getScanner(scan);
  11. int count = 0;
  12. for (Result res : results) {
  13. count += res.size();
  14. }
  15. results.close();
  16. return count;
  17. }

代码示例来源:origin: apache/hbase

  1. @Override
  2. void testRow(final int i) throws IOException {
  3. if (this.testScanner == null) {
  4. Scan scan = new Scan(format(this.startRow));
  5. scan.addColumn(FAMILY_NAME, QUALIFIER_NAME);
  6. this.testScanner = table.getScanner(scan);
  7. }
  8. testScanner.next();
  9. }

代码示例来源:origin: apache/hbase

  1. protected static void runSmallBatchTest() throws IOException, InterruptedException {
  2. // normal Batch tests
  3. loadData("", row);
  4. Scan scan = new Scan();
  5. ResultScanner scanner1 = htable1.getScanner(scan);
  6. Result[] res1 = scanner1.next(NB_ROWS_IN_BATCH);
  7. scanner1.close();
  8. assertEquals(NB_ROWS_IN_BATCH, res1.length);
  9. waitForReplication(NB_ROWS_IN_BATCH, NB_RETRIES);
  10. }

代码示例来源:origin: apache/hbase

  1. /**
  2. * Count the number of keyvalue in the table. Scans all possible versions
  3. * @param table table to scan
  4. * @return number of keyvalues over all rows in the table
  5. * @throws IOException
  6. */
  7. private int getKeyValueCount(Table table) throws IOException {
  8. Scan scan = new Scan();
  9. scan.setMaxVersions(Integer.MAX_VALUE - 1);
  10. ResultScanner results = table.getScanner(scan);
  11. int count = 0;
  12. for (Result res : results) {
  13. count += res.listCells().size();
  14. System.out.println(count + ") " + res);
  15. }
  16. results.close();
  17. return count;
  18. }
  19. }

代码示例来源:origin: apache/hbase

  1. private int cellsCount(Table table, Filter filter) throws IOException {
  2. Scan scan = new Scan().setFilter(filter).readAllVersions();
  3. try (ResultScanner scanner = table.getScanner(scan)) {
  4. List<Cell> results = new ArrayList<>();
  5. Result result;
  6. while ((result = scanner.next()) != null) {
  7. result.listCells().forEach(results::add);
  8. }
  9. return results.size();
  10. }
  11. }

代码示例来源:origin: apache/hbase

  1. @Override
  2. public Void run() throws Exception {
  3. try (Connection connection = ConnectionFactory.createConnection(conf);
  4. Table table = connection.getTable(tableName)) {
  5. Scan s = new Scan();
  6. ResultScanner scanner = table.getScanner(s);
  7. Result[] next = scanner.next(3);
  8. assertEquals(1, next.length);
  9. }
  10. return null;
  11. }
  12. };

代码示例来源:origin: apache/hbase

  1. /**
  2. * Count the number of keyvalues in the specified table with the given filter
  3. * @param table the table to scan
  4. * @return the number of keyvalues found
  5. * @throws IOException
  6. */
  7. private int getCount(Table table, Filter filter) throws IOException {
  8. Scan scan = new Scan();
  9. scan.setFilter(filter);
  10. ResultScanner results = table.getScanner(scan);
  11. int count = 0;
  12. for (Result res : results) {
  13. count += res.size();
  14. }
  15. results.close();
  16. return count;
  17. }

代码示例来源:origin: apache/hbase

  1. private void verifyRecordNotPresentInQuotaTable() throws Exception {
  2. // Verify that the record doesn't exist in the QuotaTableUtil.QUOTA_TABLE_NAME
  3. try (Table quotaTable = TEST_UTIL.getConnection().getTable(QuotaTableUtil.QUOTA_TABLE_NAME);
  4. ResultScanner scanner = quotaTable.getScanner(new Scan())) {
  5. assertNull("Did not expect to find a quota entry", scanner.next());
  6. }
  7. }

相关文章