Skip to content

Error on some queries: "column types must match schema types, expected XXX but found YYY" #1447

@alamb

Description

@alamb

Describe the bug
Some queries error with an error like

ArrowError(ExternalError(ArrowError(InvalidArgumentError("column types must match schema types, expected Boolean but found Float32 at column index 0"))))', datafusion/tests/sql.rs:3857:39

To Reproduce
Write a query that aliases one column to the name of another in the input that has a different type

Specifically:

A reproducer in sql.rs:

#[tokio::test]
async fn projection_type_alias() -> Result<()> {
    let mut ctx = ExecutionContext::new();
    register_aggregate_simple_csv(&mut ctx).await?;

    // Query that aliases one column to the name of a different column
    // that also has a different type (c1 == float32, c3 == boolean)
    let sql = "SELECT c1 as c3 FROM aggregate_simple ORDER BY c3";
    let actual = execute_to_batches(&mut ctx, sql).await;

    let expected = vec!["foo"];
    assert_batches_eq!(expected, &actual);

    Ok(())
}

Expected behavior
Query should run successfully

Additional context
This bug was caught by some of the IOx tests while updating IOx https://github.com/influxdata/influxdb_iox/pull/3359

I am pretty sure the issue was intrduced in #1378. I'll have a PR shortly

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