You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by dh...@apache.org on 2023/07/21 20:42:50 UTC

[arrow-datafusion] 01/01: Speedup scalar_to_array for decimal

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

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

commit 5c7e47d96765f2c86760a90c684b9d234a0b999e
Author: Daniƫl Heres <da...@coralogix.com>
AuthorDate: Fri Jul 21 22:42:38 2023 +0200

    Speedup scalar_to_array for decimal
---
 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.