55
66use std:: sync:: Arc ;
77
8+ use vortex_dtype:: FieldPath ;
89use vortex_layout:: LayoutStrategy ;
910use vortex_layout:: layouts:: buffered:: BufferedStrategy ;
1011use vortex_layout:: layouts:: chunked:: writer:: ChunkedLayoutStrategy ;
@@ -13,11 +14,12 @@ use vortex_layout::layouts::compressed::CompressingStrategy;
1314use vortex_layout:: layouts:: compressed:: CompressorPlugin ;
1415use vortex_layout:: layouts:: dict:: writer:: DictStrategy ;
1516use vortex_layout:: layouts:: flat:: writer:: FlatLayoutStrategy ;
17+ use vortex_layout:: layouts:: path:: PathStrategy ;
1618use vortex_layout:: layouts:: repartition:: RepartitionStrategy ;
1719use vortex_layout:: layouts:: repartition:: RepartitionWriterOptions ;
18- use vortex_layout:: layouts:: struct_:: writer:: StructStrategy ;
1920use vortex_layout:: layouts:: zoned:: writer:: ZonedLayoutOptions ;
2021use vortex_layout:: layouts:: zoned:: writer:: ZonedStrategy ;
22+ use vortex_utils:: aliases:: hash_map:: HashMap ;
2123
2224const ONE_MEG : u64 = 1 << 20 ;
2325
@@ -29,6 +31,7 @@ const ONE_MEG: u64 = 1 << 20;
2931pub struct WriteStrategyBuilder {
3032 compressor : Option < Arc < dyn CompressorPlugin > > ,
3133 row_block_size : usize ,
34+ field_writers : Option < HashMap < FieldPath , Arc < dyn LayoutStrategy > > > ,
3235}
3336
3437impl Default for WriteStrategyBuilder {
@@ -44,6 +47,7 @@ impl WriteStrategyBuilder {
4447 Self {
4548 compressor : None ,
4649 row_block_size : 8192 ,
50+ field_writers : None ,
4751 }
4852 }
4953
@@ -62,6 +66,19 @@ impl WriteStrategyBuilder {
6266 self
6367 }
6468
69+ /// Override the default write layout for a specific field somewhere in the nested
70+ /// schema tree.
71+ pub fn with_field_writer (
72+ mut self ,
73+ field : impl Into < FieldPath > ,
74+ writer : Arc < dyn LayoutStrategy > ,
75+ ) -> Self {
76+ let mut writers = self . field_writers . unwrap_or_default ( ) ;
77+ writers. insert ( field. into ( ) , writer) ;
78+ self . field_writers = Some ( writers) ;
79+ self
80+ }
81+
6582 /// Builds the canonical [`LayoutStrategy`] implementation, with the configured overrides
6683 /// applied.
6784 pub fn build ( self ) -> Arc < dyn LayoutStrategy > {
@@ -126,6 +143,15 @@ impl WriteStrategyBuilder {
126143 // 0. start with splitting columns
127144 let validity_strategy = CollectStrategy :: new ( compress_then_flat) ;
128145
129- Arc :: new ( StructStrategy :: new ( repartition, validity_strategy) )
146+ let table_strategy = PathStrategy :: new ( Arc :: new ( validity_strategy) , Arc :: new ( repartition) ) ;
147+
148+ // Take any field overrides from the builder and apply them to the final strategy.
149+ let table_strategy = if let Some ( overrides) = self . field_writers {
150+ table_strategy. set_field_writers ( overrides)
151+ } else {
152+ table_strategy
153+ } ;
154+
155+ Arc :: new ( table_strategy)
130156 }
131157}
0 commit comments