CurtHagenlocher commented on code in PR #2698:
URL: https://github.com/apache/arrow-adbc/pull/2698#discussion_r2047082128


##########
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)
+                    .ToList();

Review Comment:
   ```suggestion
                       .FirstOrDefault();
   ```
   
   No need to materialize a list if we only need one item.



##########
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:
   Is this a value that will reliably make sense to the user? i.e. does the 
`CreationTime` always line up with the order of the statements in the batch?



-- 
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

Reply via email to