本文整理了Java中org.apache.hadoop.hbase.client.Table.getScanner()
方法的一些代码示例,展示了Table.getScanner()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Table.getScanner()
方法的具体详情如下:
包路径:org.apache.hadoop.hbase.client.Table
类名称: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
/**
* 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();
}
代码示例来源:origin: apache/hbase
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;
}
代码示例来源:origin: apache/hbase
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();
}
}
代码示例来源:origin: apache/hbase
@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);
}
}
代码示例来源:origin: apache/hbase
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);
}
}
代码示例来源:origin: apache/hbase
/**
* 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();
}
代码示例来源:origin: apache/kylin
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);
}
}
代码示例来源:origin: apache/hbase
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);
}
代码示例来源:origin: apache/hbase
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();
}
代码示例来源:origin: apache/hbase
/**
* 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;
}
代码示例来源:origin: apache/hbase
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;
}
}
代码示例来源:origin: apache/hbase
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();
}
代码示例来源:origin: apache/hbase
/**
* 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;
}
代码示例来源:origin: apache/hbase
@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();
}
代码示例来源:origin: apache/hbase
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);
}
代码示例来源:origin: apache/hbase
/**
* 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;
}
}
代码示例来源:origin: apache/hbase
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();
}
}
代码示例来源:origin: apache/hbase
@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;
}
};
代码示例来源:origin: apache/hbase
/**
* 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;
}
代码示例来源:origin: apache/hbase
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());
}
}
内容来源于网络,如有侵权,请联系作者删除!