Skip to content

Commit f64dee4

Browse files
committed
Reuse chunk lookup in range selection callers
1 parent 32c74fe commit f64dee4

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,
@@ -116,13 +115,15 @@ impl PageLookup {
116115
/// descriptor is derived from the chosen mode only when a page is decoded for the first time.
117116
pub(crate) struct DecodedPages<T: Number> {
118117
decoder: PageDecoder<T>,
118+
lookup: PageLookup,
119119
pages: BTreeMap<usize, PrimitiveArray>,
120120
}
121121

122122
impl<T: Number + NativePType> DecodedPages<T> {
123123
pub fn new(array: ArrayView<'_, Pco>) -> VortexResult<Self> {
124124
Ok(Self {
125125
decoder: PageDecoder::new(array.metadata.header.as_slice())?,
126+
lookup: PageLookup::default(),
126127
pages: BTreeMap::new(),
127128
})
128129
}
@@ -136,19 +137,19 @@ impl<T: Number + NativePType> DecodedPages<T> {
136137
let entry = match self.pages.entry(page) {
137138
Entry::Occupied(entry) => entry.into_mut(),
138139
Entry::Vacant(entry) => {
139-
let info = view.physical(page)?;
140+
let (chunk_id, n_values) = self.lookup.resolve(view, array, page)?;
140141
let buffer = array
141142
.pages
142143
.get(page)
143144
.ok_or_else(|| vortex_err!("Pco compressed page is missing"))?;
144145
let chunk = array
145146
.chunk_metas
146-
.get(info.chunk)
147+
.get(chunk_id)
147148
.ok_or_else(|| vortex_err!("Pco chunk metadata is missing"))?;
148149
entry.insert(self.decoder.read(
149-
info.chunk,
150+
chunk_id,
150151
chunk.as_slice(),
151-
info.n_values,
152+
n_values,
152153
buffer.as_slice(),
153154
ctx,
154155
)?)

‎encodings/pco/src/take.rs‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ fn stream_range<T: Number + NativePType>(
657657
}
658658
let mut state = AccessState::default();
659659
let mut decoder = PageDecoder::<T>::new(array.metadata.header.as_slice())?;
660+
let mut lookup = PageLookup::default();
660661
let stop = array.slice_start() + range.end;
661662
let mut row = global_start;
662663
// Descriptor-count iteration bounds work even when optional index contents are bad.
@@ -671,24 +672,24 @@ fn stream_range<T: Number + NativePType>(
671672
.get_mut(start..start + span.mask.len())
672673
.ok_or_else(|| vortex_err!("Pco contiguous output exceeds visible range"))?;
673674
if !span.mask.all_false() {
674-
let page = view.physical(span.page)?;
675+
let (chunk_id, n_values) = lookup.resolve(view, array, span.page)?;
675676
let buffer = array
676677
.pages
677678
.get(span.page)
678679
.ok_or_else(|| vortex_err!("Pco compressed page is missing"))?;
679680
let chunk = array
680681
.chunk_metas
681-
.get(page.chunk)
682+
.get(chunk_id)
682683
.ok_or_else(|| vortex_err!("Pco chunk metadata is missing"))?;
683-
let n = page.n_values;
684+
let n = n_values;
684685
if span.mask.all_true() && span.values == (0..n) {
685-
decoder.read_into(page.chunk, chunk.as_slice(), n, buffer.as_slice(), output)?;
686+
decoder.read_into(chunk_id, chunk.as_slice(), n, buffer.as_slice(), output)?;
686687
} else {
687688
if scratch.len() < n {
688689
scratch.push_n(T::default(), n - scratch.len());
689690
}
690691
decoder.read_into(
691-
page.chunk,
692+
chunk_id,
692693
chunk.as_slice(),
693694
n,
694695
buffer.as_slice(),

0 commit comments

Comments
 (0)