Skip to content

Commit

Permalink
Expose ViewContext and page byte ranges in array reader (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
robert3005 authored Jun 4, 2024
1 parent 30ebc17 commit 681e7b3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,5 @@ zigzag = "0.1.0"
warnings = "deny"

[workspace.lints.clippy]
all = "deny"
all = { level = "deny", priority = -1 }
or_fun_call = "deny"
2 changes: 1 addition & 1 deletion vortex-fastlanes/src/bitpacking/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ pub fn unpack_single(array: &BitPackedArray, index: usize) -> VortexResult<Scala
/// The caller must ensure the following invariants hold:
/// * `packed.len() == (length + 1023) / 1024 * 128 * bit_width`
/// * `index_to_decode < length`
/// Where `length` is the length of the array/slice backed by `packed` (but is not provided to this function).
/// Where `length` is the length of the array/slice backed by `packed` (but is not provided to this function).
pub unsafe fn unpack_single_primitive<T: NativePType + TryBitPack>(
packed: &[u8],
bit_width: usize,
Expand Down
5 changes: 5 additions & 0 deletions vortex-ipc/src/stream_reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ impl<R: VortexRead> StreamArrayReader<R> {
Ok(self)
}

/// Retrieve the loaded view_context
pub fn view_context(&self) -> Option<Arc<ViewContext>> {
self.view_context.clone()
}

pub fn with_dtype(self, dtype: DType) -> Self {
assert!(self.dtype.is_none(), "DType already set");
Self {
Expand Down
15 changes: 15 additions & 0 deletions vortex-ipc/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use futures_util::{Stream, TryStreamExt};
use vortex::array::chunked::ChunkedArray;
use vortex::stream::ArrayStream;
use vortex::{Array, IntoArrayData, ViewContext};
use vortex_buffer::Buffer;
use vortex_dtype::DType;
use vortex_error::{vortex_bail, VortexResult};

Expand All @@ -14,6 +15,7 @@ pub struct ArrayWriter<W: VortexWrite> {

view_ctx_range: Option<ByteRange>,
array_layouts: Vec<ArrayLayout>,
page_ranges: Vec<ByteRange>,
}

impl<W: VortexWrite> ArrayWriter<W> {
Expand All @@ -23,6 +25,7 @@ impl<W: VortexWrite> ArrayWriter<W> {
view_ctx,
view_ctx_range: None,
array_layouts: vec![],
page_ranges: vec![],
}
}

Expand All @@ -34,6 +37,10 @@ impl<W: VortexWrite> ArrayWriter<W> {
&self.array_layouts
}

pub fn page_ranges(&self) -> &[ByteRange] {
&self.page_ranges
}

pub fn into_inner(self) -> W {
self.msgs.into_inner()
}
Expand Down Expand Up @@ -102,6 +109,14 @@ impl<W: VortexWrite> ArrayWriter<W> {
self.write_array_stream(array.into_array_stream()).await
}
}

pub async fn write_page(mut self, buffer: Buffer) -> VortexResult<Self> {
let begin = self.msgs.tell();
self.msgs.write_page(buffer).await?;
let end = self.msgs.tell();
self.page_ranges.push(ByteRange { begin, end });
Ok(self)
}
}

#[derive(Copy, Clone, Debug)]
Expand Down

0 comments on commit 681e7b3

Please sign in to comment.