mod plan_executor;
pub mod expression_eval;
mod aggregation;
mod data_source;
mod geometric;
mod vector;
mod join;
use crate::compiler::{CompiledExpression, CompiledAssignment};
use crate::types::Entity;
use crate::error::Result;
use std::collections::HashMap;
pub use plan_executor::PlanExecutor as Executor;
pub use data_source::MemoryDataSource;
pub trait DataSource: Send + Sync {
fn scan(&self, table: &str, entity_type: &str) -> Result<Vec<Entity>>;
fn scan_with_limit(&self, table: &str, entity_type: &str, limit: usize) -> Result<Vec<Entity>> {
Ok(self.scan(table, entity_type)?.into_iter().take(limit).collect())
}
fn insert(&mut self, table: &str, entities: Vec<Entity>) -> Result<u64>;
fn update(&mut self, table: &str, filter: Option<&CompiledExpression>, assignments: &[CompiledAssignment]) -> Result<u64>;
fn delete(&mut self, table: &str, filter: Option<&CompiledExpression>) -> Result<u64>;
fn get_schema(&self, table: &str) -> Result<TableSchema>;
fn traverse_graph(
&self,
start_entity_id: &crate::types::EntityId,
max_depth: usize,
edge_type_filter: Option<&str>,
) -> Result<Vec<(Entity, usize)>>;
fn count_entities_fast(&self, table: &str, entity_type: &str) -> Result<usize> {
Ok(self.scan(table, entity_type)?.len())
}
fn create_schema(&mut self, operation: &crate::ast::schema::CreateSchemaStatement) -> Result<()>;
fn drop_schema(&mut self, operation: &crate::ast::schema::DropSchemaStatement) -> Result<()>;
fn alter_schema(&mut self, operation: &crate::ast::schema::AlterSchemaStatement) -> Result<()>;
fn describe_schema(&self, operation: &crate::ast::schema::DescribeSchemaStatement) -> Result<String>;
fn execute_lua_function(
&mut self,
function_name: &str,
_args: Vec<crate::types::Value>,
) -> Result<crate::types::Value> {
Err(crate::error::HyperQLError::ExecutionError {
message: format!(
"Lua runtime not available. Function '{}' requires Hyperspatial RouterDataSource.",
function_name
),
operation: "execute_lua_function".to_string(),
entity_context: None,
})
}
fn execute_wasm_function(
&mut self,
module_name: &str,
function_name: &str,
args: Vec<crate::types::Value>,
) -> Result<crate::types::Value> {
Err(crate::error::HyperQLError::ExecutionError {
message: format!(
"WASM runtime not available. Function '{}/{}' requires Hyperspatial RouterDataSource.",
module_name, function_name
),
operation: "execute_wasm_function".to_string(),
entity_context: None,
})
}
}
#[derive(Debug, Clone)]
pub struct TableSchema {
pub name: String,
pub columns: HashMap<String, ColumnType>,
}
#[derive(Debug, Clone)]
pub enum ColumnType {
String,
Integer,
Float,
Boolean,
EntityId,
Position,
Vector,
}
pub struct StatsCollector {
pub entities_scanned: u64,
pub relationships_traversed: u64,
pub hyperbolic_operations: u64,
pub cascade_propagations: u64,
}
impl StatsCollector {
pub fn new() -> Self {
Self {
entities_scanned: 0,
relationships_traversed: 0,
hyperbolic_operations: 0,
cascade_propagations: 0,
}
}
pub fn reset(&mut self) {
self.entities_scanned = 0;
self.relationships_traversed = 0;
self.hyperbolic_operations = 0;
self.cascade_propagations = 0;
}
}
impl Default for StatsCollector {
fn default() -> Self {
Self::new()
}
}