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/15 13:10:06 UTC

(datafusion) branch gh-readonly-queue/main/pr-26311-c52eb9734b4c968ad9880fb82f3214efd88cd82b created (now 519e4c51a7)

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-26311-c52eb9734b4c968ad9880fb82f3214efd88cd82b
in repository https://gitbox.apache.org/repos/asf/datafusion.git


      at 519e4c51a7 fix: propagate CASE unparser errors (#26311)

This branch includes the following new commits:

     new 519e4c51a7 fix: propagate CASE unparser errors (#26311)

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: propagate CASE unparser errors (#26311)

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-26311-c52eb9734b4c968ad9880fb82f3214efd88cd82b
in repository https://gitbox.apache.org/repos/asf/datafusion.git

commit 519e4c51a715d4c4152c003b77a8443c497eb847
Author: Isaac Emmanuel <35...@users.noreply.github.com>
AuthorDate: Thu Oct 15 12:48:51 2026 +0000

    fix: propagate CASE unparser errors (#26311)
    
    ## Which issue does this PR close?
    
    - Closes #26295.
    
    ## Rationale for this change
    
    When a simple CASE operand or ELSE branch cannot be unparsed, the
    unparser currently drops that child and returns valid-looking SQL with
    different semantics. Callers should receive the original unparse error
    instead.
    
    ## What changes are included in this PR?
    
    Propagate errors from CASE operands and ELSE branches, matching the
    existing WHEN/THEN behavior. Add regression coverage for both paths.
    
    ## What is the testing strategy for this PR?
    
    - `cargo test -p datafusion-sql --lib` (95 passed)
    - `cargo clippy -p datafusion-sql --all-targets --all-features -- -D
    warnings`
    - `cargo fmt --all --check`
    
    The regression test was also run against the pre-fix implementation and
    failed because unparsing returned a CASE AST instead of an error.
    
    ## Are there any user-facing changes?
    
    Yes. CASE expressions with unsupported operands or ELSE branches now
    return an error instead of producing SQL with altered semantics.
---
 datafusion/sql/src/unparser/expr.rs | 44 +++++++++++++++++++++++++------------
 1 file changed, 30 insertions(+), 14 deletions(-)

diff --git a/datafusion/sql/src/unparser/expr.rs b/datafusion/sql/src/unparser/expr.rs
index 7c7fec38bf..70ee725e80 100644
--- a/datafusion/sql/src/unparser/expr.rs
+++ b/datafusion/sql/src/unparser/expr.rs
@@ -246,20 +246,14 @@ impl Unparser<'_> {
                     })
                     .collect::<Result<Vec<CaseWhen>>>()?;
 
-                let operand = match expr.as_ref() {
-                    Some(e) => match self.expr_to_sql_inner(e) {
-                        Ok(sql_expr) => Some(Box::new(sql_expr)),
-                        Err(_) => None,
-                    },
-                    None => None,
-                };
-                let else_result = match else_expr.as_ref() {
-                    Some(e) => match self.expr_to_sql_inner(e) {
-                        Ok(sql_expr) => Some(Box::new(sql_expr)),
-                        Err(_) => None,
-                    },
-                    None => None,
-                };
+                let operand = expr
+                    .as_ref()
+                    .map(|e| self.expr_to_sql_inner(e).map(Box::new))
+                    .transpose()?;
+                let else_result = else_expr
+                    .as_ref()
+                    .map(|e| self.expr_to_sql_inner(e).map(Box::new))
+                    .transpose()?;
 
                 Ok(ast::Expr::Case {
                     operand,
@@ -3453,6 +3447,28 @@ mod tests {
         Ok(())
     }
 
+    #[test]
+    fn case_propagates_operand_and_else_errors() {
+        let unsupported = Expr::Literal(ScalarValue::DurationSecond(Some(1)), None);
+        let expressions = [
+            Expr::Case(Case::new(
+                Some(Box::new(unsupported.clone())),
+                vec![(Box::new(lit(1)), Box::new(lit(2)))],
+                None,
+            )),
+            Expr::Case(Case::new(
+                None,
+                vec![(Box::new(lit(true)), Box::new(lit(1)))],
+                Some(Box::new(unsupported)),
+            )),
+        ];
+
+        for expr in expressions {
+            let error = expr_to_sql(&expr).expect_err("unsupported CASE child");
+            assert!(error.to_string().contains("Unsupported scalar"));
+        }
+    }
+
     #[test]
     fn test_window_func_support_window_frame() -> Result<()> {
         let default_dialect: Arc<dyn Dialect> =


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