Acfboy opened a new issue, #20355:
URL: https://github.com/apache/datafusion/issues/20355
### Describe the bug
## Description
```rust
#[tokio::test]
async fn test_unary_negation_on_string_error() -> Result<()> {
let ctx = SessionContext::new();
let res = ctx.sql("SELECT -'a';").await;
assert!(res.is_err());
Ok(())
}
```
Negation operator can't work on Utf8 should be reported at planning phase,
but this test failed.
## Root Cause
It invokes `Expr::to_field` to check types and get filed of each expressions
in query while generating logical plan . However, in the `Expr::Negative` bench
it only returns the field of its inner expression:
https://github.com/apache/datafusion/blob/7d217b1ec3bd4d447961e84bc3fe7f7708546b2d/datafusion/expr/src/expr_schema.rs#L452
Similarly, it also returns the types of its inner expression in
`Expr::get_type`, which cause it also escape checks in `type_coercion`.
https://github.com/apache/datafusion/blob/7d217b1ec3bd4d447961e84bc3fe7f7708546b2d/datafusion/expr/src/expr_schema.rs#L119
Finally, it will be caught while generating physical plan (in some code like
`df.show()`);
https://github.com/apache/datafusion/blob/7d217b1ec3bd4d447961e84bc3fe7f7708546b2d/datafusion/physical-expr/src/expressions/negative.rs#L188-L199
## Fix
It's quite strightforward, I'll open a pr soon.
### To Reproduce
_No response_
### Expected behavior
_No response_
### Additional context
_No response_
--
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]