This is an automated email from the ASF dual-hosted git repository.
curth pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git
The following commit(s) were added to refs/heads/main by this push:
new 80094cea7 feat(csharp/src/Drivers/BigQuery): choose the first project
ID if not specified (#2541)
80094cea7 is described below
commit 80094cea78a6e78bf394c45a3d3cfae152122b15
Author: davidhcoe <[email protected]>
AuthorDate: Sun Mar 2 22:35:01 2025 -0500
feat(csharp/src/Drivers/BigQuery): choose the first project ID if not
specified (#2541)
- The call to BigQueryClient.CreateQueryJob fails if a project ID is not
present (even though the `*detect-project-id*` value is passed). This
change locates the first project ID in the list of project IDs and uses
it if no project ID is specified.
- Adds support for multiple BigQuery test environments. Includes some
refactoring for of Apache.Arrow.Adbc.Tests.Drivers.Interop.FlightSql to
move common functionality to a shared library.
---------
Co-authored-by: David Coe <>
---
csharp/src/Drivers/BigQuery/BigQueryStatement.cs | 50 +++-
.../Apache.Arrow.Adbc.Tests.csproj | 15 +-
.../MultiEnvironmentTestConfiguration.cs | 46 ++++
.../MultiEnvironmentTestUtils.cs | 90 +++++++
.../Apache.Arrow.Adbc.Tests/TestConfiguration.cs | 5 +
.../Drivers/BigQuery/BigQueryTestConfiguration.cs | 12 +-
.../test/Drivers/BigQuery/BigQueryTestingUtils.cs | 56 ++--
csharp/test/Drivers/BigQuery/ClientTests.cs | 152 ++++++-----
csharp/test/Drivers/BigQuery/DriverTests.cs | 291 ++++++++++++---------
.../Drivers/BigQuery/Resources/bigqueryconfig.json | 46 +++-
.../test/Drivers/Interop/FlightSql/ClientTests.cs | 5 +-
.../test/Drivers/Interop/FlightSql/DriverTests.cs | 4 +-
.../FlightSql/FlightSqlTestConfiguration.cs | 19 +-
.../Interop/FlightSql/FlightSqlTestingUtils.cs | 64 -----
14 files changed, 520 insertions(+), 335 deletions(-)
diff --git a/csharp/src/Drivers/BigQuery/BigQueryStatement.cs
b/csharp/src/Drivers/BigQuery/BigQueryStatement.cs
index 289208b72..35750f5b4 100644
--- a/csharp/src/Drivers/BigQuery/BigQueryStatement.cs
+++ b/csharp/src/Drivers/BigQuery/BigQueryStatement.cs
@@ -51,7 +51,8 @@ namespace Apache.Arrow.Adbc.Drivers.BigQuery
public override QueryResult ExecuteQuery()
{
- QueryOptions? queryOptions = ValidateOptions();
+ QueryOptions queryOptions = ValidateOptions();
+
BigQueryJob job = this.client.CreateQueryJob(SqlQuery, null,
queryOptions);
GetQueryResultsOptions getQueryResultsOptions = new
GetQueryResultsOptions();
@@ -122,7 +123,26 @@ namespace Apache.Arrow.Adbc.Drivers.BigQuery
public override UpdateResult ExecuteUpdate()
{
- BigQueryResults result = this.client.ExecuteQuery(SqlQuery,
parameters: null);
+ QueryOptions options = ValidateOptions();
+ 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 result = this.client.ExecuteQuery(
+ SqlQuery,
+ parameters: null,
+ queryOptions: options,
+ resultsOptions: getQueryResultsOptions);
+
long updatedRows = result.NumDmlAffectedRows == null ? -1L :
result.NumDmlAffectedRows.Value;
return new UpdateResult(updatedRows);
@@ -208,13 +228,31 @@ namespace Apache.Arrow.Adbc.Drivers.BigQuery
return new ArrowStreamReader(stream);
}
- private QueryOptions? ValidateOptions()
+ private QueryOptions ValidateOptions()
{
- if (this.Options == null || this.Options.Count == 0)
- return null;
-
QueryOptions options = new QueryOptions();
+ if (this.client.ProjectId == BigQueryConstants.DetectProjectId)
+ {
+ // An error occurs when calling CreateQueryJob without the ID
set,
+ // so use the first one that is found. This does not prevent
from calling
+ // to other 'project IDs' (catalogs) with a query.
+ PagedEnumerable<ProjectList, CloudProject>? projects =
this.client.ListProjects();
+
+ if (projects != null)
+ {
+ string? firstProjectId = projects.Select(x =>
x.ProjectId).FirstOrDefault();
+
+ if (firstProjectId != null)
+ {
+ options.ProjectId = firstProjectId;
+ }
+ }
+ }
+
+ if (this.Options == null || this.Options.Count == 0)
+ return options;
+
foreach (KeyValuePair<string, string> keyValuePair in this.Options)
{
if (keyValuePair.Key == BigQueryParameters.AllowLargeResults)
diff --git a/csharp/test/Apache.Arrow.Adbc.Tests/Apache.Arrow.Adbc.Tests.csproj
b/csharp/test/Apache.Arrow.Adbc.Tests/Apache.Arrow.Adbc.Tests.csproj
index 28e8833ce..e0637dc8b 100644
--- a/csharp/test/Apache.Arrow.Adbc.Tests/Apache.Arrow.Adbc.Tests.csproj
+++ b/csharp/test/Apache.Arrow.Adbc.Tests/Apache.Arrow.Adbc.Tests.csproj
@@ -26,18 +26,9 @@
</ItemGroup>
<Target Name="CopyDuckDb" AfterTargets="Build"
Condition="'$(PkgDuckDB_NET_Bindings_Full)' != ''">
- <Copy
-
Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))'
== 'true'"
-
SourceFiles="$(PkgDuckDB_NET_Bindings_Full)\runtimes\win-$(ProcessArchitecture)\native\duckdb.dll"
- DestinationFolder="$(OutputPath)" />
- <Copy
-
Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))'
== 'true'"
-
SourceFiles="$(PkgDuckDB_NET_Bindings_Full)\runtimes\linux-$(ProcessArchitecture)\native\libduckdb.so"
- DestinationFolder="$(OutputPath)" />
- <Copy
-
Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))'
== 'true'"
-
SourceFiles="$(PkgDuckDB_NET_Bindings_Full)\runtimes\osx\native\libduckdb.dylib"
- DestinationFolder="$(OutputPath)" />
+ <Copy
Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))'
== 'true'"
SourceFiles="$(PkgDuckDB_NET_Bindings_Full)\runtimes\win-$(ProcessArchitecture)\native\duckdb.dll"
DestinationFolder="$(OutputPath)" />
+ <Copy
Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))'
== 'true'"
SourceFiles="$(PkgDuckDB_NET_Bindings_Full)\runtimes\linux-$(ProcessArchitecture)\native\libduckdb.so"
DestinationFolder="$(OutputPath)" />
+ <Copy
Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))'
== 'true'"
SourceFiles="$(PkgDuckDB_NET_Bindings_Full)\runtimes\osx\native\libduckdb.dylib"
DestinationFolder="$(OutputPath)" />
</Target>
</Project>
diff --git
a/csharp/test/Apache.Arrow.Adbc.Tests/MultiEnvironmentTestConfiguration.cs
b/csharp/test/Apache.Arrow.Adbc.Tests/MultiEnvironmentTestConfiguration.cs
new file mode 100644
index 000000000..33331dbd0
--- /dev/null
+++ b/csharp/test/Apache.Arrow.Adbc.Tests/MultiEnvironmentTestConfiguration.cs
@@ -0,0 +1,46 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System.Collections.Generic;
+using System.Text.Json.Serialization;
+
+namespace Apache.Arrow.Adbc.Tests
+{
+ public abstract class MultiEnvironmentTestConfiguration<T>
+ where T : TestConfiguration
+ {
+ /// <summary>
+ /// List of test environments that are used when running tests.
+ /// </summary>
+ /// <remarks>
+ /// Multiple environments can be defined in the Environments
dictionary. This is an array
+ /// of testable environment names in the JSON file:
+ /// "testEnvironments": [ "Environment_A", "Environment_B",
"Environment_C" ]
+ ///
+ /// These names match the keys in the Environments dictionary.
+ /// </remarks>
+ [JsonPropertyName("testEnvironments")]
+ public List<string> TestEnvironmentNames { get; set; } = new
List<string>();
+
+ /// <summary>
+ /// Contains the configured environments where the key is the name of
the environment
+ /// and the value is the test configuration for that environment.
+ /// </summary>
+ [JsonPropertyName("environments")]
+ public Dictionary<string, T> Environments { get; set; } = new
Dictionary<string, T>();
+ }
+}
diff --git a/csharp/test/Apache.Arrow.Adbc.Tests/MultiEnvironmentTestUtils.cs
b/csharp/test/Apache.Arrow.Adbc.Tests/MultiEnvironmentTestUtils.cs
new file mode 100644
index 000000000..aba4f6723
--- /dev/null
+++ b/csharp/test/Apache.Arrow.Adbc.Tests/MultiEnvironmentTestUtils.cs
@@ -0,0 +1,90 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Text.Json;
+
+namespace Apache.Arrow.Adbc.Tests
+{
+ public static class MultiEnvironmentTestUtils
+ {
+ public static T LoadMultiEnvironmentTestConfiguration<T>(string
environmentVariable)
+ {
+ T? testConfiguration = default(T);
+
+ if (!string.IsNullOrWhiteSpace(environmentVariable))
+ {
+ string? environmentValue =
Environment.GetEnvironmentVariable(environmentVariable);
+
+ if (!string.IsNullOrWhiteSpace(environmentValue))
+ {
+ if (File.Exists(environmentValue))
+ {
+ // use a JSON file for the various settings
+ string json = File.ReadAllText(environmentValue);
+
+ testConfiguration =
JsonSerializer.Deserialize<T>(json)!;
+ }
+ }
+ }
+
+ if (testConfiguration == null)
+ throw new InvalidOperationException($"Cannot execute test
configuration from environment variable `{environmentVariable}`");
+
+ return testConfiguration;
+ }
+
+ public static List<TEnvironment>
GetTestEnvironments<TEnvironment>(MultiEnvironmentTestConfiguration<TEnvironment>
testConfiguration)
+ where TEnvironment : TestConfiguration
+ {
+ if (testConfiguration == null)
+ throw new ArgumentNullException(nameof(testConfiguration));
+
+ if (testConfiguration.Environments == null ||
testConfiguration.Environments.Count == 0)
+ throw new InvalidOperationException("There are no environments
configured");
+
+ List<TEnvironment> environments = new List<TEnvironment>();
+
+ foreach (string environmentName in
GetEnvironmentNames(testConfiguration.TestEnvironmentNames))
+ {
+ if
(testConfiguration.Environments.TryGetValue(environmentName, out TEnvironment?
testEnvironment))
+ {
+ if (testEnvironment != null)
+ {
+ testEnvironment.Name = environmentName;
+ environments.Add(testEnvironment);
+ }
+ }
+ }
+
+ if (environments.Count == 0)
+ throw new InvalidOperationException("Could not find a
configured environment to execute the tests");
+
+ return environments;
+ }
+
+ private static List<string> GetEnvironmentNames(List<string> names)
+ {
+ if (names == null)
+ return new List<string>();
+
+ return names;
+ }
+ }
+}
diff --git a/csharp/test/Apache.Arrow.Adbc.Tests/TestConfiguration.cs
b/csharp/test/Apache.Arrow.Adbc.Tests/TestConfiguration.cs
index 36a46a55a..8ba664dad 100644
--- a/csharp/test/Apache.Arrow.Adbc.Tests/TestConfiguration.cs
+++ b/csharp/test/Apache.Arrow.Adbc.Tests/TestConfiguration.cs
@@ -25,6 +25,11 @@ namespace Apache.Arrow.Adbc.Tests
/// </summary>
public abstract class TestConfiguration : ICloneable
{
+ /// <summary>
+ /// Optional. The name of the environment.
+ /// </summary>
+ public string? Name { get; set; }
+
/// <summary>
/// The query to run.
/// </summary>
diff --git a/csharp/test/Drivers/BigQuery/BigQueryTestConfiguration.cs
b/csharp/test/Drivers/BigQuery/BigQueryTestConfiguration.cs
index 17c228ac9..b045a679f 100644
--- a/csharp/test/Drivers/BigQuery/BigQueryTestConfiguration.cs
+++ b/csharp/test/Drivers/BigQuery/BigQueryTestConfiguration.cs
@@ -15,6 +15,7 @@
* limitations under the License.
*/
+using System.Collections.Generic;
using System.Text.Json.Serialization;
namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
@@ -22,9 +23,16 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
/// <summary>
/// Configuration settings for working with BigQuery.
/// </summary>
- internal class BigQueryTestConfiguration : TestConfiguration
+ internal class BigQueryTestConfiguration :
MultiEnvironmentTestConfiguration<BigQueryTestEnvironment>
{
- public BigQueryTestConfiguration()
+ }
+
+ /// <summary>
+ /// Configuration environments for working with BigQuery.
+ /// </summary>
+ internal class BigQueryTestEnvironment : TestConfiguration
+ {
+ public BigQueryTestEnvironment()
{
AllowLargeResults = false;
IncludeTableConstraints = true;
diff --git a/csharp/test/Drivers/BigQuery/BigQueryTestingUtils.cs
b/csharp/test/Drivers/BigQuery/BigQueryTestingUtils.cs
index ff7e36139..c1dd14a6d 100644
--- a/csharp/test/Drivers/BigQuery/BigQueryTestingUtils.cs
+++ b/csharp/test/Drivers/BigQuery/BigQueryTestingUtils.cs
@@ -28,16 +28,16 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
internal const string BIGQUERY_TEST_CONFIG_VARIABLE =
"BIGQUERY_TEST_CONFIG_FILE";
/// <summary>
- /// Gets a the BigQuery ADBC driver with settings from the <see
cref="BigQueryTestConfiguration"/>.
+ /// Gets a the BigQuery ADBC driver with settings from the <see
cref="BigQueryTestEnvironment"/>.
/// </summary>
- /// <param name="testConfiguration"><see
cref="BigQueryTestConfiguration"/></param>
+ /// <param name="testEnvironment"><see
cref="BigQueryTestEnvironment"/></param>
/// <param name="parameters"></param>
/// <returns></returns>
internal static AdbcConnection GetBigQueryAdbcConnection(
- BigQueryTestConfiguration testConfiguration
+ BigQueryTestEnvironment testEnvironment
)
{
- Dictionary<string, string> parameters =
GetBigQueryParameters(testConfiguration);
+ Dictionary<string, string> parameters =
GetBigQueryParameters(testEnvironment);
AdbcDatabase database = new BigQueryDriver().Open(parameters);
AdbcConnection connection = database.Connect(new
Dictionary<string, string>());
@@ -47,57 +47,57 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
/// <summary>
/// Gets the parameters for connecting to BigQuery.
/// </summary>
- /// <param name="testConfiguration"><see
cref="BigQueryTestConfiguration"/></param>
+ /// <param name="testEnvironment"><see
cref="BigQueryTestEnvironment"/></param>
/// <returns></returns>
- internal static Dictionary<string, string>
GetBigQueryParameters(BigQueryTestConfiguration testConfiguration)
+ internal static Dictionary<string, string>
GetBigQueryParameters(BigQueryTestEnvironment testEnvironment)
{
Dictionary<string, string> parameters = new Dictionary<string,
string>{};
- if (!string.IsNullOrEmpty(testConfiguration.ProjectId))
+ if (!string.IsNullOrEmpty(testEnvironment.ProjectId))
{
- parameters.Add(BigQueryParameters.ProjectId,
testConfiguration.ProjectId!);
+ parameters.Add(BigQueryParameters.ProjectId,
testEnvironment.ProjectId!);
}
- if (!string.IsNullOrEmpty(testConfiguration.JsonCredential))
+ if (!string.IsNullOrEmpty(testEnvironment.JsonCredential))
{
parameters.Add(BigQueryParameters.AuthenticationType,
BigQueryConstants.ServiceAccountAuthenticationType);
- parameters.Add(BigQueryParameters.JsonCredential,
testConfiguration.JsonCredential);
+ parameters.Add(BigQueryParameters.JsonCredential,
testEnvironment.JsonCredential);
}
else
{
parameters.Add(BigQueryParameters.AuthenticationType,
BigQueryConstants.UserAuthenticationType);
- parameters.Add(BigQueryParameters.ClientId,
testConfiguration.ClientId);
- parameters.Add(BigQueryParameters.ClientSecret,
testConfiguration.ClientSecret);
- parameters.Add(BigQueryParameters.RefreshToken,
testConfiguration.RefreshToken);
+ parameters.Add(BigQueryParameters.ClientId,
testEnvironment.ClientId);
+ parameters.Add(BigQueryParameters.ClientSecret,
testEnvironment.ClientSecret);
+ parameters.Add(BigQueryParameters.RefreshToken,
testEnvironment.RefreshToken);
}
- if (!string.IsNullOrEmpty(testConfiguration.Scopes))
+ if (!string.IsNullOrEmpty(testEnvironment.Scopes))
{
- parameters.Add(BigQueryParameters.Scopes,
testConfiguration.Scopes);
+ parameters.Add(BigQueryParameters.Scopes,
testEnvironment.Scopes);
}
- if (testConfiguration.AllowLargeResults)
+ if (testEnvironment.AllowLargeResults)
{
- parameters.Add(BigQueryParameters.AllowLargeResults,
testConfiguration.AllowLargeResults.ToString());
+ parameters.Add(BigQueryParameters.AllowLargeResults,
testEnvironment.AllowLargeResults.ToString());
}
-
parameters.Add(BigQueryParameters.IncludeConstraintsWithGetObjects,
testConfiguration.IncludeTableConstraints.ToString());
+
parameters.Add(BigQueryParameters.IncludeConstraintsWithGetObjects,
testEnvironment.IncludeTableConstraints.ToString());
- parameters.Add(BigQueryParameters.IncludePublicProjectId,
testConfiguration.IncludePublicProjectId.ToString());
+ parameters.Add(BigQueryParameters.IncludePublicProjectId,
testEnvironment.IncludePublicProjectId.ToString());
- if
(!string.IsNullOrEmpty(testConfiguration.LargeResultsDestinationTable))
+ if
(!string.IsNullOrEmpty(testEnvironment.LargeResultsDestinationTable))
{
-
parameters.Add(BigQueryParameters.LargeResultsDestinationTable,
testConfiguration.LargeResultsDestinationTable);
+
parameters.Add(BigQueryParameters.LargeResultsDestinationTable,
testEnvironment.LargeResultsDestinationTable);
}
- if (testConfiguration.TimeoutMinutes.HasValue)
+ if (testEnvironment.TimeoutMinutes.HasValue)
{
-
parameters.Add(BigQueryParameters.GetQueryResultsOptionsTimeoutMinutes,
testConfiguration.TimeoutMinutes.Value.ToString());
+
parameters.Add(BigQueryParameters.GetQueryResultsOptionsTimeoutMinutes,
testEnvironment.TimeoutMinutes.Value.ToString());
}
- if (testConfiguration.MaxStreamCount.HasValue)
+ if (testEnvironment.MaxStreamCount.HasValue)
{
- parameters.Add(BigQueryParameters.MaxFetchConcurrency,
testConfiguration.MaxStreamCount.Value.ToString());
+ parameters.Add(BigQueryParameters.MaxFetchConcurrency,
testEnvironment.MaxStreamCount.Value.ToString());
}
return parameters;
@@ -106,8 +106,8 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
/// <summary>
/// Parses the queries from resources/BigQueryData.sql
/// </summary>
- /// <param name="testConfiguration"><see
cref="BigQueryTestConfiguration"/></param>
- internal static string[] GetQueries(BigQueryTestConfiguration
testConfiguration)
+ /// <param name="testEnvironment"><see
cref="BigQueryTestEnvironment"/></param>
+ internal static string[] GetQueries(BigQueryTestEnvironment
testEnvironment)
{
// get past the license header
StringBuilder content = new StringBuilder();
@@ -122,7 +122,7 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
{
if (line.Contains(placeholder))
{
- string modifiedLine = line.Replace(placeholder,
$"{testConfiguration.Metadata.Catalog}.{testConfiguration.Metadata.Schema}.{testConfiguration.Metadata.Table}");
+ string modifiedLine = line.Replace(placeholder,
$"{testEnvironment.Metadata.Catalog}.{testEnvironment.Metadata.Schema}.{testEnvironment.Metadata.Table}");
content.AppendLine(modifiedLine);
}
diff --git a/csharp/test/Drivers/BigQuery/ClientTests.cs
b/csharp/test/Drivers/BigQuery/ClientTests.cs
index c9b33b6c6..9405c6277 100644
--- a/csharp/test/Drivers/BigQuery/ClientTests.cs
+++ b/csharp/test/Drivers/BigQuery/ClientTests.cs
@@ -20,6 +20,7 @@ using System.Collections.Generic;
using Apache.Arrow.Adbc.Drivers.BigQuery;
using Apache.Arrow.Adbc.Tests.Xunit;
using Xunit;
+using Xunit.Abstractions;
namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
{
@@ -34,12 +35,16 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
public class ClientTests
{
private BigQueryTestConfiguration _testConfiguration;
+ readonly List<BigQueryTestEnvironment> _environments;
+ readonly ITestOutputHelper _outputHelper;
- public ClientTests()
+ public ClientTests(ITestOutputHelper outputHelper)
{
Skip.IfNot(Utils.CanExecuteTestConfig(BigQueryTestingUtils.BIGQUERY_TEST_CONFIG_VARIABLE));
- _testConfiguration =
Utils.LoadTestConfiguration<BigQueryTestConfiguration>(BigQueryTestingUtils.BIGQUERY_TEST_CONFIG_VARIABLE);
+ _testConfiguration =
MultiEnvironmentTestUtils.LoadMultiEnvironmentTestConfiguration<BigQueryTestConfiguration>(BigQueryTestingUtils.BIGQUERY_TEST_CONFIG_VARIABLE);
+ _environments =
MultiEnvironmentTestUtils.GetTestEnvironments<BigQueryTestEnvironment>(_testConfiguration);
+ _outputHelper = outputHelper;
}
/// <summary>
@@ -48,15 +53,18 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
[SkippableFact, Order(1)]
public void CanClientExecuteUpdate()
{
- using (Adbc.Client.AdbcConnection adbcConnection =
GetAdbcConnection())
+ foreach (BigQueryTestEnvironment environment in _environments)
{
- adbcConnection.Open();
+ using (Adbc.Client.AdbcConnection adbcConnection =
GetAdbcConnection(environment))
+ {
+ adbcConnection.Open();
- string[] queries =
BigQueryTestingUtils.GetQueries(_testConfiguration);
+ string[] queries =
BigQueryTestingUtils.GetQueries(environment);
- List<int> expectedResults = new List<int>() { -1, 1, 1 };
+ List<int> expectedResults = new List<int>() { -1, 1, 1 };
- Tests.ClientTests.CanClientExecuteUpdate(adbcConnection,
_testConfiguration, queries, expectedResults);
+ Tests.ClientTests.CanClientExecuteUpdate(adbcConnection,
environment, queries, expectedResults);
+ }
}
}
@@ -66,9 +74,12 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
[SkippableFact, Order(2)]
public void CanClientGetSchema()
{
- using (Adbc.Client.AdbcConnection adbcConnection =
GetAdbcConnection())
+ foreach (BigQueryTestEnvironment environment in _environments)
{
- Tests.ClientTests.CanClientGetSchema(adbcConnection,
_testConfiguration);
+ using (Adbc.Client.AdbcConnection adbcConnection =
GetAdbcConnection(environment))
+ {
+ Tests.ClientTests.CanClientGetSchema(adbcConnection,
environment);
+ }
}
}
@@ -79,9 +90,12 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
[SkippableFact, Order(3)]
public void CanClientExecuteQuery()
{
- using (Adbc.Client.AdbcConnection adbcConnection =
GetAdbcConnection())
+ foreach (BigQueryTestEnvironment environment in _environments)
{
- Tests.ClientTests.CanClientExecuteQuery(adbcConnection,
_testConfiguration);
+ using (Adbc.Client.AdbcConnection adbcConnection =
GetAdbcConnection(environment))
+ {
+ Tests.ClientTests.CanClientExecuteQuery(adbcConnection,
environment, environmentName: environment.Name);
+ }
}
}
@@ -92,26 +106,32 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
[SkippableFact, Order(4)]
public void VerifyTypesAndValues()
{
- using(Adbc.Client.AdbcConnection dbConnection =
GetAdbcConnection())
+ foreach (BigQueryTestEnvironment environment in _environments)
{
- SampleDataBuilder sampleDataBuilder =
BigQueryData.GetSampleData();
+ using (Adbc.Client.AdbcConnection dbConnection =
GetAdbcConnection(environment))
+ {
+ SampleDataBuilder sampleDataBuilder =
BigQueryData.GetSampleData();
- Tests.ClientTests.VerifyTypesAndValues(dbConnection,
sampleDataBuilder);
+ Tests.ClientTests.VerifyTypesAndValues(dbConnection,
sampleDataBuilder, environment.Name);
+ }
}
}
[SkippableFact]
public void VerifySchemaTablesWithNoConstraints()
{
- using (Adbc.Client.AdbcConnection adbcConnection =
GetAdbcConnection(includeTableConstraints: false))
+ foreach (BigQueryTestEnvironment environment in _environments)
{
- adbcConnection.Open();
+ using (Adbc.Client.AdbcConnection adbcConnection =
GetAdbcConnection(environment, includeTableConstraints: false))
+ {
+ adbcConnection.Open();
- string schema = "Tables";
+ string schema = "Tables";
- var tables = adbcConnection.GetSchema(schema);
+ var tables = adbcConnection.GetSchema(schema);
- Assert.True(tables.Rows.Count > 0, $"No tables were found in
the schema '{schema}'");
+ Assert.True(tables.Rows.Count > 0, $"No tables were found
in the schema '{schema}' for environment '{environment.Name}'");
+ }
}
}
@@ -119,76 +139,82 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
[SkippableFact]
public void VerifySchemaTables()
{
- using (Adbc.Client.AdbcConnection adbcConnection =
GetAdbcConnection())
+ foreach (BigQueryTestEnvironment environment in _environments)
{
- adbcConnection.Open();
+ using (Adbc.Client.AdbcConnection adbcConnection =
GetAdbcConnection(environment))
+ {
+ adbcConnection.Open();
- var collections =
adbcConnection.GetSchema("MetaDataCollections");
- Assert.Equal(7, collections.Rows.Count);
- Assert.Equal(2, collections.Columns.Count);
+ var collections =
adbcConnection.GetSchema("MetaDataCollections");
+ Assert.Equal(7, collections.Rows.Count);
+ Assert.Equal(2, collections.Columns.Count);
- var restrictions = adbcConnection.GetSchema("Restrictions");
- Assert.Equal(11, restrictions.Rows.Count);
- Assert.Equal(3, restrictions.Columns.Count);
+ var restrictions =
adbcConnection.GetSchema("Restrictions");
+ Assert.Equal(11, restrictions.Rows.Count);
+ Assert.Equal(3, restrictions.Columns.Count);
- var catalogs = adbcConnection.GetSchema("Catalogs");
- Assert.Single(catalogs.Columns);
- var catalog = (string?)catalogs.Rows[0].ItemArray[0];
+ var catalogs = adbcConnection.GetSchema("Catalogs");
+ Assert.Single(catalogs.Columns);
+ var catalog = (string?)catalogs.Rows[0].ItemArray[0];
- catalogs = adbcConnection.GetSchema("Catalogs", new[] {
catalog });
- Assert.Equal(1, catalogs.Rows.Count);
+ catalogs = adbcConnection.GetSchema("Catalogs", new[] {
catalog });
+ Assert.Equal(1, catalogs.Rows.Count);
- string random = "X" + Guid.NewGuid().ToString("N");
+ string random = "X" + Guid.NewGuid().ToString("N");
- catalogs = adbcConnection.GetSchema("Catalogs", new[] { random
});
- Assert.Equal(0, catalogs.Rows.Count);
+ catalogs = adbcConnection.GetSchema("Catalogs", new[] {
random });
+ Assert.Equal(0, catalogs.Rows.Count);
- var schemas = adbcConnection.GetSchema("Schemas", new[] {
catalog });
- Assert.Equal(2, schemas.Columns.Count);
- var schema = (string?)schemas.Rows[0].ItemArray[1];
+ var schemas = adbcConnection.GetSchema("Schemas", new[] {
catalog });
+ Assert.Equal(2, schemas.Columns.Count);
+ var schema = (string?)schemas.Rows[0].ItemArray[1];
- schemas = adbcConnection.GetSchema("Schemas", new[] { catalog,
schema });
- Assert.Equal(1, schemas.Rows.Count);
+ schemas = adbcConnection.GetSchema("Schemas", new[] {
catalog, schema });
+ Assert.Equal(1, schemas.Rows.Count);
- schemas = adbcConnection.GetSchema("Schemas", new[] { random
});
- Assert.Equal(0, schemas.Rows.Count);
+ schemas = adbcConnection.GetSchema("Schemas", new[] {
random });
+ Assert.Equal(0, schemas.Rows.Count);
- schemas = adbcConnection.GetSchema("Schemas", new[] { catalog,
random });
- Assert.Equal(0, schemas.Rows.Count);
+ schemas = adbcConnection.GetSchema("Schemas", new[] {
catalog, random });
+ Assert.Equal(0, schemas.Rows.Count);
- schemas = adbcConnection.GetSchema("Schemas", new[] { random,
random });
- Assert.Equal(0, schemas.Rows.Count);
+ schemas = adbcConnection.GetSchema("Schemas", new[] {
random, random });
+ Assert.Equal(0, schemas.Rows.Count);
- var tableTypes = adbcConnection.GetSchema("TableTypes");
- Assert.Single(tableTypes.Columns);
+ var tableTypes = adbcConnection.GetSchema("TableTypes");
+ Assert.Single(tableTypes.Columns);
- var tables = adbcConnection.GetSchema("Tables", new[] {
catalog, schema });
- Assert.Equal(4, tables.Columns.Count);
+ var tables = adbcConnection.GetSchema("Tables", new[] {
catalog, schema });
+ Assert.Equal(4, tables.Columns.Count);
- tables = adbcConnection.GetSchema("Tables", new[] { catalog,
random });
- Assert.Equal(0, tables.Rows.Count);
+ tables = adbcConnection.GetSchema("Tables", new[] {
catalog, random });
+ Assert.Equal(0, tables.Rows.Count);
- tables = adbcConnection.GetSchema("Tables", new[] { random,
schema });
- Assert.Equal(0, tables.Rows.Count);
+ tables = adbcConnection.GetSchema("Tables", new[] {
random, schema });
+ Assert.Equal(0, tables.Rows.Count);
- tables = adbcConnection.GetSchema("Tables", new[] { random,
random });
- Assert.Equal(0, tables.Rows.Count);
+ tables = adbcConnection.GetSchema("Tables", new[] {
random, random });
+ Assert.Equal(0, tables.Rows.Count);
- tables = adbcConnection.GetSchema("Tables", new[] { catalog,
schema, random });
- Assert.Equal(0, tables.Rows.Count);
+ tables = adbcConnection.GetSchema("Tables", new[] {
catalog, schema, random });
+ Assert.Equal(0, tables.Rows.Count);
- var columns = adbcConnection.GetSchema("Columns", new[] {
catalog, schema });
- Assert.Equal(16, columns.Columns.Count);
+ var columns = adbcConnection.GetSchema("Columns", new[] {
catalog, schema });
+ Assert.Equal(16, columns.Columns.Count);
+ }
}
}
- private Adbc.Client.AdbcConnection GetAdbcConnection(bool
includeTableConstraints = true)
+ private Adbc.Client.AdbcConnection GetAdbcConnection(
+ BigQueryTestEnvironment environment,
+ bool includeTableConstraints = true
+ )
{
- _testConfiguration.IncludeTableConstraints =
includeTableConstraints;
+ environment.IncludeTableConstraints = includeTableConstraints;
return new Adbc.Client.AdbcConnection(
new BigQueryDriver(),
- BigQueryTestingUtils.GetBigQueryParameters(_testConfiguration),
+ BigQueryTestingUtils.GetBigQueryParameters(environment),
new Dictionary<string, string>()
);
}
diff --git a/csharp/test/Drivers/BigQuery/DriverTests.cs
b/csharp/test/Drivers/BigQuery/DriverTests.cs
index 58db4db16..76447b576 100644
--- a/csharp/test/Drivers/BigQuery/DriverTests.cs
+++ b/csharp/test/Drivers/BigQuery/DriverTests.cs
@@ -38,14 +38,24 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
public class DriverTests
{
BigQueryTestConfiguration _testConfiguration;
- readonly ITestOutputHelper? outputHelper;
+ readonly List<BigQueryTestEnvironment> _environments;
+ readonly Dictionary<string, AdbcConnection> _configuredConnections =
new Dictionary<string, AdbcConnection>();
+
+ readonly ITestOutputHelper? _outputHelper;
public DriverTests(ITestOutputHelper? outputHelper)
{
- this.outputHelper = outputHelper;
-
Skip.IfNot(Utils.CanExecuteTestConfig(BigQueryTestingUtils.BIGQUERY_TEST_CONFIG_VARIABLE));
- _testConfiguration =
Utils.LoadTestConfiguration<BigQueryTestConfiguration>(BigQueryTestingUtils.BIGQUERY_TEST_CONFIG_VARIABLE);
+
+ _testConfiguration =
MultiEnvironmentTestUtils.LoadMultiEnvironmentTestConfiguration<BigQueryTestConfiguration>(BigQueryTestingUtils.BIGQUERY_TEST_CONFIG_VARIABLE);
+ _environments =
MultiEnvironmentTestUtils.GetTestEnvironments<BigQueryTestEnvironment>(_testConfiguration);
+ _outputHelper = outputHelper;
+
+ foreach (BigQueryTestEnvironment environment in _environments)
+ {
+ AdbcConnection connection =
BigQueryTestingUtils.GetBigQueryAdbcConnection(environment);
+ _configuredConnections.Add(environment.Name!, connection);
+ }
}
/// <summary>
@@ -55,22 +65,24 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
[SkippableFact, Order(1)]
public void CanExecuteUpdate()
{
+ foreach (BigQueryTestEnvironment environment in _environments)
+ {
+ AdbcConnection adbcConnection =
GetAdbcConnection(environment.Name);
- AdbcConnection adbcConnection =
BigQueryTestingUtils.GetBigQueryAdbcConnection(_testConfiguration);
-
- string[] queries =
BigQueryTestingUtils.GetQueries(_testConfiguration);
+ string[] queries =
BigQueryTestingUtils.GetQueries(environment);
- List<int> expectedResults = new List<int>() { -1, 1, 1 };
+ List<int> expectedResults = new List<int>() { -1, 1, 1 };
- for (int i = 0; i < queries.Length; i++)
- {
- string query = queries[i];
- AdbcStatement statement = adbcConnection.CreateStatement();
- statement.SqlQuery = query;
+ for (int i = 0; i < queries.Length; i++)
+ {
+ string query = queries[i];
+ AdbcStatement statement = adbcConnection.CreateStatement();
+ statement.SqlQuery = query;
- UpdateResult updateResult = statement.ExecuteUpdate();
+ UpdateResult updateResult = statement.ExecuteUpdate();
- Assert.Equal(expectedResults[i], updateResult.AffectedRows);
+ Assert.Equal(expectedResults[i],
updateResult.AffectedRows);
+ }
}
}
@@ -80,24 +92,27 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
[SkippableFact, Order(2)]
public void CanGetInfo()
{
- AdbcConnection adbcConnection =
BigQueryTestingUtils.GetBigQueryAdbcConnection(_testConfiguration);
+ foreach (BigQueryTestEnvironment environment in _environments)
+ {
+ AdbcConnection adbcConnection =
GetAdbcConnection(environment.Name);
- IArrowArrayStream stream = adbcConnection.GetInfo(new
List<AdbcInfoCode>() { AdbcInfoCode.DriverName, AdbcInfoCode.DriverVersion,
AdbcInfoCode.VendorName });
+ IArrowArrayStream stream = adbcConnection.GetInfo(new
List<AdbcInfoCode>() { AdbcInfoCode.DriverName, AdbcInfoCode.DriverVersion,
AdbcInfoCode.VendorName });
- RecordBatch recordBatch = stream.ReadNextRecordBatchAsync().Result;
- UInt32Array infoNameArray =
(UInt32Array)recordBatch.Column("info_name");
+ RecordBatch recordBatch =
stream.ReadNextRecordBatchAsync().Result;
+ UInt32Array infoNameArray =
(UInt32Array)recordBatch.Column("info_name");
- List<string> expectedValues = new List<string>() { "DriverName",
"DriverVersion", "VendorName" };
+ List<string> expectedValues = new List<string>() {
"DriverName", "DriverVersion", "VendorName" };
- for (int i = 0; i < infoNameArray.Length; i++)
- {
- AdbcInfoCode value =
(AdbcInfoCode)infoNameArray.GetValue(i)!.Value;
- DenseUnionArray valueArray =
(DenseUnionArray)recordBatch.Column("info_value");
+ for (int i = 0; i < infoNameArray.Length; i++)
+ {
+ AdbcInfoCode value =
(AdbcInfoCode)infoNameArray.GetValue(i)!.Value;
+ DenseUnionArray valueArray =
(DenseUnionArray)recordBatch.Column("info_value");
- Assert.Contains(value.ToString(), expectedValues);
+ Assert.Contains(value.ToString(), expectedValues);
- StringArray stringArray = (StringArray)valueArray.Fields[0];
- Console.WriteLine($"{value}={stringArray.GetString(i)}");
+ StringArray stringArray =
(StringArray)valueArray.Fields[0];
+ Console.WriteLine($"{value}={stringArray.GetString(i)}");
+ }
}
}
@@ -107,23 +122,26 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
[SkippableFact, Order(3)]
public void CanGetObjectsAllCatalogs()
{
- AdbcConnection adbcConnection =
BigQueryTestingUtils.GetBigQueryAdbcConnection(_testConfiguration);
+ foreach (BigQueryTestEnvironment environment in _environments)
+ {
+ AdbcConnection adbcConnection =
GetAdbcConnection(environment.Name);
- IArrowArrayStream stream = adbcConnection.GetObjects(
- depth: AdbcConnection.GetObjectsDepth.Catalogs,
- catalogPattern: null,
- dbSchemaPattern: null,
- tableNamePattern: null,
- tableTypes: BigQueryTableTypes.TableTypes,
- columnNamePattern: null);
+ IArrowArrayStream stream = adbcConnection.GetObjects(
+ depth: AdbcConnection.GetObjectsDepth.Catalogs,
+ catalogPattern: null,
+ dbSchemaPattern: null,
+ tableNamePattern: null,
+ tableTypes: BigQueryTableTypes.TableTypes,
+ columnNamePattern: null);
- RecordBatch recordBatch = stream.ReadNextRecordBatchAsync().Result;
+ RecordBatch recordBatch =
stream.ReadNextRecordBatchAsync().Result;
- List<AdbcCatalog> catalogs =
GetObjectsParser.ParseCatalog(recordBatch, null);
+ List<AdbcCatalog> catalogs =
GetObjectsParser.ParseCatalog(recordBatch, null);
- foreach (AdbcCatalog ct in catalogs)
- {
- this.outputHelper?.WriteLine(ct.Name);
+ foreach (AdbcCatalog ct in catalogs)
+ {
+ this._outputHelper?.WriteLine($"{ct.Name} in
[{environment.Name}]");
+ }
}
}
@@ -133,69 +151,75 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
[SkippableFact, Order(3)]
public void CanGetObjects()
{
- // need to add the database
- string? catalogName = _testConfiguration.Metadata.Catalog;
- string? schemaName = _testConfiguration.Metadata.Schema;
- string? tableName = _testConfiguration.Metadata.Table;
- string? columnName = null;
-
- AdbcConnection adbcConnection =
BigQueryTestingUtils.GetBigQueryAdbcConnection(_testConfiguration);
-
- IArrowArrayStream stream = adbcConnection.GetObjects(
- depth: AdbcConnection.GetObjectsDepth.All,
- catalogPattern: catalogName,
- dbSchemaPattern: schemaName,
- tableNamePattern: tableName,
- tableTypes: BigQueryTableTypes.TableTypes,
- columnNamePattern: columnName);
-
- RecordBatch recordBatch = stream.ReadNextRecordBatchAsync().Result;
-
- List<AdbcCatalog> catalogs =
GetObjectsParser.ParseCatalog(recordBatch, schemaName);
-
- List<AdbcColumn>? columns = catalogs
- .Select(s => s.DbSchemas)
- .FirstOrDefault()
- ?.Select(t => t.Tables)
- .FirstOrDefault()
- ?.Select(c => c.Columns)
- .FirstOrDefault();
-
- Assert.Equal(_testConfiguration.Metadata.ExpectedColumnCount,
columns?.Count);
+ foreach (BigQueryTestEnvironment environment in _environments)
+ {
+ // need to add the database
+ string? catalogName = environment.Metadata.Catalog;
+ string? schemaName = environment.Metadata.Schema;
+ string? tableName = environment.Metadata.Table;
+ string? columnName = null;
+
+ AdbcConnection adbcConnection =
GetAdbcConnection(environment.Name);
+
+ IArrowArrayStream stream = adbcConnection.GetObjects(
+ depth: AdbcConnection.GetObjectsDepth.All,
+ catalogPattern: catalogName,
+ dbSchemaPattern: schemaName,
+ tableNamePattern: tableName,
+ tableTypes: BigQueryTableTypes.TableTypes,
+ columnNamePattern: columnName);
+
+ RecordBatch recordBatch =
stream.ReadNextRecordBatchAsync().Result;
+
+ List<AdbcCatalog> catalogs =
GetObjectsParser.ParseCatalog(recordBatch, schemaName);
+
+ List<AdbcColumn>? columns = catalogs
+ .Select(s => s.DbSchemas)
+ .FirstOrDefault()
+ ?.Select(t => t.Tables)
+ .FirstOrDefault()
+ ?.Select(c => c.Columns)
+ .FirstOrDefault();
+
+ Assert.Equal(environment.Metadata.ExpectedColumnCount,
columns?.Count);
+ }
}
[SkippableFact, Order(3)]
public void CanGetObjectsTables()
{
- string? catalogName = _testConfiguration.Metadata.Catalog;
- string? schemaName = _testConfiguration.Metadata.Schema;
- string? tableName = _testConfiguration.Metadata.Table;
-
- AdbcConnection adbcConnection =
BigQueryTestingUtils.GetBigQueryAdbcConnection(_testConfiguration);
-
- IArrowArrayStream stream = adbcConnection.GetObjects(
- depth: AdbcConnection.GetObjectsDepth.Tables,
- catalogPattern: catalogName,
- dbSchemaPattern: schemaName,
- tableNamePattern: null,
- tableTypes: BigQueryTableTypes.TableTypes,
- columnNamePattern: null);
-
- RecordBatch recordBatch = stream.ReadNextRecordBatchAsync().Result;
-
- List<AdbcCatalog> catalogs =
GetObjectsParser.ParseCatalog(recordBatch, schemaName);
-
- List<AdbcTable>? tables = catalogs
- .Where(c => string.Equals(c.Name, catalogName))
- .Select(c => c.DbSchemas)
- .FirstOrDefault()
- ?.Where(s => string.Equals(s.Name, schemaName))
- .Select(s => s.Tables)
- .FirstOrDefault();
-
- AdbcTable? table = tables?.Where((table) =>
string.Equals(table.Name, tableName)).FirstOrDefault();
- Assert.True(table != null, "table should not be null");
- Assert.Equal("BASE TABLE", table.Type);
+ foreach (BigQueryTestEnvironment environment in _environments)
+ {
+ string? catalogName = environment.Metadata.Catalog;
+ string? schemaName = environment.Metadata.Schema;
+ string? tableName = environment.Metadata.Table;
+
+ AdbcConnection adbcConnection =
GetAdbcConnection(environment.Name);
+
+ IArrowArrayStream stream = adbcConnection.GetObjects(
+ depth: AdbcConnection.GetObjectsDepth.Tables,
+ catalogPattern: catalogName,
+ dbSchemaPattern: schemaName,
+ tableNamePattern: null,
+ tableTypes: BigQueryTableTypes.TableTypes,
+ columnNamePattern: null);
+
+ RecordBatch recordBatch =
stream.ReadNextRecordBatchAsync().Result;
+
+ List<AdbcCatalog> catalogs =
GetObjectsParser.ParseCatalog(recordBatch, schemaName);
+
+ List<AdbcTable>? tables = catalogs
+ .Where(c => string.Equals(c.Name, catalogName))
+ .Select(c => c.DbSchemas)
+ .FirstOrDefault()
+ ?.Where(s => string.Equals(s.Name, schemaName))
+ .Select(s => s.Tables)
+ .FirstOrDefault();
+
+ AdbcTable? table = tables?.Where((table) =>
string.Equals(table.Name, tableName)).FirstOrDefault();
+ Assert.True(table != null, "table should not be null in the
[" + environment.Name + "] environment");
+ Assert.Equal("BASE TABLE", table.Type);
+ }
}
/// <summary>
@@ -204,17 +228,20 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
[SkippableFact, Order(4)]
public void CanGetTableSchema()
{
- AdbcConnection adbcConnection =
BigQueryTestingUtils.GetBigQueryAdbcConnection(_testConfiguration);
+ foreach (BigQueryTestEnvironment environment in _environments)
+ {
+ AdbcConnection adbcConnection =
GetAdbcConnection(environment.Name);
- string? catalogName = _testConfiguration.Metadata.Catalog;
- string? schemaName = _testConfiguration.Metadata.Schema;
- string tableName = _testConfiguration.Metadata.Table;
+ string? catalogName = environment.Metadata.Catalog;
+ string? schemaName = environment.Metadata.Schema;
+ string tableName = environment.Metadata.Table;
- Schema schema = adbcConnection.GetTableSchema(catalogName,
schemaName, tableName);
+ Schema schema = adbcConnection.GetTableSchema(catalogName,
schemaName, tableName);
- int numberOfFields = schema.FieldsList.Count;
+ int numberOfFields = schema.FieldsList.Count;
- Assert.Equal(_testConfiguration.Metadata.ExpectedColumnCount,
numberOfFields);
+ Assert.Equal(environment.Metadata.ExpectedColumnCount,
numberOfFields);
+ }
}
/// <summary>
@@ -223,29 +250,32 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
[SkippableFact, Order(5)]
public void CanGetTableTypes()
{
- AdbcConnection adbcConnection =
BigQueryTestingUtils.GetBigQueryAdbcConnection(_testConfiguration);
-
- IArrowArrayStream arrowArrayStream =
adbcConnection.GetTableTypes();
+ foreach (BigQueryTestEnvironment environment in _environments)
+ {
+ AdbcConnection adbcConnection =
GetAdbcConnection(environment.Name);
- RecordBatch recordBatch =
arrowArrayStream.ReadNextRecordBatchAsync().Result;
+ IArrowArrayStream arrowArrayStream =
adbcConnection.GetTableTypes();
- StringArray stringArray =
(StringArray)recordBatch.Column("table_type");
+ RecordBatch recordBatch =
arrowArrayStream.ReadNextRecordBatchAsync().Result;
- List<string> known_types = BigQueryTableTypes.TableTypes.ToList();
+ StringArray stringArray =
(StringArray)recordBatch.Column("table_type");
- int results = 0;
+ List<string> known_types =
BigQueryTableTypes.TableTypes.ToList();
- for (int i = 0; i < stringArray.Length; i++)
- {
- string value = stringArray.GetString(i);
+ int results = 0;
- if (known_types.Contains(value))
+ for (int i = 0; i < stringArray.Length; i++)
{
- results++;
+ string value = stringArray.GetString(i);
+
+ if (known_types.Contains(value))
+ {
+ results++;
+ }
}
- }
- Assert.Equal(known_types.Count, results);
+ Assert.Equal(known_types.Count, results);
+ }
}
/// <summary>
@@ -255,14 +285,27 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
[SkippableFact, Order(6)]
public void CanExecuteQuery()
{
- AdbcConnection adbcConnection =
BigQueryTestingUtils.GetBigQueryAdbcConnection(_testConfiguration);
+ foreach (BigQueryTestEnvironment environment in _environments)
+ {
+ AdbcConnection adbcConnection =
GetAdbcConnection(environment.Name);
+
+ AdbcStatement statement = adbcConnection.CreateStatement();
+ statement.SqlQuery = environment.Query;
+
+ QueryResult queryResult = statement.ExecuteQuery();
- AdbcStatement statement = adbcConnection.CreateStatement();
- statement.SqlQuery = _testConfiguration.Query;
+ Tests.DriverTests.CanExecuteQuery(queryResult,
environment.ExpectedResultsCount, environment.Name);
+ }
+ }
- QueryResult queryResult = statement.ExecuteQuery();
+ private AdbcConnection GetAdbcConnection(string? environmentName)
+ {
+ if (string.IsNullOrEmpty(environmentName))
+ {
+ throw new ArgumentNullException(nameof(environmentName));
+ }
- Tests.DriverTests.CanExecuteQuery(queryResult,
_testConfiguration.ExpectedResultsCount);
+ return _configuredConnections[environmentName!];
}
}
}
diff --git a/csharp/test/Drivers/BigQuery/Resources/bigqueryconfig.json
b/csharp/test/Drivers/BigQuery/Resources/bigqueryconfig.json
index 960bcb868..01cbe84f4 100644
--- a/csharp/test/Drivers/BigQuery/Resources/bigqueryconfig.json
+++ b/csharp/test/Drivers/BigQuery/Resources/bigqueryconfig.json
@@ -1,15 +1,35 @@
{
- "projectId": "",
- "clientId": "",
- "clientSecret": "",
- "refreshToken": "",
- "maxStreamCount": 1,
- "metadata": {
- "catalog": "",
- "schema": "",
- "table": "",
- "expectedColumnCount": 0
- },
- "query": "",
- "expectedResults": 0
+ "testEnvironments": [ "", "" ],
+ "environments": {
+ "<env1>": {
+ "projectId": "",
+ "clientId": "",
+ "clientSecret": "",
+ "refreshToken": "",
+ "maxStreamCount": 1,
+ "metadata": {
+ "catalog": "",
+ "schema": "",
+ "table": "",
+ "expectedColumnCount": 0
+ },
+ "query": "",
+ "expectedResults": 0
+ },
+ "<env2>": {
+ "projectId": "",
+ "clientId": "",
+ "clientSecret": "",
+ "refreshToken": "",
+ "maxStreamCount": 1,
+ "metadata": {
+ "catalog": "",
+ "schema": "",
+ "table": "",
+ "expectedColumnCount": 0
+ },
+ "query": "",
+ "expectedResults": 0
+ }
+ }
}
diff --git a/csharp/test/Drivers/Interop/FlightSql/ClientTests.cs
b/csharp/test/Drivers/Interop/FlightSql/ClientTests.cs
index 7dc8c4409..47b76af4e 100644
--- a/csharp/test/Drivers/Interop/FlightSql/ClientTests.cs
+++ b/csharp/test/Drivers/Interop/FlightSql/ClientTests.cs
@@ -39,14 +39,13 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.FlightSql
{
readonly FlightSqlTestConfiguration _testConfiguration;
readonly List<FlightSqlTestEnvironment> _environments;
- readonly Dictionary<string, AdbcDriver> _configuredDrivers = new
Dictionary<string, AdbcDriver>();
readonly ITestOutputHelper _outputHelper;
public ClientTests(ITestOutputHelper outputHelper)
{
Skip.IfNot(Utils.CanExecuteTestConfig(FlightSqlTestingUtils.FLIGHTSQL_INTEROP_TEST_CONFIG_VARIABLE));
- _testConfiguration =
FlightSqlTestingUtils.LoadFlightSqlTestConfiguration(FlightSqlTestingUtils.FLIGHTSQL_INTEROP_TEST_CONFIG_VARIABLE);
- _environments =
FlightSqlTestingUtils.GetTestEnvironments(_testConfiguration);
+ _testConfiguration =
MultiEnvironmentTestUtils.LoadMultiEnvironmentTestConfiguration<FlightSqlTestConfiguration>(FlightSqlTestingUtils.FLIGHTSQL_INTEROP_TEST_CONFIG_VARIABLE);
+ _environments =
MultiEnvironmentTestUtils.GetTestEnvironments<FlightSqlTestEnvironment>(_testConfiguration);
_outputHelper = outputHelper;
}
diff --git a/csharp/test/Drivers/Interop/FlightSql/DriverTests.cs
b/csharp/test/Drivers/Interop/FlightSql/DriverTests.cs
index bc3ea53ef..46a0a7a9f 100644
--- a/csharp/test/Drivers/Interop/FlightSql/DriverTests.cs
+++ b/csharp/test/Drivers/Interop/FlightSql/DriverTests.cs
@@ -66,8 +66,8 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.FlightSql
public DriverTests(ITestOutputHelper outputHelper)
{
Skip.IfNot(Utils.CanExecuteTestConfig(FlightSqlTestingUtils.FLIGHTSQL_INTEROP_TEST_CONFIG_VARIABLE));
- _testConfiguration =
FlightSqlTestingUtils.LoadFlightSqlTestConfiguration();
- _environments =
FlightSqlTestingUtils.GetTestEnvironments(_testConfiguration);
+ _testConfiguration =
MultiEnvironmentTestUtils.LoadMultiEnvironmentTestConfiguration<FlightSqlTestConfiguration>(FlightSqlTestingUtils.FLIGHTSQL_INTEROP_TEST_CONFIG_VARIABLE);
+ _environments =
MultiEnvironmentTestUtils.GetTestEnvironments<FlightSqlTestEnvironment>(_testConfiguration);
_outputHelper = outputHelper;
foreach (FlightSqlTestEnvironment environment in _environments)
diff --git
a/csharp/test/Drivers/Interop/FlightSql/FlightSqlTestConfiguration.cs
b/csharp/test/Drivers/Interop/FlightSql/FlightSqlTestConfiguration.cs
index 73422fd46..971fa9163 100644
--- a/csharp/test/Drivers/Interop/FlightSql/FlightSqlTestConfiguration.cs
+++ b/csharp/test/Drivers/Interop/FlightSql/FlightSqlTestConfiguration.cs
@@ -20,7 +20,7 @@ using System.Text.Json.Serialization;
namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.FlightSql
{
- internal class FlightSqlTestConfiguration
+ internal class FlightSqlTestConfiguration :
MultiEnvironmentTestConfiguration<FlightSqlTestEnvironment>
{
/// <summary>
/// The file path location of the driver.
@@ -33,18 +33,6 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.FlightSql
/// </summary>
[JsonPropertyName("driverEntryPoint")]
public string? DriverEntryPoint { get; set; }
-
- /// <summary>
- /// A comma separated list of testable environments.
- /// </summary>
- [JsonPropertyName("testEnvironments")]
- public List<string> TestableEnvironments { get; set; } = new
List<string>();
-
- /// <summary>
- /// The active test environment.
- /// </summary>
- [JsonPropertyName("environments")]
- public Dictionary<string, FlightSqlTestEnvironment> Environments {
get; set; } = new Dictionary<string, FlightSqlTestEnvironment>();
}
internal enum FlightSqlTestEnvironmentType
@@ -62,11 +50,6 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.FlightSql
}
- /// <summary>
- /// The name of the environment.
- /// </summary>
- public string? Name { get; set; }
-
[JsonConverter(typeof(JsonStringEnumConverter))]
[JsonPropertyName("type")]
public FlightSqlTestEnvironmentType EnvironmentType { get; set; }
diff --git a/csharp/test/Drivers/Interop/FlightSql/FlightSqlTestingUtils.cs
b/csharp/test/Drivers/Interop/FlightSql/FlightSqlTestingUtils.cs
index f874ee56c..22fde0ce0 100644
--- a/csharp/test/Drivers/Interop/FlightSql/FlightSqlTestingUtils.cs
+++ b/csharp/test/Drivers/Interop/FlightSql/FlightSqlTestingUtils.cs
@@ -29,70 +29,6 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.FlightSql
{
internal const string FLIGHTSQL_INTEROP_TEST_CONFIG_VARIABLE =
"FLIGHTSQL_INTEROP_TEST_CONFIG_FILE";
- public static FlightSqlTestConfiguration
LoadFlightSqlTestConfiguration(string? environmentVariable = null)
- {
- if(string.IsNullOrEmpty(environmentVariable))
- environmentVariable = FLIGHTSQL_INTEROP_TEST_CONFIG_VARIABLE;
-
- FlightSqlTestConfiguration? testConfiguration = null;
-
- if (!string.IsNullOrWhiteSpace(environmentVariable))
- {
- string? environmentValue =
Environment.GetEnvironmentVariable(environmentVariable);
-
- if (!string.IsNullOrWhiteSpace(environmentValue))
- {
- if (File.Exists(environmentValue))
- {
- // use a JSON file for the various settings
- string json = File.ReadAllText(environmentValue);
-
- testConfiguration =
JsonSerializer.Deserialize<FlightSqlTestConfiguration>(json)!;
- }
- }
- }
-
- if (testConfiguration == null)
- throw new InvalidOperationException($"Cannot execute test
configuration from environment variable `{environmentVariable}`");
-
- return testConfiguration;
- }
-
- internal static List<FlightSqlTestEnvironment>
GetTestEnvironments(FlightSqlTestConfiguration testConfiguration)
- {
- if (testConfiguration == null)
- throw new ArgumentNullException(nameof(testConfiguration));
-
- if (testConfiguration.Environments == null ||
testConfiguration.Environments.Count == 0)
- throw new InvalidOperationException("There are no environments
configured");
-
- List<FlightSqlTestEnvironment> environments = new
List<FlightSqlTestEnvironment>();
-
- foreach (string environmentName in
GetEnvironmentNames(testConfiguration.TestableEnvironments!))
- {
- if
(testConfiguration.Environments.TryGetValue(environmentName, out
FlightSqlTestEnvironment? flightSqlTestEnvironment))
- {
- if (flightSqlTestEnvironment != null)
- {
- flightSqlTestEnvironment.Name = environmentName;
- environments.Add(flightSqlTestEnvironment);
- }
- }
- }
-
- if (environments.Count == 0)
- throw new InvalidOperationException("Could not find a
configured Flight SQL environment");
-
- return environments;
- }
-
- private static List<string> GetEnvironmentNames(List<string> names)
- {
- if (names == null)
- return new List<string>();
-
- return names;
- }
/// <summary>
/// Gets a the Snowflake ADBC driver with settings from the