我有多个HBase表。每张表都有数百万条记录。计算记录数的最佳或最快方法是什么。通过以下程序,我将得到计数,但我想要一些最快的方法来计算记录。
def getTotalRecords(connection: Connection, tableName: String): Long = {
val startTime = System.currentTimeMillis();
val table = connection.getTable(TableName.valueOf(Bytes.toBytes(tableName)))
var resultScanner: ResultScanner = table.getScanner(new Scan());
var count: Long = 0;
while (resultScanner.next() != null) {
count = count + 1;
}
val endTime = System.currentTimeMillis();
val timeDiff = endTime - startTime
println(s"$tableName - Time taken $timeDiff")
count
}