Skip to main content

Store

Struct Store 

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

Multi-dataset registry. Each dataset is registered in the shared SessionContext under its configured name. The per-dataset state is held behind ArcSwap so a reload can atomically replace it without blocking concurrent queries.

Implementations§

Source§

impl Store

Source

pub async fn load(cfg: &AppConfig) -> Result<Self, AppError>

Load every dataset declared in cfg.

Source

pub fn names(&self) -> Vec<String>

Sorted list of dataset names.

Source

pub fn dataset(&self, name: &str) -> Result<Arc<DatasetState>, AppError>

Source

pub async fn sample(&self, name: &str) -> Result<String, AppError>

JSON for the first row of the dataset, or null if empty. Used by GET /api/datasets/{name}/schema for discoverability.

Source

pub async fn reload(&self, name: &str) -> Result<ReloadStats, AppError>

Rebuild name from disk and atomically swap it in. Concurrent queries against the same name continue to see the old Arc<DatasetState> until they finish; the old data is dropped once the last reference goes away.

Source

pub async fn query( &self, name: &str, req: &QueryRequest, ) -> Result<String, AppError>

Run a QueryRequest against name. Empty predicates → O(1) Arrow slice. Otherwise → DataFusion SQL on the single registered table. Lazy datasets skip the in-memory hot paths and always dispatch to SQL.

Source

pub async fn query_sql( &self, sql: &str, max_rows: u64, ) -> Result<String, AppError>

Execute a pre-validated raw SELECT and return the JSON data array. The statement has already passed datapress_core::sql::validate; here it is wrapped in an outer LIMIT max_rows so the result is bounded regardless of the user’s own clauses, executed through the shared SessionContext, and run through the same fast JSON encoder as Self::query.

Source

pub async fn query_sql_arrow_stream( &self, sql: &str, max_rows: u64, ) -> Result<ArrowIpcStream, AppError>

Same plan as Self::query_sql, but encode the bounded result as an Arrow IPC stream instead of JSON. Backs the Arrow content-negotiated branch of POST /api/v1/sql.

Source

pub async fn query_arrow( &self, name: &str, req: &QueryRequest, ) -> Result<Vec<u8>, AppError>

Same plan as Self::query, but encode the result page as an Arrow IPC stream (one schema message + one batch + EOS). Empty results still produce a valid, self-describing zero-batch stream.

Source

pub async fn query_arrow_stream( &self, name: &str, req: &QueryRequest, ) -> Result<ArrowIpcStream, AppError>

Source

pub async fn query_arrow_stream_all( &self, name: &str, req: &QueryRequest, ) -> Result<ArrowIpcStream, AppError>

Source

pub async fn parquet(&self, name: &str) -> Result<Bytes, AppError>

Encode the entire dataset as a single self-contained Parquet file.

Collects every row (all columns, no predicates, no paging) and runs it through a single parquet::arrow::ArrowWriter, so the result carries the row-group + footer metadata a Parquet reader needs to answer count(*) straight from the footer. Powers the cached GET /datasets/{name}/parquet HTTP endpoint.

Source§

impl Store

Source

pub async fn count( &self, name: &str, req: &CountRequest, ) -> Result<i64, AppError>

Return the number of rows matching req.predicates. With no predicates this is a cheap metadata lookup on materialised datasets and a SELECT COUNT(*) on lazy ones.

Trait Implementations§

Source§

impl Backend for Store

Source§

fn names(&self) -> Vec<String>

Sorted list of dataset names.
Source§

fn summary(&self, name: &str) -> Result<DatasetSummary, AppError>

Cheap summary for the dataset listing endpoint. Err(NotFound) on unknown name.
Source§

fn schema(&self, name: &str) -> Result<Arc<DatasetSchema>, AppError>

Full schema for name. Err(NotFound) on unknown name.
Source§

fn indexed_columns(&self, name: &str) -> Result<Vec<String>, AppError>

Names of columns the backend has built an equality index over, for inclusion in the /schema response. Default impl returns an empty vec — backends without per-column indexes (e.g. DuckDB, which relies on the embedded database engine) need not override.
Source§

