一、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而拿出某些属性的值。