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 4b9eec49 feat(csharp): Translate time to either TimeSpan or TimeOnly 
(#1293)
4b9eec49 is described below

commit 4b9eec49173affc391dd3b1002a41f4f3faa205f
Author: Curt Hagenlocher <[email protected]>
AuthorDate: Tue Nov 14 08:52:40 2023 -0800

    feat(csharp): Translate time to either TimeSpan or TimeOnly (#1293)
---
 csharp/src/Apache.Arrow.Adbc/AdbcStatement.cs  | 27 ++++++++++++++++++++++++--
 csharp/src/Client/SchemaConverter.cs           |  8 +++++++-
 csharp/test/Drivers/BigQuery/BigQueryData.cs   | 12 ++++++++++--
 csharp/test/Drivers/Snowflake/SnowflakeData.cs | 12 ++++++++++--
 4 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/csharp/src/Apache.Arrow.Adbc/AdbcStatement.cs 
b/csharp/src/Apache.Arrow.Adbc/AdbcStatement.cs
index 0f537257..9e42544e 100644
--- a/csharp/src/Apache.Arrow.Adbc/AdbcStatement.cs
+++ b/csharp/src/Apache.Arrow.Adbc/AdbcStatement.cs
@@ -16,8 +16,10 @@
  */
 
 using System;
+using System.IO;
 using System.Threading.Tasks;
 using Apache.Arrow.Ipc;
+using Apache.Arrow.Types;
 
 namespace Apache.Arrow.Adbc
 {
@@ -181,10 +183,31 @@ namespace Apache.Arrow.Adbc
                     return int64Array.GetValue(index);
                 case StringArray stringArray:
                     return stringArray.GetString(index);
+#if NET6_0_OR_GREATER
                 case Time32Array time32Array:
-                    return time32Array.GetValue(index);
+                    return time32Array.GetTime(index);
                 case Time64Array time64Array:
-                    return time64Array.GetValue(index);
+                    return time64Array.GetTime(index);
+#else
+                case Time32Array time32Array:
+                    int? time32 = time32Array.GetValue(index);
+                    if (time32 == null) { return null; }
+                    return ((Time32Type)time32Array.Data.DataType).Unit switch
+                    {
+                        TimeUnit.Second => TimeSpan.FromSeconds(time32.Value),
+                        TimeUnit.Millisecond => 
TimeSpan.FromMilliseconds(time32.Value),
+                        _ => throw new InvalidDataException("Unsupported time 
unit for Time32Type")
+                    };
+                case Time64Array time64Array:
+                    long? time64 = time64Array.GetValue(index);
+                    if (time64 == null) { return null; }
+                    return ((Time64Type)time64Array.Data.DataType).Unit switch
+                    {
+                        TimeUnit.Microsecond => 
TimeSpan.FromTicks(time64.Value * 10),
+                        TimeUnit.Nanosecond => TimeSpan.FromTicks(time64.Value 
/ 100),
+                        _ => throw new InvalidDataException("Unsupported time 
unit for Time64Type")
+                    };
+#endif
                 case TimestampArray timestampArray:
                     return timestampArray.GetTimestamp(index);
                 case UInt8Array uInt8Array:
diff --git a/csharp/src/Client/SchemaConverter.cs 
b/csharp/src/Client/SchemaConverter.cs
index 7f6d1712..0c13bb47 100644
--- a/csharp/src/Client/SchemaConverter.cs
+++ b/csharp/src/Client/SchemaConverter.cs
@@ -110,9 +110,15 @@ namespace Apache.Arrow.Adbc.Client
                 case ArrowTypeId.Decimal256:
                     return typeof(string);
 
+#if NET6_0_OR_GREATER
                 case ArrowTypeId.Time32:
                 case ArrowTypeId.Time64:
-                    return typeof(long);
+                    return typeof(TimeOnly);
+#else
+                case ArrowTypeId.Time32:
+                case ArrowTypeId.Time64:
+                    return typeof(TimeSpan);
+#endif
 
                 case ArrowTypeId.Date32:
                 case ArrowTypeId.Date64:
diff --git a/csharp/test/Drivers/BigQuery/BigQueryData.cs 
b/csharp/test/Drivers/BigQuery/BigQueryData.cs
index 2ab54d8b..8ee5a1c2 100644
--- a/csharp/test/Drivers/BigQuery/BigQueryData.cs
+++ b/csharp/test/Drivers/BigQuery/BigQueryData.cs
@@ -67,7 +67,11 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
                         new ColumnNetTypeArrowTypeValue("name", 
typeof(string), typeof(StringType), "John Doe"),
                         new ColumnNetTypeArrowTypeValue("data", 
typeof(byte[]), typeof(BinaryType), UTF8Encoding.UTF8.GetBytes("abc123")),
                         new ColumnNetTypeArrowTypeValue("date", 
typeof(DateTime), typeof(Date64Type), new DateTime(2023, 9, 8)),
-                        new ColumnNetTypeArrowTypeValue("time", typeof(long), 
typeof(Time64Type), 45296000000L), //'12:34:56'
+#if NET6_0_OR_GREATER
+                        new ColumnNetTypeArrowTypeValue("time", 
typeof(TimeOnly), typeof(Time64Type), new TimeOnly(12, 34, 56)), //'12:34:56'
+#else
+                        new ColumnNetTypeArrowTypeValue("time", 
typeof(TimeSpan), typeof(Time64Type), new TimeSpan(12, 34, 56)),
+#endif
                         new ColumnNetTypeArrowTypeValue("datetime", 
typeof(DateTimeOffset), typeof(TimestampType), new DateTimeOffset(new 
DateTime(2023, 9, 8, 12, 34, 56), TimeSpan.Zero)),
                         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)"),
@@ -124,7 +128,11 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.BigQuery
                         new ColumnNetTypeArrowTypeValue("name", 
typeof(string), typeof(StringType), null),
                         new ColumnNetTypeArrowTypeValue("data", 
typeof(byte[]), typeof(BinaryType), null),
                         new ColumnNetTypeArrowTypeValue("date", 
typeof(DateTime), typeof(Date64Type), null),
-                        new ColumnNetTypeArrowTypeValue("time", typeof(long), 
typeof(Time64Type), null),
+#if NET6_0_OR_GREATER
+                        new ColumnNetTypeArrowTypeValue("time", 
typeof(TimeOnly), typeof(Time64Type), null),
+#else
+                        new ColumnNetTypeArrowTypeValue("time", 
typeof(TimeSpan), typeof(Time64Type), null),
+#endif
                         new ColumnNetTypeArrowTypeValue("datetime", 
typeof(DateTimeOffset), typeof(TimestampType), null),
                         new ColumnNetTypeArrowTypeValue("timestamp", 
typeof(DateTimeOffset), typeof(TimestampType), null),
                         new ColumnNetTypeArrowTypeValue("point", 
typeof(string), typeof(StringType), null),
diff --git a/csharp/test/Drivers/Snowflake/SnowflakeData.cs 
b/csharp/test/Drivers/Snowflake/SnowflakeData.cs
index c695d967..da73432e 100644
--- a/csharp/test/Drivers/Snowflake/SnowflakeData.cs
+++ b/csharp/test/Drivers/Snowflake/SnowflakeData.cs
@@ -97,7 +97,11 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.Snowflake
                         new ColumnNetTypeArrowTypeValue("BOOLEANTYPE", 
typeof(bool), typeof(BooleanType), true),
                         new ColumnNetTypeArrowTypeValue("DATETYPE", 
typeof(DateTime), typeof(Date32Type), new DateTime(2023, 7, 28)),
                         new ColumnNetTypeArrowTypeValue("DATETIMETYPE", 
typeof(DateTimeOffset), typeof(TimestampType), new DateTimeOffset(new 
DateTime(2023,7,28, 12,34,56), TimeSpan.Zero)),
-                        new ColumnNetTypeArrowTypeValue("TIMETYPE", 
typeof(long), typeof(Time64Type), 45296000000000L),
+#if NET6_0_OR_GREATER
+                        new ColumnNetTypeArrowTypeValue("TIMETYPE", 
typeof(TimeOnly), typeof(Time64Type), new TimeOnly(12, 34, 56)),
+#else
+                        new ColumnNetTypeArrowTypeValue("TIMETYPE", 
typeof(TimeSpan), typeof(Time64Type), new TimeSpan(12, 34, 56)),
+#endif
                         new ColumnNetTypeArrowTypeValue("TIMESTAMPTYPE", 
typeof(DateTimeOffset), typeof(TimestampType), new DateTimeOffset(new 
DateTime(2023,7,28,12,34,56), TimeSpan.Zero)),
                         new ColumnNetTypeArrowTypeValue("TIMESTAMPLTZTYPE", 
typeof(DateTimeOffset), typeof(TimestampType), new DateTimeOffset(new 
DateTime(2023,7,28,19,34,56), TimeSpan.Zero)),
                         new ColumnNetTypeArrowTypeValue("TIMESTAMPNTZTYPE", 
typeof(DateTimeOffset), typeof(TimestampType), new DateTimeOffset(new 
DateTime(2023,7,28, 12,34,56), TimeSpan.Zero)),
@@ -137,7 +141,11 @@ namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.Snowflake
                         new ColumnNetTypeArrowTypeValue("BINARYTYPE", 
typeof(byte[]), typeof(BinaryType),  null),
                         new ColumnNetTypeArrowTypeValue("BOOLEANTYPE", 
typeof(bool), typeof(BooleanType), null),
                         new ColumnNetTypeArrowTypeValue("DATETYPE", 
typeof(DateTime), typeof(Date32Type), null),
-                        new ColumnNetTypeArrowTypeValue("TIMETYPE", 
typeof(long), typeof(Time64Type), null),
+#if NET6_0_OR_GREATER
+                        new ColumnNetTypeArrowTypeValue("TIMETYPE", 
typeof(TimeOnly), typeof(Time64Type), null),
+#else
+                        new ColumnNetTypeArrowTypeValue("TIMETYPE", 
typeof(TimeSpan), typeof(Time64Type), null),
+#endif
                         new ColumnNetTypeArrowTypeValue("TIMESTAMPTYPE", 
typeof(DateTimeOffset), typeof(TimestampType), null),
                         new ColumnNetTypeArrowTypeValue("TIMESTAMPLTZTYPE", 
typeof(DateTimeOffset), typeof(TimestampType), null),
                         new ColumnNetTypeArrowTypeValue("TIMESTAMPNTZTYPE", 
typeof(DateTimeOffset), typeof(TimestampType), null),

Reply via email to