Skip to content

Commit 6390185

Browse files
author
David Coe
committed
change to Time64Type.Microsecond
1 parent b14f498 commit 6390185

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
lines changed

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

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
/*
2-
* Licensed to the Apache Software Foundation (ASF) under one or more
3-
* contributor license agreements. See the NOTICE file distributed with
4-
* this work for additional information regarding copyright ownership.
5-
* The ASF licenses this file to You under the Apache License, Version 2.0
6-
* (the "License"); you may not use this file except in compliance with
7-
* the License. You may obtain a copy of the License at
8-
*
9-
* http://www.apache.org/licenses/LICENSE-2.0
10-
*
11-
* Unless required by applicable law or agreed to in writing, software
12-
* distributed under the License is distributed on an "AS IS" BASIS,
13-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
* See the License for the specific language governing permissions and
15-
* limitations under the License.
16-
*/
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
1717

1818
using System;
1919
using System.Collections;
@@ -111,20 +111,22 @@ public static class IArrowArrayExtensions
111111
#else
112112
case ArrowTypeId.Time32:
113113
Time32Array time32Array = (Time32Array)arrowArray;
114-
if (time32Array.IsNull(index)) { return null; }
114+
int? time32 = time32Array.GetValue(index);
115+
if (time32 == null) { return null; }
115116
return ((Time32Type)time32Array.Data.DataType).Unit switch
116117
{
117-
TimeUnit.Second => TimeSpan.FromSeconds(time32Array.GetSeconds(index)!.Value),
118-
TimeUnit.Millisecond => TimeSpan.FromMilliseconds(time32Array.GetMilliSeconds(index)!.Value),
118+
TimeUnit.Second => TimeSpan.FromSeconds(time32.Value),
119+
TimeUnit.Millisecond => TimeSpan.FromMilliseconds(time32.Value),
119120
_ => throw new InvalidDataException("Unsupported time unit for Time32Type")
120121
};
121122
case ArrowTypeId.Time64:
122123
Time64Array time64Array = (Time64Array)arrowArray;
123-
if (time64Array.IsNull(index)) { return null; }
124+
long? time64 = time64Array.GetValue(index);
125+
if (time64 == null) { return null; }
124126
return ((Time64Type)time64Array.Data.DataType).Unit switch
125127
{
126-
TimeUnit.Microsecond => TimeSpan.FromTicks(time64Array.GetMicroSeconds(index)!.Value * 10),
127-
TimeUnit.Nanosecond => TimeSpan.FromTicks(time64Array.GetNanoSeconds(index)!.Value / 100),
128+
TimeUnit.Microsecond => TimeSpan.FromTicks(time64.Value * 10),
129+
TimeUnit.Nanosecond => TimeSpan.FromTicks(time64.Value / 100),
128130
_ => throw new InvalidDataException("Unsupported time unit for Time64Type")
129131
};
130132
#endif
@@ -244,9 +246,9 @@ public static class IArrowArrayExtensions
244246
switch (time32Type.Unit)
245247
{
246248
case TimeUnit.Second:
247-
return (array, index) => array.IsNull(index) ? null : TimeSpan.FromSeconds(((Time32Array)array).GetSeconds(index)!.Value);
249+
return (array, index) => array.IsNull(index) ? null : TimeSpan.FromSeconds(((Time32Array)array).GetValue(index)!.Value);
248250
case TimeUnit.Millisecond:
249-
return (array, index) => array.IsNull(index) ? null : TimeSpan.FromMilliseconds(((Time32Array)array).GetMilliSeconds(index)!.Value);
251+
return (array, index) => array.IsNull(index) ? null : TimeSpan.FromMilliseconds(((Time32Array)array).GetValue(index)!.Value);
250252
default:
251253
throw new InvalidDataException("Unsupported time unit for Time32Type");
252254
}
@@ -255,7 +257,7 @@ public static class IArrowArrayExtensions
255257
switch (time64Type.Unit)
256258
{
257259
case TimeUnit.Microsecond:
258-
return (array, index) => array.IsNull(index) ? null : TimeSpan.FromTicks(((Time64Array)array).GetMicroSeconds(index)!.Value * 10);
260+
return (array, index) => array.IsNull(index) ? null : TimeSpan.FromTicks(((Time64Array)array).GetValue(index)!.Value * 10);
259261
case TimeUnit.Nanosecond:
260262
return (array, index) => array.IsNull(index) ? null : TimeSpan.FromTicks(((Time64Array)array).GetValue(index)!.Value / 100);
261263
default:

csharp/src/Drivers/BigQuery/BigQueryConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ private Field.Builder GetFieldBuilder(string name, string type, string dataType,
967967
case "TIMESTAMP":
968968
return fieldBuilder.DataType(TimestampType.Default);
969969
case "TIME":
970-
return fieldBuilder.DataType(Time64Type.Default);
970+
return fieldBuilder.DataType(Time64Type.Microsecond);
971971
case "DATE":
972972
return fieldBuilder.DataType(Date32Type.Default);
973973
case "RECORD" or "STRUCT":

csharp/src/Drivers/BigQuery/BigQueryStatement.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ private IArrowType TranslateType(TableFieldSchema field)
192192
case "TIMESTAMP":
193193
return GetType(field, TimestampType.Default);
194194
case "TIME":
195-
return GetType(field, Time64Type.Default);
195+
return GetType(field, Time64Type.Microsecond);
196196
case "DATE":
197197
return GetType(field, Date32Type.Default);
198198
case "RECORD" or "STRUCT":

0 commit comments

Comments
 (0)