Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
tustvold committed Mar 30, 2023
1 parent 00a976e commit 07af4ff
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions arrow-schema/src/datatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,4 +663,9 @@ mod tests {
Box::new(list)
)));
}

#[test]
fn size_should_not_regress() {
assert_eq!(std::mem::size_of::<DataType>(), 24);
}
}
21 changes: 21 additions & 0 deletions arrow-schema/src/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,22 @@ impl UnionFields {
}

/// Create a new [`UnionFields`] from a [`Fields`] and array of type_ids
///
/// See <https://arrow.apache.org/docs/format/Columnar.html#union-layout>
///
/// ```
/// use arrow_schema::{DataType, Field, UnionFields};
/// // Create a new UnionFields with type id mapping
/// // 1 -> DataType::UInt8
/// // 3 -> DataType::Utf8
/// UnionFields::new(
/// vec![1, 3],
/// vec![
/// Field::new("field1", DataType::UInt8, false),
/// Field::new("field3", DataType::Utf8, false),
/// ],
/// );
/// ```
pub fn new<F, T>(type_ids: T, fields: F) -> Self
where
F: IntoIterator,
Expand Down Expand Up @@ -204,7 +220,11 @@ impl UnionFields {
self.0.iter().map(|(id, f)| (*id, f))
}

/// Merge this field into self if it is compatible.
///
/// See [`Field::try_merge`]
pub(crate) fn try_merge(&mut self, other: &Self) -> Result<(), ArrowError> {
// TODO: This currently may produce duplicate type IDs (#3982)
let mut output: Vec<_> = self.iter().map(|(id, f)| (id, f.clone())).collect();
for (field_type_id, from_field) in other.iter() {
let mut is_new_field = true;
Expand Down Expand Up @@ -235,6 +255,7 @@ impl UnionFields {

impl FromIterator<(i8, FieldRef)> for UnionFields {
fn from_iter<T: IntoIterator<Item = (i8, FieldRef)>>(iter: T) -> Self {
// TODO: Should this validate type IDs are unique (#3982)
Self(iter.into_iter().collect())
}
}

0 comments on commit 07af4ff

Please sign in to comment.