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
impl ElastiCube
Sourcepub fn new(
schema: CubeSchema,
arrow_schema: Arc<ArrowSchema>,
data: Vec<RecordBatch>,
) -> Result<Self>
pub fn new( schema: CubeSchema, arrow_schema: Arc<ArrowSchema>, data: Vec<RecordBatch>, ) -> Result<Self>
Create a new ElastiCube
Sourcepub fn schema(&self) -> &CubeSchema
pub fn schema(&self) -> &CubeSchema
Get the cube schema
Sourcepub fn arrow_schema(&self) -> &Arc<ArrowSchema>
pub fn arrow_schema(&self) -> &Arc<ArrowSchema>
Get the Arrow schema
Sourcepub fn data(&self) -> &[RecordBatch]
pub fn data(&self) -> &[RecordBatch]
Get the data batches
Sourcepub fn dimensions(&self) -> Vec<&Dimension>
pub fn dimensions(&self) -> Vec<&Dimension>
Get all dimensions
Sourcepub fn hierarchies(&self) -> Vec<&Hierarchy>
pub fn hierarchies(&self) -> Vec<&Hierarchy>
Get all hierarchies
Sourcepub fn get_dimension(&self, name: &str) -> Option<&Dimension>
pub fn get_dimension(&self, name: &str) -> Option<&Dimension>
Get a dimension by name
Sourcepub fn get_measure(&self, name: &str) -> Option<&Measure>
pub fn get_measure(&self, name: &str) -> Option<&Measure>
Get a measure by name
Sourcepub fn get_hierarchy(&self, name: &str) -> Option<&Hierarchy>
pub fn get_hierarchy(&self, name: &str) -> Option<&Hierarchy>
Get a hierarchy by name
Sourcepub fn query(self: Arc<Self>) -> Result<QueryBuilder>
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
query_with_config- Query with custom optimization settings
Sourcepub fn statistics(&self) -> CubeStatistics
pub fn statistics(&self) -> CubeStatistics
Sourcepub fn query_with_config(
self: Arc<Self>,
config: OptimizationConfig,
) -> Result<QueryBuilder>
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?;Sourcepub fn append_rows(&mut self, batch: RecordBatch) -> Result<usize>
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);Sourcepub fn append_batches(&mut self, batches: Vec<RecordBatch>) -> Result<usize>
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);Sourcepub async fn delete_rows(&mut self, filter_expr: &str) -> Result<usize>
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);Sourcepub async fn update_rows(
&mut self,
filter_expr: &str,
replacement_batch: RecordBatch,
) -> Result<(usize, usize)>
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:
- Deleting rows that match the filter
- 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 updatereplacement_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);Sourcepub fn consolidate_batches(&mut self) -> Result<usize>
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);Sourcepub fn batch_count(&self) -> usize
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
impl Clone for ElastiCube
Source§fn clone(&self) -> ElastiCube
fn clone(&self) -> ElastiCube
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ElastiCube
impl !RefUnwindSafe for ElastiCube
impl Send for ElastiCube
impl Sync for ElastiCube
impl Unpin for ElastiCube
impl !UnwindSafe for ElastiCube
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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