Example #1
0
        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_modify_apply_label]

        // [START bigtable_filters_composing_chain]
        /// <summary>
        /// /// Read using a chain 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 filterComposingChain(string projectId = "YOUR-PROJECT-ID", string instanceId = "YOUR-INSTANCE-ID", string tableId = "YOUR-TABLE-ID")
        {
            // A filter that selects one cell per column AND within the column family cell_plan
            RowFilter filter = RowFilters.Chain(RowFilters.CellsPerColumnLimit(1), RowFilters.FamilyNameExact("cell_plan"));

            return(readFilter(projectId, instanceId, tableId, filter));
        }
        public void Chain()
        {
            var filter = RowFilters.Chain(
                RowFilters.CellsPerRowLimit(1),
                RowFilters.ValueExact("abc"));

            Assert.NotNull(filter.Chain);
            Assert.Equal(2, filter.Chain.Filters.Count);
            Assert.Equal(RowFilters.CellsPerRowLimit(1), filter.Chain.Filters[0]);
            Assert.Equal(RowFilters.ValueExact("abc"), filter.Chain.Filters[1]);
        }
        public void TestRowFilter()
        {
            var rowFilter = RowFilters.Chain(
                RowFilters.CellsPerColumnLimit(1),
                RowFilters.CellsPerRowOffset(2),
                RowFilters.CellsPerRowLimit(10));

            ReadRowsRequest originalRequest = CreateRowFilterRequest(rowFilter);

            BigtableReadRowsRequestManager underTest = new BigtableReadRowsRequestManager(originalRequest);

            Assert.Equal(originalRequest, underTest.BuildUpdatedRequest());
        }
        public override async Task <long> ReadHighestSequenceNrAsync(string persistenceId, long fromSequenceNr)
        {
            var rowRange = RowRange.ClosedOpen(
                ToRowKeyBigtableByteString(persistenceId, fromSequenceNr),
                ToRowKeyBigtableByteString(persistenceId, long.MaxValue));
            var rows   = RowSet.FromRowRanges(rowRange);
            var stream = _bigtableClient.ReadRows(
                _tableName,
                rows: rows,
                filter: RowFilters.Chain(RowFilters.CellsPerRowLimit(1), RowFilters.StripValueTransformer()));
            var lastRow = await stream.LastOrDefault().ConfigureAwait(false);

            return(lastRow == null ? 0L : GetSequenceNumber(lastRow));
        }
        // [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));
        }
        public void TestRowFilter()
        {
            var rowFilter = RowFilters.Chain(
                RowFilters.CellsPerColumnLimit(1),
                RowFilters.CellsPerRowOffset(2),
                RowFilters.CellsPerRowLimit(10));

            var originalRequest = new ReadRowsRequest
            {
                Rows   = RowSet.FromRowKey("a"),
                Filter = rowFilter
            };

            BigtableReadRowsRequestManager underTest = new BigtableReadRowsRequestManager(originalRequest);

            Assert.Equal(originalRequest, underTest.BuildUpdatedRequest());
        }
Example #8
0
        private ReadRowsRequest GetReadRowsRequest(string persistenceId, SnapshotSelectionCriteria criteria)
        {
            var filter = RowFilters.Chain
                         (
                RowFilters.TimestampRange(
                    ToUtc(criteria.MinTimestamp)?.AddMilliseconds(-1),
                    // subtract millisecond since bigtable only has millisecond granularity
                    ToUtc(criteria.MaxTimeStamp)?.AddMilliseconds(1)
                    // add a milliseconds since the upper bound is exclusive
                    ),
                RowFilters.CellsPerColumnLimit(1)
                         );

            return(new ReadRowsRequest
            {
                TableNameAsTableName = _tableName,
                Filter = filter,
                Rows = GetRowSet(persistenceId, criteria.MinSequenceNr, criteria.MaxSequenceNr)
            });
        }
        /// <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 Chain_Validations()
 {
     Assert.Throws <ArgumentNullException>(() => RowFilters.Chain(default(RowFilter[])));
     Assert.Throws <ArgumentException>(() => RowFilters.Chain(new RowFilter[] { null }));
 }