Skip to content

No pushdown filters applied if temporal type was optimized into timestamp type by datafusion #942

@omerhadari

Description

@omerhadari

When running queries such as SELECT * FROM table WHERE ts_col = CAST('2024-01-01 00:12:34' AS TIMESTAMP), Datafusion converts the Cast directly to a TimestampNanosecond type. This is not handled by the code in here.

Test for example that shows the issue:

    #[test]
    fn test_comparison_with_nanos_work() {
        let left = Expr::Column(Column::new_unqualified("ts"));
        let right = Expr::Literal(ScalarValue::TimestampNanosecond(Some(1000), None));
        let op = Operator::GtEq;
        let binary_expr = Expr::BinaryExpr(BinaryExpr::new(Box::new(left), op, Box::new(right)));
        let predicate = convert_filters_to_predicate(&vec![binary_expr]).unwrap();
        let expected_predicate =
            Reference::new("ts").greater_than_or_equal_to(Datum::timestamp_nanos(1000));
        assert_eq!(predicate, expected_predicate);
    }

Note:
The correct type of Datum should be handled in values.rs, otherwise the issue will manifest as a failure to cast timestamp to whatever it's compared to.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions