Skip to content

Missing collecting column from ORDER BY clause #1151

@goldmedal

Description

@goldmedal

Describe the bug
The ModelAnalyzeRule should collect the column used by Sort.

To Reproduce
Given the model:

            ModelBuilder::new("order_items_model")
                .table_reference("datafusion.public.order_items")
                .column(ColumnBuilder::new("freight_value", "double").build())
                .column(ColumnBuilder::new("id", "bigint").build())
                .column(ColumnBuilder::new("item_number", "bigint").build())
                .column(ColumnBuilder::new("order_id", "varchar").build())
                .column(ColumnBuilder::new("price", "double").build())
                .column(ColumnBuilder::new("product_id", "varchar").build())
                .column(ColumnBuilder::new("shipping_limit_date", "varchar").build())
                .column(
                    ColumnBuilder::new("orders_model", "orders_model")
                        .relationship("orders_order_items")
                        .build(),
                )
                .column(
                    ColumnBuilder::new("customer_state", "varchar")
                        .calculated(true)
                        .expression("orders_model.customers_model.state")
                        .build(),
                )
                .primary_key("id")
                .build(),

The following SQL:

select order_id from wrenai.public.order_items_model group by order_id order by sum(price)

It will throw the error:

Error: Context("type_coercion", SchemaError(FieldNotFound { field: Column { relation: Some(Full { catalog: "wrenai", schema: "public", table: "order_items_model" }), name: "price" }, valid_fields: [Column { relation: Some(Bare { table: "order_items_model" }), name: "order_id" }] }, Some("")))

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcore

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions