Skip to content

Commit

Permalink
fix: Refactored plan
Browse files Browse the repository at this point in the history
  • Loading branch information
can-keklik committed Dec 1, 2024
1 parent 3852320 commit 211a662
Showing 1 changed file with 50 additions and 5 deletions.
55 changes: 50 additions & 5 deletions lykiadb-server/src/plan/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::Display;
use std::{collections::HashMap, fmt::Display};

use lykiadb_lang::{
ast::{
Expand All @@ -12,9 +12,25 @@ use lykiadb_lang::{
};
use serde::{Deserialize, Serialize};

use crate::value::RV;

pub mod planner;
mod scope;

enum ExprOverride {
Subquery(usize),
Aggregate,
Field
}

enum IntermediateExpr {
Expr {
root: Expr,
overrides: HashMap<usize, ExprOverride>
},
Precalculated(RV)
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum PlannerError {
ObjectNotFoundInScope(Identifier),
Expand Down Expand Up @@ -55,6 +71,7 @@ pub enum Node {
Filter {
source: Box<Node>,
predicate: Expr,
subqueries: Vec<Node>
},

Projection {
Expand Down Expand Up @@ -100,7 +117,7 @@ pub enum Node {

Subquery {
source: Box<Node>,
alias: Identifier,
alias: Option<Identifier>,
},

Nothing,
Expand Down Expand Up @@ -166,8 +183,27 @@ impl Node {

source._fmt_recursive(f, indent + 1)
}
Node::Filter { source, predicate } => {
write!(f, "{}- filter [{}]{}", indent_str, predicate, Self::NEWLINE)?;
Node::Filter { source, predicate, subqueries } => {
write!(
f,
"{}- filter [{}]{}",
indent_str,
predicate,
Self::NEWLINE
)?;
subqueries.iter().try_for_each(|subquery| {
subquery._fmt_recursive(f, indent + 1)
})?;
source._fmt_recursive(f, indent + 1)
}
Node::Subquery { source, alias } => {
write!(
f,
"{}- subquery [{}]{}",
indent_str,
alias.as_ref().map(|x| x.name.clone()).unwrap_or("unnamed".to_string()),
Self::NEWLINE
)?;
source._fmt_recursive(f, indent + 1)
}
Node::Scan { source, filter } => {
Expand Down Expand Up @@ -226,12 +262,21 @@ impl Node {
"{}- join [type={:?}, {}]{}",
indent_str,
join_type,
constraint.as_ref().unwrap(),
constraint.as_ref().map(|x| x.to_string()).unwrap_or("None".to_string()),
Self::NEWLINE
)?;
left._fmt_recursive(f, indent + 1)?;
right._fmt_recursive(f, indent + 1)
}
Node::EvalScan { source, filter } => {
write!(
f,
"{}- eval_scan [{}]{}",
indent_str,
source.expr,
Self::NEWLINE
)
}
_ => "<NotImplementedYet>".fmt(f),
}
}
Expand Down

0 comments on commit 211a662

Please sign in to comment.