Skip to content

Commit

Permalink
fix(12733): because either the left or right fields may be chosen, ad…
Browse files Browse the repository at this point in the history
…d metadata from both to each other
  • Loading branch information
wiedld committed Oct 15, 2024
1 parent a9b6bd5 commit 059e13e
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions datafusion/physical-plan/src/union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,21 +472,20 @@ fn union_schema(inputs: &[Arc<dyn ExecutionPlan>]) -> SchemaRef {
.map(|i| {
inputs
.iter()
.filter_map(|input| {
if input.schema().fields().len() > i {
let field = input.schema().field(i).clone();
let right_hand_metdata = inputs
.get(1)
.map(|right_input| {
right_input.schema().field(i).metadata().clone()
})
.unwrap_or_default();
let mut metadata = field.metadata().clone();
metadata.extend(right_hand_metdata);
Some(field.with_metadata(metadata))
} else {
None
}
.enumerate()
.map(|(input_idx, input)| {
let field = input.schema().field(i).clone();
let mut metadata = field.metadata().clone();

let other_side_metdata = inputs
.get(input_idx ^ (1 << 0))
.map(|other_input| {
other_input.schema().field(i).metadata().clone()
})
.unwrap_or_default();

metadata.extend(other_side_metdata);
field.with_metadata(metadata)
})
.find_or_first(|f| f.is_nullable())
.unwrap()
Expand Down

0 comments on commit 059e13e

Please sign in to comment.