.setFamilyNameRegexFilterBytes(ByteStringer.wrap(columnFamilyBytes)) .build(); if (fields != null && fields.size() > 0) { Builder filterChain = RowFilter.Chain.newBuilder(); filterChain.addFilters(filter); filterChain.addFilters(RowFilter.newBuilder() .setCellsPerColumnLimitFilter(1) .build()); int count = 0; .setColumnQualifierRegexFilter( ByteStringer.wrap(regex.toString().getBytes()))).build(); filter = RowFilter.newBuilder().setChain(filterChain.build()).build();
@Test public void testFromProto() { ReadRowsRequest request = ReadRowsRequest.newBuilder() .setTableName(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID)) .setAppProfileId(APP_PROFILE_ID) .setFilter(RowFilter.newBuilder().setRowKeyRegexFilter(ByteString.copyFromUtf8(".*"))) .setRows( RowSet.newBuilder() .addRowKeys(ByteString.copyFromUtf8("row-key")) .addRowRanges( RowRange.newBuilder() .setStartKeyClosed(ByteString.copyFromUtf8("j")) .setEndKeyClosed(ByteString.copyFromUtf8("z")))) .build(); Query query = Query.fromProto(request); assertThat(query.toProto(requestContext)).isEqualTo(request); }
/** * Matches all cells from a row with `probability`, and matches no cells from the row with * probability 1-`probability`. */ public Filter sample(double probability) { Preconditions.checkArgument(0 <= probability, "Probability must be positive"); Preconditions.checkArgument(probability <= 1.0, "Probability must be less than 1.0"); return new SimpleFilter(RowFilter.newBuilder().setRowSampleFilter(probability).build()); } }
mergeChain(other.getChain()); break; mergeInterleave(other.getInterleave()); break; mergeCondition(other.getCondition()); break; setSink(other.getSink()); break; setPassAllFilter(other.getPassAllFilter()); break; setBlockAllFilter(other.getBlockAllFilter()); break; setRowKeyRegexFilter(other.getRowKeyRegexFilter()); break; setRowSampleFilter(other.getRowSampleFilter()); break; onChanged(); break; setColumnQualifierRegexFilter(other.getColumnQualifierRegexFilter()); break;
switch (other.getFilterCase()) { case CHAIN: { mergeChain(other.getChain()); break; mergeInterleave(other.getInterleave()); break; mergeCondition(other.getCondition()); break; setSink(other.getSink()); break; setPassAllFilter(other.getPassAllFilter()); break; setBlockAllFilter(other.getBlockAllFilter()); break; setRowKeyRegexFilter(other.getRowKeyRegexFilter()); break; setRowSampleFilter(other.getRowSampleFilter()); break; filterCase_ = 5; filter_ = other.filter_; onChanged();
/** Tests reading all rows from a sub-split table. */ @Test public void testReadingWithFilterAndSubSplits() throws Exception { final String table = "TEST-FILTER-SUB-SPLITS"; final int numRows = 1700; final int numSamples = 10; final int numSplits = 20; final long bytesPerRow = 100L; // Set up test table data and sample row keys for size estimation and splitting. makeTableData(table, numRows); service.setupSampleRowKeys(table, numSamples, bytesPerRow); // Generate source and split it. RowFilter filter = RowFilter.newBuilder().setRowKeyRegexFilter(ByteString.copyFromUtf8(".*17.*")).build(); BigtableSource source = new BigtableSource( config.withTableId(ValueProvider.StaticValueProvider.of(table)), filter, Arrays.asList(ByteKeyRange.ALL_KEYS), null /*size*/); List<BigtableSource> splits = source.split(numRows * bytesPerRow / numSplits, null); // Test num splits and split equality. assertThat(splits, hasSize(numSplits)); assertSourcesEqualReferenceSource(source, splits, null /* options */); }
@Test public void testReadingPrimitiveDisplayData() throws IOException, InterruptedException { final String table = "fooTable"; service.createTable(table); RowFilter rowFilter = RowFilter.newBuilder().setRowKeyRegexFilter(ByteString.copyFromUtf8("foo.*")).build(); DisplayDataEvaluator evaluator = DisplayDataEvaluator.create(); BigtableIO.Read read = BigtableIO.read() .withBigtableOptions(BIGTABLE_OPTIONS) .withTableId(table) .withRowFilter(rowFilter) .withBigtableService(service); Set<DisplayData> displayData = evaluator.displayDataForPrimitiveSourceTransforms(read); assertThat( "BigtableIO.Read should include the table id in its primitive display data", displayData, Matchers.hasItem(hasDisplayItem("tableId"))); assertThat( "BigtableIO.Read should include the row filter, if it exists, in its primitive " + "display data", displayData, Matchers.hasItem(hasDisplayItem("rowFilter"))); }
/** Tests reading all rows using a filter. */ @Test public void testReadingWithFilter() throws Exception { final String table = "TEST-FILTER-TABLE"; final int numRows = 1001; List<Row> testRows = makeTableData(table, numRows); String regex = ".*17.*"; final KeyMatchesRegex keyPredicate = new KeyMatchesRegex(regex); Iterable<Row> filteredRows = testRows .stream() .filter( input -> { verifyNotNull(input, "input"); return keyPredicate.apply(input.getKey()); }) .collect(Collectors.toList()); RowFilter filter = RowFilter.newBuilder().setRowKeyRegexFilter(ByteString.copyFromUtf8(regex)).build(); service.setupSampleRowKeys(table, 5, 10L); runReadTest( defaultRead.withTableId(table).withRowFilter(filter), Lists.newArrayList(filteredRows)); }
@Test public void testReadingDisplayData() { RowFilter rowFilter = RowFilter.newBuilder().setRowKeyRegexFilter(ByteString.copyFromUtf8("foo.*")).build(); ByteKeyRange keyRange = ByteKeyRange.ALL_KEYS.withEndKey(ByteKey.of(0xab, 0xcd)); BigtableIO.Read read = BigtableIO.read() .withBigtableOptions(BIGTABLE_OPTIONS) .withTableId("fooTable") .withRowFilter(rowFilter) .withKeyRange(keyRange); DisplayData displayData = DisplayData.from(read); assertThat( displayData, hasDisplayItem( allOf(hasKey("tableId"), hasLabel("Bigtable Table Id"), hasValue("fooTable")))); assertThat(displayData, hasDisplayItem("rowFilter", rowFilter.toString())); assertThat(displayData, hasDisplayItem("keyRange 0", keyRange.toString())); // BigtableIO adds user-agent to options; assert only on key and not value. assertThat(displayData, hasDisplayItem("bigtableOptions")); }
/** * <pre> * The filter to apply to the input row if `predicate_filter` returns any * results. If not provided, no results will be returned in the true case. * </pre> * * <code>.google.bigtable.v2.RowFilter true_filter = 2;</code> */ public Builder setTrueFilter( com.google.bigtable.v2.RowFilter.Builder builderForValue) { if (trueFilterBuilder_ == null) { trueFilter_ = builderForValue.build(); onChanged(); } else { trueFilterBuilder_.setMessage(builderForValue.build()); } return this; } /**
/** * Applies the given label to all cells in the output row. This allows the caller to determine * which results were produced from which part of the filter. * * <p>Due to a technical limitation, it is not currently possible to apply multiple labels to a * cell. As a result, a {@link ChainFilter} may have no more than one sub-filter which contains a * label. It is okay for an {@link InterleaveFilter} to contain multiple labels, as they will be * applied to separate copies of the input. This may be relaxed in the future. */ public Filter label(@Nonnull String label) { Preconditions.checkNotNull(label); return new SimpleFilter(RowFilter.newBuilder().setApplyLabelTransformer(label).build()); }
@InternalApi @Override public RowFilter toProto() { switch (builder.getFiltersCount()) { case 0: return PASS.toProto(); case 1: return builder.getFilters(0); default: return RowFilter.newBuilder().setInterleave(builder.build()).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 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()); }
/** * 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()); } }
/** * 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()); } }
/** * Applies the given label to all cells in the output row. This allows the caller to determine * which results were produced from which part of the filter. * * <p>Due to a technical limitation, it is not currently possible to apply multiple labels to a * cell. As a result, a {@link ChainFilter} may have no more than one sub-filter which contains a * label. It is okay for an {@link InterleaveFilter} to contain multiple labels, as they will be * applied to separate copies of the input. This may be relaxed in the future. */ public Filter label(@Nonnull String label) { Preconditions.checkNotNull(label); return new SimpleFilter(RowFilter.newBuilder().setApplyLabelTransformer(label).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()); }
/** * 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()); } }