protected override async Task DeleteAsync(string persistenceId, SnapshotSelectionCriteria criteria) { var filter = RowFilters.Chain ( RowFilters.ColumnQualifierExact(SnapshotMetaDataColumnQualifier), // this filter ensures that we only download snapshot metadata RowFilters.TimestampRange( ToUtc(criteria.MinTimestamp), ToUtc(criteria.MaxTimeStamp)?.AddMilliseconds(1) // add a milliseconds since the upper bound is exclusive ), RowFilters.CellsPerColumnLimit(1) ); var readRowsRequest = new ReadRowsRequest { TableNameAsTableName = _tableName, Filter = filter, Rows = GetRowSet(persistenceId, criteria.MinSequenceNr, criteria.MaxSequenceNr) }; var deleteMutations = await _bigtableClient .ReadRows(readRowsRequest) .Select(SnapshotMetadataFromBigtableRow) .Where(metadata => SatisfiesTimestampCriteria(criteria, metadata)) .Select(metadata => Mutations.CreateEntry(GetRowKey(persistenceId, metadata.SequenceNr), Mutations.DeleteFromRow())) .ToList() .ConfigureAwait(false); if (deleteMutations.Count > 0) { await _bigtableClient.MutateRowsAsync(_tableName, deleteMutations).ConfigureAwait(false); } }
// [END bigtable_filters_composing_chain] // [START bigtable_filters_composing_interleave] /// <summary> /// /// Read using an interleave filter from an existing table. ///</summary> /// <param name="projectId">Your Google Cloud Project ID.</param> /// <param name="instanceId">Your Google Cloud Bigtable Instance ID.</param> /// <param name="tableId">Your Google Cloud Bigtable table ID.</param> public string filterComposingInterleave( String projectId, String instanceId, String tableId) { // A filter that matches cells with the value true OR with the column qualifier os_build RowFilter filter = RowFilters.Interleave(RowFilters.ValueExact("true"), RowFilters.ColumnQualifierExact("os_build")); return(readFilter(projectId, instanceId, tableId, filter)); }
// [END bigtable_reads_row] // [START bigtable_reads_row_partial] /// <summary> /// /// Reads part of one row from an existing table. ///</summary> /// <param name="projectId">Your Google Cloud Project ID.</param> /// <param name="instanceId">Your Google Cloud Bigtable Instance ID.</param> /// <param name="tableId">Your Google Cloud Bigtable table ID.</param> public string readRowPartial(string projectId = "YOUR-PROJECT-ID", string instanceId = "YOUR-INSTANCE-ID", string tableId = "YOUR-TABLE-ID") { BigtableClient bigtableClient = BigtableClient.Create(); TableName tableName = new TableName(projectId, instanceId, tableId); String rowkey = "phone#4c410523#20190501"; RowFilter filter = RowFilters.ColumnQualifierExact("os_build"); Row row = bigtableClient.ReadRow(tableName, rowkey, filter); return(printRow(row)); }
// [END bigtable_filters_composing_interleave] // [START bigtable_filters_composing_condition] /// <summary> /// /// Read using a conditional filter from an existing table. ///</summary> /// <param name="projectId">Your Google Cloud Project ID.</param> /// <param name="instanceId">Your Google Cloud Bigtable Instance ID.</param> /// <param name="tableId">Your Google Cloud Bigtable table ID.</param> public string filterComposingCondition(string projectId = "YOUR-PROJECT-ID", string instanceId = "YOUR-INSTANCE-ID", string tableId = "YOUR-TABLE-ID") { // A filter that applies the label passed-filter IF the cell has the column qualifier // data_plan_10gb AND the value true, OTHERWISE applies the label filtered-out RowFilter filter = RowFilters.Condition( RowFilters.Chain(RowFilters.ColumnQualifierExact("data_plan_10gb"), RowFilters.ValueExact("true")), new RowFilter { ApplyLabelTransformer = "passed-filter" }, new RowFilter { ApplyLabelTransformer = "filtered-out" } ); return(readFilter(projectId, instanceId, tableId, filter)); }
/// <summary> /// Check if a row has a certain value then mutate the row if it does. ///</summary> /// <param name="projectId">Your Google Cloud Project ID.</param> /// <param name="instanceId">Your Google Cloud Bigtable Instance ID.</param> /// <param name="tableId">Your Google Cloud Bigtable table ID.</param> public string writeConditional( string projectId = "YOUR-PROJECT-ID", string instanceId = "YOUR-INSTANCE-ID", string tableId = "YOUR-TABLE-ID") { BigtableClient bigtableClient = BigtableClient.Create(); TableName tableName = new TableName(projectId, instanceId, tableId); BigtableByteString rowkey = new BigtableByteString("phone#4c410523#20190501"); BigtableVersion timestamp = new BigtableVersion(DateTime.UtcNow); String COLUMN_FAMILY = "stats_summary"; CheckAndMutateRowResponse checkAndMutateRowResponse = bigtableClient.CheckAndMutateRow( tableName, rowkey, RowFilters.Chain( RowFilters.FamilyNameExact(COLUMN_FAMILY), RowFilters.ColumnQualifierExact("os_build"), RowFilters.ValueRegex("PQ2A\\..*")), Mutations.SetCell(COLUMN_FAMILY, "os_name", "android", timestamp)); return($"Successfully updated row's os_name: {checkAndMutateRowResponse.PredicateMatched}"); }
public void ColumnQualifierExact() { var filter = RowFilters.ColumnQualifierExact("a\\b\0c\t"); Assert.Equal(ByteString.CopyFromUtf8(@"a\\b\x00c\ "), filter.ColumnQualifierRegexFilter); }