ElastiCube

Struct ElastiCube 

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

The main ElastiCube structure

Represents a multidimensional cube with dimensions, measures, and data stored in Apache Arrow’s columnar format for efficient analytical queries.

Implementations§

Source§

impl ElastiCube

Source

pub fn new( schema: CubeSchema, arrow_schema: Arc<ArrowSchema>, data: Vec<RecordBatch>, ) -> Result<Self>

Create a new ElastiCube

Source

pub fn schema(&self) -> &CubeSchema

Get the cube schema

Source

pub fn arrow_schema(&self) -> &Arc<ArrowSchema>

Get the Arrow schema

Source

pub fn data(&self) -> &[RecordBatch]

Get the data batches

Source

pub fn row_count(&self) -> usize

Get the total number of rows

Source

pub fn dimensions(&self) -> Vec<&Dimension>

Get all dimensions

Source

pub fn measures(&self) -> Vec<&Measure>

Get all measures

Source

pub fn hierarchies(&self) -> Vec<&Hierarchy>

Get all hierarchies

Source

pub fn get_dimension(&self, name: &str) -> Option<&Dimension>

Get a dimension by name

Source

pub fn get_measure(&self, name: &str) -> Option<&Measure>

Get a measure by name

Source

pub fn get_hierarchy(&self, name: &str) -> Option<&Hierarchy>

Get a hierarchy by name

Source

pub fn query(self: Arc<Self>) -> Result<QueryBuilder>

Create a query builder for this cube

This method requires the cube to be wrapped in an Arc<ElastiCube> because the query builder needs to share ownership of the cube data across async query execution and potential caching operations.

§Returns

A QueryBuilder instance for executing queries against this cube

§Arc Requirement

The cube must be wrapped in Arc before calling this method:

use std::sync::Arc;

let cube = ElastiCubeBuilder::new("sales")
    .load_csv("data.csv")?
    .build()?;

// Wrap in Arc for querying
let cube = Arc::new(cube);

// Now we can query
let results = cube.query()?
    .select(&["region", "SUM(sales) as total"])
    .group_by(&["region"])
    .execute()
    .await?;
§See Also
Source

pub fn statistics(&self) -> CubeStatistics

Get cube statistics for performance analysis

Returns statistics about the cube’s data including row count, partition count, memory usage, and column-level statistics.

§Example
let stats = cube.statistics();
println!("Cube: {}", stats.summary());
Source

pub fn query_with_config( self: Arc<Self>, config: OptimizationConfig, ) -> Result<QueryBuilder>

Create a query builder with custom optimization configuration

Like query, this requires the cube to be wrapped in Arc. Use this method when you need to customize query execution behavior such as parallelism, batch size, or caching settings.

§Arguments
  • config - Optimization configuration to use for queries
§Returns

A QueryBuilder instance with the specified optimization settings

§Example
use std::sync::Arc;
use elasticube_core::OptimizationConfig;

let cube = Arc::new(cube); // Wrap in Arc

let config = OptimizationConfig::new()
    .with_target_partitions(8)
    .with_batch_size(4096);

let results = cube.query_with_config(config)?
    .select(&["region", "SUM(sales)"])
    .execute()
    .await?;
Source

pub fn append_rows(&mut self, batch: RecordBatch) -> Result<usize>

Append new rows from a RecordBatch to the cube

This method adds new rows to the cube by appending a RecordBatch. The schema of the new batch must match the cube’s schema exactly.

§Arguments
  • batch - RecordBatch containing rows to append
§Returns

Number of rows added

§Example
let new_batch = RecordBatch::try_new(schema, columns)?;
let rows_added = cube.append_rows(new_batch)?;
println!("Added {} rows", rows_added);
Source

pub fn append_batches(&mut self, batches: Vec<RecordBatch>) -> Result<usize>

Append multiple RecordBatches to the cube (incremental loading)

This method adds new data incrementally by appending multiple batches. All batches must have schemas compatible with the cube’s schema.

§Arguments
  • batches - Vector of RecordBatches to append
§Returns

Total number of rows added

§Example
let batches = vec![batch1, batch2, batch3];
let total_rows = cube.append_batches(batches)?;
println!("Appended {} rows total", total_rows);
Source

pub async fn delete_rows(&mut self, filter_expr: &str) -> Result<usize>

Delete rows from the cube based on a SQL filter expression

This method removes rows that match the given SQL WHERE clause predicate. Since RecordBatch is immutable, this creates new batches without the deleted rows.

§Arguments
  • filter_expr - SQL WHERE clause expression (e.g., “age < 18” or “region = ‘North’”)
§Returns

Number of rows deleted

§Example
// Delete all rows where sales < 100
let deleted = cube.delete_rows("sales < 100").await?;
println!("Deleted {} rows", deleted);
Source

pub async fn update_rows( &mut self, filter_expr: &str, replacement_batch: RecordBatch, ) -> Result<(usize, usize)>

Update rows in the cube based on a filter and replacement batch

This method updates rows matching a filter expression by:

  1. Deleting rows that match the filter
  2. Appending the replacement batch

The replacement batch must have a schema compatible with the cube.

§Arguments
  • filter_expr - SQL WHERE clause to identify rows to update
  • replacement_batch - RecordBatch containing updated rows
§Returns

Tuple of (rows_deleted, rows_added)

§Example
// Update all North region sales with new values
let updated_data = create_updated_batch()?;
let (deleted, added) = cube.update_rows("region = 'North'", updated_data).await?;
println!("Updated {} rows", deleted);
Source

pub fn consolidate_batches(&mut self) -> Result<usize>

Consolidate all data batches into a single batch

This operation can improve query performance by reducing the number of batches, but may increase memory usage temporarily during consolidation.

§Returns

Number of batches before consolidation

§Example
let old_batch_count = cube.consolidate_batches()?;
println!("Consolidated from {} batches to 1 batch", old_batch_count);
Source

pub fn batch_count(&self) -> usize

Get the number of data batches in the cube

Useful for monitoring fragmentation and deciding when to consolidate.

Trait Implementations§

Source§

impl Clone for ElastiCube

Source§

fn clone(&self) -> ElastiCube

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ElastiCube

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,