More type checking at logical planning
- Dominant language
- Rust
- Stars
- 9.3k
- Forks
- 2.4k
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 344
Description
### Is your feature request related to a problem or challenge?
Now, types of expressions in `WHERE/HAVING/ORDER BY/ON` closure would not be checked at logical planning but checked in type_coercion while generating physical plan.
For instance:
```rust
#[tokio::test]
async fn test_unary_negation_on_string_error() -> Result<()> {
let test_sqls = vec![
// "SELECT (1 + 'a') FROM (SELECT 1);",
"SELECT * FROM (SELECT 1) WHERE (1 + 'a');",
// "SELECT count(*) FROM (SELECT 1) GROUP BY (1 + 'a');",
"SELECT column1 FROM (VALUES (1)) AS t(column1) GROUP BY column1 HAVING (1 + 'a');",
"SELECT * FROM (SELECT 1) ORDER BY (1 + 'a');",
"SELECT * FROM (SELECT 1) AS t1 JOIN (SELECT 1) AS t2 ON (1 + 'a');",
];
let mut cnt = 0;
for sql in test_sqls {
let ctx = SessionContext::new();
if ctx.sql(sql).await.is_err() {
cnt += 1;
}
}
assert_eq!(4, cnt);
Ok(())
}
```
The test above will fail.
I think we should report error as early as possible, the statements above should reject invalid expressions in logical planning phase just as `SELECT (1 + 'a') FROM (SELECT 1);`
### Describe the solution you'd like
I plan to follow the error-handling pattern used for `SELECT 1 + 'a'`; by invoking `Expr::to_field`. I would welcome any alternative approaches or suggestions on the implementation details.
### Describe alternatives you've considered
_No response_
### Additional context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.