Skip to content

fail to sql query if column contains capitalized letter #399

@hu6360567

Description

@hu6360567

Describe the bug
fail to execute sql when select with column if the column contains capitalized letter

To Reproduce

import pyarrow as pa
import datafusion

if __name__ == "__main__":
    tbl = pa.Table.from_arrays([[1, 2, 3]], names=["id"])

    for column_name in ["id", "ID", "iD"]:
        ctx = datafusion.SessionContext()
        ctx.register_record_batches(name="tbl", partitions=[tbl.rename_columns([column_name]).to_batches()])

        sql = f"SELECT {column_name} from tbl"


        try:
            print(sql)
            ctx.sql(sql)
        except Exception as e:
            print(e)
SELECT id from tbl
SELECT ID from tbl
DataFusion error: SchemaError(FieldNotFound { field: Column { relation: None, name: "id" }, valid_fields: [Column { relation: Some(Bare { table: "tbl" }), name: "ID" }] })
SELECT iD from tbl
DataFusion error: SchemaError(FieldNotFound { field: Column { relation: None, name: "id" }, valid_fields: [Column { relation: Some(Bare { table: "tbl" }), name: "iD" }] })

Expected behavior
All sql should executed successfully.

Additional context
Python 3.8.16
pyarrow 12.0.0
datafusion 23.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions