Skip to content

Commit 3e481a6

Browse files
authored
feat(csharp/src/Drivers/BigQuery): Enhanced tracing and large resultset improvements (#3022)
- Adds tracing for the BigQuery driver - Modifies the behavior for large result sets: - Uses a default dataset ID for large result sets if one is not specified. - The caller can specify their own dataset. If it does not exist, the driver will attempt to create it. --------- Co-authored-by: David Coe <>
1 parent 218708c commit 3e481a6

File tree

10 files changed

+1096
-688
lines changed

10 files changed

+1096
-688
lines changed

csharp/src/Apache.Arrow.Adbc/Tracing/ActivityExtensions.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,25 @@ public static class ActivityExtensions
6363
return activity?.AddTag(key, value());
6464
}
6565

66+
/// <summary>
67+
/// Update the Activity to have a tag with an additional 'key' and value 'value'.
68+
/// This shows up in the <see cref="TagObjects"/> enumeration. It is meant for information that
69+
/// is useful to log but not needed for runtime control (for the latter, <see cref="Baggage"/>)
70+
/// </summary>
71+
/// <returns><see langword="this" /> for convenient chaining.</returns>
72+
/// <param name="key">The tag key name as a function</param>
73+
/// <param name="value">The tag value mapped to the input key</param>
74+
/// /// <param name="condition">The condition to check before adding the tag</param>
75+
public static Activity? AddConditionalTag(this Activity? activity, string key, string? value, bool condition)
76+
{
77+
if (condition)
78+
{
79+
return activity?.AddTag(key, value);
80+
}
81+
82+
return activity;
83+
}
84+
6685
/// <summary>
6786
/// Update the Activity to have a tag with an additional 'key' and value 'value'.
6887
/// This shows up in the <see cref="TagObjects"/> enumeration. It is meant for information that
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
using System.Diagnostics;
19+
using Apache.Arrow.Adbc.Tracing;
20+
21+
namespace Apache.Arrow.Adbc.Drivers.BigQuery
22+
{
23+
internal static class ActivityExtensions
24+
{
25+
private const string bigQueryKeyPrefix = "adbc.bigquery.tracing.";
26+
private const string bigQueryParameterKeyValueSuffix = ".value";
27+
28+
public static Activity AddBigQueryTag(this Activity activity, string key, object? value)
29+
{
30+
string bigQueryKey = bigQueryKeyPrefix + key;
31+
return activity.AddTag(bigQueryKey, value);
32+
}
33+
34+
public static Activity AddConditionalBigQueryTag(this Activity activity, string key, string? value, bool condition)
35+
{
36+
string bigQueryKey = bigQueryKeyPrefix + key;
37+
return activity.AddConditionalTag(key, value, condition)!;
38+
}
39+
40+
public static Activity AddBigQueryParameterTag(this Activity activity, string parameterName, object? value)
41+
{
42+
if (BigQueryParameters.IsSafeToLog(parameterName))
43+
{
44+
string bigQueryParameterValueKey = parameterName + bigQueryParameterKeyValueSuffix;
45+
return activity.AddTag(bigQueryParameterValueKey, value);
46+
}
47+
48+
return activity;
49+
}
50+
}
51+
}

csharp/src/Drivers/BigQuery/BigQueryConnection.cs

Lines changed: 597 additions & 511 deletions
Large diffs are not rendered by default.

csharp/src/Drivers/BigQuery/BigQueryParameters.cs

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
* limitations under the License.
1616
*/
1717

