Skip to content

SqltoRel doesn't honor enable_ident_normalization some cases #5626

@ayushdg

Description

@ayushdg

Describe the bug

When creating a logical plan using SqlToRel with options that do not enable_ident_normalization, identifiers still end up getting normalized in some cases.

To Reproduce

let sql = "SELECT UPPERCASE from test";
let dialect = GenericDialect {};
let ast = Parser::parse_sql(&dialect, sql).unwrap();
let statement = &ast[0];
let schema_provider = MySchemaProvider::new();
let options = ParserOptions {
    parse_float_as_decimal: false,
    enable_ident_normalization: false,
};
let sql_to_rel = SqlToRel::new_with_options(&schema_provider, options);
let plan = sql_to_rel.sql_statement_to_plan(statement.clone()).unwrap();
println!("{plan:?}");

Where MySchemaProvider has the following

tables.insert(
    "test".to_string(),
    create_table_source(vec![Field::new("UPPERCASE", DataType::Int32, false)]),
);

Leads to:

SchemaError(FieldNotFound { field: Column { relation: None, name: "uppercase" }, valid_fields: [Column { relation: Some(Bare { table: "test" }), name: "UPPERCASE" }] })'

Definition of everything else is taken from this example.

Expected behavior

When enable_ident_normalization is false, the identified UPPERCASE shouldn't be normalized to uppercase.

Additional context
Looks like this particular case stems from https://github.com/apache/arrow-datafusion/blob/36fe9745407351277649ce07a12f036a2bb653a5/datafusion/sql/src/expr/identifier.rs#L46-L48

but generally a few places use utils::normalize_ident instead of planner::normalize_ident.

Metadata

Metadata

Assignees

No one assigned

    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