Skip to content

Type coercion should select cheapest cast. #5928

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
Tracked by #5927
jackwener opened this issue Apr 9, 2023 · 0 comments
Open
Tracked by #5927

Type coercion should select cheapest cast. #5928

jackwener opened this issue Apr 9, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@jackwener
Copy link
Member

Describe the bug

a Expr like col(a) > utf('8').
We shouldn't cast col(a).

To Reproduce

    #[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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant