|
18 | 18 | //! Logical plan types |
19 | 19 |
|
20 | 20 | use std::cmp::Ordering; |
21 | | -use std::collections::{BTreeMap, HashMap, HashSet}; |
| 21 | +use std::collections::{HashMap, HashSet}; |
22 | 22 | use std::fmt::{self, Debug, Display, Formatter}; |
23 | 23 | use std::hash::{Hash, Hasher}; |
24 | 24 | use std::sync::{Arc, LazyLock}; |
@@ -2741,35 +2741,34 @@ impl Union { |
2741 | 2741 | ) -> Result<DFSchemaRef> { |
2742 | 2742 | type FieldData<'a> = |
2743 | 2743 | (&'a DataType, bool, Vec<&'a HashMap<String, String>>, usize); |
2744 | | - // Prefer `BTreeMap` as it produces items in order by key when iterated over |
2745 | | - let mut cols: BTreeMap<&str, FieldData> = BTreeMap::new(); |
| 2744 | + let mut cols: Vec<(&str, FieldData)> = Vec::new(); |
2746 | 2745 | for input in inputs.iter() { |
2747 | 2746 | for field in input.schema().fields() { |
2748 | | - match cols.entry(field.name()) { |
2749 | | - std::collections::btree_map::Entry::Occupied(mut occupied) => { |
2750 | | - let (data_type, is_nullable, metadata, occurrences) = |
2751 | | - occupied.get_mut(); |
2752 | | - if !loose_types && *data_type != field.data_type() { |
2753 | | - return plan_err!( |
2754 | | - "Found different types for field {}", |
2755 | | - field.name() |
2756 | | - ); |
2757 | | - } |
2758 | | - |
2759 | | - metadata.push(field.metadata()); |
2760 | | - // If the field is nullable in any one of the inputs, |
2761 | | - // then the field in the final schema is also nullable. |
2762 | | - *is_nullable |= field.is_nullable(); |
2763 | | - *occurrences += 1; |
| 2747 | + if let Some((_, (data_type, is_nullable, metadata, occurrences))) = |
| 2748 | + cols.iter_mut().find(|(name, _)| name == field.name()) |
| 2749 | + { |
| 2750 | + if !loose_types && *data_type != field.data_type() { |
| 2751 | + return plan_err!( |
| 2752 | + "Found different types for field {}", |
| 2753 | + field.name() |
| 2754 | + ); |
2764 | 2755 | } |
2765 | | - std::collections::btree_map::Entry::Vacant(vacant) => { |
2766 | | - vacant.insert(( |
| 2756 | + |
| 2757 | + metadata.push(field.metadata()); |
| 2758 | + // If the field is nullable in any one of the inputs, |
| 2759 | + // then the field in the final schema is also nullable. |
| 2760 | + *is_nullable |= field.is_nullable(); |
| 2761 | + *occurrences += 1; |
| 2762 | + } else { |
| 2763 | + cols.push(( |
| 2764 | + field.name(), |
| 2765 | + ( |
2767 | 2766 | field.data_type(), |
2768 | 2767 | field.is_nullable(), |
2769 | 2768 | vec![field.metadata()], |
2770 | 2769 | 1, |
2771 | | - )); |
2772 | | - } |
| 2770 | + ), |
| 2771 | + )); |
2773 | 2772 | } |
2774 | 2773 | } |
2775 | 2774 | } |
|
0 commit comments