Hbase 简单操作

一、Put、Get几个特殊情况

 首先Put。
    情况一:String x = null;
    put.add(Bytes.toBytes("info"), Bytes.toBytes("name"), System.currentTimeMillis(), Bytes.toBytes(x));
    这个代码会报错,因为Bytes.toBytes(x)会抛出异常。
 
    情况二:x = "";
    put.add(Bytes.toBytes("info"), Bytes.toBytes("name"), System.currentTimeMillis(), Bytes.toBytes(x));
    这样的数值在hbase中就是value=   后面没有数值。
    
    情况三:x=0;
    Get的时候,value不是null,且value.length>0
    
其次Get。
    针对情况一、直接就入不到hbase,不讨论。
    针对情况二、使用Get取出数据的时候,如下代码,
    byte[] value = result.getValue(Bytes.toBytes("info"), Bytes.toBytes("name"));
    value一定不是null,但是value.length会是0。
    如果说是根据如此方法取出一个根本么有的字段,那么value一定是null。

最后Result。
    //如果想取name字段,但是在hbase中某个rowkey下没有该字段,那么result一定是emtpy,什么都拿不到包括rowkey。    
    get.addColumn(Bytes.toBytes("info"), Bytes.toBytes("name"));        
    byte[] value = result.getValue(Bytes.toBytes("info"), Bytes.toBytes("name"));
    最终的数值一定是什么也得不到,不要妄想拿result而拿出某些属性的值。

        



转载于:https://my.oschina.net/momisabuilder/blog/540222

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值