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 a5fd4c54 fix(csharp/src/Drivers/BigQuery): Add JSON support (#1308)
a5fd4c54 is described below

commit a5fd4c54580c9bf1bb7dfbe1fd8b0b46324fe0f3
Author: davidhcoe <[email protected]>
AuthorDate: Mon Nov 20 11:50:10 2023 -0500

    fix(csharp/src/Drivers/BigQuery): Add JSON support (#1308)
    
    Fixes https://github.com/apache/arrow-adbc/issues/1307
    
    ---------
    
    Co-authored-by: David Coe <[email protected]>
---
 csharp/src/Drivers/BigQuery/BigQueryConnection.cs | 6 +++---
 csharp/src/Drivers/BigQuery/BigQueryStatement.cs  | 5 ++---
 csharp/test/Drivers/BigQuery/BigQueryData.cs      | 7 +++++--
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/csharp/src/Drivers/BigQuery/BigQueryConnection.cs 
b/csharp/src/Drivers/BigQuery/BigQueryConnection.cs
index 6d2378a5..d1a91e70 100644
--- a/csharp/src/Drivers/BigQuery/BigQueryConnection.cs
+++ b/csharp/src/Drivers/BigQuery/BigQueryConnection.cs
@@ -667,7 +667,7 @@ namespace Apache.Arrow.Adbc.Drivers.BigQuery
                     return XdbcDataType.XdbcDataType_XDBC_FLOAT;
                 case "BOOL" or "BOOLEAN":
                     return XdbcDataType.XdbcDataType_XDBC_BIT;
-                case "STRING":
+                case "STRING" or "GEOGRAPHY" or "JSON":
                     return XdbcDataType.XdbcDataType_XDBC_VARCHAR;
                 case "BYTES":
                     return XdbcDataType.XdbcDataType_XDBC_BINARY;
@@ -748,7 +748,7 @@ namespace Apache.Arrow.Adbc.Drivers.BigQuery
                     return fieldBuilder.DataType(DoubleType.Default);
                 case "BOOL" or "BOOLEAN":
                     return fieldBuilder.DataType(BooleanType.Default);
-                case "STRING" or "GEOGRAPHY":
+                case "STRING" or "GEOGRAPHY" or "JSON":
                     return fieldBuilder.DataType(StringType.Default);
                 case "BYTES":
                     return fieldBuilder.DataType(BinaryType.Default);
@@ -784,7 +784,7 @@ namespace Apache.Arrow.Adbc.Drivers.BigQuery
                     string arrayType = 
type.Substring(dataType.Length).Replace("<", "").Replace(">", "");
                     return GetFieldBuilder(name, type, arrayType, index);
 
-                default: throw new InvalidOperationException();
+                default: throw new InvalidOperationException($"{dataType} 
cannot be handled");
             }
         }
 
diff --git a/csharp/src/Drivers/BigQuery/BigQueryStatement.cs 
b/csharp/src/Drivers/BigQuery/BigQueryStatement.cs
index c82d6d31..1c5347ef 100644
--- a/csharp/src/Drivers/BigQuery/BigQueryStatement.cs
+++ b/csharp/src/Drivers/BigQuery/BigQueryStatement.cs
@@ -129,7 +129,7 @@ namespace Apache.Arrow.Adbc.Drivers.BigQuery
                     return StringType.Default;
 
                 // treat these values as strings
-                case "GEOGRAPHY":
+                case "GEOGRAPHY" or "JSON":
                     return StringType.Default;
 
                 // get schema cannot get precision and scale for NUMERIC or 
BIGNUMERIC types
@@ -143,8 +143,7 @@ namespace Apache.Arrow.Adbc.Drivers.BigQuery
                 case "BIGNUMERIC" or "BIGDECIMAL":
                     return 
bool.Parse(this.Options[BigQueryParameters.LargeDecimalsAsString]) ? 
StringType.Default : new Decimal256Type(76, 38);
 
-                // Google.Apis.Bigquery.v2.Data.TableFieldSchema do not 
include Array and Geography in types
-                default: throw new InvalidOperationException();
+                default: throw new InvalidOperationException($"{field.Type} 
cannot be translated");
             }
         }
 
diff --git a/csharp/test/Drivers/BigQuery/BigQueryData.cs 
b/csharp/test/Drivers/BigQuery/BigQueryData.cs
index 8ee5a1c2..2a39fcab 100644
--- a/csharp/test/Drivers/BigQuery/BigQueryData.cs
+++ b/csharp/test/Drivers/BigQuery/BigQueryData.cs
@@ -56,7 +56,8 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
                             "CAST('2023-09-08 12:34:56+00:00' as TIMESTAMP) as 
timestamp, " +
                             "ST_GEOGPOINT(1, 2) as point, " +
                             "ARRAY[1, 2, 3] as numbers, " +
-                            "STRUCT('John Doe' as name, 30 as age) as person",
+                            "STRUCT('John Doe' as name, 30 as age) as person," 
+
+                            "PARSE_JSON('{\"name\":\"Jane Doe\",\"age\":29}') 
as json",
                     ExpectedValues = new List<ColumnNetTypeArrowTypeValue>()
                     {
                         new ColumnNetTypeArrowTypeValue("id", typeof(long), 
typeof(Int64Type), 1L),
@@ -76,7 +77,9 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
                         new ColumnNetTypeArrowTypeValue("timestamp", 
typeof(DateTimeOffset), typeof(TimestampType), new DateTimeOffset(new 
DateTime(2023, 9, 8, 12, 34, 56), TimeSpan.Zero)),
                         new ColumnNetTypeArrowTypeValue("point", 
typeof(string), typeof(StringType), "POINT(1 2)"),
                         new ColumnNetTypeArrowTypeValue("numbers", 
typeof(long), typeof(Int64Type), numbersArray),
-                        new ColumnNetTypeArrowTypeValue("person", 
typeof(string), typeof(StringType), "{\"name\":\"John Doe\",\"age\":30}")
+                        new ColumnNetTypeArrowTypeValue("person", 
typeof(string), typeof(StringType), "{\"name\":\"John Doe\",\"age\":30}"),
+                        new ColumnNetTypeArrowTypeValue("json", 
typeof(string), typeof(StringType), "{\"age\":29,\"name\":\"Jane Doe\"}")
+
                     }
                 });
 

Reply via email to