Type coercion should select cheapest cast.
- Dominant language
- Rust
- Stars
- 9.3k
- Forks
- 2.4k
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 344
Description
### Describe the bug
a Expr like `col(a) > utf('8')`.
We shouldn't cast `col(a)`.
### To Reproduce
```rs
#[test]
fn between_infer_cheap_type() -> Result<()> {
let expr = Expr::Between(Between::new(
Box::new(col("a")),
false,
// (cast('2002-05-08' as date) + interval '1 months')
Box::new(Expr::BinaryExpr(BinaryExpr {
left: Box::new(Expr::Cast(Cast {
expr: Box::new(Expr::Literal(Utf8(Some("2002-05-08".to_string())))),
data_type: DataType::Date32,
})),
op: Operator::Plus,
right: Box::new(Expr::Literal(ScalarValue::IntervalYearMonth(Some(1)))),
})),
Box::new(Expr::Literal(Utf8(Some("2002-12-08".to_string())))),
));
let empty = empty_with_type(DataType::Utf8);
let plan = LogicalPlan::Filter(Filter::try_new(expr, empty)?);
// TODO
let expected =
"Filter: CAST(a AS Date32) BETWEEN CAST(Utf8(\"2002-05-08\") AS Date32) + IntervalYearMonth(\"1\") AND CAST(Utf8(\"2002-12-08\") AS Date32)\
\n EmptyRelation";
assert_analyzed_plan_eq(Arc::new(TypeCoercion::new()), &plan, expected)
}
```
### Expected behavior
_No response_
### Additional context
_No response_
Contributor guide
Research direction
Start with the between_infer_cheap_type test in the issue and inspect the TypeCoercion analyzer used by assert_analyzed_plan_eq. Reproduce the current analyzed plan, then determine how the test should express choosing the cheapest cast for the comparison. Done means the analyzer and regression test agree with the intended plan without unnecessarily casting col(a).
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100