Skip to content

Commit d1d06be

Browse files
author
David Coe
committed
bug fix for Time conversion; run code clean up on both of the projects that were part of the bug fix
1 parent a353b96 commit d1d06be

File tree

5 files changed

+16
-18
lines changed

5 files changed

+16
-18
lines changed

csharp/src/Apache.Arrow.Adbc/C/CAdbcDriverImporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ public unsafe override Schema GetParameterSchema()
10101010
#else
10111011
Marshal.GetDelegateForFunctionPointer<StatementGetParameterSchema>(Driver.StatementGetParameterSchema)
10121012
#endif
1013-
(statement, caller.CreateSchema(), & caller._error));
1013+
(statement, caller.CreateSchema(), &caller._error));
10141014
}
10151015
return caller.ImportSchema();
10161016
}

csharp/src/Apache.Arrow.Adbc/Extensions/IArrowArrayExtensions.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,20 @@ public static class IArrowArrayExtensions
111111
#else
112112
case ArrowTypeId.Time32:
113113
Time32Array time32Array = (Time32Array)arrowArray;
114-
int? time32 = time32Array.GetValue(index);
115-
if (time32 == null) { return null; }
114+
if (time32Array.IsNull(index)) { return null; }
116115
return ((Time32Type)time32Array.Data.DataType).Unit switch
117116
{
118-
TimeUnit.Second => TimeSpan.FromSeconds(time32.Value),
119-
TimeUnit.Millisecond => TimeSpan.FromMilliseconds(time32.Value),
117+
TimeUnit.Second => TimeSpan.FromSeconds(time32Array.GetSeconds(index)!.Value),
118+
TimeUnit.Millisecond => TimeSpan.FromMilliseconds(time32Array.GetMilliSeconds(index)!.Value),
120119
_ => throw new InvalidDataException("Unsupported time unit for Time32Type")
121120
};
122121
case ArrowTypeId.Time64:
123122
Time64Array time64Array = (Time64Array)arrowArray;
124-
long? time64 = time64Array.GetValue(index);
125-
if (time64 == null) { return null; }
123+
if (time64Array.IsNull(index)) { return null; }
126124
return ((Time64Type)time64Array.Data.DataType).Unit switch
127125
{
128-
TimeUnit.Microsecond => TimeSpan.FromTicks(time64.Value * 10),
129-
TimeUnit.Nanosecond => TimeSpan.FromTicks(time64.Value / 100),
126+
TimeUnit.Microsecond => TimeSpan.FromTicks(time64Array.GetMicroSeconds(index)!.Value * 10),
127+
TimeUnit.Nanosecond => TimeSpan.FromTicks(time64Array.GetNanoSeconds(index)!.Value / 100),
130128
_ => throw new InvalidDataException("Unsupported time unit for Time64Type")
131129
};
132130
#endif
@@ -257,9 +255,9 @@ public static class IArrowArrayExtensions
257255
switch (time64Type.Unit)
258256
{
259257
case TimeUnit.Microsecond:
260-
return (array, index) => array.IsNull(index) ? null : TimeSpan.FromTicks(((Time64Array)array).GetValue(index)!.Value * 10);
258+
return (array, index) => array.IsNull(index) ? null : TimeSpan.FromTicks(((Time64Array)array).GetMicroSeconds(index)!.Value * 10);
261259
case TimeUnit.Nanosecond:
262-
return (array, index) => array.IsNull(index) ? null : TimeSpan.FromTicks(((Time64Array)array).GetValue(index)!.Value / 100);
260+
return (array, index) => array.IsNull(index) ? null : TimeSpan.FromTicks(((Time64Array)array).GetNanoSeconds(index)!.Value / 100);
263261
default:
264262
throw new InvalidDataException("Unsupported time unit for Time64Type");
265263
}

csharp/src/Apache.Arrow.Adbc/Extensions/MarshalExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717

1818
using System;
19-
using System.Diagnostics.CodeAnalysis;
2019
using System.Runtime.InteropServices;
2120
using System.Text;
2221

csharp/src/Client/AdbcParameter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
* limitations under the License.
1616
*/
1717

18-
using System.Data.Common;
18+
using System;
1919
using System.Data;
20+
using System.Data.Common;
2021
using System.Diagnostics.CodeAnalysis;
21-
using System;
2222

2323
namespace Apache.Arrow.Adbc.Client
2424
{

csharp/src/Client/SchemaConverter.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public static DataTable ConvertArrowSchema(Schema schema, AdbcStatement adbcStat
8989
row[SchemaTableColumn.NumericPrecision] = decimal32Type.Precision;
9090
row[SchemaTableColumn.NumericScale] = decimal32Type.Scale;
9191
}
92-
else if (f.DataType is Decimal128Type decimal64Type)
92+
else if (f.DataType is Decimal64Type decimal64Type)
9393
{
9494
row[SchemaTableColumn.NumericPrecision] = decimal64Type.Precision;
9595
row[SchemaTableColumn.NumericScale] = decimal64Type.Scale;
@@ -194,7 +194,7 @@ public static Type GetArrowType(Field f, DecimalBehavior decimalBehavior, Struct
194194
return typeof(string);
195195

196196
case ArrowTypeId.Struct:
197-
return structBehavior == StructBehavior.JsonString ? typeof(string) : typeof(Dictionary<string, object?>);
197+
return structBehavior == StructBehavior.JsonString ? typeof(string) : typeof(Dictionary<string, object?>);
198198

199199
case ArrowTypeId.Timestamp:
200200
return typeof(DateTimeOffset);
@@ -203,7 +203,8 @@ public static Type GetArrowType(Field f, DecimalBehavior decimalBehavior, Struct
203203
return typeof(DBNull);
204204

205205
case ArrowTypeId.Interval:
206-
switch (((IntervalType)f.DataType).Unit) {
206+
switch (((IntervalType)f.DataType).Unit)
207+
{
207208
case IntervalUnit.MonthDayNanosecond:
208209
return typeof(MonthDayNanosecondInterval);
209210
case IntervalUnit.DayTime:
@@ -227,7 +228,7 @@ public static Type GetArrowArrayType(IArrowType dataType)
227228
case ArrowTypeId.Boolean:
228229
return typeof(BooleanArray);
229230
case ArrowTypeId.Decimal128:
230-
return typeof(Decimal128Array);
231+
return typeof(Decimal128Array);
231232
case ArrowTypeId.Decimal256:
232233
return typeof(Decimal256Array);
233234
case ArrowTypeId.Time32:

0 commit comments

Comments
 (0)