stoty commented on code in PR #6361: URL: https://github.com/apache/hbase/pull/6361#discussion_r1822256059
########## hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestPrefixFilter.java: ########## @@ -82,13 +87,182 @@ private void prefixRowTests(Filter filter, boolean lastFilterAllRemaining) throw } String yahooSite = "com.yahoo.www"; byte[] yahooSiteBytes = Bytes.toBytes(yahooSite); - assertTrue("Failed with character " + yahooSite, - filter.filterRowKey(KeyValueUtil.createFirstOnRow(yahooSiteBytes))); - assertEquals(filter.filterAllRemaining(), lastFilterAllRemaining); + KeyValue yahooSiteCell = KeyValueUtil.createFirstOnRow(yahooSiteBytes); + assertFalse("Failed with character " + yahooSite, filter.filterRowKey(yahooSiteCell)); + assertEquals(Filter.ReturnCode.SEEK_NEXT_USING_HINT, filter.filterCell(yahooSiteCell)); + assertEquals(lastFilterAllRemaining, filter.filterAllRemaining()); } private byte[] createRow(final char c) { return Bytes.toBytes(HOST_PREFIX + Character.toString(c)); } + @Test + public void shouldProvideHintWhenKeyBefore() { + byte[] prefix = Bytes.toBytes("gg"); + PrefixFilter filter = new PrefixFilter(prefix); + + KeyValue cell = KeyValueUtil.createFirstOnRow(Bytes.toBytes("aa")); + + // Should include this row so that filterCell() will be invoked. + assertFalse(filter.filterRowKey(cell)); + assertEquals(Filter.ReturnCode.SEEK_NEXT_USING_HINT, filter.filterCell(cell)); + Cell actualCellHint = filter.getNextCellHint(cell); + assertNotNull(actualCellHint); + Cell expectedCellHint = KeyValueUtil.createFirstOnRow(prefix); + assertEquals(expectedCellHint, actualCellHint); + assertFalse(filter.filterAllRemaining()); + assertTrue(filter.filterRow()); + } + + @Test + public void shouldProvideHintWhenKeyBeforeAndShorter() { + byte[] prefix = Bytes.toBytes("gggg"); + PrefixFilter filter = new PrefixFilter(prefix); + + KeyValue cell = KeyValueUtil.createFirstOnRow(Bytes.toBytes("aa")); + + // Should include this row so that filterCell() will be invoked. + assertFalse(filter.filterRowKey(cell)); + assertEquals(Filter.ReturnCode.SEEK_NEXT_USING_HINT, filter.filterCell(cell)); + Cell actualCellHint = filter.getNextCellHint(cell); + assertNotNull(actualCellHint); + Cell expectedCellHint = KeyValueUtil.createFirstOnRow(prefix); + assertEquals(expectedCellHint, actualCellHint); + assertFalse(filter.filterAllRemaining()); + assertTrue(filter.filterRow()); + } + + @Test + public void shouldIncludeWhenKeyMatches() { + PrefixFilter filter = new PrefixFilter(Bytes.toBytes("gg")); + + KeyValue matchingCell = KeyValueUtil.createFirstOnRow(Bytes.toBytes("gg")); + + assertFalse(filter.filterRowKey(matchingCell)); + assertEquals(Filter.ReturnCode.INCLUDE, filter.filterCell(matchingCell)); + assertFalse(filter.filterAllRemaining()); + assertFalse(filter.filterRow()); + } + + @Test + public void shouldReturnNextRowWhenKeyAfter() { + PrefixFilter filter = new PrefixFilter(Bytes.toBytes("gg")); + + KeyValue afterCell = KeyValueUtil.createFirstOnRow(Bytes.toBytes("pp")); + + assertTrue(filter.filterRowKey(afterCell)); + assertEquals(Filter.ReturnCode.NEXT_ROW, filter.filterCell(afterCell)); + assertTrue(filter.filterAllRemaining()); Review Comment: This API is so awkward... -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@hbase.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org