Skip to content

Commit

Permalink
Don't assert nullability in with_keys_field
Browse files Browse the repository at this point in the history
  • Loading branch information
rshkv committed Feb 9, 2025
1 parent 53bbbfc commit 0cd50a2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
30 changes: 7 additions & 23 deletions arrow-array/src/builder/map_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,14 @@ impl<K: ArrayBuilder, V: ArrayBuilder> MapBuilder<K, V> {
///
/// By default, a nullable field is created with the name `keys`
///
/// Returns an error if the given field is nullable.
///
/// Note: [`Self::finish`] and [`Self::finish_cloned`] will panic if the
/// field's data type does not match that of `K`
pub fn with_keys_field(self, field: impl Into<FieldRef>) -> Result<Self, ArrowError> {
let field: FieldRef = field.into();
if field.is_nullable() {
return Err(ArrowError::InvalidArgumentError(format!(
"Key field must not be nullable: {field:?}"
)));
}
Ok(Self {
key_field: Some(field),
/// field's data type does not match that of `K`, or if the keys array
/// contains any null values.
pub fn with_keys_field(self, field: impl Into<FieldRef>) -> Self {
Self {
key_field: Some(field.into()),
..self
})
}
}

/// Override the field passed to [`MapBuilder::new`]
Expand Down Expand Up @@ -412,8 +405,7 @@ mod tests {
Field::new("keys", DataType::Int32, false).with_metadata(key_metadata.clone()),
);
let mut builder = MapBuilder::new(None, Int32Builder::new(), Int32Builder::new())
.with_keys_field(key_field.clone())
.unwrap();
.with_keys_field(key_field.clone());
builder.keys().append_value(1);
builder.values().append_value(2);
builder.append(true).unwrap();
Expand Down Expand Up @@ -441,12 +433,4 @@ mod tests {
)
);
}

#[test]
fn test_with_nullable_keys_field() {
let result = MapBuilder::new(None, Int32Builder::new(), Int32Builder::new())
.with_keys_field(Arc::new(Field::new("keys", DataType::Int32, true)));

assert!(result.is_err());
}
}
1 change: 0 additions & 1 deletion arrow-array/src/builder/struct_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ pub fn make_builder(datatype: &DataType, capacity: usize) -> Box<dyn ArrayBuilde
capacity,
)
.with_keys_field(fields[0].clone())
.expect("Illegal key field")
.with_values_field(fields[1].clone()),
)
}
Expand Down

0 comments on commit 0cd50a2

Please sign in to comment.