Skip to content

Commit 1ead11e

Browse files
committed
simplify strategy
Signed-off-by: Matt Katz <mhkatz97@gmail.com>
1 parent 4a41176 commit 1ead11e

1 file changed

Lines changed: 18 additions & 65 deletions

File tree

vortex-file/src/strategy.rs

Lines changed: 18 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,19 @@ impl WriteStrategyBuilder {
208208
flat
209209
};
210210

211-
// 7. for each chunk create a flat layout
212-
let chunked = ChunkedLayoutStrategy::new(Arc::clone(&flat));
211+
// 7. write each compressed chunk as either a shallow list layout or a flat layout.
212+
// Chunking stays outside ListLayoutStrategy so every list layout receives exactly one
213+
// complete page and its elements, offsets, and validity are direct flat leaves.
214+
let terminal: Arc<dyn LayoutStrategy> = if self.use_list_layout {
215+
Arc::new(
216+
ListLayoutStrategy::default()
217+
.with_leaf(Arc::clone(&flat))
218+
.with_fallback(Arc::clone(&flat)),
219+
)
220+
} else {
221+
Arc::clone(&flat)
222+
};
223+
let chunked = ChunkedLayoutStrategy::new(terminal);
213224
// 6. buffer chunks so they end up with closer segment ids physically
214225
let buffered = BufferedStrategy::new(chunked, 2 * ONE_MEG); // 2MB
215226

@@ -226,7 +237,7 @@ impl WriteStrategyBuilder {
226237
),
227238
CompressorConfig::Opaque(compressor) => Arc::clone(compressor),
228239
};
229-
let compressing = CompressingStrategy::new(buffered, Arc::clone(&data_compressor));
240+
let compressing = CompressingStrategy::new(buffered, data_compressor);
230241

231242
// 4. prior to compression, coalesce up to a minimum size
232243
let coalescing = RepartitionStrategy::new(
@@ -264,7 +275,7 @@ impl WriteStrategyBuilder {
264275
compress_then_flat.clone(),
265276
coalescing,
266277
Default::default(),
267-
Arc::clone(&probe_compressor),
278+
probe_compressor,
268279
);
269280

270281
let row_block_size = NonZeroUsize::new(self.row_block_size).vortex_expect("must be non 0");
@@ -293,69 +304,11 @@ impl WriteStrategyBuilder {
293304
);
294305

295306
// 0. start with splitting columns
296-
let validity_strategy = CollectStrategy::new(compress_then_flat.clone());
307+
let validity_strategy = CollectStrategy::new(compress_then_flat);
297308

298309
// Take any field overrides from the builder and apply them to the final strategy.
299-
let mut table_strategy =
300-
TableStrategy::new(Arc::new(validity_strategy), Arc::new(repartition))
301-
.with_field_writers(self.field_writers);
302-
303-
if self.use_list_layout {
304-
let list_flat = Arc::clone(&flat);
305-
let list_data_compressor = Arc::clone(&data_compressor);
306-
let list_probe_compressor = Arc::clone(&probe_compressor);
307-
let list_compress_then_flat = compress_then_flat;
308-
let data_block_target_bytes = self.data_block_target_bytes;
309-
let row_block_len = self.row_block_size;
310-
table_strategy = table_strategy.with_list_layout_factory(
311-
move |list_layout: ListLayoutStrategy| -> Arc<dyn LayoutStrategy> {
312-
let list_layout = list_layout
313-
.with_leaf(Arc::clone(&list_flat))
314-
.with_fallback(Arc::clone(&list_flat));
315-
316-
// Preserve the normal flat-column pipeline and replace only its terminal
317-
// FlatLayout with a ListLayout. Compression therefore sees the complete list
318-
// page and makes the same recursive encoding choices as the flat format.
319-
let chunked = ChunkedLayoutStrategy::new(list_layout);
320-
let buffered = BufferedStrategy::new(chunked, 2 * ONE_MEG);
321-
let compressing =
322-
CompressingStrategy::new(buffered, Arc::clone(&list_data_compressor));
323-
let coalescing = RepartitionStrategy::new(
324-
compressing,
325-
RepartitionWriterOptions {
326-
block_size_minimum: data_block_target_bytes.unwrap_or(0),
327-
block_len_multiple: row_block_len,
328-
block_size_target: data_block_target_bytes,
329-
canonicalize: true,
330-
},
331-
);
332-
let dict = DictStrategy::new(
333-
coalescing.clone(),
334-
list_compress_then_flat.clone(),
335-
coalescing,
336-
Default::default(),
337-
Arc::clone(&list_probe_compressor),
338-
);
339-
let zoned = ZonedStrategy::new(
340-
dict,
341-
list_compress_then_flat.clone(),
342-
ZonedLayoutOptions {
343-
block_size: row_block_size,
344-
..Default::default()
345-
},
346-
);
347-
Arc::new(RepartitionStrategy::new(
348-
zoned,
349-
RepartitionWriterOptions {
350-
block_size_minimum: 0,
351-
block_len_multiple: row_block_len,
352-
block_size_target: None,
353-
canonicalize: false,
354-
},
355-
))
356-
},
357-
);
358-
}
310+
let table_strategy = TableStrategy::new(Arc::new(validity_strategy), Arc::new(repartition))
311+
.with_field_writers(self.field_writers);
359312

360313
Arc::new(table_strategy)
361314
}

0 commit comments

Comments
 (0)