Skip to content

Placeholder datatype not inferred after LIMIT clause #15978

@kczimm

Description

@kczimm

Describe the bug

When using a parameterized query with a placeholder indicating the value in the LIMIT clause, the datatype is not inferred.

To Reproduce

let schema = Arc::new(Schema::new(vec![Field::new("A", DataType::Int32, true)]));
let source = Arc::new(LogicalTableSource::new(schema.clone()));

let placeholder_value = "$1";

// SELECT * FROM my_table LIMIT $1
let plan = LogicalPlan::Limit(Limit {
    skip: None,
    fetch: Some(Box::new(Expr::Placeholder(Placeholder {
        id: placeholder_value.to_string(),
        data_type: None,
    }))),
    input: Arc::new(LogicalPlan::TableScan(TableScan {
        table_name: TableReference::from("my_table"),
        source,
        projected_schema: Arc::new(DFSchema::try_from(schema.clone())?),
        projection: None,
        filters: vec![],
        fetch: None,
    })),
});

let params = plan.get_parameter_types().expect("to infer type");
assert_eq!(params.len(), 1);

let parameter_type = params
    .clone()
    .get(placeholder_value)
    .expect("to get type")
    .clone();
assert_eq!(parameter_type, Some(DataType::Int64));
assertion `left == right` failed
  left: None
 right: Some(Int64)

Expected behavior

Assertion passes.

Additional context

No response

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