使用SingleColumnValueFilter时,BigTable模拟器似乎无法正确过滤,如下例所示。但是,此相同的代码在BigTable的生产版本中也可以正常工作。
错误的结果输出:“第1行第2行第3行第4行”
应该打印:“ row3”
byte[] cf = "cf".getBytes();
byte[] cq = "cq".getBytes();
Connection conn = BigtableConfiguration.connect("fake-project", "fake-instance");
Admin admin = conn.getAdmin();
TableName testTableName = TableName.valueOf("testTable");
HTableDescriptor descriptor = new HTableDescriptor(testTableName);
descriptor.addFamily(new HColumnDescriptor(cf));
admin.createTable(descriptor);
byte[] val = { 0x1a };
byte[] val2 = { 0x11 };
byte[] val3 = "a".getBytes();
byte[] val4 = "b".getBytes();
Table table = conn.getTable(testTableName);
table.put(new Put("row1".getBytes()).addColumn(cf, cq, val));
table.put(new Put("row2".getBytes()).addColumn(cf, cq, val2));
table.put(new Put("row3".getBytes()).addColumn(cf, cq, val3));
table.put(new Put("row4".getBytes()).addColumn(cf, cq, val4));
Scan scan = new Scan().setFilter(new SingleColumnValueFilter(cf, cq, CompareOp.EQUAL, val3));
// THIS wrongly prints all rows in the table rather than just row3
for(Result r: table.getScanner(scan)) {
String row = new String(r.getRow());
System.out.print(row);
}