我在HBase中尝试了一个非常简单的例子。以下是我创建表格和放置数据的方法:
create 'newdb3','data'
put 'newdb3','row1','data:name','Thexxx Beatles'
put 'newdb3','row2','data:name','The Beatles'
put 'newdb3','row3','data:name','Beatles'
put 'newdb3','row4','data:name','Thexxx'
put 'newdb3','row1','data:duration',400
put 'newdb3','row2','data:duration',300
put 'newdb3','row3','data:duration',200
put 'newdb3','row4','data:duration',100
scan 'newdb3', {COLUMNS => 'data:name', FILTER => "SingleColumnValueFilter('data','duration', > ,'binaryprefix:200')"}
但结果总是全部4列。我尝试使用或不使用字符串编号,并使用十六进制值。我也试过二进制'而不是' binaryprefix'。如何在hbase中存储和比较整数?
答案 0 :(得分:0)
这会产生预期的输出吗?
import org.apache.hadoop.hbase.filter.CompareFilter
import org.apache.hadoop.hbase.filter.SingleColumnValueFilter
import org.apache.hadoop.hbase.filter.SubstringComparator
import org.apache.hadoop.hbase.util.Bytes
scan 'newdb3', { FILTER => SingleColumnValueFilter.new(Bytes.toBytes('data'), \
Bytes.toBytes('duration'),
CompareFilter::CompareOp.valueOf('GREATER'), \
BinaryComparator.new(Bytes.toBytes('200'))) }
注意:这将进行二进制比较,对于数字,仅当它们是0填充时才会起作用