Skip to content

Commit 5b48659

Browse files
authored
chore: default_value for nullable dtypes (#3643)
Closes #3574 Signed-off-by: blaginin <[email protected]>
1 parent 8d20b3c commit 5b48659

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

vortex-array/src/arrays/constant/canonical.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,7 @@ impl CanonicalVTable<ConstantVTable> for ConstantVTable {
101101
struct_dtype
102102
.fields()
103103
.map(|dt| {
104-
// TODO(blaginin): remove this workaround once we've decided on the default value for nullable fields (#3553)
105-
let scalar = match dt.nullability() {
106-
Nullability::NonNullable => Scalar::default_value(dt),
107-
Nullability::Nullable => Scalar::null(dt),
108-
};
109-
104+
let scalar = Scalar::default_value(dt);
110105
ConstantArray::new(scalar, array.len()).into_array()
111106
})
112107
.collect()

vortex-scalar/src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub use pvalue::*;
3636
pub use scalar_value::*;
3737
pub use struct_::*;
3838
pub use utf8::*;
39-
use vortex_error::{VortexExpect, VortexResult, vortex_bail, vortex_panic};
39+
use vortex_error::{VortexExpect, VortexResult, vortex_bail};
4040

4141
/// A single logical item, composed of both a [`ScalarValue`] and a logical [`DType`].
4242
///
@@ -182,8 +182,7 @@ impl Scalar {
182182
/// Create a "default" scalar value for the given data type.
183183
pub fn default_value(dtype: DType) -> Self {
184184
if dtype.is_nullable() {
185-
// We need to decide if we want to return "None" or "0"
186-
vortex_panic!("default for nullable dtype {dtype} is not implemented");
185+
return Self::null(dtype);
187186
}
188187

189188
match dtype {
@@ -599,7 +598,7 @@ mod test {
599598
}
600599

601600
#[test]
602-
fn zero_for_complex_dtype() {
601+
fn default_value_for_complex_dtype() {
603602
let struct_dtype = DType::struct_(
604603
[
605604
("a", DType::Primitive(PType::I32, Nullability::NonNullable)),
@@ -610,6 +609,7 @@ mod test {
610609
Nullability::NonNullable,
611610
),
612611
),
612+
("c", DType::Primitive(PType::I32, Nullability::Nullable)),
613613
],
614614
Nullability::NonNullable,
615615
);
@@ -623,6 +623,9 @@ mod test {
623623
assert_eq!(a_field.as_primitive().pvalue().unwrap(), PValue::I32(0));
624624

625625
let b_field = scalar.field("b").unwrap();
626-
assert!(b_field.as_list().is_empty())
626+
assert!(b_field.as_list().is_empty());
627+
628+
let c_field = scalar.field("c").unwrap();
629+
assert!(c_field.is_null());
627630
}
628631
}

0 commit comments

Comments
 (0)