From 4f633b40a3310926450e7ff512d88bf1235dcb68 Mon Sep 17 00:00:00 2001 From: David Coe Date: Tue, 24 Sep 2024 19:11:06 -0400 Subject: [PATCH] add support for IntervalType --- csharp/src/Apache.Arrow.Adbc/AdbcStatement.cs | 8 +++++++- csharp/src/Client/SchemaConverter.cs | 12 ++++++++++++ ...Arrow.Adbc.Tests.Drivers.Interop.FlightSql.csproj | 2 +- .../test/Drivers/Interop/FlightSql/FlightSqlData.cs | 6 ++---- .../Interop/FlightSql/FlightSqlTestingUtils.cs | 2 -- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/csharp/src/Apache.Arrow.Adbc/AdbcStatement.cs b/csharp/src/Apache.Arrow.Adbc/AdbcStatement.cs index 1fbd28c1a6..cbc688c594 100644 --- a/csharp/src/Apache.Arrow.Adbc/AdbcStatement.cs +++ b/csharp/src/Apache.Arrow.Adbc/AdbcStatement.cs @@ -241,7 +241,12 @@ public virtual void Dispose() return uInt32Array.GetValue(index); case UInt64Array uInt64Array: return uInt64Array.GetValue(index); - + case DayTimeIntervalArray dayTimeIntervalArray: + return dayTimeIntervalArray.GetValue(index); + case MonthDayNanosecondIntervalArray monthDayNanosecondIntervalArray: + return monthDayNanosecondIntervalArray.GetValue(index); + case YearMonthIntervalArray yearMonthIntervalArray: + return yearMonthIntervalArray.GetValue(index); case BinaryArray binaryArray: if (!binaryArray.IsNull(index)) return binaryArray.GetBytes(index).ToArray(); @@ -250,6 +255,7 @@ public virtual void Dispose() // not covered: // -- struct array + // -- map array // -- dictionary array // -- fixed size binary // -- list array diff --git a/csharp/src/Client/SchemaConverter.cs b/csharp/src/Client/SchemaConverter.cs index 1d43207b2b..c0e4a97618 100644 --- a/csharp/src/Client/SchemaConverter.cs +++ b/csharp/src/Client/SchemaConverter.cs @@ -19,6 +19,7 @@ using System.Data; using System.Data.Common; using System.Data.SqlTypes; +using Apache.Arrow.Scalars; using Apache.Arrow.Types; namespace Apache.Arrow.Adbc.Client @@ -190,6 +191,17 @@ public static Type GetArrowType(Field f, DecimalBehavior decimalBehavior) case ArrowTypeId.Null: return typeof(DBNull); + case ArrowTypeId.Interval: + switch (((IntervalType)f.DataType).Unit) { + case IntervalUnit.MonthDayNanosecond: + return typeof(MonthDayNanosecondInterval); + case IntervalUnit.DayTime: + return typeof(DayTimeInterval); + case IntervalUnit.YearMonth: + return typeof(YearMonthInterval); + } + goto default; + default: return f.DataType.GetType(); } diff --git a/csharp/test/Drivers/Interop/FlightSql/Apache.Arrow.Adbc.Tests.Drivers.Interop.FlightSql.csproj b/csharp/test/Drivers/Interop/FlightSql/Apache.Arrow.Adbc.Tests.Drivers.Interop.FlightSql.csproj index 25b4f81628..6fa1d7e736 100644 --- a/csharp/test/Drivers/Interop/FlightSql/Apache.Arrow.Adbc.Tests.Drivers.Interop.FlightSql.csproj +++ b/csharp/test/Drivers/Interop/FlightSql/Apache.Arrow.Adbc.Tests.Drivers.Interop.FlightSql.csproj @@ -5,7 +5,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/csharp/test/Drivers/Interop/FlightSql/FlightSqlData.cs b/csharp/test/Drivers/Interop/FlightSql/FlightSqlData.cs index 017ffb1623..e8d0b823d0 100644 --- a/csharp/test/Drivers/Interop/FlightSql/FlightSqlData.cs +++ b/csharp/test/Drivers/Interop/FlightSql/FlightSqlData.cs @@ -19,6 +19,7 @@ using System.Collections.Generic; using System.Data.SqlTypes; using System.Text; +using Apache.Arrow.Scalars; using Apache.Arrow.Types; namespace Apache.Arrow.Adbc.Tests.Drivers.Interop.FlightSql @@ -85,10 +86,7 @@ public static SampleDataBuilder GetSampleData() new ColumnNetTypeArrowTypeValue("Time", typeof(TimeSpan), typeof(Time64Type), new TimeSpan(12, 34, 56)), #endif new ColumnNetTypeArrowTypeValue("Timestamp", typeof(DateTimeOffset), typeof(TimestampType), new DateTimeOffset(new DateTime(2024, 9, 10, 12, 34, 56), TimeSpan.Zero)), - - // despite a value specified, this is coming back as null from the client call - new ColumnNetTypeArrowTypeValue("Interval", typeof(IntervalType), typeof(IntervalType), null), - + new ColumnNetTypeArrowTypeValue("Interval", typeof(MonthDayNanosecondInterval), typeof(IntervalType), new MonthDayNanosecondInterval(12, 0, 0)), new ColumnNetTypeArrowTypeValue("JSON", typeof(string), typeof(StringType), "[1, 2, 3]"), new ColumnNetTypeArrowTypeValue("JSON_Array", typeof(string), typeof(StringType), "[{\"key\": \"value\"}]"), diff --git a/csharp/test/Drivers/Interop/FlightSql/FlightSqlTestingUtils.cs b/csharp/test/Drivers/Interop/FlightSql/FlightSqlTestingUtils.cs index 6fbe9761bf..6d66ad6f9e 100644 --- a/csharp/test/Drivers/Interop/FlightSql/FlightSqlTestingUtils.cs +++ b/csharp/test/Drivers/Interop/FlightSql/FlightSqlTestingUtils.cs @@ -131,8 +131,6 @@ private void TrySetFlightSqlEnvironment(string? environmentName) { if (string.IsNullOrEmpty(environmentName)) return; - - } ///