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/11 13:22:49 UTC

(datafusion) branch gh-readonly-queue/main/pr-26205-75ddead2b765ff6c574c4cc989538fabcf250c9f created (now 454ca08b43)

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

github-merge-queue[bot] pushed a change to branch gh-readonly-queue/main/pr-26205-75ddead2b765ff6c574c4cc989538fabcf250c9f
in repository https://gitbox.apache.org/repos/asf/datafusion.git


      at 454ca08b43 fix(spark): derive concat_ws nullability from separator (#26205)

This branch includes the following new commits:

     new 454ca08b43 fix(spark): derive concat_ws nullability from separator (#26205)

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



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


(datafusion) 01/01: fix(spark): derive concat_ws nullability from separator (#26205)

Posted by gi...@apache.org.
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-26205-75ddead2b765ff6c574c4cc989538fabcf250c9f
in repository https://gitbox.apache.org/repos/asf/datafusion.git

commit 454ca08b43fd8bb83362f575750850d5745ddee3
Author: Vova Kot <vo...@gmail.com>
AuthorDate: Sun Oct 11 13:22:25 2026 +0000

    fix(spark): derive concat_ws nullability from separator (#26205)
    
    ## Which issue does this PR close?
    
    <!--
    We generally require a GitHub issue to be filed for all bug fixes and
    enhancements and this helps us generate change logs for our releases.
    You can link an issue to this PR using the GitHub syntax. For example
    `Closes #123` indicates that this PR will close issue #123.
    -->
    
    Part of the work towards
    https://github.com/apache/datafusion/issues/15914
    
    ## Rationale for this change
    
    <!--
    Why are you proposing this change? If this is already explained clearly
    in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand
    your changes and offer better suggestions for fixes.
    
    Please explain the problem you are trying to solve in terms of the
    user-visible
    behavior, rather than the implementation.
    
    For example, "The code in `foo.rs` doesn't handle nulls" is a symptom of
    the
    implementation. "COUNT(DISTINCT) returns wrong results when the column
    contains
    nulls" is the user-visible problem.
    -->
    
    `concat_ws` return value is always nullable in DF, which is incorrect.
    Per upstream Spark implementation, this is only true when separator
    itself is null.
    
    ## What changes are included in this PR?
    
    <!--
    There is no need to duplicate the description in the issue here, but it
    is sometimes worth providing a summary of the individual changes in this
    PR.
    -->
    
    Derive the nullability based on the separator nullability.
    
    ## What is the testing strategy for this PR?
    
    <!--
    We typically require tests for all PRs in order to:
    1. Prevent the code from being accidentally broken by subsequent changes
    2. Serve as another way to document the expected behavior of the code
    
    Briefly describe how this PR is tested, and point to the specific tests
    you added. For example: 'This new feature is covered by the
    `sqllogictest` cases added in `foo.slt`'.
    
    If this PR does not add tests, explain why. For example, if the change
    is already covered by existing tests, please mention it.
    
    You should also check the `codecov` bot reply on this PR to confirm the
    changed code is exercised.
    -->
    
    Add SLT tests for schema.
    
    ## Are there any user-facing changes?
    
    <!--
    If there are user-facing changes then we may require documentation to be
    updated before approving the PR.
    
    If there are any breaking changes to public APIs, please add the `api
    change` label.
    -->
    
    I believe this doesn't count as an API change but would like guidance
    from a committer.
---
 datafusion/spark/src/function/string/concat_ws.rs       | 15 ++++++++++++++-
 .../sqllogictest/test_files/spark/string/concat_ws.slt  | 17 +++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/datafusion/spark/src/function/string/concat_ws.rs b/datafusion/spark/src/function/string/concat_ws.rs
index c9ed1369a5..77e25bbe3b 100644
--- a/datafusion/spark/src/function/string/concat_ws.rs
+++ b/datafusion/spark/src/function/string/concat_ws.rs
@@ -34,9 +34,11 @@ use arrow::array::{
     StringArray, StringBuilder, StringViewArray,
 };
 use arrow::datatypes::{DataType, Field};
+use datafusion_common::arrow::datatypes::FieldRef;
 use datafusion_common::{Result, ScalarValue};
 use datafusion_expr::{
-    ColumnarValue, ScalarFunctionArgs, ScalarUDFImpl, Signature, Volatility,
+    ColumnarValue, ReturnFieldArgs, ScalarFunctionArgs, ScalarUDFImpl, Signature,
+    Volatility,
 };
 
 use crate::function::error_utils::{
@@ -75,6 +77,17 @@ impl ScalarUDFImpl for SparkConcatWs {
         Ok(DataType::Utf8)
     }
 
+    fn return_field_from_args(&self, args: ReturnFieldArgs<'_>) -> Result<FieldRef> {
+        // Spark skips null values after the separator, so only the separator controls nullability:
+        // https://github.com/apache/spark/blob/32f7299601108917fb01920a54e084595b7b3bf8/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala#L94-L96
+        let separator = &args.arg_fields[0];
+        Ok(Arc::new(Field::new(
+            self.name(),
+            DataType::Utf8,
+            separator.is_nullable(),
+        )))
+    }
+
     fn coerce_types(&self, arg_types: &[DataType]) -> Result<Vec<DataType>> {
         if arg_types.is_empty() {
             return Err(invalid_arg_count_exec_err("concat_ws", (1, i32::MAX), 0));
diff --git a/datafusion/sqllogictest/test_files/spark/string/concat_ws.slt b/datafusion/sqllogictest/test_files/spark/string/concat_ws.slt
index f40408447f..94c6ea0265 100644
--- a/datafusion/sqllogictest/test_files/spark/string/concat_ws.slt
+++ b/datafusion/sqllogictest/test_files/spark/string/concat_ws.slt
@@ -53,6 +53,11 @@ SELECT concat_ws(',');
 ----
 (empty)
 
+query TTT
+DESCRIBE SELECT concat_ws(',') AS result;
+----
+result Utf8 NO
+
 ## Null separator returns null
 query T
 SELECT concat_ws(NULL, 'a', 'b', 'c');
@@ -113,6 +118,12 @@ SELECT concat_ws(sep) AS result FROM VALUES (CAST(NULL AS STRING)), (',') AS t(s
 NULL
 (empty)
 
+query TTT
+DESCRIBE SELECT concat_ws(sep) AS result
+FROM VALUES (CAST(NULL AS STRING)), (',') AS t(sep);
+----
+result Utf8 YES
+
 ## ── Column expressions ──────────────────────────────────────
 
 ## concat_ws on columns
@@ -130,6 +141,12 @@ a,b
 c
 d
 
+query TTT
+DESCRIBE SELECT concat_ws(',', a, b) AS result
+FROM VALUES ('a', 'b'), ('c', CAST(NULL AS STRING)), (CAST(NULL AS STRING), 'd') AS t(a, b);
+----
+result Utf8 NO
+
 ## Scalar-only arguments over multiple rows (broadcast test)
 query T
 SELECT concat_ws(',', 'a', 'b') AS result FROM VALUES (1), (2), (3) AS t(x);


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