You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2026/10/08 14:04:22 UTC

(datafusion) 01/01: fix(spark): return NULL from `char` for a NULL scalar argument (#26126)

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

github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-26126-55b2f093bb80780b8ce253873ff816cc4740fbe2
in repository https://gitbox.apache.org/repos/asf/datafusion.git

commit 415f25db4b768cc2090f5740823fbcf561518074
Author: ranflarion <ra...@flarion.io>
AuthorDate: Thu Oct 8 14:03:57 2026 +0000

    fix(spark): return NULL from `char` for a NULL scalar argument (#26126)
    
    ## Which issue does this PR close?
    
    - Closes #26125.
    
    ## Rationale for this change
    
    `SELECT char(NULL::INT)` fails with `Execution error: The argument must
    be an Int64 array or scalar.` where Spark returns NULL. NULL rows of an
    array argument already return NULL, only a NULL scalar argument reaches
    the error.
    
    ## What changes are included in this PR?
    
    `spark_chr` returns a NULL `Utf8` scalar for a NULL `Int64` scalar.
    
    ## What is the testing strategy for this PR?
    
    A `char(NULL::INT)` case in `spark/string/char.slt`, which fails on main
    with the error above.
    
    ## Are there any user-facing changes?
    
    `char` of a NULL scalar returns NULL instead of an error.
---
 datafusion/spark/src/function/string/char.rs             | 3 +++
 datafusion/sqllogictest/test_files/spark/string/char.slt | 5 +++++
 2 files changed, 8 insertions(+)

diff --git a/datafusion/spark/src/function/string/char.rs b/datafusion/spark/src/function/string/char.rs
index 5d6de3ae36..6e8666f0b8 100644
--- a/datafusion/spark/src/function/string/char.rs
+++ b/datafusion/spark/src/function/string/char.rs
@@ -100,6 +100,9 @@ fn spark_chr(args: &[ColumnarValue]) -> Result<ColumnarValue> {
                 }
             }
         }
+        ColumnarValue::Scalar(ScalarValue::Int64(None)) => {
+            Ok(ColumnarValue::Scalar(ScalarValue::Utf8(None)))
+        }
         _ => exec_err!("The argument must be an Int64 array or scalar."),
     }
 }
diff --git a/datafusion/sqllogictest/test_files/spark/string/char.slt b/datafusion/sqllogictest/test_files/spark/string/char.slt
index 152ebfe805..47aa1dc844 100644
--- a/datafusion/sqllogictest/test_files/spark/string/char.slt
+++ b/datafusion/sqllogictest/test_files/spark/string/char.slt
@@ -25,6 +25,11 @@ SELECT char(321::INT);
 ----
 A
 
+query T
+SELECT char(NULL::INT);
+----
+NULL
+
 query T
 SELECT char(a) FROM (VALUES (-1::INT), (0::INT), (65::INT), (321::INT)) AS t(a);
 ----


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org