18+
using System;
19+
using System.Collections.Generic;
20+
1821
namespace Apache.Arrow.Adbc.Drivers.BigQuery
1922
{
2023
/// <summary>
@@ -23,29 +26,48 @@ namespace Apache.Arrow.Adbc.Drivers.BigQuery
2326
internal class BigQueryParameters
2427
{
2528
public const string AccessToken = "adbc.bigquery.access_token";
29+
public const string AllowLargeResults = "adbc.bigquery.allow_large_results";
2630
public const string AudienceUri = "adbc.bigquery.audience_uri";
27-
public const string ProjectId = "adbc.bigquery.project_id";
31+
public const string AuthenticationType = "adbc.bigquery.auth_type";
2832
public const string BillingProjectId = "adbc.bigquery.billing_project_id";
2933
public const string ClientId = "adbc.bigquery.client_id";
3034
public const string ClientSecret = "adbc.bigquery.client_secret";
31-
public const string RefreshToken = "adbc.bigquery.refresh_token";
32-
public const string AuthenticationType = "adbc.bigquery.auth_type";
35+
public const string ClientTimeout = "adbc.bigquery.client.timeout";
36+
public const string EvaluationKind = "adbc.bigquery.multiple_statement.evaluation_kind";
37+
public const string GetQueryResultsOptionsTimeout = "adbc.bigquery.get_query_results_options.timeout";
38+
public const string IncludeConstraintsWithGetObjects = "adbc.bigquery.include_constraints_getobjects";
39+
public const string IncludePublicProjectId = "adbc.bigquery.include_public_project_id";
3340
public const string JsonCredential = "adbc.bigquery.auth_json_credential";
34-
public const string AllowLargeResults = "adbc.bigquery.allow_large_results";
35-
public const string LargeResultsDestinationTable = "adbc.bigquery.large_results_destination_table";
36-
public const string UseLegacySQL = "adbc.bigquery.use_legacy_sql";
3741
public const string LargeDecimalsAsString = "adbc.bigquery.large_decimals_as_string";
38-
public const string Scopes = "adbc.bigquery.scopes";
39-
public const string IncludeConstraintsWithGetObjects = "adbc.bigquery.include_constraints_getobjects";
40-
public const string ClientTimeout = "adbc.bigquery.client.timeout";
42+
public const string LargeResultsDataset = "adbc.bigquery.large_results_dataset";
43+
public const string LargeResultsDestinationTable = "adbc.bigquery.large_results_destination_table";
44+
public const string MaxFetchConcurrency = "adbc.bigquery.max_fetch_concurrency";
4145
public const string MaximumRetryAttempts = "adbc.bigquery.maximum_retries";
46+
public const string ProjectId = "adbc.bigquery.project_id";
47+
public const string RefreshToken = "adbc.bigquery.refresh_token";
4248
public const string RetryDelayMs = "adbc.bigquery.retry_delay_ms";
43-
public const string GetQueryResultsOptionsTimeout = "adbc.bigquery.get_query_results_options.timeout";
44-
public const string MaxFetchConcurrency = "adbc.bigquery.max_fetch_concurrency";
45-
public const string IncludePublicProjectId = "adbc.bigquery.include_public_project_id";
46-
public const string StatementType = "adbc.bigquery.multiple_statement.statement_type";
49+
public const string Scopes = "adbc.bigquery.scopes";
4750
public const string StatementIndex = "adbc.bigquery.multiple_statement.statement_index";
48-
public const string EvaluationKind = "adbc.bigquery.multiple_statement.evaluation_kind";
51+
public const string StatementType = "adbc.bigquery.multiple_statement.statement_type";
52+
public const string UseLegacySQL = "adbc.bigquery.use_legacy_sql";
53+
54+
// these values are safe to log any time
55+
private static HashSet<string> safeToLog = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
56+
{
57+
AllowLargeResults, AuthenticationType, BillingProjectId, ClientId, ClientTimeout,
58+
EvaluationKind, GetQueryResultsOptionsTimeout, IncludeConstraintsWithGetObjects,
59+
IncludePublicProjectId, LargeDecimalsAsString, LargeResultsDataset, LargeResultsDestinationTable,
60+
MaxFetchConcurrency, MaximumRetryAttempts, ProjectId, RetryDelayMs, StatementIndex,
61+
StatementType, UseLegacySQL
62+
};
63+
64+
public static bool IsSafeToLog(string name)
65+
{
66+
if (safeToLog.Contains(name))
67+
return true;
68+
69+
return false;
70+
}
4971
}
5072

5173
/// <summary>
@@ -68,5 +90,11 @@ internal class BigQueryConstants
6890

6991
// default value per https://pkg.go.dev/cloud.google.com/go/bigquery#section-readme
7092
public const string DetectProjectId = "*detect-project-id*";
93+
94+
// Reuse what the ODBC driver already has in place, in case a caller
95+
// has permission issues trying to create a new dataset
96+
public const string DefaultLargeDatasetId = "_bqodbc_temp_tables";
97+
98+
public const string PublicProjectId = "bigquery-public-data";
7199
}
72100
}

0 commit comments

Comments
 (0)