Skip to content

Commit 7546876

Browse files
committed
some docs and tests
Signed-off-by: Adam Gutglick <adam@spiraldb.com>
1 parent f8467cb commit 7546876

2 files changed

Lines changed: 43 additions & 13 deletions

File tree

  • vortex-array/src

vortex-array/src/arrays/variant/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@ pub(super) const SLOT_NAMES: [&str; NUM_SLOTS] = ["core_storage", "shredded"];
2525

2626
/// Accessors for canonical variant storage.
2727
///
28-
/// A canonical variant array keeps raw variant semantics in `core_storage` and may carry a
29-
/// row-aligned, storage-agnostic `shredded` typed tree for selected paths. The shredded child may
30-
/// have any dtype; its dtype is recorded during serialization and validated by normal child
31-
/// deserialization.
28+
/// A canonical variant array keeps the full variant value for every row in `core_storage` and may
29+
/// carry a row-aligned, storage-agnostic `shredded` typed tree for selected paths.
30+
///
31+
/// `core_storage` is a logical `DType::Variant` array, not a specific physical encoding: it may be
32+
/// chunked, constant, or otherwise encoded. Callers must use normal array operations instead of
33+
/// assuming a particular slot layout. The shredded child may have any dtype; its dtype is recorded
34+
/// during serialization and validated by normal child deserialization.
3235
pub trait VariantArrayExt: TypedArrayRef<Variant> {
33-
/// Returns the raw storage that preserves the full variant value for every row.
36+
/// Returns the logical variant storage that preserves the full value for every row.
3437
fn core_storage(&self) -> &ArrayRef {
3538
self.as_ref().slots()[CORE_STORAGE_SLOT]
3639
.as_ref()
@@ -45,7 +48,7 @@ pub trait VariantArrayExt: TypedArrayRef<Variant> {
4548
impl<T: TypedArrayRef<Variant>> VariantArrayExt for T {}
4649

4750
impl Array<Variant> {
48-
/// Creates a new `VariantArray` with raw core storage and optional shredded storage.
51+
/// Creates a new `VariantArray` with logical variant core storage and optional shredded storage.
4952
pub fn try_new(core_storage: ArrayRef, shredded: Option<ArrayRef>) -> VortexResult<Self> {
5053
let dtype = core_storage.dtype().clone();
5154
vortex_ensure!(

vortex-array/src/scalar_fn/fns/variant_get/mod.rs

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,38 @@ mod tests {
676676
Ok(())
677677
}
678678

679+
#[test]
680+
fn variant_get_reads_chunked_variant_input() -> VortexResult<()> {
681+
let array = variant_rows([
682+
Scalar::variant(variant_object([(
683+
"a",
684+
Scalar::primitive(10i32, Nullability::NonNullable),
685+
)])),
686+
Scalar::variant(variant_object([(
687+
"b",
688+
Scalar::primitive(20i32, Nullability::NonNullable),
689+
)])),
690+
Scalar::variant(variant_object([(
691+
"a",
692+
Scalar::primitive(30i32, Nullability::NonNullable),
693+
)])),
694+
Scalar::null(DType::Variant(Nullability::Nullable)),
695+
])?;
696+
assert!(array.is::<Chunked>());
697+
698+
let result = execute_variant_get(
699+
array,
700+
"$.a",
701+
Some(DType::Primitive(PType::I32, Nullability::NonNullable)),
702+
)?;
703+
704+
assert_arrays_eq!(
705+
result,
706+
PrimitiveArray::from_option_iter([Some(10i32), None, Some(30), None])
707+
);
708+
Ok(())
709+
}
710+
679711
#[test]
680712
fn variant_get_fallback_typed_output_is_contiguous() -> VortexResult<()> {
681713
let array = variant_rows([
@@ -769,13 +801,8 @@ mod tests {
769801

770802
assert_eq!(variant.len(), 2);
771803
assert_eq!(canonical_variant.len(), 2);
772-
assert!(variant.core_storage().is::<Chunked>());
773-
774-
let core_variant = variant
775-
.core_storage()
776-
.clone()
777-
.execute::<VariantArray>(&mut LEGACY_SESSION.create_execution_ctx())?;
778-
assert_eq!(core_variant.len(), 2);
804+
assert_eq!(variant.core_storage().dtype(), variant.dtype());
805+
assert_eq!(variant.core_storage().len(), variant.len());
779806

780807
let mut ctx = LEGACY_SESSION.create_execution_ctx();
781808
for (idx, expected) in [10i32, 20].into_iter().enumerate() {

0 commit comments

Comments
 (0)