Esempio n. 1
0
        /// <summary>Snippet for MutateRows</summary>
        public async Task MutateRows2ResourceNames()
        {
            // Snippet: MutateRows(TableName, IEnumerable<MutateRowsRequest.Types.Entry>, string, CallSettings)
            // Create client
            BigtableClient bigtableClient = BigtableClient.Create();
            // Initialize request argument(s)
            TableName tableName = TableName.FromProjectInstanceTable("[PROJECT]", "[INSTANCE]", "[TABLE]");
            IEnumerable <MutateRowsRequest.Types.Entry> entries = new MutateRowsRequest.Types.Entry[]
            {
                new MutateRowsRequest.Types.Entry(),
            };
            string appProfileId = "";

            // Make the request, returning a streaming response
            BigtableClient.MutateRowsStream response = bigtableClient.MutateRows(tableName, entries, appProfileId);

            // Read streaming responses from server until complete
            // Note that C# 8 code can use await foreach
            AsyncResponseStream <MutateRowsResponse> responseStream = response.GetResponseStream();

            while (await responseStream.MoveNextAsync())
            {
                MutateRowsResponse responseItem = responseStream.Current;
                // Do something with streamed response
            }
            // The response stream has completed
            // End snippet
        }
Esempio n. 2
0
        /// <summary>Snippet for MutateRows</summary>
        public async Task MutateRows1()
        {
            // Snippet: MutateRows(string, IEnumerable<MutateRowsRequest.Types.Entry>, CallSettings)
            // Create client
            BigtableClient bigtableClient = BigtableClient.Create();
            // Initialize request argument(s)
            string tableName = "projects/[PROJECT]/instances/[INSTANCE]/tables/[TABLE]";
            IEnumerable <MutateRowsRequest.Types.Entry> entries = new MutateRowsRequest.Types.Entry[]
            {
                new MutateRowsRequest.Types.Entry(),
            };

            // Make the request, returning a streaming response
            BigtableClient.MutateRowsStream response = bigtableClient.MutateRows(tableName, entries);

            // Read streaming responses from server until complete
            // Note that C# 8 code can use await foreach
            AsyncResponseStream <MutateRowsResponse> responseStream = response.GetResponseStream();

            while (await responseStream.MoveNextAsync())
            {
                MutateRowsResponse responseItem = responseStream.Current;
                // Do something with streamed response
            }
            // The response stream has completed
            // End snippet
        }
        /// <summary>Snippet for MutateRows</summary>
        public async Task MutateRows2_ResourceNames()
        {
            // Snippet: MutateRows(TableName, IEnumerable<MutateRowsRequest.Types.Entry>, string, CallSettings)
            // Create client
            BigtableServiceApiClient bigtableServiceApiClient = BigtableServiceApiClient.Create();
            // Initialize request argument(s)
            TableName tableName = new TableName("[PROJECT]", "[INSTANCE]", "[TABLE]");
            IEnumerable <MutateRowsRequest.Types.Entry> entries = new MutateRowsRequest.Types.Entry[]
            {
                new MutateRowsRequest.Types.Entry(),
            };
            string appProfileId = "";

            // Make the request, returning a streaming response
            BigtableServiceApiClient.MutateRowsStream response = bigtableServiceApiClient.MutateRows(tableName, entries, appProfileId);

            // Read streaming responses from server until complete
            IAsyncEnumerator <MutateRowsResponse> responseStream = response.ResponseStream;

            while (await responseStream.MoveNext())
            {
                MutateRowsResponse responseItem = responseStream.Current;
                // Do something with streamed response
            }
            // The response stream has completed
            // End snippet
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a <see cref="MutateRowsRequest.Types.Entry"/> to use with MutateRows requests.
        /// Each Entry is an atomic, ordered set of mutations for a particular row.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Note that string is implicitly convertible to <see cref="BigtableByteString"/>, so <paramref name="rowKey"/> can
        /// be specified using a string as well and its UTF-8 representations will be used.
        /// </para>
        /// </remarks>
        /// <param name="rowKey">
        /// The key of the row to which the <paramref name="mutations"/> should be applied. Must not be empty.
        /// </param>
        /// <param name="mutations">
        /// Changes to be atomically applied to the specified row. Mutations are
        /// applied in order, meaning that earlier mutations can be masked by
        /// later ones. You must specify at least one mutation. Must not be null, or contain null
        /// elements.
        /// </param>
        /// <returns>The MutateRows entry describing mutations for a single row.</returns>
        /// <seealso cref="BigtableClient.MutateRows(MutateRowsRequest, Api.Gax.Grpc.CallSettings)"/>
        /// <seealso cref="BigtableClient.MutateRows(TableName, MutateRowsRequest.Types.Entry[])"/>
        /// <seealso cref="BigtableClient.MutateRows(TableName, System.Collections.Generic.IEnumerable{MutateRowsRequest.Types.Entry}, Api.Gax.Grpc.CallSettings)"/>
        public static MutateRowsRequest.Types.Entry CreateEntry(BigtableByteString rowKey, params Mutation[] mutations)
        {
            GaxPreconditions.CheckArgument(rowKey.Length != 0, nameof(rowKey), "The row key must not empty");
            var entry = new MutateRowsRequest.Types.Entry
            {
                RowKey    = (ByteString)rowKey,
                Mutations = { Utilities.ValidateCollection(mutations, nameof(mutations)) }
            };

            GaxPreconditions.CheckArgument(
                entry.Mutations.Count != 0, nameof(mutations), "There must be at least one entry.");
            return(entry);
        }
Esempio n. 5
0
        /// <summary>
        /// Mutate multiple rows in an existing table and column family. Updates multiple cells within each row.
        ///</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 writeBatch(
            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);
            BigtableVersion timestamp     = new BigtableVersion(DateTime.UtcNow);
            String          COLUMN_FAMILY = "stats_summary";

            MutateRowsRequest.Types.Entry mutations1 = Mutations.CreateEntry(new BigtableByteString("tablet#a0b81f74#20190501"),
                                                                             Mutations.SetCell(COLUMN_FAMILY, "connected_cell", 1, timestamp),
                                                                             Mutations.SetCell(COLUMN_FAMILY, "os_build", "12155.0.0-rc1", timestamp)
                                                                             );
            MutateRowsRequest.Types.Entry mutations2 = Mutations.CreateEntry(new BigtableByteString("tablet#a0b81f74#20190502"),
                                                                             Mutations.SetCell(COLUMN_FAMILY, "connected_cell", 1, timestamp),
                                                                             Mutations.SetCell(COLUMN_FAMILY, "os_build", "12145.0.0-rc6", timestamp)
                                                                             );
            MutateRowsRequest.Types.Entry[] entries =
            {
                mutations1,
                mutations2
            };
            MutateRowsResponse mutateRowResponse = bigtableClient.MutateRows(tableName, entries);

            foreach (MutateRowsResponse.Types.Entry entry in mutateRowResponse.Entries)
            {
                if (entry.Status.Code == 0)
                {
                    Console.WriteLine($"Row {entry.Index} written successfully");
                }
                else
                {
                    Console.WriteLine($"\tFailed to write row {entry.Index}");
                    Console.WriteLine(entry.Status.Message);
                    return(entry.Status.Message);
                }
            }
            return("Successfully wrote 2 rows");
        }
Esempio n. 6
0
 internal static bool IsIdempotent(this MutateRowsRequest.Types.Entry entry) =>
 entry.Mutations.All(IsIdempotent);