pub struct MemTable {
schema: Arc<Schema>,
pub batches: Vec<Arc<RwLock<Vec<RecordBatch>>>>,
constraints: Constraints,
column_defaults: HashMap<String, Expr>,
pub sort_order: Arc<Mutex<RawMutex, Vec<Vec<Sort>>>>,
}Expand description
In-memory data source for presenting a Vec<RecordBatch> as a
data source that can be queried by DataFusion. This allows data to
be pre-loaded into memory and then repeatedly queried without
incurring additional file I/O overhead.
Fields§
§schema: Arc<Schema>§batches: Vec<Arc<RwLock<Vec<RecordBatch>>>>§constraints: Constraints§column_defaults: HashMap<String, Expr>§sort_order: Arc<Mutex<RawMutex, Vec<Vec<Sort>>>>Optional pre-known sort order(s). Must be SortExprs.
inserting data into this table removes the order
Implementations§
Source§impl MemTable
impl MemTable
Sourcepub fn try_new(
schema: Arc<Schema>,
partitions: Vec<Vec<RecordBatch>>,
) -> Result<MemTable, DataFusionError>
pub fn try_new( schema: Arc<Schema>, partitions: Vec<Vec<RecordBatch>>, ) -> Result<MemTable, DataFusionError>
Create a new in-memory table from the provided schema and record batches.
Requires at least one partition. To construct an empty MemTable, pass
vec![vec![]] as the partitions argument, this represents one partition with
no batches.
Sourcepub fn with_constraints(self, constraints: Constraints) -> MemTable
pub fn with_constraints(self, constraints: Constraints) -> MemTable
Assign constraints
Sourcepub fn with_column_defaults(
self,
column_defaults: HashMap<String, Expr>,
) -> MemTable
pub fn with_column_defaults( self, column_defaults: HashMap<String, Expr>, ) -> MemTable
Assign column defaults
Sourcepub fn with_sort_order(self, sort_order: Vec<Vec<Sort>>) -> MemTable
pub fn with_sort_order(self, sort_order: Vec<Vec<Sort>>) -> MemTable
Specify an optional pre-known sort order(s). Must be SortExprs.
If the data is not sorted by this order, DataFusion may produce incorrect results.
DataFusion may take advantage of this ordering to omit sorts or use more efficient algorithms.
Note that multiple sort orders are supported, if some are known to be equivalent,
Sourcepub async fn load(
t: Arc<dyn TableProvider>,
output_partitions: Option<usize>,
state: &dyn Session,
) -> Result<MemTable, DataFusionError>
pub async fn load( t: Arc<dyn TableProvider>, output_partitions: Option<usize>, state: &dyn Session, ) -> Result<MemTable, DataFusionError>
Create a mem table by reading from another data source
Trait Implementations§
Source§impl TableProvider for MemTable
impl TableProvider for MemTable
Source§fn insert_into<'life0, 'life1, 'async_trait>(
&'life0 self,
_state: &'life1 dyn Session,
input: Arc<dyn ExecutionPlan>,
insert_op: InsertOp,
) -> Pin<Box<dyn Future<Output = Result<Arc<dyn ExecutionPlan>, DataFusionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MemTable: 'async_trait,
fn insert_into<'life0, 'life1, 'async_trait>(
&'life0 self,
_state: &'life1 dyn Session,
input: Arc<dyn ExecutionPlan>,
insert_op: InsertOp,
) -> Pin<Box<dyn Future<Output = Result<Arc<dyn ExecutionPlan>, DataFusionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
MemTable: 'async_trait,
Returns an ExecutionPlan that inserts the execution results of a given ExecutionPlan into this MemTable.
The ExecutionPlan must have the same schema as this MemTable.
§Arguments
state- TheSessionStatecontaining the context for executing the plan.input- TheExecutionPlanto execute and insert.
§Returns
- A plan that returns the number of rows written.
Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Any so that it can be
downcast to a specific implementation.Source§fn constraints(&self) -> Option<&Constraints>
fn constraints(&self) -> Option<&Constraints>
Source§fn table_type(&self) -> TableType
fn table_type(&self) -> TableType
Source§fn scan<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
state: &'life1 dyn Session,
projection: Option<&'life2 Vec<usize>>,
_filters: &'life3 [Expr],
_limit: Option<usize>,
) -> Pin<Box<dyn Future<Output = Result<Arc<dyn ExecutionPlan>, DataFusionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
MemTable: 'async_trait,
fn scan<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
state: &'life1 dyn Session,
projection: Option<&'life2 Vec<usize>>,
_filters: &'life3 [Expr],
_limit: Option<usize>,
) -> Pin<Box<dyn Future<Output = Result<Arc<dyn ExecutionPlan>, DataFusionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
MemTable: 'async_trait,
ExecutionPlan for scanning the table with optionally
specified projection, filter and limit, described below. Read moreSource§fn get_column_default(&self, column: &str) -> Option<&Expr>
fn get_column_default(&self, column: &str) -> Option<&Expr>
Source§fn get_table_definition(&self) -> Option<&str>
fn get_table_definition(&self) -> Option<&str>
Source§fn get_logical_plan(&self) -> Option<Cow<'_, LogicalPlan>>
fn get_logical_plan(&self) -> Option<Cow<'_, LogicalPlan>>
LogicalPlan of this table, if available.Source§fn scan_with_args<'a, 'life0, 'life1, 'async_trait>(
&'life0 self,
state: &'life1 dyn Session,
args: ScanArgs<'a>,
) -> Pin<Box<dyn Future<Output = Result<ScanResult, DataFusionError>> + Send + 'async_trait>>where
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn scan_with_args<'a, 'life0, 'life1, 'async_trait>(
&'life0 self,
state: &'life1 dyn Session,
args: ScanArgs<'a>,
) -> Pin<Box<dyn Future<Output = Result<ScanResult, DataFusionError>> + Send + 'async_trait>>where
'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
ExecutionPlan for scanning the table using structured arguments. Read moreSource§fn supports_filters_pushdown(
&self,
filters: &[&Expr],
) -> Result<Vec<TableProviderFilterPushDown>, DataFusionError>
fn supports_filters_pushdown( &self, filters: &[&Expr], ) -> Result<Vec<TableProviderFilterPushDown>, DataFusionError>
Source§fn statistics(&self) -> Option<Statistics>
fn statistics(&self) -> Option<Statistics>
Auto Trait Implementations§
impl Freeze for MemTable
impl !RefUnwindSafe for MemTable
impl Send for MemTable
impl Sync for MemTable
impl Unpin for MemTable
impl !UnwindSafe for MemTable
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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