/** * 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()); }
@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 familyRegexTest() { RowFilter actualFilter = FILTERS.family().regex("^hi").toProto(); RowFilter expectedFilter = RowFilter.newBuilder().setFamilyNameRegexFilter("^hi").build(); assertThat(actualFilter).isEqualTo(expectedFilter); }
/** * 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 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()); }
@Test public void chainTest() { RowFilter actualProto = FILTERS .chain() .filter(FILTERS.key().regex(".*")) .filter(FILTERS.key().sample(0.5)) .filter(FILTERS.chain().filter(FILTERS.family().regex("hi$")).filter(FILTERS.pass())) .toProto(); RowFilter expectedFilter = RowFilter.newBuilder() .setChain( Chain.newBuilder() .addFilters( RowFilter.newBuilder().setRowKeyRegexFilter(ByteString.copyFromUtf8(".*"))) .addFilters(RowFilter.newBuilder().setRowSampleFilter(0.5)) .addFilters( RowFilter.newBuilder() .setChain( Chain.newBuilder() .addFilters( RowFilter.newBuilder().setFamilyNameRegexFilter("hi$")) .addFilters(RowFilter.newBuilder().setPassAllFilter(true))))) .build(); assertThat(actualProto).isEqualTo(expectedFilter); }
@Test public void interleaveTest() { RowFilter actualProto = FILTERS .interleave() .filter(FILTERS.key().regex(".*")) .filter(FILTERS.key().sample(0.5)) .filter( FILTERS.interleave().filter(FILTERS.family().regex("hi$")).filter(FILTERS.pass())) .toProto(); RowFilter expectedFilter = RowFilter.newBuilder() .setInterleave( Interleave.newBuilder() .addFilters( RowFilter.newBuilder().setRowKeyRegexFilter(ByteString.copyFromUtf8(".*"))) .addFilters(RowFilter.newBuilder().setRowSampleFilter(0.5)) .addFilters( RowFilter.newBuilder() .setInterleave( Interleave.newBuilder() .addFilters( RowFilter.newBuilder().setFamilyNameRegexFilter("hi$")) .addFilters( RowFilter.newBuilder().setPassAllFilter(true).build())))) .build(); assertThat(actualProto).isEqualTo(expectedFilter); }