Trikooo commented on code in PR #20012:
URL: https://github.com/apache/datafusion/pull/20012#discussion_r2749230588
##########
datafusion/expr/src/expr_schema.rs:
##########
@@ -598,13 +598,32 @@ impl ExprSchemable for Expr {
)
})?;
- let arguments = args
+ let coerced_values: Vec<Option<ScalarValue>> = args
.iter()
- .map(|e| match e {
- Expr::Literal(sv, _) => Some(sv),
- _ => None,
+ .zip(new_fields.iter())
+ .map(|(expr, field)| {
+ let mut current_expr = expr;
+
+ // Loop to remove all casting layers
+ loop {
+ match current_expr {
+ Expr::Cast(cast) => current_expr = &cast.expr,
+ Expr::TryCast(cast) => current_expr =
&cast.expr,
+ _ => break,
+ }
+ }
+
+ let literal = if let Expr::Literal(sv, _) =
current_expr {
+ Some(sv)
+ } else {
+ None
+ };
+
+ literal.map(|sv|
sv.cast_to(field.data_type())).transpose()
Review Comment:
Thank you, so would that mean we should handle removing the casting layers
in a follow up PR before making a change here? because even if we only consider
raw `Literal`s this assert in the test added:
```Rust
assert_eq!(
args.arg_fields[0].data_type(),
&args.scalar_arguments[0].unwrap().data_type()
);
```
is still going to fail because the Analyzer is going to wrap the raw
`Literal`s in a `Cast` as I have noticed when I logged the expression:
```Rust
Literal(Int64(1), None)
```
during the third call it becomes:
```Rust
Cast(Cast { expr: Literal(Int64(1), None), data_type: Int16 })
```
Can you point out where should we deal with the casts?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]