This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new 466b6c3193 Speedup scalar_to_array for decimal (#7055)
466b6c3193 is described below

commit 466b6c319326c84f74ef37e8ecea85151e779fa1
Author: Daniël Heres <[email protected]>
AuthorDate: Sat Jul 22 18:15:55 2023 +0200

    Speedup scalar_to_array for decimal (#7055)
    
    Co-authored-by: Daniël Heres <[email protected]>
---
 datafusion/common/src/scalar.rs | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/datafusion/common/src/scalar.rs b/datafusion/common/src/scalar.rs
index 2011247346..99ff5f3384 100644
--- a/datafusion/common/src/scalar.rs
+++ b/datafusion/common/src/scalar.rs
@@ -2750,11 +2750,18 @@ impl ScalarValue {
         scale: i8,
         size: usize,
     ) -> Decimal128Array {
-        std::iter::repeat(value)
-            .take(size)
-            .collect::<Decimal128Array>()
-            .with_precision_and_scale(precision, scale)
-            .unwrap()
+        match value {
+            Some(val) => Decimal128Array::from(vec![val; size])
+                .with_precision_and_scale(precision, scale)
+                .unwrap(),
+            None => {
+                let mut builder = Decimal128Array::builder(size)
+                    .with_precision_and_scale(precision, scale)
+                    .unwrap();
+                builder.append_nulls(size);
+                builder.finish()
+            }
+        }
     }
 
     /// Converts a scalar value into an array of `size` rows.

Reply via email to