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

Conversation

wiedld
Copy link
Contributor

@wiedld wiedld commented Sep 28, 2024

Which issue does this PR close?

Related to #12560

Rationale for this change

A PR merged (and released in 42.0.0) has added a check that the logical and physical plan input schemas (to an aggregate node) are the same.

Once released into the wild, it began being triggered. One example case is where field metadata is in the logical plan, but missing from the physical plan.

I haven't yet re-created that exact reproducer. However, I ended up creating the inverse case -- where the metadata is in the physical plan, but missing from the logical plan.

What changes are included in this PR?

First commit: changed the From DFSchema for SchemaRef, so it stops dropping the metadata.

Second commit: demonstrate that test cases (where metadata is on the data) end up failing due to the same error as in #12560.

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions bot added sqllogictest SQL Logic Tests (.slt) common Related to common crate labels Sep 28, 2024
@@ -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: {} 
}

@wiedld
Copy link
Contributor Author

wiedld commented Sep 28, 2024

Note: CI is failing due to this change merged today. @akurmustafa

@alamb
Copy link
Contributor

alamb commented Sep 28, 2024

Note: CI is failing due to this change merged today. @akurmustafa

I believe this was fixed by @doupache in #12657. I will retrigger CI

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks @wiedld

I am not sure about this particular change as it seems to introduce a bug

Here is an idea of how to try and reproduce the issue we see:

  1. Add a new sqllogictest like metadata.rs or something: https://github.com/apache/datafusion/tree/main/datafusion/sqllogictest
  2. Add custom / rust setup code here that creates a table that has schemas with metadata (both metadata on the schema and on the fields):
    "joins.slt" => {
    info!("Registering partition table tables");
    let example_udf = create_example_udf();
    test_ctx.ctx.register_udf(example_udf);
    register_partition_table(&mut test_ctx).await;
    }
  3. Add various queries in metadata.slt with the appropriate plan nodes (GROUP BY, ORDER BY, etc) and see if you can provoke the same error.

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)

@alamb
Copy link
Contributor

alamb commented Sep 30, 2024

I filed #12687 to track the metadata lost bug we are seeing

@wiedld
Copy link
Contributor Author

wiedld commented Sep 30, 2024

Have the correct reproducer & fix. Closing this one.

@wiedld wiedld closed this Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
common Related to common crate sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants