11// SPDX-License-Identifier: Apache-2.0
22// SPDX-FileCopyrightText: Copyright the Vortex contributors
33
4+ use vortex_dtype:: DType ;
5+ use vortex_error:: vortex_panic;
6+ use vortex_mask:: Mask ;
7+
48use crate :: Scalar ;
59use crate :: ScalarOps ;
610use crate :: VectorMut ;
11+ use crate :: VectorMutOps ;
712use crate :: VectorOps ;
813use crate :: fixed_size_list:: FixedSizeListVector ;
9- use vortex_mask:: Mask ;
1014
1115/// A scalar value for fixed-size list types.
1216///
13- /// The inner value is a length-1 fsl vector .
17+ /// The inner value is a length-1 [`FixedSizeListVector`] .
1418// NOTE(ngates): the reason we don't hold Option<Vector> representing the elements is that we
1519// wouldn't be able to go back to a vector using "repeat".
1620#[ derive( Clone , Debug ) ]
1721pub struct FixedSizeListScalar ( FixedSizeListVector ) ;
1822
1923impl FixedSizeListScalar {
20- /// Create a new FixedSizeListScalar from a length-1 FixedSizeListVector.
24+ /// Create a new [` FixedSizeListScalar`] from a length-1 [` FixedSizeListVector`] .
2125 ///
2226 /// # Panics
2327 ///
@@ -33,6 +37,42 @@ impl FixedSizeListScalar {
3337 }
3438}
3539
40+ impl FixedSizeListScalar {
41+ /// Creates a zero (default elements) fixed-size list scalar of the given [`DType`].
42+ ///
43+ /// # Panics
44+ ///
45+ /// Panics if the dtype is not a [`DType::FixedSizeList`].
46+ pub fn zero ( dtype : & DType ) -> Self {
47+ if !matches ! ( dtype, DType :: FixedSizeList ( ..) ) {
48+ vortex_panic ! ( "Expected FixedSizeList dtype, got {}" , dtype) ;
49+ }
50+
51+ let mut vec = VectorMut :: with_capacity ( dtype, 1 ) ;
52+ vec. append_zeros ( 1 ) ;
53+ vec. freeze ( ) . scalar_at ( 0 ) . into_fixed_size_list ( )
54+ }
55+
56+ /// Creates a null fixed-size list scalar of the given [`DType`].
57+ ///
58+ /// # Panics
59+ ///
60+ /// Panics if the dtype is not a nullable [`DType::FixedSizeList`].
61+ pub fn null ( dtype : & DType ) -> Self {
62+ match dtype {
63+ DType :: FixedSizeList ( _, _, n) if n. is_nullable ( ) => { }
64+ DType :: FixedSizeList ( ..) => {
65+ vortex_panic ! ( "Expected nullable FixedSizeList dtype, got {}" , dtype)
66+ }
67+ _ => vortex_panic ! ( "Expected FixedSizeList dtype, got {}" , dtype) ,
68+ }
69+
70+ let mut vec = VectorMut :: with_capacity ( dtype, 1 ) ;
71+ vec. append_nulls ( 1 ) ;
72+ vec. freeze ( ) . scalar_at ( 0 ) . into_fixed_size_list ( )
73+ }
74+ }
75+
3676impl ScalarOps for FixedSizeListScalar {
3777 fn is_valid ( & self ) -> bool {
3878 self . 0 . validity ( ) . value ( 0 )
0 commit comments