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 3828e0bc feat(csharp/src/Drivers/BigQuery): add override for excluding 
table constraints (#1512)
3828e0bc is described below

commit 3828e0bccef9525de9be4eb71dffbd9764f2e145
Author: davidhcoe <[email protected]>
AuthorDate: Sun Feb 4 21:33:57 2024 -0500

    feat(csharp/src/Drivers/BigQuery): add override for excluding table 
constraints (#1512)
    
    - Adds a new parameter value to exclude the additional calls to obtain
    table constraints
    - Fixes some common nits about spacing
    
    ---------
    
    Co-authored-by: David Coe <[email protected]>
---
 csharp/src/Client/AdbcColumn.cs                      |  2 +-
 csharp/src/Client/AdbcCommand.cs                     |  6 +++---
 csharp/src/Client/AdbcDataReader.cs                  |  6 +++---
 csharp/src/Client/SchemaConverter.cs                 |  2 +-
 csharp/src/Drivers/BigQuery/BigQueryConnection.cs    | 18 ++++++++++++++++--
 csharp/src/Drivers/BigQuery/BigQueryParameters.cs    |  1 +
 csharp/src/Drivers/BigQuery/BigQueryStatement.cs     |  4 ++--
 csharp/src/Drivers/BigQuery/readme.md                |  8 ++++++--
 .../Interop/Snowflake/SnowflakeDriverLoader.cs       |  2 +-
 .../Drivers/BigQuery/BigQueryTestConfiguration.cs    |  4 ++++
 csharp/test/Drivers/BigQuery/BigQueryTestingUtils.cs |  6 ++++--
 csharp/test/Drivers/BigQuery/ClientTests.cs          | 20 +++++++++++++++++++-
 12 files changed, 61 insertions(+), 18 deletions(-)

diff --git a/csharp/src/Client/AdbcColumn.cs b/csharp/src/Client/AdbcColumn.cs
index 426fad43..154e0484 100644
--- a/csharp/src/Client/AdbcColumn.cs
+++ b/csharp/src/Client/AdbcColumn.cs
@@ -59,7 +59,7 @@ namespace Apache.Arrow.Adbc.Client
             this.DataType = dataType;
             this.ArrowType = arrowType;
 
-            if(precision.HasValue && scale.HasValue)
+            if (precision.HasValue && scale.HasValue)
             {
                 this.NumericScale = scale.Value;
                 this.NumericPrecision = precision.Value;
diff --git a/csharp/src/Client/AdbcCommand.cs b/csharp/src/Client/AdbcCommand.cs
index 2fcf6c30..e9906813 100644
--- a/csharp/src/Client/AdbcCommand.cs
+++ b/csharp/src/Client/AdbcCommand.cs
@@ -42,10 +42,10 @@ namespace Apache.Arrow.Adbc.Client
         /// <exception cref="ArgumentNullException"></exception>
         public AdbcCommand(AdbcStatement adbcStatement, AdbcConnection 
adbcConnection) : base()
         {
-            if(adbcStatement == null)
+            if (adbcStatement == null)
                 throw new ArgumentNullException(nameof(adbcStatement));
 
-            if(adbcConnection == null)
+            if (adbcConnection == null)
                 throw new ArgumentNullException(nameof(adbcConnection));
 
             this.adbcStatement = adbcStatement;
@@ -183,7 +183,7 @@ namespace Apache.Arrow.Adbc.Client
 
         protected override void Dispose(bool disposing)
         {
-            if(disposing)
+            if (disposing)
             {
                 // TODO: ensure not in the middle of pulling
                 this.adbcStatement?.Dispose();
diff --git a/csharp/src/Client/AdbcDataReader.cs 
b/csharp/src/Client/AdbcDataReader.cs
index c58adc45..552ae812 100644
--- a/csharp/src/Client/AdbcDataReader.cs
+++ b/csharp/src/Client/AdbcDataReader.cs
@@ -217,7 +217,7 @@ namespace Apache.Arrow.Adbc.Client
             if (value == null)
                 return null;
 
-            if(value is SqlDecimal dValue)
+            if (value is SqlDecimal dValue)
             {
                 if (this.DecimalBehavior == DecimalBehavior.UseSqlDecimal)
                 {
@@ -317,7 +317,7 @@ namespace Apache.Arrow.Adbc.Client
                 {
                     Type t = SchemaConverter.ConvertArrowType(f, 
this.DecimalBehavior);
 
-                    if(f.HasMetadata &&
+                    if (f.HasMetadata &&
                        f.Metadata.ContainsKey("precision") &&
                        f.Metadata.ContainsKey("scale"))
                     {
@@ -361,7 +361,7 @@ namespace Apache.Arrow.Adbc.Client
 
             RecordBatch recordBatch = 
this.adbcQueryResult.Stream.ReadNextRecordBatchAsync(cancellationToken).Result;
 
-            if( recordBatch != null )
+            if (recordBatch != null)
             {
                 this.TotalBatches += 1;
             }
diff --git a/csharp/src/Client/SchemaConverter.cs 
b/csharp/src/Client/SchemaConverter.cs
index 0573e224..38863417 100644
--- a/csharp/src/Client/SchemaConverter.cs
+++ b/csharp/src/Client/SchemaConverter.cs
@@ -34,7 +34,7 @@ namespace Apache.Arrow.Adbc.Client
         /// <exception cref="ArgumentNullException"></exception>
         public static DataTable ConvertArrowSchema(Schema schema, 
AdbcStatement adbcStatement, DecimalBehavior decimalBehavior)
         {
-            if(schema == null)
+            if (schema == null)
                 throw new ArgumentNullException(nameof(schema));
 
             if (adbcStatement == null)
diff --git a/csharp/src/Drivers/BigQuery/BigQueryConnection.cs 
b/csharp/src/Drivers/BigQuery/BigQueryConnection.cs
index a06b72eb..44b11f54 100644
--- a/csharp/src/Drivers/BigQuery/BigQueryConnection.cs
+++ b/csharp/src/Drivers/BigQuery/BigQueryConnection.cs
@@ -427,6 +427,13 @@ namespace Apache.Arrow.Adbc.Drivers.BigQuery
 
             if (result != null)
             {
+                bool includeConstraints = true;
+
+                if 
(this.properties.TryGetValue(BigQueryParameters.IncludeConstraintsWithGetObjects,
 out string includeConstraintsValue))
+                {
+                    bool.TryParse(includeConstraintsValue, out 
includeConstraints);
+                }
+
                 foreach (BigQueryRow row in result)
                 {
                     tableNameBuilder.Append(GetValue(row["table_name"]));
@@ -434,8 +441,15 @@ namespace Apache.Arrow.Adbc.Drivers.BigQuery
                     nullBitmapBuffer.Append(true);
                     length++;
 
-                    tableConstraintsValues.Add(GetConstraintSchema(
-                        depth, catalog, dbSchema, GetValue(row["table_name"]), 
columnNamePattern));
+                    if (includeConstraints)
+                    {
+                        tableConstraintsValues.Add(GetConstraintSchema(
+                            depth, catalog, dbSchema, 
GetValue(row["table_name"]), columnNamePattern));
+                    }
+                    else
+                    {
+                        tableConstraintsValues.Add(null);
+                    }
 
                     if (depth == GetObjectsDepth.Tables)
                     {
diff --git a/csharp/src/Drivers/BigQuery/BigQueryParameters.cs 
b/csharp/src/Drivers/BigQuery/BigQueryParameters.cs
index ff57ea8f..0f812910 100644
--- a/csharp/src/Drivers/BigQuery/BigQueryParameters.cs
+++ b/csharp/src/Drivers/BigQuery/BigQueryParameters.cs
@@ -33,6 +33,7 @@ namespace Apache.Arrow.Adbc.Drivers.BigQuery
         public const string UseLegacySQL = "adbc.bigquery.use_legacy_sql";
         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";
     }
 
     /// <summary>
diff --git a/csharp/src/Drivers/BigQuery/BigQueryStatement.cs 
b/csharp/src/Drivers/BigQuery/BigQueryStatement.cs
index f4f21740..f901e75b 100644
--- a/csharp/src/Drivers/BigQuery/BigQueryStatement.cs
+++ b/csharp/src/Drivers/BigQuery/BigQueryStatement.cs
@@ -199,14 +199,14 @@ namespace Apache.Arrow.Adbc.Drivers.BigQuery
 
                     string[] segments = destinationTable.Split('.');
 
-                    if(segments.Length != 3)
+                    if (segments.Length != 3)
                         throw new 
InvalidOperationException($"{BigQueryParameters.LargeResultsDestinationTable} 
cannot be parsed");
 
                     projectId = segments[0];
                     datasetId = segments[1];
                     tableId = segments[2];
 
-                    if(string.IsNullOrEmpty(projectId.Trim()) || 
string.IsNullOrEmpty(datasetId.Trim()) || string.IsNullOrEmpty(tableId.Trim()))
+                    if (string.IsNullOrEmpty(projectId.Trim()) || 
string.IsNullOrEmpty(datasetId.Trim()) || string.IsNullOrEmpty(tableId.Trim()))
                         throw new 
InvalidOperationException($"{BigQueryParameters.LargeResultsDestinationTable} 
contains invalid values");
 
                     options.DestinationTable = new TableReference()
diff --git a/csharp/src/Drivers/BigQuery/readme.md 
b/csharp/src/Drivers/BigQuery/readme.md
index 847513c4..c9cad190 100644
--- a/csharp/src/Drivers/BigQuery/readme.md
+++ b/csharp/src/Drivers/BigQuery/readme.md
@@ -32,6 +32,8 @@ The ADBC driver passes the configured credentials to 
BigQuery, but you may need
 
 ## Parameters
 
+The following parameters can be used to configure the driver behavior. The 
parameters are case sensitive.
+
 **adbc.bigquery.allow_large_results**<br>
 &nbsp;&nbsp;&nbsp;&nbsp;Sets the 
[AllowLargeResults](https://cloud.google.com/dotnet/docs/reference/Google.Cloud.BigQuery.V2/latest/Google.Cloud.BigQuery.V2.QueryOptions#Google_Cloud_BigQuery_V2_QueryOptions_AllowLargeResults)
 value of the QueryOptions to `true` if configured; otherwise, the default is 
`false`.
 
@@ -49,9 +51,11 @@ 
https://cloud.google.com/dotnet/docs/reference/Google.Cloud.BigQuery.V2/latest/G
 **adbc.bigquery.auth_json_credential**<br>
 &nbsp;&nbsp;&nbsp;&nbsp;Required if using `service` authentication. This value 
is passed to the 
[GoogleCredential.FromJson](https://cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential#Google_Apis_Auth_OAuth2_GoogleCredential_FromJson_System_String)
 method.
 
-**adbc.bigquery.large_results_destination_table**<br>
-&nbsp;&nbsp;&nbsp;&nbsp;Sets the 
[DestinationTable](https://cloud.google.com/dotnet/docs/reference/Google.Cloud.BigQuery.V2/latest/Google.Cloud.BigQuery.V2.QueryOptions#Google_Cloud_BigQuery_V2_QueryOptions_DestinationTable)
 value of the QueryOptions if configured. Expects the format to be 
`{projectId}.{datasetId}.{tableId}` to set the corresponding values in the 
[TableReference](https://github.com/googleapis/google-api-dotnet-client/blob/6c415c73788b848711e47c6dd33c2f93c76faf97/Src/Gene
 [...]
+**adbc.bigquery.include_constraints_getobjects**<br>
+&nbsp;&nbsp;&nbsp;&nbsp;Optional. Some callers do not need the constraint 
details when they get the table information and can improve the speed of 
obtaining the results. Setting this value to `"false"` will not include the 
constraint details. The default value is `"true"`.
 
+**adbc.bigquery.large_results_destination_table**<br>
+&nbsp;&nbsp;&nbsp;&nbsp;Optional. Sets the 
[DestinationTable](https://cloud.google.com/dotnet/docs/reference/Google.Cloud.BigQuery.V2/latest/Google.Cloud.BigQuery.V2.QueryOptions#Google_Cloud_BigQuery_V2_QueryOptions_DestinationTable)
 value of the QueryOptions if configured. Expects the format to be 
`{projectId}.{datasetId}.{tableId}` to set the corresponding values in the 
[TableReference](https://github.com/googleapis/google-api-dotnet-client/blob/6c415c73788b848711e47c6dd33c2f93c76faf9
 [...]
 
 **adbc.bigquery.project_id**<br>
 &nbsp;&nbsp;&nbsp;&nbsp;The [Project 
ID](https://cloud.google.com/resource-manager/docs/creating-managing-projects) 
used for accessing BigQuery.
diff --git a/csharp/src/Drivers/Interop/Snowflake/SnowflakeDriverLoader.cs 
b/csharp/src/Drivers/Interop/Snowflake/SnowflakeDriverLoader.cs
index c2d247d7..2719ac59 100644
--- a/csharp/src/Drivers/Interop/Snowflake/SnowflakeDriverLoader.cs
+++ b/csharp/src/Drivers/Interop/Snowflake/SnowflakeDriverLoader.cs
@@ -34,7 +34,7 @@ namespace Apache.Arrow.Adbc.Drivers.Interop.Snowflake
         {
             string file = "libadbc_driver_snowflake.dll";
 
-            if(File.Exists(file))
+            if (File.Exists(file))
             {
                 // get the full path because some .NET versions need it
                 file = Path.GetFullPath(file);
diff --git a/csharp/test/Drivers/BigQuery/BigQueryTestConfiguration.cs 
b/csharp/test/Drivers/BigQuery/BigQueryTestConfiguration.cs
index a7a56229..69066979 100644
--- a/csharp/test/Drivers/BigQuery/BigQueryTestConfiguration.cs
+++ b/csharp/test/Drivers/BigQuery/BigQueryTestConfiguration.cs
@@ -27,6 +27,7 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
         public BigQueryTestConfiguration()
         {
             AllowLargeResults = false;
+            IncludeTableConstraints = true;
         }
 
         [JsonPropertyName("projectId")]
@@ -52,5 +53,8 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
 
         [JsonPropertyName("largeResultsDestinationTable")]
         public string LargeResultsDestinationTable { get; set; }
+
+        [JsonPropertyName("includeTableConstraints")]
+        public bool IncludeTableConstraints { get; set; }
     }
 }
diff --git a/csharp/test/Drivers/BigQuery/BigQueryTestingUtils.cs 
b/csharp/test/Drivers/BigQuery/BigQueryTestingUtils.cs
index ffca233c..a323ae46 100644
--- a/csharp/test/Drivers/BigQuery/BigQueryTestingUtils.cs
+++ b/csharp/test/Drivers/BigQuery/BigQueryTestingUtils.cs
@@ -74,12 +74,14 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
                 parameters.Add(BigQueryParameters.Scopes, 
testConfiguration.Scopes);
             }
 
-            if(testConfiguration.AllowLargeResults)
+            if (testConfiguration.AllowLargeResults)
             {
                 parameters.Add(BigQueryParameters.AllowLargeResults, 
testConfiguration.AllowLargeResults.ToString());
             }
 
-            
if(!string.IsNullOrEmpty(testConfiguration.LargeResultsDestinationTable))
+            
parameters.Add(BigQueryParameters.IncludeConstraintsWithGetObjects, 
testConfiguration.IncludeTableConstraints.ToString());
+
+            if 
(!string.IsNullOrEmpty(testConfiguration.LargeResultsDestinationTable))
             {
                 
parameters.Add(BigQueryParameters.LargeResultsDestinationTable, 
testConfiguration.LargeResultsDestinationTable);
             }
diff --git a/csharp/test/Drivers/BigQuery/ClientTests.cs 
b/csharp/test/Drivers/BigQuery/ClientTests.cs
index 94b28833..efd976d3 100644
--- a/csharp/test/Drivers/BigQuery/ClientTests.cs
+++ b/csharp/test/Drivers/BigQuery/ClientTests.cs
@@ -100,6 +100,22 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
             }
         }
 
+        [SkippableFact]
+        public void VerifySchemaTablesWithNoConstraints()
+        {
+            using (Adbc.Client.AdbcConnection adbcConnection = 
GetAdbcConnection(includeTableConstraints: false))
+            {
+                adbcConnection.Open();
+
+                string schema = "Tables";
+
+                var tables = adbcConnection.GetSchema(schema);
+
+                Assert.True(tables.Rows.Count > 0, $"No tables were found in 
the schema '{schema}'");
+            }
+        }
+
+
         [SkippableFact]
         public void VerifySchemaTables()
         {
@@ -166,8 +182,10 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
             }
         }
 
-        private Adbc.Client.AdbcConnection GetAdbcConnection()
+        private Adbc.Client.AdbcConnection GetAdbcConnection(bool 
includeTableConstraints = true)
         {
+            _testConfiguration.IncludeTableConstraints = 
includeTableConstraints;
+
             return new Adbc.Client.AdbcConnection(
                 new BigQueryDriver(),
                 BigQueryTestingUtils.GetBigQueryParameters(_testConfiguration),

Reply via email to