Skip to content

Commit

Permalink
fix: updated assertions and scan for firstKeyOnlyFilter test (#2483)
Browse files Browse the repository at this point in the history
* chore(test): updated assertions for firstKeyOnlyFilter

This PR updates integration tests assertions to verify firstKeyOnlyFilter.

* chore: reverting back FirstKeyOnlyFilterAdapter to return cell with value

This commit partially reverts changes from #1996 to have consistent behavior with HBase FirstKeyOnlyFilter.

* to trigger failed CI Job
  • Loading branch information
rahulKQL authored Apr 17, 2020
1 parent 2915bfd commit a2cbe7a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1363,22 +1363,38 @@ public void testValueFilter() throws IOException {
@Test
public void testFirstKeyFilter() throws IOException {
// Initialize
int rowCount = 5;
int numCols = 5;
String columnValue = "includeThisValue";
String rowPrefix = dataHelper.randomString("testFirstKeyValue-");
byte[] columnValue = Bytes.toBytes("includeThisValue");
Table table = getDefaultTable();
byte[] rowKey = dataHelper.randomData("testRow-");
Put put = new Put(rowKey);
for (int i = 0; i < numCols; ++i) {
put.addColumn(COLUMN_FAMILY, dataHelper.randomData(""), Bytes.toBytes(columnValue));

List<Put> puts = new ArrayList<>(rowCount);
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
Put put = new Put(Bytes.toBytes(rowPrefix + rowIndex));
for (int i = 0; i < numCols; ++i) {
put.addColumn(COLUMN_FAMILY, dataHelper.randomData(""), columnValue);
}
puts.add(put);
}
table.put(put);
table.put(puts);

// Filter for results
Filter filter = new FirstKeyOnlyFilter();

Get get = new Get(rowKey).setFilter(filter);
Result result = table.get(get);
Assert.assertEquals("Should only return 1 keyvalue", 1, result.size());
Scan scan = new Scan().setRowPrefixFilter(Bytes.toBytes(rowPrefix)).setFilter(filter);
try (ResultScanner resultScanner = table.getScanner(scan)) {
int rowIndex = 0;
for (Result result : resultScanner) {
Assert.assertArrayEquals(Bytes.toBytes(rowPrefix + rowIndex), result.getRow());
Assert.assertEquals("Should only return 1 keyvalue", 1, result.size());
Assert.assertTrue(
"Should contains column value",
CellUtil.matchingValue(result.rawCells()[0], columnValue));

rowIndex++;
}
}

table.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
@InternalApi("For internal usage only")
public class FirstKeyOnlyFilterAdapter extends TypedFilterAdapterBase<FirstKeyOnlyFilter> {

private static Filters.Filter LIMIT_ONE =
FILTERS.chain().filter(FILTERS.limit().cellsPerRow(1)).filter(FILTERS.value().strip());
private static Filters.Filter LIMIT_ONE = FILTERS.limit().cellsPerRow(1);

/** {@inheritDoc} */
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ public class TestFirstKeyOnlyFilterAdapter {
public void onlyTheFirstKeyFromEachRowIsEmitted() throws IOException {
Filters.Filter adaptedFilter =
adapter.adapt(new FilterAdapterContext(new Scan(), null), new FirstKeyOnlyFilter());
Assert.assertEquals(
FILTERS
.chain()
.filter(FILTERS.limit().cellsPerRow(1))
.filter(FILTERS.value().strip())
.toProto(),
adaptedFilter.toProto());
Assert.assertEquals(FILTERS.limit().cellsPerRow(1).toProto(), adaptedFilter.toProto());
}
}

0 comments on commit a2cbe7a

Please sign in to comment.