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

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


The following commit(s) were added to refs/heads/main by this push:
     new fa30489692 perf: use `new_repeated` when converting scalar to an array 
(#19018)
fa30489692 is described below

commit fa30489692f2372f8d009b541452a218d0e2be54
Author: Raz Luvaton <[email protected]>
AuthorDate: Mon Dec 1 21:17:26 2025 +0200

    perf: use `new_repeated` when converting scalar to an array (#19018)
    
    ## Which issue does this PR close?
    
    N/A
    
    ## Rationale for this change
    
    new_repeated is much faster than the iterator itself
    
    ## What changes are included in this PR?
    
    use `new_repeated` when convert scalar to array for
    Utf8/LargeUtf8/Binary/LargeBinary
    
    ## Are these changes tested?
    Existing tests
    
    ## Are there any user-facing changes?
    
    Nope
---
 datafusion/common/src/scalar/mod.rs | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/datafusion/common/src/scalar/mod.rs 
b/datafusion/common/src/scalar/mod.rs
index 229225b46c..2eb7e970df 100644
--- a/datafusion/common/src/scalar/mod.rs
+++ b/datafusion/common/src/scalar/mod.rs
@@ -3022,9 +3022,7 @@ impl ScalarValue {
                 )
             }
             ScalarValue::Utf8(e) => match e {
-                Some(value) => {
-                    Arc::new(StringArray::from_iter_values(repeat_n(value, 
size)))
-                }
+                Some(value) => Arc::new(StringArray::new_repeated(value, 
size)),
                 None => new_null_array(&DataType::Utf8, size),
             },
             ScalarValue::Utf8View(e) => match e {
@@ -3034,15 +3032,13 @@ impl ScalarValue {
                 None => new_null_array(&DataType::Utf8View, size),
             },
             ScalarValue::LargeUtf8(e) => match e {
-                Some(value) => {
-                    
Arc::new(LargeStringArray::from_iter_values(repeat_n(value, size)))
-                }
+                Some(value) => Arc::new(LargeStringArray::new_repeated(value, 
size)),
                 None => new_null_array(&DataType::LargeUtf8, size),
             },
             ScalarValue::Binary(e) => match e {
-                Some(value) => Arc::new(
-                    repeat_n(Some(value.as_slice()), 
size).collect::<BinaryArray>(),
-                ),
+                Some(value) => {
+                    Arc::new(BinaryArray::new_repeated(value.as_slice(), size))
+                }
                 None => new_null_array(&DataType::Binary, size),
             },
             ScalarValue::BinaryView(e) => match e {
@@ -3069,9 +3065,9 @@ impl ScalarValue {
                 }
             },
             ScalarValue::LargeBinary(e) => match e {
-                Some(value) => Arc::new(
-                    repeat_n(Some(value.as_slice()), 
size).collect::<LargeBinaryArray>(),
-                ),
+                Some(value) => {
+                    Arc::new(LargeBinaryArray::new_repeated(value.as_slice(), 
size))
+                }
                 None => new_null_array(&DataType::LargeBinary, size),
             },
             ScalarValue::List(arr) => {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to