Skip to content

Commit 332f981

Browse files
committed
comments
Signed-off-by: Andrew Duffy <[email protected]>
1 parent b439ec4 commit 332f981

File tree

1 file changed

+64
-12
lines changed

1 file changed

+64
-12
lines changed

vortex-layout/src/layouts/path.rs

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,82 @@ use crate::sequence::SequencePointer;
4141
use crate::sequence::SequentialStreamAdapter;
4242
use crate::sequence::SequentialStreamExt;
4343

44+
/// A configurable strategy for writing tables with nested field columns, allowing
45+
/// overrides for specific leaf columns.
4446
pub struct PathStrategy {
45-
// A set of leaf field overrides, e.g. to force one column to be compact-compressed.
47+
/// A set of leaf field overrides, e.g. to force one column to be compact-compressed.
4648
leaf_writers: HashMap<FieldPath, Arc<dyn LayoutStrategy>>,
47-
// The writer for any validity arrays that may be present
49+
/// The writer for any validity arrays that may be present
4850
validity: Arc<dyn LayoutStrategy>,
49-
// The fallback writer for any fields that do not have an explicit writer set in `leaf_writers`
51+
/// The fallback writer for any fields that do not have an explicit writer set in `leaf_writers`
5052
fallback: Arc<dyn LayoutStrategy>,
5153
}
5254

5355
impl PathStrategy {
54-
/// Create a new field writer with the given path validity
55-
pub fn new(
56-
leaf_writers: HashMap<FieldPath, Arc<dyn LayoutStrategy>>,
57-
validity: Arc<dyn LayoutStrategy>,
58-
fallback: Arc<dyn LayoutStrategy>,
59-
) -> Self {
56+
/// Create a new writer with the specified write strategies for validity, and for all leaf
57+
/// fields, with no overrides.
58+
///
59+
/// Additional overrides can be configured using the `with_leaf_strategy` method.
60+
///
61+
/// ## Example
62+
///
63+
/// ```
64+
/// # use vortex_layout::layouts::flat::writer::FlatLayoutStrategy;
65+
/// # use vortex_layout::layouts::path::PathStrategy;
66+
/// // Build a write strategy that does not compress validity or any leaf fields.
67+
/// let strategy = PathStrategy::new(
68+
/// // strategy for validity buffer
69+
/// FlatLayoutStrategy::default(),
70+
/// // strategy for all leaf columns
71+
/// FlatLayoutStrategy::default(),
72+
/// );
73+
/// ```
74+
pub fn new(validity: Arc<dyn LayoutStrategy>, fallback: Arc<dyn LayoutStrategy>) -> Self {
6075
Self {
61-
leaf_writers,
76+
leaf_writers: Default::default(),
6277
validity,
6378
fallback,
6479
}
6580
}
81+
82+
/// Add a custom write strategy for the given leaf field.
83+
///
84+
/// ## Example
85+
///
86+
/// ```no_run
87+
/// # use std::sync::Arc;
88+
/// # use vortex_dtype::{Field, FieldPath};
89+
/// # use vortex_layout::layouts::compact::CompactCompressor;
90+
/// # use vortex_layout::layouts::compressed::CompressingStrategy;
91+
/// # use vortex_layout::layouts::flat::writer::FlatLayoutStrategy;
92+
/// # use vortex_layout::layouts::path::PathStrategy;
93+
///
94+
/// // A strategy for compressing data using the balanced BtrBlocks compressor.
95+
/// let compress_btrblocks = CompressingStrategy::new_btrblocks(FlatLayoutStrategy::default(), true);
96+
///
97+
/// // A strategy that compresses data using ZSTD
98+
/// let compress_compact = CompressingStrategy::new_compact(FlatLayoutStrategy::default(), CompactCompressor::default());
99+
///
100+
/// // Our combined strategy uses no compression for validity buffers, BtrBlocks compression
101+
/// // for most columns, and will use ZSTD compression for a nested binary column that we know
102+
/// // is never filtered in.
103+
/// let strategy = PathStrategy::new(
104+
/// Arc::new(FlatLayoutStrategy::default()),
105+
/// Arc::new(compress_btrblocks),
106+
/// )
107+
/// .with_leaf_strategy(
108+
/// vec![Field::from("request"), Field::from("body"), Field::from("bytes")],
109+
/// Arc::new(compress_compact),
110+
/// );
111+
/// ```
112+
pub fn with_leaf_strategy(
113+
mut self,
114+
field_path: impl Into<FieldPath>,
115+
writer: Arc<dyn LayoutStrategy>,
116+
) -> Self {
117+
self.leaf_writers.insert(field_path.into(), writer);
118+
self
119+
}
66120
}
67121

68122
impl PathStrategy {
@@ -199,7 +253,6 @@ impl LayoutStrategy for PathStrategy {
199253
let child_eof = eof.split_off();
200254
let field = Field::Name(name.clone());
201255
handle.spawn_nested(|h| {
202-
let fallback = self.fallback.clone();
203256
let validity = self.validity.clone();
204257
// descend further and try with new fields
205258
let writer = self
@@ -216,7 +269,6 @@ impl LayoutStrategy for PathStrategy {
216269
}
217270
});
218271
let ctx = ctx.clone();
219-
let dtype = dtype.clone();
220272
let segment_sink = segment_sink.clone();
221273

222274
async move {

0 commit comments

Comments
 (0)