@@ -0,0 +1,2014 @@
+package hbase.misc.scan;%0A%0Aimport org.apache.hadoop.conf.Configuration;%0Aimport org.apache.hadoop.hbase.HBaseConfiguration;%0Aimport org.apache.hadoop.hbase.TableName;%0Aimport org.apache.hadoop.hbase.client.*;%0Aimport org.apache.hadoop.hbase.client.metrics.ScanMetrics;%0Aimport org.apache.hadoop.hbase.filter.Filter;%0Aimport org.apache.hadoop.hbase.filter.KeyOnlyFilter;%0A%0Aimport java.io.IOException;%0Aimport java.text.DateFormat;%0Aimport java.text.ParseException;%0Aimport java.text.SimpleDateFormat;%0A%0A/**%0A * Created by Fasten on 2016/6/12.%0A *%0A * Temporary get row count between time range%0A * The better way is create an endpoint in server-side.%0A *%0A * java -Djava.library.path=$HADOOP_HOME/lib/native ScanTimeRange %3CtableName%3E %3CstartDay%3E %3CendDay%3E%0A */%0Apublic class TimeRangeCount %7B%0A    public static void main(String%5B%5D args) %7B%0A%0A        DateFormat df = new SimpleDateFormat(%22yyyyMMdd%22);%0A%0A        Configuration conf = HBaseConfiguration.create();%0A        try (Connection conn = ConnectionFactory.createConnection(conf);%0A             Table table = conn.getTable(TableName.valueOf(args%5B0%5D))) %7B%0A            Scan scan = new Scan();%0A            scan.setScanMetricsEnabled(true);%0A            scan.setTimeRange(df.parse(args%5B1%5D).getTime(), df.parse(args%5B2%5D).getTime());%0A            Filter filter = new KeyOnlyFilter();%0A            scan.setFilter(filter);%0A            ResultScanner resultScanner = table.getScanner(scan);%0A            int count = 0;%0A            for (Result result : resultScanner) %7B%0A                count++;%0A            %7D%0A%0A            System.out.println(%0A                    String.format(%22Row count of table: %25s between %25s and %25s is %25d%22,%0A                            args%5B0%5D, args%5B1%5D, args%5B2%5D, count));%0A%0A            resultScanner.close();%0A%0A            ScanMetrics metrics = scan.getScanMetrics();%0A            System.out.println(%22Maps: %22 + metrics.getMetricsMap());%0A%0A        %7D catch (IOException e) %7B%0A            e.printStackTrace();%0A        %7D catch (ParseException e) %7B%0A            e.printStackTrace();%0A        %7D%0A    %7D%0A%7D%0A

check in one simple hbase program