-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
115 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,114 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use partiql_ast_passes::error::AstTransformationError; | ||
use partiql_catalog::{Catalog, PartiqlCatalog}; | ||
use partiql_eval as eval; | ||
use partiql_eval::env::basic::MapBindings; | ||
use partiql_eval::error::{EvalErr, PlanErr}; | ||
use partiql_eval::eval::{EvalPlan, EvalResult, Evaluated}; | ||
use partiql_eval::plan::EvaluationMode; | ||
use partiql_logical as logical; | ||
use partiql_parser::{Parsed, ParserError, ParserResult}; | ||
use partiql_value::Value; | ||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug)] | ||
enum TestError<'a> { | ||
#[error("Parse error: {0:?}")] | ||
Parse(ParserError<'a>), | ||
#[error("Lower error: {0:?}")] | ||
Lower(AstTransformationError), | ||
#[error("Plan error: {0:?}")] | ||
Plan(PlanErr), | ||
#[error("Evaluation error: {0:?}")] | ||
Eval(EvalErr), | ||
} | ||
|
||
impl<'a> From<ParserError<'a>> for TestError<'a> { | ||
fn from(err: ParserError<'a>) -> Self { | ||
TestError::Parse(err) | ||
} | ||
} | ||
|
||
impl From<AstTransformationError> for TestError<'_> { | ||
fn from(err: AstTransformationError) -> Self { | ||
TestError::Lower(err) | ||
} | ||
} | ||
|
||
impl From<PlanErr> for TestError<'_> { | ||
fn from(err: PlanErr) -> Self { | ||
TestError::Plan(err) | ||
} | ||
} | ||
|
||
impl From<EvalErr> for TestError<'_> { | ||
fn from(err: EvalErr) -> Self { | ||
TestError::Eval(err) | ||
} | ||
} | ||
|
||
#[track_caller] | ||
#[inline] | ||
pub(crate) fn parse(statement: &str) -> ParserResult { | ||
partiql_parser::Parser::default().parse(statement) | ||
} | ||
|
||
#[track_caller] | ||
#[inline] | ||
pub(crate) fn lower( | ||
catalog: &dyn Catalog, | ||
parsed: &Parsed, | ||
) -> Result<logical::LogicalPlan<logical::BindingsOp>, AstTransformationError> { | ||
let planner = partiql_logical_planner::LogicalPlanner::new(catalog); | ||
planner.lower(parsed) | ||
} | ||
|
||
#[track_caller] | ||
#[inline] | ||
pub(crate) fn compile( | ||
mode: EvaluationMode, | ||
catalog: &dyn Catalog, | ||
logical: logical::LogicalPlan<logical::BindingsOp>, | ||
) -> Result<EvalPlan, PlanErr> { | ||
let mut planner = eval::plan::EvaluatorPlanner::new(mode.into(), catalog); | ||
planner.compile(&logical) | ||
} | ||
|
||
#[track_caller] | ||
#[inline] | ||
pub(crate) fn evaluate(mut plan: EvalPlan, bindings: MapBindings<Value>) -> EvalResult { | ||
plan.execute_mut(bindings) | ||
} | ||
|
||
#[track_caller] | ||
#[inline] | ||
pub(crate) fn eval<'a>( | ||
statement: &'a str, | ||
mode: EvaluationMode, | ||
) -> Result<Evaluated, TestError<'a>> { | ||
let catalog = PartiqlCatalog::default(); | ||
|
||
let parsed = parse(statement)?; | ||
let lowered = lower(&catalog, &parsed)?; | ||
let bindings = Default::default(); | ||
let plan = compile(mode, &catalog, lowered)?; | ||
Ok(evaluate(plan, bindings)?) | ||
} | ||
|
||
#[test] | ||
fn todo() {} | ||
fn todo() { | ||
let query = "select foo, count(1) as n from | ||
<< | ||
{ 'foo': 'foo' }, | ||
{ 'foo': 'bar' }, | ||
{ 'foo': 'qux' }, | ||
{ 'foo': 'bar' }, | ||
{ 'foo': 'baz' }, | ||
{ 'foo': 'bar' }, | ||
{ 'foo': 'baz' } | ||
>> group by foo order by n desc"; | ||
|
||
let res = eval(query, EvaluationMode::Permissive); | ||
} | ||
} |