birschick-bq commented on code in PR #2152:
URL: https://github.com/apache/arrow-adbc/pull/2152#discussion_r1774210140
##########
csharp/src/Drivers/Apache/Hive2/HiveServer2Reader.cs:
##########
@@ -78,6 +105,55 @@ static IArrowArray GetArray(TColumn column)
(IArrowArray?)column.StringVal?.Values ??
(IArrowArray?)column.BinaryVal?.Values ??
throw new InvalidOperationException("unsupported data type");
+ if (expectedArrowType != null && arrowArray is StringArray
stringArray && s_arrowStringConverters.ContainsKey(expectedArrowType.TypeId))
+ {
+ // Perform a conversion from string to native/scalar type.
+ Func<StringArray, IArrowType, IArrowArray> converter =
s_arrowStringConverters[expectedArrowType.TypeId];
+ return converter(stringArray, expectedArrowType);
+ }
+ return arrowArray;
+ }
+
+ private static Date32Array ConvertToDate32(StringArray array,
IArrowType _)
+ {
+ var resultArray = new Date32Array.Builder();
+ foreach (string item in (IReadOnlyCollection<string>)array)
+ {
+ resultArray.Append(DateTime.Parse(item));
+ }
+
+ return resultArray.Build();
+ }
+
+ private static Decimal128Array ConvertToDecimal128(StringArray array,
IArrowType schemaType)
+ {
+ // Using the schema type to get the precision and scale.
+ var resultArray = new
Decimal128Array.Builder((Decimal128Type)schemaType);
+ foreach (string item in (IReadOnlyList<string>)array)
+ {
+ // Trying to parse the value into a decimal to handle the
exponent syntax. But this might overflow.
+ if (decimal.TryParse(item, NumberStyles.Float,
CultureInfo.InvariantCulture, out decimal decimalValue))
+ {
+ resultArray.Append(new SqlDecimal(decimalValue));
+ }
+ else
+ {
+ resultArray.Append(item);
+ }
+ }
+ return resultArray.Build();
+ }
+
+ private static TimestampArray ConvertToTimestamp(StringArray array,
IArrowType _)
+ {
+ // Match the precision of the server
+ var resultArrayBuiilder = new
TimestampArray.Builder(TimeUnit.Microsecond);
Review Comment:
fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]