You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "officialasishkumar (via GitHub)" <gi...@apache.org> on 2026/04/08 08:13:21 UTC

[PR] fix(sql): return planner error for malformed typed literals [datafusion]

officialasishkumar opened a new pull request, #21454:
URL: https://github.com/apache/datafusion/pull/21454

   ## Which issue does this PR close?
   
   - Closes #21431.
   
   ## Rationale for this change
   
   Planning a malformed typed literal such as `time 17542368000000000` currently panics in `datafusion-sql` because the planner assumes every `TypedString` payload is string-backed and calls `into_string().unwrap()`.
   
   Invalid SQL should surface as a normal planner error rather than aborting the planning path.
   
   ## What changes are included in this PR?
   
   - Replace the `unwrap()` in the `SQLExpr::TypedString` planning path with explicit validation.
   - Return a planner error when the typed literal payload is not string-backed.
   - Add a regression test covering the invalid `TIME` typed literal reported in the issue.
   
   ## Are these changes tested?
   
   - `cargo test -p datafusion-sql`
   
   ## Are there any user-facing changes?
   
   Users now receive a planner error for malformed typed literals instead of a panic.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] fix(sql): return planner error for malformed typed literals [datafusion]

Posted by "officialasishkumar (via GitHub)" <gi...@apache.org>.
officialasishkumar commented on code in PR #21454:
URL: https://github.com/apache/datafusion/pull/21454#discussion_r3064768547


##########
datafusion/sql/src/expr/mod.rs:
##########
@@ -306,10 +306,22 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
                 data_type,
                 value,
                 uses_odbc_syntax: _,
-            }) => Ok(Expr::Cast(Cast::new_from_field(
-                Box::new(lit(value.into_string().unwrap())),
-                self.convert_data_type_to_field(&data_type)?,
-            ))),
+            }) => {
+                let raw_value = value.to_string();

Review Comment:
   Adjusted this to avoid the happy-path allocation in f416e7120.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] fix(sql): return planner error for malformed typed literals [datafusion]

Posted by "jonahgao (via GitHub)" <gi...@apache.org>.
jonahgao merged PR #21454:
URL: https://github.com/apache/datafusion/pull/21454


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [PR] fix(sql): return planner error for malformed typed literals [datafusion]

Posted by "jonahgao (via GitHub)" <gi...@apache.org>.
jonahgao commented on code in PR #21454:
URL: https://github.com/apache/datafusion/pull/21454#discussion_r3061609452


##########
datafusion/sql/src/expr/mod.rs:
##########
@@ -306,10 +306,22 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
                 data_type,
                 value,
                 uses_odbc_syntax: _,
-            }) => Ok(Expr::Cast(Cast::new_from_field(
-                Box::new(lit(value.into_string().unwrap())),
-                self.convert_data_type_to_field(&data_type)?,
-            ))),
+            }) => {
+                let raw_value = value.to_string();

Review Comment:
   `raw_value` is only used in the error branch,introducing a redundant string allocation on the happy path. 
   How about excluding it from the error message?
   ```rust
   let value = value.into_string().ok_or_else(|| {
         plan_datafusion_err!("Typed literal requires a string payload")
     })?;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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