reifydb_engine/table_virtual/
mod.rs

1// Copyright (c) reifydb.com 2025
2// This file is licensed under the AGPL-3.0-or-later, see license.md file
3
4use reifydb_core::{
5	SortKey,
6	interface::{Params, TableVirtualDef},
7};
8use reifydb_rql::expression::Expression;
9
10use crate::{execute::Batch, transaction::StandardTransaction};
11
12pub(crate) mod system;
13
14/// Context passed to virtual table queries
15pub enum TableVirtualContext<'a> {
16	Basic {
17		/// Query parameters
18		params: Params,
19	},
20	PushDown {
21		/// Filter conditions from filter operations
22		filters: Vec<Expression<'a>>,
23		/// Projection expressions from map operations (empty = select
24		/// all)
25		projections: Vec<Expression<'a>>,
26		/// Sort keys from order operations
27		order_by: Vec<SortKey>,
28		/// Limit from take operations
29		limit: Option<usize>,
30		/// Query parameters
31		params: Params,
32	},
33}
34
35/// Trait for virtual table instances that follow the volcano iterator pattern
36pub trait TableVirtual<'a>: Send + Sync {
37	/// Initialize the virtual table iterator with context
38	/// Called once before iteration begins
39	fn initialize(&mut self, txn: &mut StandardTransaction<'a>, ctx: TableVirtualContext<'a>) -> crate::Result<()>;
40
41	/// Get the next batch of results (volcano iterator pattern)
42	fn next(&mut self, txn: &mut StandardTransaction<'a>) -> crate::Result<Option<Batch<'a>>>;
43
44	/// Get the table definition
45	fn definition(&self) -> &TableVirtualDef;
46}