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

wayne 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 59bfe773b6 fix: fix string repeat for negative numbers (#10760)
59bfe773b6 is described below

commit 59bfe773b61c8bcc83a89502221f849fc12def23
Author: Trent Hauck <[email protected]>
AuthorDate: Sun Jun 2 20:33:56 2024 -0700

    fix: fix string repeat for negative numbers (#10760)
    
    * fix: fix string repeat for negative numbers
    
    * style: run cargo fmt
---
 datafusion/functions/src/string/repeat.rs   | 5 ++++-
 datafusion/sqllogictest/test_files/expr.slt | 5 +++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/datafusion/functions/src/string/repeat.rs 
b/datafusion/functions/src/string/repeat.rs
index a70d0a1625..9d122f6101 100644
--- a/datafusion/functions/src/string/repeat.rs
+++ b/datafusion/functions/src/string/repeat.rs
@@ -88,7 +88,10 @@ fn repeat<T: OffsetSizeTrait>(args: &[ArrayRef]) -> 
Result<ArrayRef> {
         .iter()
         .zip(number_array.iter())
         .map(|(string, number)| match (string, number) {
-            (Some(string), Some(number)) => Some(string.repeat(number as 
usize)),
+            (Some(string), Some(number)) if number >= 0 => {
+                Some(string.repeat(number as usize))
+            }
+            (Some(_), Some(_)) => Some("".to_string()),
             _ => None,
         })
         .collect::<GenericStringArray<T>>();
diff --git a/datafusion/sqllogictest/test_files/expr.slt 
b/datafusion/sqllogictest/test_files/expr.slt
index 2dc00cbc50..b6477f0b57 100644
--- a/datafusion/sqllogictest/test_files/expr.slt
+++ b/datafusion/sqllogictest/test_files/expr.slt
@@ -541,6 +541,11 @@ SELECT repeat('Pg', 4)
 ----
 PgPgPgPg
 
+query T
+SELECT repeat('Pg', -1)
+----
+(empty)
+
 query T
 SELECT repeat('Pg', CAST(NULL AS INT))
 ----


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

Reply via email to