Skip to content

Commit fd2543b

Browse files
committed
implement more
Signed-off-by: Andrew Duffy <[email protected]>
1 parent b7440bb commit fd2543b

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

vortex-file/src/strategy.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
use std::sync::Arc;
77

8+
use vortex_dtype::FieldPath;
89
use vortex_layout::LayoutStrategy;
910
use vortex_layout::layouts::buffered::BufferedStrategy;
1011
use vortex_layout::layouts::chunked::writer::ChunkedLayoutStrategy;
@@ -13,11 +14,12 @@ use vortex_layout::layouts::compressed::CompressingStrategy;
1314
use vortex_layout::layouts::compressed::CompressorPlugin;
1415
use vortex_layout::layouts::dict::writer::DictStrategy;
1516
use vortex_layout::layouts::flat::writer::FlatLayoutStrategy;
17+
use vortex_layout::layouts::path::PathStrategy;
1618
use vortex_layout::layouts::repartition::RepartitionStrategy;
1719
use vortex_layout::layouts::repartition::RepartitionWriterOptions;
18-
use vortex_layout::layouts::struct_::writer::StructStrategy;
1920
use vortex_layout::layouts::zoned::writer::ZonedLayoutOptions;
2021
use vortex_layout::layouts::zoned::writer::ZonedStrategy;
22+
use vortex_utils::aliases::hash_map::HashMap;
2123

2224
const ONE_MEG: u64 = 1 << 20;
2325

@@ -29,6 +31,7 @@ const ONE_MEG: u64 = 1 << 20;
2931
pub struct WriteStrategyBuilder {
3032
compressor: Option<Arc<dyn CompressorPlugin>>,
3133
row_block_size: usize,
34+
field_writers: Option<HashMap<FieldPath, Arc<dyn LayoutStrategy>>>,
3235
}
3336

3437
impl 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
}

vortex-layout/src/layouts/path.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,30 @@ impl PathStrategy {
103103
/// Arc::new(FlatLayoutStrategy::default()),
104104
/// Arc::new(compress_btrblocks),
105105
/// )
106-
/// .with_leaf_strategy(
106+
/// .set_field_writer(
107107
/// field_path!(request.body.bytes),
108108
/// Arc::new(compress_compact),
109109
/// );
110110
/// ```
111-
pub fn with_leaf_strategy(
111+
pub fn set_field_writer(
112112
mut self,
113113
field_path: impl Into<FieldPath>,
114114
writer: Arc<dyn LayoutStrategy>,
115115
) -> Self {
116116
self.leaf_writers.insert(field_path.into(), writer);
117117
self
118118
}
119+
120+
/// Set writers for several fields at once.
121+
///
122+
/// See also: [`set_field_writer`][Self::set_field_writer].
123+
pub fn set_field_writers(
124+
mut self,
125+
writers: impl IntoIterator<Item = (FieldPath, Arc<dyn LayoutStrategy>)>,
126+
) -> Self {
127+
self.leaf_writers.extend(writers);
128+
self
129+
}
119130
}
120131

121132
impl PathStrategy {

0 commit comments

Comments
 (0)