Skip to content

'Date32 + Interval(DayTime)' can't be evaluated because there isn't a common type to coerce the types to #2229

Closed

Description

@andygrove

Describe the bug
I am trying to produce a logical plan for a SQL query that adds an interval to a date as part of the where clause and it fails with a type coercion error.

To Reproduce

Create the test file t1.csv:

d_date
1999-12-13

Run this test:

#[tokio::test]
async fn repro_date32_add_interval() -> Result<()> {
    let ctx = SessionContext::new();
    let schema = Schema::new(vec![
        Field::new("d_date", DataType::Date32, false),
    ]);
    let options = CsvReadOptions::new()
        .has_header(true)
        .schema(&schema);
    ctx.register_csv("t1", "tests/t1.csv", options).await?;
    let df = ctx.sql("SELECT * FROM t1 WHERE d_date between cast('2002-05-30' as date) and cast('2002-05-30' as date) + INTERVAL '60 days'").await?;
    let plan = df.to_logical_plan();
    println!("{:?}", plan);
    Ok(())
}

Expected behavior
I expect this query to run without error. Here is a similar query running in Postgres.

postgres=# select * from test where a between cast('2022-04-12' as date) and cast('2022-04-12' as date) + INTERVAL '60 days';
             a              
----------------------------
 2022-04-13 20:29:35.879229
(1 row)

Additional context
None

Activity

  1. self-assigned this
    on Apr 14, 2022
  2. andygrove commented on Apr 15, 2022

    @andygrove
    MemberAuthor

    Fixed in #2235

  3. alamb commented on Apr 15, 2022

    @alamb
    Contributor

    Also related #194

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions