Skip to content

Commit

Permalink
fix: preserve field metadata from right side of union
Browse files Browse the repository at this point in the history
  • Loading branch information
wiedld committed Oct 3, 2024
1 parent 31cbfbd commit 0a18ba4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion datafusion/physical-plan/src/union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,12 @@ fn union_schema(inputs: &[Arc<dyn ExecutionPlan>]) -> SchemaRef {
.iter()
.filter_map(|input| {
if input.schema().fields().len() > i {
Some(input.schema().field(i).clone())
let field = input.schema().field(i).clone();
let right_hand_metdata =
inputs[1].schema().field(i).metadata().clone();
let mut metadata = field.metadata().clone();
metadata.extend(right_hand_metdata);
Some(field.with_metadata(metadata))
} else {
None
}
Expand Down
8 changes: 7 additions & 1 deletion datafusion/sqllogictest/test_files/metadata.slt
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,17 @@ FROM
6

# Regression test: missing field metadata, from the NULL field on the left side of the union
statement error DataFusion error: Internal error: Physical input schema should be the same as the one converted from logical input schema..
query ITT
(SELECT id, NULL::string as name, l_name FROM "table_with_metadata")
UNION
(SELECT id, name, NULL::string as l_name FROM "table_with_metadata")
ORDER BY id, name, l_name;
----
1 NULL NULL
3 baz NULL
3 NULL l_baz
NULL bar NULL
NULL NULL l_bar



Expand Down

0 comments on commit 0a18ba4

Please sign in to comment.