我在HBase表中有20行,行键是长格式的,从1开始到20行。我想从这里查询行键以1开头的记录。我尝试使用PrefixFilter和BinaryPrefixComparator,但是只有在行键在字符串fromat中时,行键才能正常工作。如果是在long中,则查询将返回所有记录。我怎样才能做到这一点?
滤波表达式
Scan scan=new Scan();
Filter rowFilter=new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(Bytes.toBytes("1")));
//Filter rowFilter=new RowFilter(CompareOp.NOT_EQUAL, new BinaryPrefixComparator(Bytes.toBytes("1")));
scan.setFilter(rowFilter);
ResultScanner resultscanner=htable.getScanner(scan);发布于 2012-11-24 22:08:08
如果行键是long,则必须在查询中将它们引用为long,而不是字符串。
不要使用Bytes.toBytes("1"),而是使用Bytes.toBytes(1L)。
您可以设置要扫描的范围:
scan.setStartRow(Bytes.toBytes(1L));
scan.setStopRow(Bytes.toBytes(21L)); //since stopRow is exclusivehttps://stackoverflow.com/questions/13524657
复制相似问题