qifanzhang-ms commented on code in PR #2698: URL: https://github.com/apache/arrow-adbc/pull/2698#discussion_r2050342068
########## csharp/src/Drivers/BigQuery/BigQueryStatement.cs: ########## @@ -51,52 +51,60 @@ public BigQueryStatement(BigQueryClient client, GoogleCredential credential) public override QueryResult ExecuteQuery() { + // Create job QueryOptions queryOptions = ValidateOptions(); - BigQueryJob job = this.client.CreateQueryJob(SqlQuery, null, queryOptions); + // Get results GetQueryResultsOptions getQueryResultsOptions = new GetQueryResultsOptions(); - if (this.Options?.TryGetValue(BigQueryParameters.GetQueryResultsOptionsTimeout, out string? timeoutSeconds) == true && int.TryParse(timeoutSeconds, out int seconds) && seconds >= 0) { getQueryResultsOptions.Timeout = TimeSpan.FromSeconds(seconds); } - BigQueryResults results = job.GetQueryResults(getQueryResultsOptions); - BigQueryReadClientBuilder readClientBuilder = new BigQueryReadClientBuilder(); - readClientBuilder.Credential = this.credential; - BigQueryReadClient readClient = readClientBuilder.Build(); - + // For multi-statement queries, the results.TableReference is null if (results.TableReference == null) { - // To get the results of all statements in a multi-statement query, enumerate the child jobs and call jobs.getQueryResults on each of them. - // Related public docs: https://cloud.google.com/bigquery/docs/multi-statement-queries#get_all_executed_statements + string statementType = string.Empty; + if (this.Options?.TryGetValue(BigQueryParameters.StatementType, out string? statementTypeString) == true) + { + statementType = statementTypeString; + } + string evaluationKind = string.Empty; + if (this.Options?.TryGetValue(BigQueryParameters.EvaluationKind, out string? evaluationKindString) == true) + { + evaluationKind = evaluationKindString; + } + + // To get the results of all statements in a multi-statement query, enumerate the child jobs. Related public docs: https://cloud.google.com/bigquery/docs/multi-statement-queries#get_all_executed_statements. + // Can filter by StatementType and EvaluationKind. Related public docs: https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#jobstatistics2, https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#evaluationkind ListJobsOptions listJobsOptions = new ListJobsOptions(); listJobsOptions.ParentJobId = results.JobReference.JobId; - PagedEnumerable<JobList, BigQueryJob> joblist = client.ListJobs(listJobsOptions); - BigQueryJob firstQueryJob = new BigQueryJob(client, job.Resource); - foreach (BigQueryJob childJob in joblist) + var joblist = client.ListJobs(listJobsOptions) + .Select(job => client.GetJob(job.Reference)) + .Where(job => string.IsNullOrEmpty(evaluationKind) || job.Statistics.ScriptStatistics.EvaluationKind.Equals(evaluationKind, StringComparison.OrdinalIgnoreCase)) + .Where(job => string.IsNullOrEmpty(statementType) || job.Statistics.Query.StatementType.Equals(statementType,StringComparison.OrdinalIgnoreCase)) + .OrderBy(job => job.Resource.Statistics.CreationTime) Review Comment: The order of jobs on the gbq service portal is based on creationTime. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org