From d1ffc74ed88f3412b9da6d5a0acc5a057f55efe1 Mon Sep 17 00:00:00 2001 From: wiedld Date: Thu, 3 Oct 2024 20:34:24 -0700 Subject: [PATCH] chore: safe indexing --- datafusion/physical-plan/src/union.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/datafusion/physical-plan/src/union.rs b/datafusion/physical-plan/src/union.rs index 2df85655e0b9..1cf22060b62a 100644 --- a/datafusion/physical-plan/src/union.rs +++ b/datafusion/physical-plan/src/union.rs @@ -475,8 +475,12 @@ fn union_schema(inputs: &[Arc]) -> SchemaRef { .filter_map(|input| { if input.schema().fields().len() > i { let field = input.schema().field(i).clone(); - let right_hand_metdata = - inputs[1].schema().field(i).metadata().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))