/** * Tests that scan on a table throws {@link RetriesExhaustedException} when the operation takes * longer than 'hbase.client.scanner.timeout.period'. */ @Test(expected = RetriesExhaustedException.class) public void testScanTimeout() throws Exception { DELAY_SCAN = 600; ResultScanner scanner = table.getScanner(new Scan()); scanner.next(); }
private static Result [] getResult(Table table, Scan scan) throws IOException { ResultScanner scanner = table.getScanner(scan); Result[] next = scanner.next(1); assertTrue(next.length == 1); return next; }
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(); } }
@Test public void testReadRequestsCountWithTTLExpiration() throws Exception { putTTLExpiredData(); Scan scan = new Scan(); scan.addFamily(CF2); try (ResultScanner scanner = table.getScanner(scan)) { int resultCount = 0; for (Result ignore : scanner) { resultCount++; } testReadRequests(resultCount, 2, 1); } }
private static void assertRowCount(Table t, int expected) throws IOException { try (ResultScanner scanner = t.getScanner(new Scan())) { int i = 0; for (Result r: scanner) { LOG.info(r.toString()); i++; } assertEquals(expected, i); } }
/** * Return an md5 digest of the entire contents of a table. */ public String checksumRows(final Table table) throws Exception { Scan scan = new Scan(); ResultScanner results = table.getScanner(scan); MessageDigest digest = MessageDigest.getInstance("MD5"); for (Result res : results) { digest.update(res.getRow()); } results.close(); return digest.toString(); }
private void convertToResourceStore(KylinConfig kylinConfig, String tableName, ResourceStore store, ResultConverter converter) throws IOException { Table table = null; ResultScanner rs = null; Scan scan = new Scan(); try { table = HBaseConnection.get(kylinConfig.getStorageUrl()).getTable(TableName.valueOf(tableName)); rs = table.getScanner(scan); converter.convertResult(rs, store); store.checkAndPutResource(MIGRATE_OK_PREFIX + tableName, new StringEntity(tableName + " migrated"), StringEntity.serializer); } finally { IOUtils.closeQuietly(rs); IOUtils.closeQuietly(table); } }
private List<Result> doScan(Scan scan) throws IOException { List<Result> results = new ArrayList<>(); try (Table table = TEST_UTIL.getConnection().getTable(TABLE_NAME); ResultScanner scanner = table.getScanner(scan)) { for (Result r; (r = scanner.next()) != null;) { results.add(r); } } return assertAndCreateCompleteResults(results); }
private void verifyRowCount(Table table, int expectedRegionNum) throws IOException { ResultScanner scanner = table.getScanner(new Scan()); int rowCount = 0; while (scanner.next() != null) { rowCount++; } assertEquals(expectedRegionNum, rowCount); scanner.close(); }
/** * Provide an existing table name to truncate. * Scans the table and issues a delete for each row read. * @param tableName existing table * @return HTable to that new table * @throws IOException */ public Table deleteTableData(TableName tableName) throws IOException { Table table = getConnection().getTable(tableName); Scan scan = new Scan(); ResultScanner resScan = table.getScanner(scan); for(Result res : resScan) { Delete del = new Delete(res.getRow()); table.delete(del); } resScan = table.getScanner(scan); resScan.close(); return table; }
private boolean peerHasAllNormalRows() throws IOException { try (ResultScanner scanner = htable2.getScanner(new Scan())) { Result[] results = scanner.next(ROWS_COUNT); if (results.length != ROWS_COUNT) { return false; } for (int i = 0; i < results.length; i++) { Assert.assertArrayEquals(generateRowKey(i), results[i].getRow()); } return true; } }
public void testEquivalenceOfScanResults(Table table, Scan scan1, Scan scan2) throws Exception { ResultScanner scanner1 = table.getScanner(scan1); ResultScanner scanner2 = table.getScanner(scan2); Result r1 = null; Result r2 = null; int count = 0; while ((r1 = scanner1.next()) != null) { r2 = scanner2.next(); assertTrue(r2 != null); compareResults(r1, r2, "Comparing result #" + count); count++; } r2 = scanner2.next(); assertTrue("r2: " + r2 + " Should be null", r2 == null); scanner1.close(); scanner2.close(); }
/** * Gets the number of cells in the given table. * @param table to get the scanner * @return the number of cells */ private int countMobCells(final Table table) throws IOException { Scan scan = new Scan(); // Do not retrieve the mob data when scanning scan.setAttribute(MobConstants.MOB_SCAN_RAW, Bytes.toBytes(Boolean.TRUE)); ResultScanner results = table.getScanner(scan); int count = 0; for (Result res : results) { count += res.size(); } results.close(); return count; }
@Override void testRow(final int i) throws IOException { if (this.testScanner == null) { Scan scan = new Scan(format(this.startRow)); scan.addColumn(FAMILY_NAME, QUALIFIER_NAME); this.testScanner = table.getScanner(scan); } testScanner.next(); }
protected static void runSmallBatchTest() throws IOException, InterruptedException { // normal Batch tests loadData("", row); Scan scan = new Scan(); ResultScanner scanner1 = htable1.getScanner(scan); Result[] res1 = scanner1.next(NB_ROWS_IN_BATCH); scanner1.close(); assertEquals(NB_ROWS_IN_BATCH, res1.length); waitForReplication(NB_ROWS_IN_BATCH, NB_RETRIES); }
/** * Count the number of keyvalue in the table. Scans all possible versions * @param table table to scan * @return number of keyvalues over all rows in the table * @throws IOException */ private int getKeyValueCount(Table table) throws IOException { Scan scan = new Scan(); scan.setMaxVersions(Integer.MAX_VALUE - 1); ResultScanner results = table.getScanner(scan); int count = 0; for (Result res : results) { count += res.listCells().size(); System.out.println(count + ") " + res); } results.close(); return count; } }
private int cellsCount(Table table, Filter filter) throws IOException { Scan scan = new Scan().setFilter(filter).readAllVersions(); try (ResultScanner scanner = table.getScanner(scan)) { List<Cell> results = new ArrayList<>(); Result result; while ((result = scanner.next()) != null) { result.listCells().forEach(results::add); } return results.size(); } }
@Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); Table table = connection.getTable(tableName)) { Scan s = new Scan(); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); assertEquals(1, next.length); } return null; } };
/** * Count the number of keyvalues in the specified table with the given filter * @param table the table to scan * @return the number of keyvalues found * @throws IOException */ private int getCount(Table table, Filter filter) throws IOException { Scan scan = new Scan(); scan.setFilter(filter); ResultScanner results = table.getScanner(scan); int count = 0; for (Result res : results) { count += res.size(); } results.close(); return count; }
private void verifyRecordNotPresentInQuotaTable() throws Exception { // Verify that the record doesn't exist in the QuotaTableUtil.QUOTA_TABLE_NAME try (Table quotaTable = TEST_UTIL.getConnection().getTable(QuotaTableUtil.QUOTA_TABLE_NAME); ResultScanner scanner = quotaTable.getScanner(new Scan())) { assertNull("Did not expect to find a quota entry", scanner.next()); } }