You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@auron.apache.org by "Sigma-Ma (via GitHub)" <gi...@apache.org> on 2026/09/01 06:47:26 UTC

Re: [PR] [AURON #2475] Fix float-to-decimal precision loss [auron]

Sigma-Ma commented on code in PR #2496:
URL: https://github.com/apache/auron/pull/2496#discussion_r3901466346


##########
native-engine/datafusion-ext-commons/src/arrow/cast.rs:
##########
@@ -223,6 +223,21 @@ pub fn cast_impl(
         (&DataType::Utf8, DataType::Decimal128(..)) => {
             arrow::compute::kernels::cast::cast(&to_plain_string_array(array), cast_type)?
         }
+        // spark compatible float to decimal
+        (&DataType::Float32, DataType::Decimal128(..))
+        | (&DataType::Float64, DataType::Decimal128(..)) => {
+            let floats = arrow::compute::cast(array, &DataType::Float64)?;
+            let strings = floats
+                .as_primitive::<Float64Type>()
+                .iter()
+                .map(|value| {
+                    value
+                        .filter(|value| value.is_finite())
+                        .map(|value| value.to_string())
+                })
+                .collect::<StringArray>();
+            cast_impl(&strings, cast_type, match_struct_fields)?
+        }

Review Comment:
   Updated the comment to explain the shortest round-trip conversion, exact decimal rescaling, and non-finite-to-NULL behavior.



-- 
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: commits-unsubscribe@auron.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org