Skip to content

Commit

Permalink
feat: support null constant arrays in into canonical (#1171)
Browse files Browse the repository at this point in the history
  • Loading branch information
danking authored Nov 1, 2024
1 parent e5d1275 commit f7a4d61
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion vortex-array/src/array/constant/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use vortex_scalar::{BinaryScalar, BoolScalar, Utf8Scalar};

use crate::array::constant::ConstantArray;
use crate::array::primitive::PrimitiveArray;
use crate::array::{BinaryView, BoolArray, VarBinViewArray, VIEW_SIZE_BYTES};
use crate::array::{BinaryView, BoolArray, NullArray, VarBinViewArray, VIEW_SIZE_BYTES};
use crate::validity::Validity;
use crate::{ArrayDType, Canonical, IntoArray, IntoCanonical};

Expand Down Expand Up @@ -59,6 +59,10 @@ impl IntoCanonical for ConstantArray {
});
}

if matches!(self.dtype(), DType::Null) {
return Ok(Canonical::Null(NullArray::new(self.len())));
}

vortex_bail!("Unsupported scalar type {}", self.dtype())
}
}
Expand Down Expand Up @@ -117,10 +121,21 @@ fn canonical_byte_view(

#[cfg(test)]
mod tests {
use vortex_dtype::DType;
use vortex_scalar::Scalar;

use crate::array::ConstantArray;
use crate::compute::unary::scalar_at;
use crate::IntoCanonical;

#[test]
fn test_canonicalize_null() {
let const_null = ConstantArray::new(Scalar::null(DType::Null), 42);
let actual = const_null.into_canonical().unwrap().into_null().unwrap();
assert_eq!(actual.len(), 42);
assert_eq!(scalar_at(actual, 33).unwrap(), Scalar::null(DType::Null));
}

#[test]
fn test_canonicalize_const_str() {
let const_array = ConstantArray::new("four".to_string(), 4);
Expand Down

0 comments on commit f7a4d61

Please sign in to comment.