Skip to content

Optimizer check errors if resulting schema has different metadata #4346

Closed

Description

@alamb

Describe the bug
Some passes may change the metadata for a plan and I think that is ok.

In paticular, we have a case in IOx where the projection_push_down actually exposes some more metadata (as it unwraps a projection that had masked it).

This new metadata actually fails with the newly added schema check added in #4233 by @jackwener. This currently causes our test to break

To Reproduce
Make a projection that doesn't do anything other than to mask some other plan that produces metadata

thread 'cases::test_cases_pushdown_sql' panicked at 'built plan successfully: Internal("Optimizer rule 'projection_push_down' failed, due to generate a different schema, original schema: DFSchema { fields: [DFField { qualifier: Some("restaurant"), field: Field { name: "count", data_type: UInt64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: None } }, DFField { qualifier: Some("restaurant"), field: Field { name: "system", data_type: Float64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: None } }, DFField { qualifier: Some("restaurant"), field: Field { name: "time", data_type: Timestamp(Nanosecond, None), nullable: false, dict_id: 0, dict_is_ordered: false, metadata: None } }, DFField { qualifier: Some("restaurant"), field: Field { name: "town", data_type: Dictionary(Int32, Utf8), nullable: true, dict_id: 0, dict_is_ordered: false, metadata: None } }], metadata: {} }, new schema: DFSchema { fields: [DFField { qualifier: Some("restaurant"), field: Field { name: "count", data_type: UInt64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: Some({"iox::column::type": "iox::column_type::field::uinteger"}) } }, DFField { qualifier: Some("restaurant"), field: Field { name: "system", data_type: Float64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: Some({"iox::column::type": "iox::column_type::field::float"}) } }, DFField { qualifier: Some("restaurant"), field: Field { name: "time", data_type: Timestamp(Nanosecond, None), nullable: false, dict_id: 0, dict_is_ordered: false, metadata: Some({"iox::column::type": "iox::column_type::timestamp"}) } }, DFField { qualifier: Some("restaurant"), field: Field { name: "town", data_type: Dictionary(Int32, Utf8), nullable: true, dict_id: 0, dict_is_ordered: false, metadata: Some({"iox::column::type": "iox::column_type::tag"}) } }], metadata: {} }")', query_tests/src/runner.rs:289:18

Expected behavior
The query should run successfully

Additional context
I also considered adding a config flag to turn off the check, but that seems worse than this less stringent test

Here is the PR where i am working to upgrade datafusion: https://github.com/influxdata/influxdb_iox/pull/6218#issuecomment-1325323048

Activity

  1. added
    bug
    on Nov 23, 2022
  2. self-assigned this
    on Nov 23, 2022
  3. alamb commented on Nov 23, 2022

    @alamb
    ContributorAuthor

    If you are curious, here is an example of the before/after schema:

    �[2m2022-11-23T19:28:01.303927Z�[0m �[35mTRACE�[0m �[2mdatafusion_optimizer::optimizer�[0m�[2m:�[0m original schema: DFSchema {
        fields: [
            DFField {
                qualifier: Some(
                    "restaurant",
                ),
                field: Field {
                    name: "count",
                    data_type: UInt64,
                    nullable: true,
                    dict_id: 0,
                    dict_is_ordered: false,
                    metadata: None,
                },
            },
            DFField {
                qualifier: Some(
                    "restaurant",
                ),
                field: Field {
                    name: "system",
                    data_type: Float64,
                    nullable: true,
                    dict_id: 0,
                    dict_is_ordered: false,
                    metadata: None,
                },
            },
            DFField {
                qualifier: Some(
                    "restaurant",
                ),
                field: Field {
                    name: "time",
                    data_type: Timestamp(
                        Nanosecond,
                        None,
                    ),
                    nullable: false,
                    dict_id: 0,
                    dict_is_ordered: false,
                    metadata: None,
                },
            },
            DFField {
                qualifier: Some(
                    "restaurant",
                ),
                field: Field {
                    name: "town",
                    data_type: Dictionary(
                        Int32,
                        Utf8,
                    ),
                    nullable: true,
                    dict_id: 0,
                    dict_is_ordered: false,
                    metadata: None,
                },
            },
        ],
        metadata: {},
    }
    �[2m2022-11-23T19:28:01.303963Z�[0m �[35mTRACE�[0m �[2mdatafusion_optimizer::optimizer�[0m�[2m:�[0m new plan schema: DFSchema {
        fields: [
            DFField {
                qualifier: Some(
                    "restaurant",
                ),
                field: Field {
                    name: "count",
                    data_type: UInt64,
                    nullable: true,
                    dict_id: 0,
                    dict_is_ordered: false,
                    metadata: Some(
                        {
                            "iox::column::type": "iox::column_type::field::uinteger",
                        },
                    ),
                },
            },
            DFField {
                qualifier: Some(
                    "restaurant",
                ),
                field: Field {
                    name: "system",
                    data_type: Float64,
                    nullable: true,
                    dict_id: 0,
                    dict_is_ordered: false,
                    metadata: Some(
                        {
                            "iox::column::type": "iox::column_type::field::float",
                        },
                    ),
                },
            },
            DFField {
                qualifier: Some(
                    "restaurant",
                ),
                field: Field {
                    name: "time",
                    data_type: Timestamp(
                        Nanosecond,
                        None,
                    ),
                    nullable: false,
                    dict_id: 0,
                    dict_is_ordered: false,
                    metadata: Some(
                        {
                            "iox::column::type": "iox::column_type::timestamp",
                        },
                    ),
                },
            },
            DFField {
                qualifier: Some(
                    "restaurant",
                ),
                field: Field {
                    name: "town",
                    data_type: Dictionary(
                        Int32,
                        Utf8,
                    ),
                    nullable: true,
                    dict_id: 0,
                    dict_is_ordered: false,
                    metadata: Some(
                        {
                            "iox::column::type": "iox::column_type::tag",
                        },
                    ),
                },
            },
        ],
        metadata: {},
    }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions