Reputation: 748
Hi I am new to hbase and in phase of learning it. I created a table using hbase shell and put values into that table uing shell. But now when i want to get thos values using some filter like this:
HTable table = new HTable(conf, "test");
List<Filter> filters = new ArrayList<Filter>();
SingleColumnValueFilter colValFilter = new SingleColumnValueFilter(Bytes.toBytes("col"), Bytes.toBytes("age")
, CompareFilter.CompareOp.GREATER, new BinaryComparator(Bytes.toBytes("118")));
colValFilter.setFilterIfMissing(false);
filters.add(colValFilter);
FilterList fl = new FilterList( FilterList.Operator.MUST_PASS_ALL, filters);
Scan s = new Scan();
s.setFilter(fl);
ResultScanner ss = table.getScanner(s);
JSONArray arr=new JSONArray();
for(Result r:ss){
JSONObject obj=new JSONObject();
for(KeyValue kv : r.raw()){
String column=new String(kv.getQualifier());
String value=new String(kv.getValue());
obj.accumulate(column, value);
}
arr.put(obj);
}
Now when i run this program i get different results. Like i get users whose age are less than 118 but still they get displayed.
My Question:
Why SingleColumnValueFilter do this? Any other way to solve this problem?
Upvotes: 0
Views: 1210
Reputation: 441
If you put data from hbase shell like put 'test','r1','col:age','19'
it will be stored as String-bytes so when you compare it with > on BinaryComparator, it will compare lexicographicly and return any string that starts with character > than '1'
you should put it put 'test','r1','col:age','\x13'
(hexadecimal value) if you want to put it as integer-bytes
Upvotes: 1