Skip to main content

SegmentReader

Struct SegmentReader 

Source
pub struct SegmentReader { /* private fields */ }
Expand description

Reads data from a .csx segment file.

§I/O model

The segment file is memory-mapped (Mmap) so all column block reads are zero-copy slices into the OS page cache. No per-column File::read() calls are issued; instead the kernel pages data in on first access and the MADV_WILLNEED advisory hint triggers asynchronous prefetch of upcoming blocks while the current block is being decoded. This means sequential scans benefit from kernel-level read-ahead without any user-space prefetch thread or buffer.

§Predicate pushdown

read_projected_filtered_with_predicates evaluates predicates at row-group granularity using per-block ColumnStats before touching any column bytes. This can skip entire row groups when the query’s time window doesn’t overlap a row group’s timestamp range, or when a tag column’s value_count proves it cannot match an equality filter.

Implementations§

Source§

impl SegmentReader

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self>

Open a segment file, validate integrity, and parse metadata.

§Errors

Returns an error if the file doesn’t exist, is corrupt, or has an invalid checksum.

Source

pub fn header(&self) -> &SegmentHeader

Returns the segment header.

Source

pub fn column_metadata(&self) -> &[ColumnMeta]

Returns the column metadata.

Source

pub fn row_group_count(&self) -> usize

Returns the number of row groups.

Source

pub fn row_group_blocks(&self, row_group: usize) -> Option<&[ColumnBlockMeta]>

Returns the per-column block metadata for one row group.

Each entry carries the codec that was actually used for that block — ColumnMeta::default_encoding is only the writer’s initial guess — along with its on-disk length. Together they answer “which encoding won, and what did it cost”, which is what compression regressions and codec benchmarks need to see.

Returns None if row_group is out of range.

Source

pub fn path(&self) -> &Path

Returns the file path.

Source

pub fn set_key_provider(&mut self, provider: Arc<dyn FieldKeyProvider>)

Set a field-level encryption key provider for decrypting encrypted column blocks. Must be called before reading any encrypted columns.

Source

pub fn read_columns( &self, column_names: &[&str], row_group: usize, ) -> Result<Vec<ArrayRef>>

Read specific columns from a specific row group as Arrow arrays.

§Read-ahead / prefetch

When reading column N, the reader issues an madvise(MADV_WILLNEED) hint for column N+1’s byte range so the OS can begin paging it in from disk while the current column is being decoded. Combined with the Sequential advice set at open time, this reduces I/O stalls on sequential scans.

§Errors

Returns an error if the row group index is out of range or a column is not found.

Source

pub fn read_all(&self) -> Result<RecordBatch>

Read all data as a single Arrow RecordBatch.

This is a convenience wrapper around read_projected that passes every column name. When only a subset of columns is needed, prefer calling read_projected or read_projected_filtered directly — they skip I/O and decompression for unrequested columns ( column pruning).

§Errors

Returns an error if any column data is corrupt.

Source

pub fn read_row_group(&self, row_group: usize) -> Result<RecordBatch>

Read all columns from a single row group as a RecordBatch.

This is useful for reverse-order scanning (e.g. last_value) where only one row group at a time needs to be materialised.

§Errors

Returns an error if row_group is out of range or column data is corrupt.

Source

pub fn read_projected(&self, column_names: &[&str]) -> Result<RecordBatch>

Read selected columns across all row groups as a single RecordBatch.

Only the byte ranges for the requested columns are decoded and decompressed — all other column data on disk is skipped entirely. The timestamp column is always included even if not listed.

§Errors

Returns an error if any requested column name is not found in the segment metadata, or if column data is corrupt.

Source

pub fn read_projected_filtered( &self, column_names: &[&str], time_range: Option<(i64, i64)>, ) -> Result<RecordBatch>

Read selected columns with optional row-group-level time-range predicate pushdown.

When time_range is Some((start_ns, end_ns)), row groups whose timestamp range does not overlap [start_ns, end_ns] are skipped entirely — no I/O or decompression is performed for them.

Both boundaries are inclusive, matching the semantics of chronix_query::plan::TimeRange.

This is the primary entry point for query-time segment reads where the caller already knows the desired time window.

Source

pub fn read_projected_filtered_with_predicates( &self, column_names: &[&str], time_range: Option<(i64, i64)>, tag_predicates: &[(&str, &str)], ) -> Result<RecordBatch>

Read selected columns with row-group-level time-range and tag predicate pushdown.

In addition to time-range pruning, this method also pushes tag equality predicates down to row-group level. A row group is skipped when a tag column’s per-block statistics indicate that it has zero non-null values (value_count == 0), which means it cannot possibly match an equality filter on that tag.

§Arguments
  • column_names — Columns to read (empty = all).
  • time_range — Optional inclusive time range (start, end).
  • tag_predicates — Tag equality filters as (column_name, value) pairs.
Source

pub fn read_projected_with_zone_maps( &self, column_names: &[&str], time_range: Option<(i64, i64)>, tag_predicates: &[(&str, &str)], field_predicates: &[FieldPredicate], ) -> Result<RecordBatch>

Read selected columns with full predicate pushdown: time-range, tag equality, and zone-map field predicates (late materialisation).

Zone-map field predicates evaluate per-row-group column min/max statistics to skip row groups that cannot possibly match numeric comparisons. This avoids decompressing and decoding column data for entire row groups.

§Arguments
  • column_names — Columns to read (empty = all).
  • time_range — Optional inclusive time range (start, end).
  • tag_predicates — Tag equality filters as (column_name, value) pairs.
  • field_predicates — Numeric field predicates for zone-map pruning.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more