-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix bug in field level metadata matching code #8286
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
.ok() | ||
.map(|f| f.metadata().clone()) | ||
// Look up field by index in schema (not NAME) | ||
e.as_any() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the fix -- look up metadata by column index rather than name
@@ -299,3 +299,31 @@ fn table_with_many_types() -> Arc<dyn TableProvider> { | |||
let provider = MemTable::try_new(Arc::new(schema), vec![vec![batch]]).unwrap(); | |||
Arc::new(provider) | |||
} | |||
|
|||
/// Registers a table_with_metadata that contains both field level and Table level metadata | |||
pub async fn register_metadata_tables(ctx: &SessionContext) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intend to port several existing metadata tests to sqllogictest as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks @alamb
e.as_any() | ||
.downcast_ref::<Column>() | ||
.map(|column| column.index()) | ||
.map(|idx| input_schema.field(idx).metadata()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can likely be done within a single map
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea -- done in f5c557e
Thank you for the review @comphead |
* Fix bug in field level metadata matching code * improve comment * single map
Which issue does this PR close?
Closes #8285
Rationale for this change
Bug fix
What changes are included in this PR?
What was happening is that the input to a join has metadata on one side, but not the other. When the inputs were reordered then metadata was not properly reordered as well
Specifically:
So the output schema looks like:
When the join reorders the inputs, the result had the metadata incorrectly set:
There is code in the join reordering that tries to remap the output so the schema is the same, however
it had a bug (was looking up field by name, not column index), so it picked the wrong column.
Are these changes tested?
Are there any user-facing changes?