Skip to content

Commit 15d2c31

Browse files
committed
Reuse chunk lookup in range selection callers
1 parent e59b0ac commit 15d2c31

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

‎encodings/pco/src/decoder.rs‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use crate::Pco;
2323
use crate::array::vortex_err_from_pco;
2424
use crate::page_index::LogicalPageIndex;
2525
use crate::page_index::PhysicalPage;
26-
use crate::page_index::ChunkCursor;
2726

2827
pub(crate) struct PageDecoder<T: Number> {
2928
file: FileDecompressor,
@@ -114,13 +113,15 @@ impl PageLookup {
114113
/// descriptor is derived from the chosen mode only when a page is decoded for the first time.
115114
pub(crate) struct DecodedPages<T: Number> {
116115
decoder: PageDecoder<T>,
116+
lookup: PageLookup,
117117
pages: BTreeMap<usize, PrimitiveArray>,
118118
}
119119

120120
impl<T: Number + NativePType> DecodedPages<T> {
121121
pub fn new(array: ArrayView<'_, Pco>) -> VortexResult<Self> {
122122
Ok(Self {
123123
decoder: PageDecoder::new(array.metadata.header.as_slice())?,
124+
lookup: PageLookup::default(),
124125
pages: BTreeMap::new(),
125126
})
126127
}
@@ -134,19 +135,19 @@ impl<T: Number + NativePType> DecodedPages<T> {
134135
let entry = match self.pages.entry(page) {
135136
Entry::Occupied(entry) => entry.into_mut(),
136137
Entry::Vacant(entry) => {
137-
let info = view.physical(page)?;
138+
let (chunk_id, n_values) = self.lookup.resolve(view, array, page)?;
138139
let buffer = array
139140
.pages
140141
.get(page)
141142
.ok_or_else(|| vortex_err!("Pco compressed page is missing"))?;
142143
let chunk = array
143144
.chunk_metas
144-
.get(info.chunk)
145+
.get(chunk_id)
145146
.ok_or_else(|| vortex_err!("Pco chunk metadata is missing"))?;
146147
entry.insert(self.decoder.read(
147-
info.chunk,
148+
chunk_id,
148149
chunk.as_slice(),
149-
info.n_values,
150+
n_values,
150151
buffer.as_slice(),
151152
ctx,
152153
)?)

‎encodings/pco/src/take.rs‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ fn stream_range<T: Number + NativePType>(
672672
}
673673
let mut state = AccessState::default();
674674
let mut decoder = PageDecoder::<T>::new(array.metadata.header.as_slice())?;
675+
let mut lookup = PageLookup::default();
675676
let stop = array.slice_start() + range.end;
676677
let mut row = global_start;
677678
// Descriptor-count iteration bounds work even when optional index contents are bad.
@@ -686,24 +687,24 @@ fn stream_range<T: Number + NativePType>(
686687
.get_mut(start..start + span.mask.len())
687688
.ok_or_else(|| vortex_err!("Pco contiguous output exceeds visible range"))?;
688689
if !span.mask.all_false() {
689-
let page = view.physical(span.page)?;
690+
let (chunk_id, n_values) = lookup.resolve(view, array, span.page)?;
690691
let buffer = array
691692
.pages
692693
.get(span.page)
693694
.ok_or_else(|| vortex_err!("Pco compressed page is missing"))?;
694695
let chunk = array
695696
.chunk_metas
696-
.get(page.chunk)
697+
.get(chunk_id)
697698
.ok_or_else(|| vortex_err!("Pco chunk metadata is missing"))?;
698-
let n = page.n_values;
699+
let n = n_values;
699700
if span.mask.all_true() && span.values == (0..n) {
700-
decoder.read_into(page.chunk, chunk.as_slice(), n, buffer.as_slice(), output)?;
701+
decoder.read_into(chunk_id, chunk.as_slice(), n, buffer.as_slice(), output)?;
701702
} else {
702703
if scratch.len() < n {
703704
scratch.push_n(T::default(), n - scratch.len());
704705
}
705706
decoder.read_into(
706-
page.chunk,
707+
chunk_id,
707708
chunk.as_slice(),
708709
n,
709710
buffer.as_slice(),

0 commit comments

Comments
 (0)