Reputation: 637
It seems that the Bigtable emulator is not filtering properly when using the SingleColumnValueFilter
as shown in the example below; however, this same code works correctly in the production version of Bigtable.
Incorrect Result output: "row1 row2 row3 row4"
Should have printed: "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);
}
Upvotes: 1
Views: 1329
Reputation: 92
The code in the question is correct.
This was a bug in an older emulator version (Emulator: gcloud beta 2019.02.22).
This bug has since been fixed (see original report here).
Upvotes: 1