Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(csharp/src/Drivers/BigQuery): add support for configurable query timeouts #2043

Merged
merged 3 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions csharp/src/Drivers/BigQuery/BigQueryConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -997,23 +997,19 @@ private IReadOnlyDictionary<string, string> ParseOptions()
{
Dictionary<string, string> options = new Dictionary<string, string>();

foreach (KeyValuePair<string, string> 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;
}
}

Expand Down
1 change: 1 addition & 0 deletions csharp/src/Drivers/BigQuery/BigQueryParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

/// <summary>
Expand Down
16 changes: 15 additions & 1 deletion csharp/src/Drivers/BigQuery/BigQueryStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions csharp/test/Drivers/BigQuery/BigQueryTestConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,8 @@ public BigQueryTestConfiguration()

[JsonPropertyName("includeTableConstraints")]
public bool IncludeTableConstraints { get; set; }

[JsonPropertyName("timeoutMinutes")]
public int? TimeoutMinutes { get; set; }
}
}
5 changes: 5 additions & 0 deletions csharp/test/Drivers/BigQuery/BigQueryTestingUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ internal static Dictionary<string, string> GetBigQueryParameters(BigQueryTestCon
parameters.Add(BigQueryParameters.LargeResultsDestinationTable, testConfiguration.LargeResultsDestinationTable);
}

if (testConfiguration.TimeoutMinutes.HasValue)
{
parameters.Add(BigQueryParameters.GetQueryResultsOptionsTimeoutMinutes, testConfiguration.TimeoutMinutes.Value.ToString());
}

return parameters;
}

Expand Down
Loading