|
20 | 20 | using Grpc.Core;
|
21 | 21 | using System;
|
22 | 22 | using System.Collections.Generic;
|
| 23 | +using System.Linq; |
23 | 24 | using System.Threading.Tasks;
|
24 | 25 |
|
25 | 26 | namespace Google.Cloud.Bigtable.V2.ConformanceTests;
|
@@ -307,6 +308,51 @@ public override async Task<RowResult> ReadModifyWriteRow(ReadModifyWriteRowReque
|
307 | 308 | }
|
308 | 309 | }
|
309 | 310 |
|
| 311 | + public override async Task<ExecuteQueryResult> ExecuteQuery(ExecuteQueryRequest request, ServerCallContext context) |
| 312 | + { |
| 313 | + CbtClient cbtClient = GetClient(request.ClientId, context); |
| 314 | + try |
| 315 | + { |
| 316 | + BigtableServiceApiClient.ExecuteQueryStream stream = cbtClient.Client.ExecuteQuery(request.Request); |
| 317 | + AsyncResponseStream<ExecuteQueryResponse> enumerator = stream.GetResponseStream(); |
| 318 | + ExecuteQueryResult result = new ExecuteQueryResult() |
| 319 | + { |
| 320 | + Metadata = new ResultSetMetadata() |
| 321 | + }; |
| 322 | + IEnumerable<byte> bytes = Enumerable.Empty<byte>(); |
| 323 | + while (await enumerator.MoveNextAsync()) |
| 324 | + { |
| 325 | + ExecuteQueryResponse response = enumerator.Current; |
| 326 | + if (response.ResponseCase == ExecuteQueryResponse.ResponseOneofCase.Metadata) |
| 327 | + { |
| 328 | + result.ResultSetMetadata = response.Metadata; |
| 329 | + result.Metadata.Columns.Add(response.Metadata.ProtoSchema.Columns); |
| 330 | + } |
| 331 | + // TODO: confirm this implementation works as intended |
| 332 | + else if (response.ResponseCase == ExecuteQueryResponse.ResponseOneofCase.Results |
| 333 | + && response.Results.PartialRowsCase == PartialResultSet.PartialRowsOneofCase.ProtoRowsBatch) |
| 334 | + { |
| 335 | + SqlRow sqlRow = new SqlRow(); |
| 336 | + sqlRow.Values.Add(ProtoRows.Parser.ParseFrom(response.Results.ProtoRowsBatch.BatchData).Values); |
| 337 | + result.Rows.Add(sqlRow); |
| 338 | + } |
| 339 | + else |
| 340 | + { |
| 341 | + break; |
| 342 | + } |
| 343 | + } |
| 344 | + result.Status = SetSuccessStatus("ExecuteQuery succeeded", context); |
| 345 | + return result; |
| 346 | + } |
| 347 | + catch (Exception e) |
| 348 | + { |
| 349 | + return new ExecuteQueryResult |
| 350 | + { |
| 351 | + Status = SetExceptionStatus(e, context) |
| 352 | + }; |
| 353 | + } |
| 354 | + } |
| 355 | + |
310 | 356 | public static CloudBigtableV2TestProxyImpl Create() => new();
|
311 | 357 |
|
312 | 358 | private CloudBigtableV2TestProxyImpl() => _idClientMap = new();
|
|
0 commit comments