协处理器统计行数

最初使用下面代码

import org.apache.hadoop.conf.Configuration;  
import org.apache.hadoop.hbase.HBaseConfiguration;  
import org.apache.hadoop.hbase.TableName;  
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.coprocessor.ColumnInterpreter;  
import org.apache.hadoop.hbase.util.Bytes;  
  
public class MyAggregationClient {  
  
    public static void main(String[] args) throws Throwable {  
    Configuration customConf = new Configuration();  
    customConf.set("hbase.zookeeper.quorum", "h40:2181,h40:2181,h40:2181");//最初是在这把zookeeperserver 及端口号写死
    //提高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(Bytes.toBytes("grade"));
//    scan.addColumn(Bytes.toBytes("course"), Bytes.toBytes("art"));
    /**
    private static final byte[] TABLE_NAME = Bytes.toBytes("scores");  
    long rowCount = aggregationClient.rowCount(TABLE_NAME, null, scan);
    这两行代码报错,显示TABLE_NAME必须是个TableName类型的,但也不知道这个TableName是个什么类型,该咋么表示,网上有这么写的,也不知道他们是咋么执行成功的,真厉害。。。下面的这行是正解
     * */
    long rowCount = aggregationClient.rowCount(TableName.valueOf("scores"), new LongColumnInterpreter(), scan); //这里表是写死了 ,操作中直接传入参数
    System.out.println("row count is " + rowCount);
    }
}

一直报错:

Exception in thread “main” org.apache.hadoop.hbase.client.RetriesExhaustedException:Can't get the locations

后来在resources目录下导入:

core-site.xml

hbase-site.xml

hdfs-site.xml

customConf set方法便可省略后解决。

具体代码见另外一篇博客

posted @ 2020-01-07 10:00  勤奋的园  阅读(220)  评论(0编辑  收藏  举报