做了一个统计hbase总数的的例子
但是好像 报错, 也不知道是什么问题 ,请大神看看
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.coprocessor.AggregationClient;
import org.apache.hadoop.hbase.client.coprocessor.LongColumnInterpreter;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Test;
private static void myAggregationClient(Configuration conf) throws Throwable {
final byte[] CF = Bytes.toBytes("base_info");
System.setProperty("hadoop.home.dir", "E:/hadoop");
Configuration customConf = new Configuration();
customConf.set("hbase.zookeeper.quorum", "hadoop01:2181,hadoop02:2181,hadoop03:2181");
// 提高RPC通信时长
customConf.setLong("hbase.rpc.timeout", 600000);
// 设置Scan缓存
customConf.setLong("hbase.client.scanner.caching", 1000);
Configuration configuration = HBaseConfiguration.create(customConf);
AggregationClient aggregationClient = new AggregationClient(configuration);
Scan scan = new Scan();
// 指定扫描列族,唯一值
scan.addFamily(CF);
long rowCount = aggregationClient.rowCount(TableName.valueOf(Bytes.toBytes("ruiftest")), null, scan);
System.out.println("row count is " + rowCount);
}
错误信息是
Exception in thread "main" java.lang.NullPointerException
at org.apache.hadoop.hbase.client.coprocessor.AggregationClient.validateArgAndGetPB(AggregationClient.java:803)
at org.apache.hadoop.hbase.client.coprocessor.AggregationClient.rowCount(AggregationClient.java:305)
at org.apache.hadoop.hbase.client.coprocessor.AggregationClient.rowCount(AggregationClient.java:285)
at cn.itcast.hbase.HbaseTest2.myAggregationClient(HbaseTest2.java:102)
at cn.itcast.hbase.HbaseTest2.main(HbaseTest2.java:56) |
|