• 协处理器统计行数


    最初使用下面代码

    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方法便可省略后解决。

    具体代码见另外一篇博客

  • 相关阅读:
    30行左右代码实现一个类似httprunner的接口框架
    Python中一些高效的数据操作
    使用jsonpath解析多层嵌套的json响应信息
    操作系统的启动流程
    I/O延迟
    存储器
    多线程和多核芯片
    CPU详解(内核态和用户态)
    操作系统
    计算机组成
  • 原文地址:https://www.cnblogs.com/qfdy123/p/12159913.html
Copyright © 2020-2023  润新知