Exemple #1
0
        /// <summary>
        /// Executes a PartitionQuery RPC asynchronously.
        /// </summary>
        /// <param name="request">The partitioning request. Must not be null. The request will be modified with session details
        /// from this object.</param>
        /// <param name="timeoutSeconds">The timeout for this RPC, in seconds.</param>
        /// <param name="cancellationToken">An optional token for canceling the call.</param>
        /// <returns>A task representing the asynchronous operation. When the task completes, the result is the response from the RPC.</returns>
        public Task <PartitionResponse> PartitionQueryAsync(PartitionQueryRequest request, int timeoutSeconds, CancellationToken cancellationToken)
        {
            CheckNotDisposed();
            GaxPreconditions.CheckNotNull(request, nameof(request));
            GaxPreconditions.CheckState(TransactionId != null, "Cannot call PartitionQueryAsync with no associated transaction");
            request.SessionAsSessionName = SessionName;
            request.Transaction          = new TransactionSelector {
                Id = TransactionId
            };

            var settings = CreateSettings(Client.Settings.PartitionQuerySettings, timeoutSeconds, cancellationToken);

            return(RecordSuccessAndExpiredSessions(Client.PartitionQueryAsync(request, settings)));
        }
Exemple #2
0
        /// <summary>Snippet for PartitionQueryAsync</summary>
        public async Task PartitionQueryRequestObjectAsync()
        {
            // Snippet: PartitionQueryAsync(PartitionQueryRequest, CallSettings)
            // Create client
            FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();

            // Initialize request argument(s)
            PartitionQueryRequest request = new PartitionQueryRequest
            {
                Parent          = "",
                StructuredQuery = new StructuredQuery(),
                PartitionCount  = 0L,
            };
            // Make the request
            PagedAsyncEnumerable <PartitionQueryResponse, Cursor> response = firestoreClient.PartitionQueryAsync(request);

            // Iterate over all response items, lazily performing RPCs as required
            await response.ForEachAsync((Cursor item) =>
            {
                // Do something with each item
                Console.WriteLine(item);
            });

            // Or iterate over pages (of server-defined size), performing one RPC per page
            await response.AsRawResponses().ForEachAsync((PartitionQueryResponse page) =>
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (Cursor item in page)
                {
                    // Do something with each item
                    Console.WriteLine(item);
                }
            });

            // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
            int           pageSize   = 10;
            Page <Cursor> singlePage = await response.ReadPageAsync(pageSize);

            // Do something with the page of items
            Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
            foreach (Cursor item in singlePage)
            {
                // Do something with each item
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
            // End snippet
        }
Exemple #3
0
 /// <summary>Snippet for PartitionQuery</summary>
 public void PartitionQuery_RequestObject()
 {
     // Snippet: PartitionQuery(PartitionQueryRequest,CallSettings)
     // Create client
     SpannerClient spannerClient = SpannerClient.Create();
     // Initialize request argument(s)
     PartitionQueryRequest request = new PartitionQueryRequest
     {
         Session = new SessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").ToString(),
         Sql     = "",
     };
     // Make the request
     PartitionResponse response = spannerClient.PartitionQuery(request);
     // End snippet
 }
        /*
         * Probe to test PartitionQuery and PartitionRead grpc call from Spanner stub.
         *
         * Args:
         *  stub: An object of SpannerStub.
         *  metrics: A list of metrics.
         */

        public static void partition(Spanner.SpannerClient client, ref Dictionary <string, long> metrics)
        {
            long latency;

            //Start Session
            Session session = StartSession(client);

            TransactionOptions txn_options = new TransactionOptions();

            TransactionOptions.Types.ReadOnly ro = new TransactionOptions.Types.ReadOnly();
            txn_options.ReadOnly = ro;
            TransactionSelector txn_selector = new TransactionSelector();

            txn_selector.Begin = txn_options;

            //Probing PartitionQuery call
            PartitionQueryRequest ptn_query_request = new PartitionQueryRequest();

            ptn_query_request.Session     = session.Name;
            ptn_query_request.Sql         = "select * FROM users";
            ptn_query_request.Transaction = txn_selector;

            stopwatch.Start();
            client.PartitionQuery(ptn_query_request);
            stopwatch.Stop();
            latency = stopwatch.ElapsedMilliseconds;
            metrics.Add("partition_query_latency_ms", latency);

            //Probing PartitionRead Call
            PartitionReadRequest ptn_read_request = new PartitionReadRequest();

            ptn_read_request.Session     = session.Name;
            ptn_read_request.Table       = "users";
            ptn_read_request.Transaction = txn_selector;
            KeySet keyset = new KeySet();

            keyset.All = true;
            ptn_read_request.KeySet = keyset;
            stopwatch.Start();
            client.PartitionRead(ptn_read_request);
            stopwatch.Stop();
            latency = stopwatch.ElapsedMilliseconds;
            metrics.Add("partition_read_latency_ms", latency);

            //Delete Session
            EndSession(client, session);
        }
Exemple #5
0
        /// <summary>Snippet for PartitionQueryAsync</summary>
        public async Task PartitionQueryAsync_RequestObject()
        {
            // Snippet: PartitionQueryAsync(PartitionQueryRequest,CallSettings)
            // Additional: PartitionQueryAsync(PartitionQueryRequest,CancellationToken)
            // Create client
            SpannerClient spannerClient = await SpannerClient.CreateAsync();

            // Initialize request argument(s)
            PartitionQueryRequest request = new PartitionQueryRequest
            {
                Session = new SessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").ToString(),
                Sql     = "",
            };
            // Make the request
            PartitionResponse response = await spannerClient.PartitionQueryAsync(request);

            // End snippet
        }
Exemple #6
0
        public async Task PartitionQueryAsync()
        {
            Mock <Spanner.SpannerClient> mockGrpcClient = new Mock <Spanner.SpannerClient>(MockBehavior.Strict);
            PartitionQueryRequest        request        = new PartitionQueryRequest
            {
                Session = new SessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").ToString(),
                Sql     = "sql114126",
            };
            PartitionResponse expectedResponse = new PartitionResponse();

            mockGrpcClient.Setup(x => x.PartitionQueryAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <PartitionResponse>(Task.FromResult(expectedResponse), null, null, null, null));
            SpannerClient     client   = new SpannerClientImpl(mockGrpcClient.Object, null);
            PartitionResponse response = await client.PartitionQueryAsync(request);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Exemple #7
0
        public void PartitionQuery()
        {
            Mock <Spanner.SpannerClient> mockGrpcClient = new Mock <Spanner.SpannerClient>(MockBehavior.Strict);
            PartitionQueryRequest        request        = new PartitionQueryRequest
            {
                Session = new SessionName("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").ToString(),
                Sql     = "sql114126",
            };
            PartitionResponse expectedResponse = new PartitionResponse();

            mockGrpcClient.Setup(x => x.PartitionQuery(request, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            SpannerClient     client   = new SpannerClientImpl(mockGrpcClient.Object, null);
            PartitionResponse response = client.PartitionQuery(request);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }