ITPub博客

首页 > 大数据 > Hadoop > Hbase计数器异常Attempted to increment field that isn

Hbase计数器异常Attempted to increment field that isn

原创 Hadoop 作者:破棉袄 时间:2015-06-18 11:17:01 0 删除 编辑

该异常为要自增的字段不为数字类型,所以调用incrementColumnValue方法会报错

首次put时指定为long字段:
put.add(Bytes.toBytes("cf"),Bytes.toBytes("count"), Bytes.toBytes(1l));     //1后边有个l

再次自增:
table.incrementColumnValue("rowkey1".getBytes(),"cf".getBytes(),"count".getBytes(),1);


查询:
      byte[] b;
       long temp;  
       long res;  

       for (Result r : rs) {  
           if(new String(r.getRow()).equals("rowkey1")){
           for (KeyValue keyValue : r.raw()) {
           
             b =keyValue.getValue();
             temp = 0;  
             res = 0;  
             for (int i=0;i<8;i++) {  
                 res <<= 8;  
                 temp = b[i] & 0xff;  
                 res |= temp;  
             }  
             System.out.println(res);
           }  
         }
       }  

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29754888/viewspace-1703713/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-07-16

  • 博文量
    180
  • 访问量
    1158162