alamb commented on code in PR #12954:
URL: https://github.com/apache/datafusion/pull/12954#discussion_r1803499698
##########
datafusion/physical-plan/src/union.rs:
##########
@@ -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))
Review Comment:
what is the `^ (1 << 0)` construction used for?
##########
datafusion/physical-plan/src/union.rs:
##########
@@ -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)| {
Review Comment:
I would like to recommend extracting this logic into a function that is
commented to help explain what it is doing -- specifically I think it is trying
to get the first non-null metadata from any previous input
Reading it more closely, though, doesn't this code assume there are exactly
2 inputs to the Union? What if there are more than 2 inputs?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]