diff --git a/csharp/src/Drivers/BigQuery/BigQueryConnection.cs b/csharp/src/Drivers/BigQuery/BigQueryConnection.cs index 629ac5d0c2..acba314ebf 100644 --- a/csharp/src/Drivers/BigQuery/BigQueryConnection.cs +++ b/csharp/src/Drivers/BigQuery/BigQueryConnection.cs @@ -997,23 +997,19 @@ private IReadOnlyDictionary ParseOptions() { Dictionary options = new Dictionary(); - foreach (KeyValuePair keyValuePair in this.properties) + string[] statementOptions = new string[] { + BigQueryParameters.AllowLargeResults, + BigQueryParameters.UseLegacySQL, + BigQueryParameters.LargeDecimalsAsString, + BigQueryParameters.LargeResultsDestinationTable, + BigQueryParameters.GetQueryResultsOptionsTimeoutMinutes + }; + + foreach (string key in statementOptions) { - if (keyValuePair.Key == BigQueryParameters.AllowLargeResults) - { - options[keyValuePair.Key] = keyValuePair.Value; - } - if (keyValuePair.Key == BigQueryParameters.UseLegacySQL) - { - options[keyValuePair.Key] = keyValuePair.Value; - } - if (keyValuePair.Key == BigQueryParameters.LargeDecimalsAsString) - { - options[keyValuePair.Key] = keyValuePair.Value; - } - if (keyValuePair.Key == BigQueryParameters.LargeResultsDestinationTable) + if (properties.TryGetValue(key, out string? value)) { - options[keyValuePair.Key] = keyValuePair.Value; + options[key] = value; } } diff --git a/csharp/src/Drivers/BigQuery/BigQueryParameters.cs b/csharp/src/Drivers/BigQuery/BigQueryParameters.cs index 0f81291011..3f9aafb20b 100644 --- a/csharp/src/Drivers/BigQuery/BigQueryParameters.cs +++ b/csharp/src/Drivers/BigQuery/BigQueryParameters.cs @@ -34,6 +34,7 @@ public class BigQueryParameters public const string LargeDecimalsAsString = "adbc.bigquery.large_decimals_as_string"; public const string Scopes = "adbc.bigquery.scopes"; public const string IncludeConstraintsWithGetObjects = "adbc.bigquery.include_constraints_getobjects"; + public const string GetQueryResultsOptionsTimeoutMinutes = "adbc.bigquery.get_query_results_options.timeout"; } /// diff --git a/csharp/src/Drivers/BigQuery/BigQueryStatement.cs b/csharp/src/Drivers/BigQuery/BigQueryStatement.cs index 297becff6d..fbc2e3c2d4 100644 --- a/csharp/src/Drivers/BigQuery/BigQueryStatement.cs +++ b/csharp/src/Drivers/BigQuery/BigQueryStatement.cs @@ -55,7 +55,21 @@ public override QueryResult ExecuteQuery() { QueryOptions? queryOptions = ValidateOptions(); BigQueryJob job = this.client.CreateQueryJob(SqlQuery, null, queryOptions); - BigQueryResults results = job.GetQueryResults(); + + GetQueryResultsOptions getQueryResultsOptions = new GetQueryResultsOptions(); + + if (this.Options?.TryGetValue(BigQueryParameters.GetQueryResultsOptionsTimeoutMinutes, out string? timeoutMinutes) == true) + { + if (int.TryParse(timeoutMinutes, out int minutes)) + { + if (minutes >= 0) + { + getQueryResultsOptions.Timeout = TimeSpan.FromMinutes(minutes); + } + } + } + + BigQueryResults results = job.GetQueryResults(getQueryResultsOptions); BigQueryReadClientBuilder readClientBuilder = new BigQueryReadClientBuilder(); readClientBuilder.Credential = this.credential; diff --git a/csharp/test/Drivers/BigQuery/BigQueryTestConfiguration.cs b/csharp/test/Drivers/BigQuery/BigQueryTestConfiguration.cs index 20390deb3a..a1782910ff 100644 --- a/csharp/test/Drivers/BigQuery/BigQueryTestConfiguration.cs +++ b/csharp/test/Drivers/BigQuery/BigQueryTestConfiguration.cs @@ -56,5 +56,8 @@ public BigQueryTestConfiguration() [JsonPropertyName("includeTableConstraints")] public bool IncludeTableConstraints { get; set; } + + [JsonPropertyName("timeoutMinutes")] + public int? TimeoutMinutes { get; set; } } } diff --git a/csharp/test/Drivers/BigQuery/BigQueryTestingUtils.cs b/csharp/test/Drivers/BigQuery/BigQueryTestingUtils.cs index 654cdea2e5..bf80aa2562 100644 --- a/csharp/test/Drivers/BigQuery/BigQueryTestingUtils.cs +++ b/csharp/test/Drivers/BigQuery/BigQueryTestingUtils.cs @@ -86,6 +86,11 @@ internal static Dictionary GetBigQueryParameters(BigQueryTestCon parameters.Add(BigQueryParameters.LargeResultsDestinationTable, testConfiguration.LargeResultsDestinationTable); } + if (testConfiguration.TimeoutMinutes.HasValue) + { + parameters.Add(BigQueryParameters.GetQueryResultsOptionsTimeoutMinutes, testConfiguration.TimeoutMinutes.Value.ToString()); + } + return parameters; }