Skip to content

Commit a56fb4f

Browse files
committed
Handle nested Union constant placeholders
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
1 parent 9d47234 commit a56fb4f

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ fn constant_canonical_union(
213213
Some((selected_child, selected_value)) if index == selected_child => {
214214
selected_value.clone()
215215
}
216+
_ if matches!(&dtype, DType::Union(_, Nullability::NonNullable)) => {
217+
Scalar::zero_value(&dtype)
218+
}
216219
_ => Scalar::default_value(&dtype),
217220
};
218221
ConstantArray::new(value, len).into_array()

vortex-array/src/arrays/union/tests.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,50 @@ fn constant_union_executes_to_sparse_union() -> VortexResult<()> {
295295
Ok(())
296296
}
297297

298+
#[test]
299+
fn constant_union_builds_nested_union_placeholders() -> VortexResult<()> {
300+
let nested_variants = UnionVariants::try_new(
301+
["value"].into(),
302+
vec![DType::Primitive(PType::I64, Nullability::NonNullable)],
303+
vec![3],
304+
)?;
305+
let nested_dtype = DType::Union(nested_variants, Nullability::NonNullable);
306+
let outer_variants = UnionVariants::try_new(
307+
["number", "nested"].into(),
308+
vec![
309+
DType::Primitive(PType::I32, Nullability::NonNullable),
310+
nested_dtype.clone(),
311+
],
312+
vec![5, 9],
313+
)?;
314+
let mut ctx = array_session().create_execution_ctx();
315+
316+
let selected_number = Scalar::union(
317+
outer_variants.clone(),
318+
5,
319+
42i32.into(),
320+
Nullability::NonNullable,
321+
)?;
322+
let array = ConstantArray::new(selected_number, 2)
323+
.into_array()
324+
.execute::<UnionArray>(&mut ctx)?;
325+
assert_eq!(
326+
array.child_by_name("nested")?.execute_scalar(0, &mut ctx)?,
327+
Scalar::zero_value(&nested_dtype)
328+
);
329+
330+
let outer_null = Scalar::null(DType::Union(outer_variants, Nullability::Nullable));
331+
let array = ConstantArray::new(outer_null, 2)
332+
.into_array()
333+
.execute::<UnionArray>(&mut ctx)?;
334+
assert_eq!(
335+
array.child_by_name("nested")?.execute_scalar(0, &mut ctx)?,
336+
Scalar::zero_value(&nested_dtype)
337+
);
338+
339+
Ok(())
340+
}
341+
298342
#[test]
299343
fn chunked_union_packs_components() -> VortexResult<()> {
300344
let first = union_array()?.into_array().slice(0..1)?;

0 commit comments

Comments
 (0)