Skip to content

Commit 0cd50a2

Browse files
committed
Don't assert nullability in with_keys_field
1 parent 53bbbfc commit 0cd50a2

File tree

2 files changed

+7
-24
lines changed

2 files changed

+7
-24
lines changed

arrow-array/src/builder/map_builder.rs

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,14 @@ impl<K: ArrayBuilder, V: ArrayBuilder> MapBuilder<K, V> {
117117
///
118118
/// By default, a nullable field is created with the name `keys`
119119
///
120-
/// Returns an error if the given field is nullable.
121-
///
122120
/// Note: [`Self::finish`] and [`Self::finish_cloned`] will panic if the
123-
/// field's data type does not match that of `K`
124-
pub fn with_keys_field(self, field: impl Into<FieldRef>) -> Result<Self, ArrowError> {
125-
let field: FieldRef = field.into();
126-
if field.is_nullable() {
127-
return Err(ArrowError::InvalidArgumentError(format!(
128-
"Key field must not be nullable: {field:?}"
129-
)));
130-
}
131-
Ok(Self {
132-
key_field: Some(field),
121+
/// field's data type does not match that of `K`, or if the keys array
122+
/// contains any null values.
123+
pub fn with_keys_field(self, field: impl Into<FieldRef>) -> Self {
124+
Self {
125+
key_field: Some(field.into()),
133126
..self
134-
})
127+
}
135128
}
136129

137130
/// Override the field passed to [`MapBuilder::new`]
@@ -412,8 +405,7 @@ mod tests {
412405
Field::new("keys", DataType::Int32, false).with_metadata(key_metadata.clone()),
413406
);
414407
let mut builder = MapBuilder::new(None, Int32Builder::new(), Int32Builder::new())
415-
.with_keys_field(key_field.clone())
416-
.unwrap();
408+
.with_keys_field(key_field.clone());
417409
builder.keys().append_value(1);
418410
builder.values().append_value(2);
419411
builder.append(true).unwrap();
@@ -441,12 +433,4 @@ mod tests {
441433
)
442434
);
443435
}
444-
445-
#[test]
446-
fn test_with_nullable_keys_field() {
447-
let result = MapBuilder::new(None, Int32Builder::new(), Int32Builder::new())
448-
.with_keys_field(Arc::new(Field::new("keys", DataType::Int32, true)));
449-
450-
assert!(result.is_err());
451-
}
452436
}

arrow-array/src/builder/struct_builder.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ pub fn make_builder(datatype: &DataType, capacity: usize) -> Box<dyn ArrayBuilde
297297
capacity,
298298
)
299299
.with_keys_field(fields[0].clone())
300-
.expect("Illegal key field")
301300
.with_values_field(fields[1].clone()),
302301
)
303302
}

0 commit comments

Comments
 (0)