Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}