birschick-bq commented on code in PR #2152:
URL: https://github.com/apache/arrow-adbc/pull/2152#discussion_r1774219431


##########
csharp/src/Drivers/Apache/Hive2/HiveServer2Reader.cs:
##########
@@ -78,6 +107,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))

Review Comment:
   Since both `decimal.TryParse` and `Hive2.DecimalUtility.GetBytes` both 
support exponent notation. The key take away is that `decimal.TryParse` is 
significantly better performing (i.e., 5-times) than the alternative. It is 
worth the hit/failure if most of the data can be handled by `decimal.TryParse`.



-- 
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]

Reply via email to