Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support null constant arrays in into canonical #1171

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading