You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hbase.apache.org by Harry Chen <ha...@gmail.com> on 2016/03/20 02:44:37 UTC
Java Thrift Question: how to filter Integer values?
My program talks to a remote HBase via Thrift (v1). I want to scan a table
with "SingleColumnValueFilter".
http://hbase.apache.org/0.94/book/thrift.html
*Question: *
When creating a TScan object, what's the correct syntax to use for
"filterString" if I want to match an Integer column value?
*Failed Test:*
hbase(main):024:0> scan 'apitest'
ROW
COLUMN+CELL
qq:k1 column=cf1:m_boolean,
timestamp=1458436830752,
value=\xFF
qq:k1 column=cf1:m_double,
timestamp=1458436830752,
value=@\x08\x00\x00\x00\x00\x00\x00
qq:k1 column=cf1:m_int,
timestamp=1458436830752,
value=\x00\x00\x00\x01
qq:k1 column=cf1:m_long,
timestamp=1458436830752,
value=\x00\x00\x00\x00\x00\x00\x00\x02
qq:k1 column=cf1:m_string,
timestamp=1458436830752, value=4
My program can match a String column value (i.e., "cf1:m_string") with the
following implementation:
byte[] sf = Bytes.toBytes("(SingleColumnValueFilter 'cf1', 'm_string', =
, 'binary:4')");
ByteBuffer sf_b = ByteBuffer.wrap(sf);
TScan tscan = new TScan();
// ... other tscan init impl omitted
tscan.setFilterString(sf_b);
However, none of the following works when I want to match an Integer value
(e.g., "cf1:m_int", which store java.lang.Integer = 1).
Option 1:
String sf = "(SingleColumnValueFilter 'cf1', 'm_int, = , 'binary:1')"
Option 2:
String sf = "(SingleColumnValueFilter 'cf1', 'm_int', = , 1)"
Option 3:
String x = Bytes.toStringFromBinary(Bytes.toBytes(1))
String sf = "(SingleColumnValueFilter 'cf1', 'm_int', = , " + x + ")"
// filter string: (SingleColumnValueFilter 'cf1', 'm_int', = ,
\x00\x00\x00\x01)
Option 4:
String x = "'binary:" + Bytes.toStringFromBinary(Bytes.toBytes(1)) + "'"
String sf = "(SingleColumnValueFilter 'cf1', 'm_int', = , " + x + ")"
// filter string: (SingleColumnValueFilter 'cf1', 'm_int', = ,
'binary:\x00\x00\x00\x01')
I thought Option 4 should work, but it didn't, since it works in HBase
Shell.
hbase(main):026:0> scan 'apitest', {FILTER => "SingleColumnValueFilter
('cf1','m_int',=,'binary:\x00\x00\x00\x01',true,false)"}
ROW
COLUMN+CELL
qq:k1 column=cf1:m_boolean,
timestamp=1458437678117,
value=\xFF
qq:k1 column=cf1:m_double,
timestamp=1458437678117,
value=@\x08\x00\x00\x00\x00\x00\x00
qq:k1 column=cf1:m_int,
timestamp=1458437678117,
value=\x00\x00\x00\x01
qq:k1 column=cf1:m_long,
timestamp=1458437678117,
value=\x00\x00\x00\x00\x00\x00\x00\x02
qq:k1 column=cf1:m_string,
timestamp=1458437678117,
value=4
1 row(s) in 0.0190 seconds
Thoughts?