Skip to content

Commit cb8689a

Browse files
authored
feat(csharp): port updates from Apache repo (#43)
## What's Changed - Updates to the latest commit from the Apache repo - Renames the namespaces **This contains breaking changes.** <!-- Remove this line if there are no breaking changes. --> Closes #NNN. --------- Co-authored-by: David Coe <>
1 parent f56fcb2 commit cb8689a

31 files changed

+905
-293
lines changed

csharp/AdbcDrivers.BigQuery.sln

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.4.33403.182
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdbcDrivers.BigQuery", "src\AdbcDrivers.BigQuery.csproj", "{A748041C-EF9A-4E88-B6FB-9F2D6CB79170}"
6+
EndProject
7+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdbcDrivers.BigQuery.Tests", "test\AdbcDrivers.BigQuery.Tests.csproj", "{EA43BB7C-BC00-4701-BDF4-367880C2495C}"
8+
EndProject
9+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apache.Arrow.Adbc", "arrow-adbc\csharp\src\Apache.Arrow.Adbc\Apache.Arrow.Adbc.csproj", "{8BFC2CBA-D9B9-C719-0617-59A21A7D7DF9}"
10+
EndProject
11+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apache.Arrow.Adbc.Telemetry.Traces.Listeners", "arrow-adbc\csharp\src\Telemetry\Traces\Listeners\Apache.Arrow.Adbc.Telemetry.Traces.Listeners.csproj", "{CE59B9B8-E2D9-68B5-D25D-6CC418E5BE00}"
12+
EndProject
13+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apache.Arrow.Adbc.Tests", "arrow-adbc\csharp\test\Apache.Arrow.Adbc.Tests\Apache.Arrow.Adbc.Testing.csproj", "{9C9EDBEB-BAE2-E3C2-BD74-7E34C6AFEE51}"
14+
EndProject
15+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Dependencies", "Dependencies", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
16+
EndProject
17+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apache.Arrow.Adbc.Client", "arrow-adbc\csharp\src\Client\Apache.Arrow.Adbc.Client.csproj", "{80163E19-0794-37AE-1FA0-FFFA6A2DEC62}"
18+
EndProject
19+
Global
20+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
21+
Debug|Any CPU = Debug|Any CPU
22+
Release|Any CPU = Release|Any CPU
23+
EndGlobalSection
24+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
25+
{A748041C-EF9A-4E88-B6FB-9F2D6CB79170}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26+
{A748041C-EF9A-4E88-B6FB-9F2D6CB79170}.Debug|Any CPU.Build.0 = Debug|Any CPU
27+
{A748041C-EF9A-4E88-B6FB-9F2D6CB79170}.Release|Any CPU.ActiveCfg = Release|Any CPU
28+
{A748041C-EF9A-4E88-B6FB-9F2D6CB79170}.Release|Any CPU.Build.0 = Release|Any CPU
29+
{EA43BB7C-BC00-4701-BDF4-367880C2495C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
30+
{EA43BB7C-BC00-4701-BDF4-367880C2495C}.Debug|Any CPU.Build.0 = Debug|Any CPU
31+
{EA43BB7C-BC00-4701-BDF4-367880C2495C}.Release|Any CPU.ActiveCfg = Release|Any CPU
32+
{EA43BB7C-BC00-4701-BDF4-367880C2495C}.Release|Any CPU.Build.0 = Release|Any CPU
33+
{8BFC2CBA-D9B9-C719-0617-59A21A7D7DF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
34+
{8BFC2CBA-D9B9-C719-0617-59A21A7D7DF9}.Debug|Any CPU.Build.0 = Debug|Any CPU
35+
{8BFC2CBA-D9B9-C719-0617-59A21A7D7DF9}.Release|Any CPU.ActiveCfg = Release|Any CPU
36+
{8BFC2CBA-D9B9-C719-0617-59A21A7D7DF9}.Release|Any CPU.Build.0 = Release|Any CPU
37+
{CE59B9B8-E2D9-68B5-D25D-6CC418E5BE00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38+
{CE59B9B8-E2D9-68B5-D25D-6CC418E5BE00}.Debug|Any CPU.Build.0 = Debug|Any CPU
39+
{CE59B9B8-E2D9-68B5-D25D-6CC418E5BE00}.Release|Any CPU.ActiveCfg = Release|Any CPU
40+
{CE59B9B8-E2D9-68B5-D25D-6CC418E5BE00}.Release|Any CPU.Build.0 = Release|Any CPU
41+
{9C9EDBEB-BAE2-E3C2-BD74-7E34C6AFEE51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42+
{9C9EDBEB-BAE2-E3C2-BD74-7E34C6AFEE51}.Debug|Any CPU.Build.0 = Debug|Any CPU
43+
{9C9EDBEB-BAE2-E3C2-BD74-7E34C6AFEE51}.Release|Any CPU.ActiveCfg = Release|Any CPU
44+
{9C9EDBEB-BAE2-E3C2-BD74-7E34C6AFEE51}.Release|Any CPU.Build.0 = Release|Any CPU
45+
{80163E19-0794-37AE-1FA0-FFFA6A2DEC62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
46+
{80163E19-0794-37AE-1FA0-FFFA6A2DEC62}.Debug|Any CPU.Build.0 = Debug|Any CPU
47+
{80163E19-0794-37AE-1FA0-FFFA6A2DEC62}.Release|Any CPU.ActiveCfg = Release|Any CPU
48+
{80163E19-0794-37AE-1FA0-FFFA6A2DEC62}.Release|Any CPU.Build.0 = Release|Any CPU
49+
EndGlobalSection
50+
GlobalSection(SolutionProperties) = preSolution
51+
HideSolutionNode = FALSE
52+
EndGlobalSection
53+
GlobalSection(NestedProjects) = preSolution
54+
{8BFC2CBA-D9B9-C719-0617-59A21A7D7DF9} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
55+
{CE59B9B8-E2D9-68B5-D25D-6CC418E5BE00} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
56+
{9C9EDBEB-BAE2-E3C2-BD74-7E34C6AFEE51} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
57+
{80163E19-0794-37AE-1FA0-FFFA6A2DEC62} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
58+
EndGlobalSection
59+
GlobalSection(ExtensibilityGlobals) = postSolution
60+
SolutionGuid = {4795CF16-0FDB-4BE0-9768-5CF31564DC03}
61+
EndGlobalSection
62+
EndGlobal

csharp/AdbcDrivers.bigquery.sln

Lines changed: 0 additions & 30 deletions
This file was deleted.

csharp/arrow-adbc

Submodule arrow-adbc updated 284 files

csharp/src/ActivityExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
using System.Diagnostics;
2525
using Apache.Arrow.Adbc.Tracing;
2626

27-
namespace Apache.Arrow.Adbc.Drivers.BigQuery
27+
namespace AdbcDrivers.BigQuery
2828
{
2929
internal static class ActivityExtensions
3030
{
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFrameworks Condition="'$(IsWindows)'=='true'">netstandard2.0;net472;net8.0</TargetFrameworks>
4+
<TargetFrameworks Condition="'$(TargetFrameworks)'==''">netstandard2.0;net8.0</TargetFrameworks>
5+
<PackageReadmeFile>readme.md</PackageReadmeFile>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<PackageReference Include="System.Net.Http.WinHttpHandler" Version="8.0.3" Condition="'$(TargetFrameworkIdentifier)' == '.NETStandard'" />
9+
<PackageReference Include="Google.Cloud.BigQuery.Storage.V1" Version="3.17.0" />
10+
<PackageReference Include="Google.Cloud.BigQuery.V2" Version="3.11.0" />
11+
</ItemGroup>
12+
<ItemGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible($(TargetFramework), 'net6.0'))">
13+
<PackageReference Include="System.Text.Json" Version="9.0.9" />
14+
</ItemGroup>
15+
<ItemGroup>
16+
<ProjectReference Include="..\arrow-adbc\csharp\src\Apache.Arrow.Adbc\Apache.Arrow.Adbc.csproj" />
17+
<ProjectReference Include="..\arrow-adbc\csharp\src\Telemetry\Traces\Listeners\Apache.Arrow.Adbc.Telemetry.Traces.Listeners.csproj" />
18+
</ItemGroup>
19+
<ItemGroup>
20+
<Content Include="readme.md">
21+
<Pack>true</Pack>
22+
<PackagePath>\</PackagePath>
23+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
24+
</Content>
25+
</ItemGroup>
26+
</Project>

csharp/src/Apache.Arrow.Adbc.Drivers.BigQuery.csproj

Lines changed: 0 additions & 30 deletions
This file was deleted.

csharp/src/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323

2424
using System.Runtime.CompilerServices;
2525

26-
[assembly: InternalsVisibleTo("Apache.Arrow.Adbc.Tests.Drivers.BigQuery")]
26+
[assembly: InternalsVisibleTo("AdbcDrivers.BigQuery.Tests")]

csharp/src/BigQueryConnection.cs

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@
3030
using System.Text.Json;
3131
using System.Text.RegularExpressions;
3232
using System.Threading.Tasks;
33+
using Apache.Arrow;
34+
using Apache.Arrow.Adbc;
3335
using Apache.Arrow.Adbc.Extensions;
36+
using Apache.Arrow.Adbc.Telemetry.Traces.Listeners;
37+
using Apache.Arrow.Adbc.Telemetry.Traces.Listeners.FileListener;
3438
using Apache.Arrow.Adbc.Tracing;
3539
using Apache.Arrow.Ipc;
3640
using Apache.Arrow.Types;
@@ -39,7 +43,7 @@
3943
using Google.Apis.Bigquery.v2.Data;
4044
using Google.Cloud.BigQuery.V2;
4145

42-
namespace Apache.Arrow.Adbc.Drivers.BigQuery
46+
namespace AdbcDrivers.BigQuery
4347
{
4448
/// <summary>
4549
/// BigQuery-specific implementation of <see cref="AdbcConnection"/>
@@ -51,6 +55,9 @@ public class BigQueryConnection : TracingConnection, ITokenProtectedResource
5155
bool includePublicProjectIds = false;
5256
const string infoDriverName = "ADBC BigQuery Driver";
5357
const string infoVendorName = "BigQuery";
58+
// Note: this needs to be set before the constructor runs
59+
private readonly string _traceInstanceId = Guid.NewGuid().ToString("N");
60+
private readonly FileActivityListener? _fileActivityListener;
5461

5562
private readonly string infoDriverArrowVersion = BigQueryUtils.GetAssemblyVersion(typeof(IArrowArray));
5663

@@ -72,10 +79,20 @@ public BigQueryConnection(IReadOnlyDictionary<string, string> properties) : base
7279
this.properties = properties.ToDictionary(k => k.Key, v => v.Value);
7380
}
7481

75-
// add the default value for now and set to true until C# has a BigDecimal
76-
this.properties[BigQueryParameters.LargeDecimalsAsString] = BigQueryConstants.TreatLargeDecimalAsString;
82+
TryInitTracerProvider(out _fileActivityListener);
83+
7784
this.httpClient = new HttpClient();
7885

86+
if (this.properties.TryGetValue(BigQueryParameters.LargeDecimalsAsString, out string? sLargeDecimalsAsString) &&
87+
bool.TryParse(sLargeDecimalsAsString, out bool largeDecimalsAsString))
88+
{
89+
this.properties[BigQueryParameters.LargeDecimalsAsString] = largeDecimalsAsString.ToString();
90+
}
91+
else
92+
{
93+
this.properties[BigQueryParameters.LargeDecimalsAsString] = BigQueryConstants.TreatLargeDecimalAsString;
94+
}
95+
7996
if (this.properties.TryGetValue(BigQueryParameters.MaximumRetryAttempts, out string? sRetryAttempts) &&
8097
int.TryParse(sRetryAttempts, out int retries) &&
8198
retries >= 0)
@@ -89,8 +106,40 @@ public BigQueryConnection(IReadOnlyDictionary<string, string> properties) : base
89106
{
90107
RetryDelayMs = delay;
91108
}
109+
110+
if (this.properties.TryGetValue(BigQueryParameters.DefaultClientLocation, out string? location) &&
111+
!string.IsNullOrEmpty(location) &&
112+
BigQueryConstants.ValidLocations.Any(l => l.Equals(location, StringComparison.OrdinalIgnoreCase)))
113+
{
114+
DefaultClientLocation = location;
115+
}
92116
}
93117

118+
private bool TryInitTracerProvider(out FileActivityListener? fileActivityListener)
119+
{
120+
properties.TryGetValue(ListenersOptions.Exporter, out string? exporterOption);
121+
// This listener will only listen for activity from this specific connection instance.
122+
bool shouldListenTo(ActivitySource source) => source.Tags?.Any(t => ReferenceEquals(t.Key, _traceInstanceId)) == true;
123+
return FileActivityListener.TryActivateFileListener(AssemblyName, exporterOption, out fileActivityListener, shouldListenTo: shouldListenTo);
124+
}
125+
126+
public override IEnumerable<KeyValuePair<string, object?>>? GetActivitySourceTags(IReadOnlyDictionary<string, string> properties)
127+
{
128+
IEnumerable<KeyValuePair<string, object?>>? tags = base.GetActivitySourceTags(properties);
129+
tags ??= [];
130+
tags = tags.Concat([new(_traceInstanceId, null)]);
131+
return tags;
132+
}
133+
134+
/// <summary>
135+
/// Conditional used to determines if it is safe to trace
136+
/// </summary>
137+
/// <remarks>
138+
/// It is safe to write to some output types (ie, files) but not others (ie, a shared resource).
139+
/// </remarks>
140+
/// <returns></returns>
141+
internal bool IsSafeToTrace => _fileActivityListener != null;
142+
94143
/// <summary>
95144
/// The function to call when updating the token.
96145
/// </summary>
@@ -106,6 +155,9 @@ public BigQueryConnection(IReadOnlyDictionary<string, string> properties) : base
106155

107156
internal int RetryDelayMs { get; private set; } = 200;
108157

158+
// if this value is null, the BigQuery API chooses the location (typically the `US` multi-region)
159+
internal string? DefaultClientLocation { get; private set; }
160+
109161
public override string AssemblyVersion => BigQueryUtils.BigQueryAssemblyVersion;
110162

111163
public override string AssemblyName => BigQueryUtils.BigQueryAssemblyName;
@@ -177,6 +229,24 @@ internal BigQueryClient Open(string? projectId = null)
177229
GoogleCredential = Credential
178230
};
179231

232+
if (!string.IsNullOrEmpty(DefaultClientLocation))
233+
{
234+
// If the user selects a public dataset (from a multi-region) but sets this
235+
// value to a specific location like us-east4, then there is an error produced
236+
// that the caller doesn't have permission to call to the public dataset.
237+
// Example:
238+
// Access Denied: Table bigquery-public-data:blockchain_analytics_ethereum_mainnet_us.accounts:
239+
// User does not have permission to query table bigquery-public-data:blockchain_analytics_ethereum_mainnet_us.accounts,
240+
// or perhaps it does not exist.'
241+
242+
bigQueryClientBuilder.DefaultLocation = DefaultClientLocation;
243+
activity?.AddBigQueryParameterTag(BigQueryParameters.DefaultClientLocation, DefaultClientLocation);
244+
}
245+
else
246+
{
247+
activity?.AddBigQueryTag("client.default_location", null);
248+
}
249+
180250
BigQueryClient client = bigQueryClientBuilder.Build();
181251

182252
if (clientTimeout.HasValue)
@@ -476,7 +546,7 @@ internal void UpdateClientToken()
476546

477547
return this.TraceActivity(activity =>
478548
{
479-
activity?.AddConditionalTag(SemanticConventions.Db.Query.Text, sql, BigQueryUtils.IsSafeToTrace());
549+
activity?.AddConditionalTag(SemanticConventions.Db.Query.Text, sql, IsSafeToTrace);
480550

481551
Func<Task<BigQueryResults?>> func = () => Client.ExecuteQueryAsync(sql, parameters ?? Enumerable.Empty<BigQueryParameter>(), queryOptions, resultsOptions);
482552
BigQueryResults? result = ExecuteWithRetriesAsync<BigQueryResults?>(func, activity).GetAwaiter().GetResult();
@@ -1279,6 +1349,7 @@ public override void Dispose()
12791349
Client?.Dispose();
12801350
Client = null;
12811351
this.httpClient?.Dispose();
1352+
this._fileActivityListener?.Dispose();
12821353
}
12831354

12841355
private static Regex sanitizedInputRegex = new Regex("^[a-zA-Z0-9_-]+");

csharp/src/BigQueryDatabase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
*/
2323

2424
using System.Collections.Generic;
25+
using Apache.Arrow.Adbc;
2526

26-
namespace Apache.Arrow.Adbc.Drivers.BigQuery
27+
namespace AdbcDrivers.BigQuery
2728
{
2829
/// <summary>
2930
/// BigQuery-specific implementation of <see cref="AdbcDatabase"/>

csharp/src/BigQueryDriver.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
*/
2323

2424
using System.Collections.Generic;
25+
using Apache.Arrow.Adbc;
2526

26-
namespace Apache.Arrow.Adbc.Drivers.BigQuery
27+
namespace AdbcDrivers.BigQuery
2728
{
2829
/// <summary>
2930
/// BigQuery-specific implementation of <see cref="AdbcDriver"/>

0 commit comments

Comments
 (0)