Skip to content

Remove SubQuery from logical plan and evaluation #428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions partiql-eval/src/eval/evaluable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1374,36 +1374,6 @@ impl Evaluable for EvalSink {
}
}

/// Represents an evaluation operator for sub-queries, e.g. `SELECT a FROM b` in
/// `SELECT b.c, (SELECT a FROM b) FROM books AS b`.
#[derive(Debug)]
pub(crate) struct EvalSubQueryExpr {
pub(crate) plan: Rc<RefCell<EvalPlan>>,
}

impl EvalSubQueryExpr {
pub(crate) fn new(plan: EvalPlan) -> Self {
EvalSubQueryExpr {
plan: Rc::new(RefCell::new(plan)),
}
}
}

impl EvalExpr for EvalSubQueryExpr {
fn evaluate<'a>(&'a self, bindings: &'a Tuple, _ctx: &'a dyn EvalContext) -> Cow<'a, Value> {
let value = if let Ok(evaluated) = self
.plan
.borrow_mut()
.execute_mut(MapBindings::from(bindings))
{
evaluated.result
} else {
Missing
};
Cow::Owned(value)
}
}

///
/// Coercion function F for bag operators described in RFC-0007
/// - F(absent_value) -> << >>
Expand Down
21 changes: 20 additions & 1 deletion partiql-eval/src/eval/expr/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use partiql_types::{
ArrayType, BagType, PartiqlType, StructType, TypeKind, TYPE_ANY, TYPE_BOOL, TYPE_NUMERIC_TYPES,
};
use partiql_value::Value::{Boolean, Missing, Null};
use partiql_value::{BinaryAnd, BinaryOr, EqualityValue, NullableEq, NullableOrd, Value};
use partiql_value::{BinaryAnd, BinaryOr, EqualityValue, NullableEq, NullableOrd, Tuple, Value};

use std::borrow::{Borrow, Cow};
use std::fmt::Debug;
Expand Down Expand Up @@ -51,6 +51,25 @@ impl ExecuteEvalExpr<0> for Value {
}
}

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub(crate) struct EvalOpIdentity {}

impl BindEvalExpr for EvalOpIdentity {
fn bind<const STRICT: bool>(
&self,
args: Vec<Box<dyn EvalExpr>>,
) -> Result<Box<dyn EvalExpr>, BindError> {
return Ok(Box::new(self.clone()));
}
}

impl EvalExpr for EvalOpIdentity {
#[inline]
fn evaluate<'a>(&'a self, bindings: &'a Tuple, ctx: &'a dyn EvalContext) -> Cow<'a, Value> {
Cow::Owned(Value::from(bindings.clone()))
}
}

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub(crate) enum EvalOpUnary {
Pos,
Expand Down
19 changes: 9 additions & 10 deletions partiql-eval/src/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ use crate::error::{ErrorNode, PlanErr, PlanningError};
use crate::eval;
use crate::eval::evaluable::{
Any, Avg, Count, EvalGroupingStrategy, EvalJoinKind, EvalOrderBy, EvalOrderBySortCondition,
EvalOrderBySortSpec, EvalOuterExcept, EvalOuterIntersect, EvalOuterUnion, EvalSubQueryExpr,
Evaluable, Every, Max, Min, Sum,
EvalOrderBySortSpec, EvalOuterExcept, EvalOuterIntersect, EvalOuterUnion, Evaluable, Every,
Max, Min, Sum,
};
use crate::eval::expr::{
BindError, BindEvalExpr, EvalBagExpr, EvalBetweenExpr, EvalCollFn, EvalDynamicLookup, EvalExpr,
EvalExtractFn, EvalFnAbs, EvalFnBaseTableExpr, EvalFnCardinality, EvalFnExists, EvalFnOverlay,
EvalFnPosition, EvalFnSubstring, EvalIsTypeExpr, EvalLikeMatch,
EvalLikeNonStringNonLiteralMatch, EvalListExpr, EvalLitExpr, EvalOpBinary, EvalOpUnary,
EvalPath, EvalSearchedCaseExpr, EvalStringFn, EvalTrimFn, EvalTupleExpr, EvalVarRef,
EvalLikeNonStringNonLiteralMatch, EvalListExpr, EvalLitExpr, EvalOpBinary, EvalOpIdentity,
EvalOpUnary, EvalPath, EvalSearchedCaseExpr, EvalStringFn, EvalTrimFn, EvalTupleExpr,
EvalVarRef,
};
use crate::eval::EvalPlan;
use partiql_catalog::Catalog;
Expand Down Expand Up @@ -405,6 +406,10 @@ impl<'c> EvaluatorPlanner<'c> {
};

let (name, bind) = match ve {
ValueExpr::Identity => (
"identity operator",
EvalOpIdentity {}.bind::<{ STRICT }>(vec![]),
),
ValueExpr::UnExpr(op, operand) => (
"unary operator",
EvalOpUnary::from(op).bind::<{ STRICT }>(plan_args(&[operand])),
Expand Down Expand Up @@ -510,12 +515,6 @@ impl<'c> EvaluatorPlanner<'c> {

("pattern expr", expr)
}
ValueExpr::SubQueryExpr(expr) => (
"subquery",
Ok(Box::new(EvalSubQueryExpr::new(
self.plan_eval::<{ STRICT }>(&expr.plan),
)) as Box<dyn EvalExpr>),
),
ValueExpr::SimpleCase(e) => {
let cases = e
.cases
Expand Down
Loading