1.第一种方法(适用于表数据量不太大的情况)最直接的方式是在hbase shell中执行count的命令可以统计行数。 hbase> count ‘t1′ hbase> count ‘t1′, INTERVAL => 100000 hbase> count ‘t1′, CACHE => 1000 hbase> count ‘t1′, INTERVAL => 10, CACHE => 1000 其中,INTERVAL为统计的行数间隔,默认为1000,CACHE为统计的数据缓存。这种方式效率很低,如果表行数很大的话不建议采用这种方式2.第二种方法 public class HbaseDemoTest { // public static Admin admin = null; // public static Connection conn = null; // public static Configuration getConfiguration() { // Configuration conf = HBaseConfiguration.create(); // conf.set("hbase.rootdir", "hdfs://192.168.8.40:9000/hbase"); // conf.set("hbase.zookeeper.quorum", "h40:2181,h41:2181,h42:2181"); // return conf; // } public static void main(String[] args) throws Exception { //表名 long count = rowCount("TOPIC_TABLE");//括号里写入要查询的表名 } public static long rowCount(String tableName) { Connection connection = HBaseHelper.getConnection(); long rowCount = 0; try { HTable table = new HTable(TableName.valueOf(tableName),connection); Scan scan = new Scan(); scan.setFilter(new FirstKeyOnlyFilter()); ResultScanner resultScanner = table.getScanner(scan); for (Result result : resultScanner) { rowCount += result.size(); } System.out.println("rowCount-->"+rowCount); } catch (IOException e) { } return rowCount; } }
注意:因为关于连接hbase的配置我自己写了一个帮助类,hbasehelp 里面了,这个自己跟据自己的情况写就可以了
参考文献:感谢博主的知识分享:
https://blog.youkuaiyun.com/u013709332/article/details/52296748/
https://blog.youkuaiyun.com/m0_37739193/article/details/75286496
本文介绍了如何在HBase中查询表的行数,包括使用HBaseHelp辅助类进行操作,参考了相关博客资源。
1万+

被折叠的 条评论
为什么被折叠?



