@@ -7,15 +7,15 @@ use std::sync::Arc;
77use bitvec:: macros:: internal:: funty:: Fundamental ;
88use num_traits:: AsPrimitive ;
99use parking_lot:: Mutex ;
10- use vortex:: arrays:: PrimitiveArray ;
10+ use vortex:: arrays:: { ConstantArray , ConstantVTable , PrimitiveArray } ;
1111use vortex:: dtype:: { NativePType , match_each_integer_ptype} ;
1212use vortex:: encodings:: dict:: DictArray ;
1313use vortex:: error:: VortexResult ;
1414use vortex:: { Array , ToCanonical } ;
1515
1616use crate :: duckdb:: { SelectionVector , Vector } ;
1717use crate :: exporter:: cache:: ConversionCache ;
18- use crate :: exporter:: { ColumnExporter , new_array_exporter} ;
18+ use crate :: exporter:: { ColumnExporter , constant , new_array_exporter} ;
1919
2020struct DictExporter < I : NativePType > {
2121 // Store the dictionary values once and export the same dictionary with each codes chunk.
@@ -33,6 +33,14 @@ pub(crate) fn new_exporter(
3333) -> VortexResult < Box < dyn ColumnExporter > > {
3434 // Grab the cache dictionary values.
3535 let values = array. values ( ) ;
36+ if let Some ( constant) = values. as_opt :: < ConstantVTable > ( ) {
37+ return constant:: new_exporter_with_mask (
38+ & ConstantArray :: new ( constant. scalar ( ) . clone ( ) , array. codes ( ) . len ( ) ) ,
39+ array. codes ( ) . validity_mask ( ) ,
40+ cache,
41+ ) ;
42+ }
43+
3644 let values_key = Arc :: as_ptr ( values) . addr ( ) ;
3745
3846 // Check if we have a cached vector and extract it if we do.
@@ -95,3 +103,38 @@ impl<I: NativePType + AsPrimitive<u32>> ColumnExporter for DictExporter<I> {
95103 Ok ( ( ) )
96104 }
97105}
106+
107+ #[ cfg( test) ]
108+ mod tests {
109+ use vortex:: IntoArray ;
110+ use vortex:: arrays:: { ConstantArray , PrimitiveArray } ;
111+ use vortex:: encodings:: dict:: DictArray ;
112+
113+ use crate :: cpp;
114+ use crate :: duckdb:: { DataChunk , LogicalType } ;
115+ use crate :: exporter:: ConversionCache ;
116+ use crate :: exporter:: dict:: new_exporter;
117+
118+ #[ test]
119+ fn test_constant_dict ( ) {
120+ let arr = DictArray :: new (
121+ PrimitiveArray :: from_option_iter ( [ None , Some ( 0u32 ) ] ) . into_array ( ) ,
122+ ConstantArray :: new ( 10 , 1 ) . into_array ( ) ,
123+ ) ;
124+
125+ let mut chunk = DataChunk :: new ( [ LogicalType :: new ( cpp:: duckdb_type:: DUCKDB_TYPE_INTEGER ) ] ) ;
126+
127+ new_exporter ( & arr, & ConversionCache :: default ( ) )
128+ . unwrap ( )
129+ . export ( 0 , 2 , & mut chunk. get_vector ( 0 ) )
130+ . unwrap ( ) ;
131+ chunk. set_len ( 2 ) ;
132+
133+ assert_eq ! (
134+ format!( "{}" , String :: try_from( & chunk) . unwrap( ) ) ,
135+ r#"Chunk - [1 Columns]
136+ - FLAT INTEGER: 2 = [ NULL, 10]
137+ "#
138+ ) ;
139+ }
140+ }
0 commit comments