fn sample<'life0, 'life1, 'async_trait>( &'life0 self, name: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<String, AppError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

JSON for the first row of the dataset, or the literal string "null" if the dataset is empty.
Source§

fn query<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, name: &'life1 str, req: &'life2 QueryRequest, ) -> Pin<Box<dyn Future<Output = Result<String, AppError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Execute req against name, returning the JSON-encoded data array (without the {"data": …, "page": …} envelope — that’s added by the handler).
Source§

fn query_arrow<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, name: &'life1 str, req: &'life2 QueryRequest, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, AppError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Execute req against name, returning the result as an Arrow IPC stream byte buffer (one schema message + zero or more RecordBatch messages + EOS). The handler ships this verbatim with Content-Type: application/vnd.apache.arrow.stream. Read more
Source§

fn query_arrow_stream<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, name: &'life1 str, req: &'life2 QueryRequest, ) -> Pin<Box<dyn Future<Output = Result<ArrowIpcStream, AppError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Execute req and stream the Arrow IPC bytes. The default adapter preserves compatibility for backends that only implement Backend::query_arrow, but high-throughput backends should override this to avoid building one full response buffer.
Source§

fn query_arrow_stream_all<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, name: &'life1 str, req: &'life2 QueryRequest, ) -> Pin<Box<dyn Future<Output = Result<ArrowIpcStream, AppError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Execute req and stream all matching Arrow IPC batches in one HTTP response. Unlike Backend::query_arrow_stream, this is not page scoped; limit may still cap the total rows returned.
Source§

fn count<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, name: &'life1 str, req: &'life2 CountRequest, ) -> Pin<Box<dyn Future<Output = Result<i64, AppError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Count rows in name matching req.predicates.
Source§

fn query_sql<'life0, 'life1, 'async_trait>( &'life0 self, sql: &'life1 str, max_rows: u64, ) -> Pin<Box<dyn Future<Output = Result<String, AppError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Execute a pre-validated raw SELECT and return the JSON-encoded data array (same shape as Backend::query — the handler adds the {"data": …} envelope). Read more
Source§

fn query_sql_arrow_stream<'life0, 'life1, 'async_trait>( &'life0 self, sql: &'life1 str, max_rows: u64, ) -> Pin<Box<dyn Future<Output = Result<ArrowIpcStream, AppError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Execute a pre-validated raw SELECT and stream the result as Arrow IPC bytes (one schema message + zero or more RecordBatch messages Read more
Source§

fn parquet<'life0, 'life1, 'async_trait>( &'life0 self, name: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Bytes, AppError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Encode the entire dataset as a single self-contained Parquet file, returned as in-memory bytes. Read more
Source§

fn reload<'life0, 'life1, 'async_trait>( &'life0 self, name: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<ReloadStats, AppError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Rebuild name from its configured source and atomically swap it in.

Auto Trait Implementations§

§

impl !Freeze for Store

§

impl !RefUnwindSafe for Store

§

impl !UnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl UnsafeUnpin for Store

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> AsAny for T
where T: Any + Send + Sync,

Source§

fn any_ref(&self) -> &(dyn Any + Sync + Send + 'static)

Obtains a dyn Any reference to the object: Read more
Source§

fn as_any(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Obtains an Arc<dyn Any> reference to the object: Read more
Source§

fn into_any(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts the object to Box<dyn Any>: Read more
Source§

fn type_name(&self) -> &'static str

Convenient wrapper for std::any::type_name, since Any does not provide it and Any::type_id is useless as a debugging aid (its Debug is just a mess of hex digits).
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<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<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<KernelType, ArrowType> TryIntoArrow<ArrowType> for KernelType
where ArrowType: TryFromKernel<KernelType>,

Source§

fn try_into_arrow(self) -> Result<ArrowType, ArrowError>

Source§

impl<KernelType, ArrowType> TryIntoKernel<KernelType> for ArrowType
where KernelType: TryFromArrow<ArrowType>,

Source§

fn try_into_kernel(self) -> Result<KernelType, ArrowError>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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