Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible reproducer of schema metadata bug. #12658

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion datafusion/common/src/dfschema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,10 @@ impl TryFrom<SchemaRef> for DFSchema {

impl From<DFSchema> for SchemaRef {
fn from(df_schema: DFSchema) -> Self {
SchemaRef::new(df_schema.into())
Arc::new(Schema::new_with_metadata(
df_schema.fields().to_owned(),
HashMap::new(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change effectively discards the metadata when converting from DFSchema --> Schema (HashMap::new() is empty metadata)

So I am not surprised this can trigger the issue described (as it introduces a bug)

Copy link
Contributor Author

@wiedld wiedld Sep 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is why I wasn't pushing (other) code yesterday. Knew I was brain fried. Sorry about that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no worries -- I think we are making progress. I am particularly stoked about the metadata.slt idea to try and trigger some of the errors we are seeing (and I think that would make it easier to avoid this kind of regression going forward)

))
}
}

Expand Down
11 changes: 2 additions & 9 deletions datafusion/sqllogictest/test_files/metadata.slt
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,14 @@ select * from table_with_metadata;
NULL bar
3 baz

query I rowsort
statement error DataFusion error: Internal error: Physical input schema should be the same as the one converted from logical input schema..
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check failed with:

physical_input_schema: 
Schema { 
    fields: [
        Field { 
            name: "id", 
            data_type: Int32, 
            nullable: true, 
            dict_id: 0, 
            dict_is_ordered: false, 
            metadata: {"metadata_key": "the id field"} 
        }
    ], 
    metadata: {"metadata_key": "the entire schema"} 
}

physical_input_schema_from_logical: 
Schema { 
    fields: [
        Field { 
            name: "id", 
            data_type: Int32, 
            nullable: true, 
            dict_id: 0, 
            dict_is_ordered: false, 
            metadata: {"metadata_key": "the id field"} 
        }
    ], 
    metadata: {} 
}

SELECT (
SELECT id FROM table_with_metadata
) UNION (
SELECT id FROM table_with_metadata
);
----
1
3
NULL

query I rowsort
statement error DataFusion error: Internal error: Physical input schema should be the same as the one converted from logical input schema..
SELECT "data"."id"
FROM
(
Expand All @@ -54,9 +50,6 @@ FROM
SELECT "id" FROM "table_with_metadata"
) as "samples"
WHERE "data"."id" = "samples"."id";
----
1
3

statement ok
drop table table_with_metadata;
Loading