Skip to content

Commit 45365ab

Browse files
committed
more
Signed-off-by: Robert Kruszewski <github@robertk.io>
1 parent fedf232 commit 45365ab

2 files changed

Lines changed: 24 additions & 16 deletions

File tree

vortex-layout/src/layouts/zoned/writer.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl LayoutStrategy for ZonedStrategy {
155155
)
156156
.await?;
157157

158-
let Some(stats_table) = stats_accumulator.lock().as_stats_table()? else {
158+
let Some((stats_table, stats)) = stats_accumulator.lock().as_stats_table()? else {
159159
// If we have no stats (e.g. the DType doesn't support them), then we just return the
160160
// child layout.
161161
return Ok(data_layout);
@@ -174,13 +174,7 @@ impl LayoutStrategy for ZonedStrategy {
174174
.write_stream(ctx, Arc::clone(&segment_sink), stats_stream, eof, &session)
175175
.await?;
176176

177-
Ok(ZonedLayout::new(
178-
data_layout,
179-
zones_layout,
180-
block_size,
181-
Arc::clone(stats_table.present_stats()),
182-
)
183-
.into_layout())
177+
Ok(ZonedLayout::new(data_layout, zones_layout, block_size, stats).into_layout())
184178
}
185179

186180
fn buffered_bytes(&self) -> u64 {

vortex-layout/src/layouts/zoned/zone_map.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ pub struct ZoneMap {
4343
array: StructArray,
4444
// The statistics that are included in the table.
4545
stats: Arc<[Stat]>,
46+
// The length of each zone in the zone map.
47+
zone_len: usize,
48+
// Number of rows that the zone map covers
49+
row_count: u64,
4650
}
4751

4852
impl ZoneMap {
@@ -52,24 +56,35 @@ impl ZoneMap {
5256
column_dtype: DType,
5357
array: StructArray,
5458
stats: Arc<[Stat]>,
59+
zone_len: usize,
60+
row_count: u64,
5561
) -> VortexResult<Self> {
5662
let expected_dtype = stats_table_dtype(&column_dtype, &stats);
5763
if &expected_dtype != array.dtype() {
5864
vortex_bail!("Array dtype does not match expected zone map dtype: {expected_dtype}");
5965
}
6066

6167
// SAFETY: We checked that the array matches the expected stats-table schema.
62-
Ok(unsafe { Self::new_unchecked(array, stats) })
68+
Ok(unsafe { Self::new_unchecked(array, stats, zone_len, row_count) })
6369
}
6470

6571
/// Creates [`ZoneMap`] without validating return array against expected stats.
6672
///
6773
/// # Safety
6874
///
6975
/// Assumes that the input struct array has the correct statistics as fields. Or in other words,
70-
/// the [`DType`] of the input array is equal to the result of `stats_table_dtype`.
71-
pub unsafe fn new_unchecked(array: StructArray, stats: Arc<[Stat]>) -> Self {
72-
Self { array, stats }
76+
pub unsafe fn new_unchecked(
77+
array: StructArray,
78+
stats: Arc<[Stat]>,
79+
zone_len: usize,
80+
row_count: u64,
81+
) -> Self {
82+
Self {
83+
array,
84+
stats,
85+
zone_len,
86+
row_count,
87+
}
7388
}
7489

7590
/// Returns the [`DType`] of the statistics table given a set of statistics and column [`DType`].
@@ -144,8 +159,6 @@ impl ZoneMap {
144159
pub fn prune(
145160
&self,
146161
predicate: &Expression,
147-
zone_len: u64,
148-
row_count: u64,
149162
session: &VortexSession,
150163
) -> VortexResult<Mask> {
151164
let mut ctx = session.create_execution_ctx();
@@ -157,7 +170,7 @@ impl ZoneMap {
157170
return applied.execute::<Mask>(&mut ctx);
158171
}
159172

160-
let row_count_array = row_count_array(zone_len, row_count, num_zones, &mut ctx)?;
173+
let row_count_array = row_count_array(self.zone_len, self.row_count, num_zones, &mut ctx)?;
161174
let substituted = substitute_stats_fn_array::<RowCount>(applied, &row_count_array)?;
162175
substituted.execute::<Mask>(&mut ctx)
163176
}
@@ -169,7 +182,7 @@ impl ZoneMap {
169182
/// result is a [`ConstantArray`] for uniform zone sizes, otherwise a two-run
170183
/// run-end encoded array whose trailing run carries the final zone length.
171184
fn row_count_array(
172-
zone_len: u64,
185+
zone_len: usize,
173186
row_count: u64,
174187
num_zones: usize,
175188
ctx: &mut ExecutionCtx,
@@ -263,6 +276,7 @@ mod tests {
263276
])
264277
.unwrap(),
265278
Arc::new([Stat::Max, Stat::Min]),
279+
10,
266280
)
267281
.unwrap();
268282

0 commit comments

Comments
 (0)