/** * Matches only cells from columns whose qualifiers satisfy the given <a * href="https://github.com/google/re2/wiki/Syntax">RE2 regex</a>. Note that, since column * qualifiers can contain arbitrary bytes, the `\C` escape sequence must be used if a true * wildcard is desired. The `.` character will not match the new line character `\n`, which may * be present in a binary qualifier. */ public Filter regex(@Nonnull ByteString regex) { Preconditions.checkNotNull(regex); return new SimpleFilter(RowFilter.newBuilder().setColumnQualifierRegexFilter(regex).build()); }
/** * Matches only cells from columns whose families satisfy the given <a * href="https://github.com/google/re2/wiki/Syntax">RE2 regex</a>. For technical reasons, the * regex must not contain the `:` character, even if it is not being used as a literal. Note * that, since column families cannot contain the new line character `\n`, it is sufficient to * use `.` as a full wildcard when matching column family names. */ public Filter regex(@Nonnull String regex) { Preconditions.checkNotNull(regex); return new SimpleFilter(RowFilter.newBuilder().setFamilyNameRegexFilter(regex).build()); }
/** * Matches only cells with values that satisfy the given <a * href="https://github.com/google/re2/wiki/Syntax">RE2 regex</a>. Note that, since cell values * can contain arbitrary bytes, the `\C` escape sequence must be used if a true wildcard is * desired. The `.` character will not match the new line character `\n`, which may be present * in a binary value. */ public Filter regex(@Nonnull ByteString regex) { Preconditions.checkNotNull(regex); return new SimpleFilter(RowFilter.newBuilder().setValueRegexFilter(regex).build()); }
/** * Matches only the first N cells of each row. If duplicate cells are present, as is possible * when using an Interleave, each copy of the cell is counted separately. */ public Filter cellsPerRow(int count) { return new SimpleFilter(RowFilter.newBuilder().setCellsPerRowLimitFilter(count).build()); }
/** * Skips the first N cells of each row, matching all subsequent cells. If duplicate cells are * present, as is possible when using an {@link InterleaveFilter}, each copy of the cell is * counted separately. */ public Filter cellsPerRow(int count) { return new SimpleFilter(RowFilter.newBuilder().setCellsPerRowOffsetFilter(count).build()); } }
/** * Matches only cells from rows whose keys satisfy the given <a * href="https://github.com/google/re2/wiki/Syntax">RE2 regex</a>. In other words, passes * through the entire row when the key matches, and otherwise produces an empty row. Note that, * since row keys can contain arbitrary bytes, the `\C` escape sequence must be used if a true * wildcard is desired. The `.` character will not match the new line character `\n`, which may * be present in a binary key. */ public Filter regex(@Nonnull ByteString regex) { Preconditions.checkNotNull(regex); return new SimpleFilter(RowFilter.newBuilder().setRowKeyRegexFilter(regex).build()); }
@Test public void blockTest() { RowFilter actualFilter = FILTERS.block().toProto(); RowFilter expectedFilter = RowFilter.newBuilder().setBlockAllFilter(true).build(); assertThat(actualFilter).isEqualTo(expectedFilter); }
@Test public void passTest() { RowFilter actualFilter = FILTERS.pass().toProto(); RowFilter expectedFilter = RowFilter.newBuilder().setPassAllFilter(true).build(); assertThat(actualFilter).isEqualTo(expectedFilter); }
@Test public void valueStripTest() { RowFilter actualFilter = FILTERS.value().strip().toProto(); RowFilter expectedFilter = RowFilter.newBuilder().setStripValueTransformer(true).build(); assertThat(actualFilter).isEqualTo(expectedFilter); }
@Test public void qualifierExactStringMatchTest() { RowFilter actualFilter = FILTERS.qualifier().exactMatch("^hi").toProto(); RowFilter expectedFilter = RowFilter.newBuilder() .setColumnQualifierRegexFilter(ByteString.copyFromUtf8("\\^hi")) .build(); assertThat(actualFilter).isEqualTo(expectedFilter); }
@Test public void keyExactMatchStringTest() { RowFilter actualFilter = FILTERS.key().exactMatch(".*").toProto(); RowFilter expectedFilter = RowFilter.newBuilder().setRowKeyRegexFilter(ByteString.copyFromUtf8("\\.\\*")).build(); assertThat(actualFilter).isEqualTo(expectedFilter); }
/** * Matches only the most recent `count` cells within each column. For example, if count=2, this * filter would match column `foo:bar` at timestamps 10 and 9 skip all earlier cells in * `foo:bar`, and then begin matching again in column `foo:bar2`. If duplicate cells are * present, as is possible when using an {@link InterleaveFilter}, each copy of the cell is * counted separately. */ public Filter cellsPerColumn(int count) { return new SimpleFilter(RowFilter.newBuilder().setCellsPerColumnLimitFilter(count).build()); } }
@Test public void conditionTest() { ConditionalRowMutation mutation = ConditionalRowMutation.create(TABLE_ID, TEST_KEY) .condition(Filters.FILTERS.key().regex("a.*")) .then(Mutation.create().deleteRow()); CheckAndMutateRowRequest actualProto = mutation.toProto(REQUEST_CONTEXT); assertThat(actualProto.getPredicateFilter()) .isEqualTo( RowFilter.newBuilder().setRowKeyRegexFilter(ByteString.copyFromUtf8("a.*")).build()); }
@Test public void valueRangeClosedOpen() { RowFilter actualFilter = FILTERS.value().range().startClosed("begin").endOpen("end").toProto(); RowFilter expectedFilter = RowFilter.newBuilder() .setValueRangeFilter( ValueRange.newBuilder() .setStartValueClosed(ByteString.copyFromUtf8("begin")) .setEndValueOpen(ByteString.copyFromUtf8("end"))) .build(); assertThat(actualFilter).isEqualTo(expectedFilter); }
@Test public void valueExactStringMatch() { RowFilter actualFilter = FILTERS.value().exactMatch("some[0-9]regex").toProto(); RowFilter expectedFilter = RowFilter.newBuilder() .setValueRegexFilter(ByteString.copyFromUtf8("some\\[0\\-9\\]regex")) .build(); assertThat(actualFilter).isEqualTo(expectedFilter); }
@Test public void valueExactMatch() { RowFilter actualFilter = FILTERS.value().exactMatch(ByteString.copyFromUtf8("some[0-9]regex")).toProto(); RowFilter expectedFilter = RowFilter.newBuilder() .setValueRegexFilter(ByteString.copyFromUtf8("some\\[0\\-9\\]regex")) .build(); assertThat(actualFilter).isEqualTo(expectedFilter); }
@Test public void qualifierExactMatchTest() { RowFilter actualFilter = FILTERS.qualifier().exactMatch(ByteString.copyFromUtf8("^hi")).toProto(); RowFilter expectedFilter = RowFilter.newBuilder() .setColumnQualifierRegexFilter(ByteString.copyFromUtf8("\\^hi")) .build(); assertThat(actualFilter).isEqualTo(expectedFilter); }
@Test public void fromProtoTest() { RowFilter inner = RowFilter.newBuilder().setRowSampleFilter(0.5).build(); RowFilter actualFilter = FILTERS.fromProto(inner).toProto(); assertThat(actualFilter).isEqualTo(inner); }
@Test public void familyExactMatchTest() { RowFilter actualFilter = FILTERS.family().exactMatch("^hi").toProto(); RowFilter expectedFilter = RowFilter.newBuilder().setFamilyNameRegexFilter("\\^hi").build(); assertThat(actualFilter).isEqualTo(expectedFilter); }
@Test public void keyRegexStringTest() { RowFilter actualFilter = FILTERS.key().regex(".*").toProto(); RowFilter expectedFilter = RowFilter.newBuilder().setRowKeyRegexFilter(ByteString.copyFromUtf8(".*")).build(); assertThat(actualFilter).isEqualTo(expectedFilter); }