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/06/13 01:51:34 UTC

(datafusion) branch main updated: fix: preserve Spark next_day whitespace validation (#22720)

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

github-merge-queue[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 574a1e6b39 fix: preserve Spark next_day whitespace validation (#22720)
574a1e6b39 is described below

commit 574a1e6b39acd5b2c521d554863ac50fc0855654
Author: Ahmed EL. <xf...@gmail.com>
AuthorDate: Sat Jun 13 02:40:47 2026 +0100

    fix: preserve Spark next_day whitespace validation (#22720)
    
    ## Which issue does this PR close?
    
    - Closes #22717.
    
    ## Rationale for this change
    
    Spark does not trim `dayOfWeek` before matching it in `next_day`, but
    `datafusion-spark` currently does. That makes values like `' MO '`
    succeed in DataFusion even though Spark treats them as invalid.
    
    ## What changes are included in this PR?
    
    - remove the `.trim()` call from `spark_next_day`
    - add a regression test proving whitespace-padded day names are rejected
    
    ## Are these changes tested?
    
    - `cargo test -p datafusion-spark
    next_day_rejects_whitespace_padded_day_names -- --nocapture`
    - `cargo test -p datafusion-spark`
    - `cargo fmt --all --check`
    - `cargo clippy -p datafusion-spark --all-targets --all-features
    --no-deps -- -D warnings`
    
    Note: the broader package clippy invocation still reports an existing
    unused import warning in untouched
    `datafusion/core/src/execution/session_state.rs` on current main.
    
    ## Are there any user-facing changes?
    
    Behavior now matches Spark for whitespace-padded `dayOfWeek` inputs in
    `next_day`.
    
    ---------
    
    Signed-off-by: xfocus3 <xf...@users.noreply.github.com>
    Co-authored-by: xfocus3 <xf...@users.noreply.github.com>
    Co-authored-by: Ahmed El amraouiyine <ah...@vilavi.fr>
---
 datafusion/spark/src/function/datetime/next_day.rs             | 8 +++++++-
 datafusion/sqllogictest/test_files/spark/datetime/next_day.slt | 6 ++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/datafusion/spark/src/function/datetime/next_day.rs b/datafusion/spark/src/function/datetime/next_day.rs
index 2241043d44..2ef222526f 100644
--- a/datafusion/spark/src/function/datetime/next_day.rs
+++ b/datafusion/spark/src/function/datetime/next_day.rs
@@ -210,7 +210,7 @@ where
 fn spark_next_day(days: i32, day_of_week: &str) -> Option<i32> {
     let date = Date32Type::to_naive_date_opt(days)?;
 
-    let day_of_week = day_of_week.trim().to_uppercase();
+    let day_of_week = day_of_week.to_uppercase();
     let day_of_week = match day_of_week.as_str() {
         "MO" | "MON" | "MONDAY" => Some("MONDAY"),
         "TU" | "TUE" | "TUESDAY" => Some("TUESDAY"),
@@ -279,4 +279,10 @@ mod tests {
         assert_eq!(field.data_type(), &DataType::Date32);
         assert!(field.is_nullable());
     }
+
+    #[test]
+    fn next_day_rejects_whitespace_padded_day_names() {
+        let monday = 19723; // 2024-01-01
+        assert_eq!(spark_next_day(monday, " MO "), None);
+    }
 }
diff --git a/datafusion/sqllogictest/test_files/spark/datetime/next_day.slt b/datafusion/sqllogictest/test_files/spark/datetime/next_day.slt
index 872d1f2b58..b0ffd7d0e4 100644
--- a/datafusion/sqllogictest/test_files/spark/datetime/next_day.slt
+++ b/datafusion/sqllogictest/test_files/spark/datetime/next_day.slt
@@ -36,6 +36,12 @@ SELECT next_day('2015-07-27'::DATE, 'Sat'::string);
 ----
 2015-08-01
 
+# Whitespace-padded day names should be rejected (return NULL) per Spark behavior
+query D
+SELECT next_day('2015-01-14'::DATE, ' MO '::string);
+----
+NULL
+
 query error Failed to coerce arguments to satisfy a call to 'next_day' function
 SELECT next_day('2015-07-27'::DATE);
 


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