Skip to content

Commit

Permalink
fix: "Subquery" definition is removed
Browse files Browse the repository at this point in the history
  • Loading branch information
can-keklik committed Aug 24, 2024
1 parent a7700d6 commit 84a8a31
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 35 deletions.
22 changes: 0 additions & 22 deletions lykiadb-lang/src/ast/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,3 @@ pub trait VisitorMut<O, E> {
fn visit_expr(&mut self, e: &Expr) -> Result<O, E>;
fn visit_stmt(&mut self, s: &Stmt) -> Result<O, E>;
}

pub trait SqlVisitor<T, Q> {
fn visit_sql_select(&self, e: &SqlSelect) -> Result<T, Q>;
fn visit_sql_insert(&self, sql_insert: &SqlInsert) -> Result<T, Q>;
fn visit_sql_update(&self, sql_update: &SqlUpdate) -> Result<T, Q>;
fn visit_sql_delete(&self, sql_delete: &SqlDelete) -> Result<T, Q>;
//
fn visit_sql_select_core(&self, core: &SqlSelectCore) -> Result<T, Q>;
fn visit_sql_subquery(&self, subquery: &SqlFrom) -> Result<T, Q>;
fn visit_sql_expr(&self, sql_expr: &SqlExpr) -> Result<T, Q>;
}

pub trait SqlVisitorMut<T, Q> {
fn visit_sql_select(&mut self, e: &SqlSelect) -> Result<T, Q>;
fn visit_sql_insert(&mut self, sql_insert: &SqlInsert) -> Result<T, Q>;
fn visit_sql_update(&mut self, sql_update: &SqlUpdate) -> Result<T, Q>;
fn visit_sql_delete(&mut self, sql_delete: &SqlDelete) -> Result<T, Q>;
//
fn visit_sql_select_core(&mut self, core: &SqlSelectCore) -> Result<T, Q>;
fn visit_sql_subquery(&mut self, subquery: &SqlFrom) -> Result<T, Q>;
fn visit_sql_expr(&mut self, sql_expr: &SqlExpr) -> Result<T, Q>;
}
26 changes: 13 additions & 13 deletions lykiadb-lang/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1116,19 +1116,19 @@ impl<'a> Parser<'a> {

fn sql_select_from(&mut self) -> ParseResult<Option<SqlFrom>> {
if self.match_next(skw!(From)) {
return Ok(Some(self.sql_select_subquery_join()?));
return Ok(Some(self.sql_select_from_join()?));
}
Ok(None)
}

fn sql_select_subquery_join(&mut self) -> ParseResult<SqlFrom> {
let mut subquery_group: Vec<SqlFrom> = vec![];
fn sql_select_from_join(&mut self) -> ParseResult<SqlFrom> {
let mut from_group: Vec<SqlFrom> = vec![];

loop {
let left = self.sql_select_subquery_collection()?;
subquery_group.push(left);
let left = self.sql_select_from_collection()?;
from_group.push(left);
while self.match_next_one_of(&[skw!(Left), skw!(Right), skw!(Inner), skw!(Join)]) {
// If the next token is a join keyword, then it must be a join subquery
// If the next token is a join keyword, then it must be a join from
let peek = self.peek_bw(1);
let join_type = if peek.tok_type == skw!(Inner) {
self.expected(skw!(Join))?;
Expand All @@ -1146,16 +1146,16 @@ impl<'a> Parser<'a> {
token: peek.clone(),
});
};
let right = self.sql_select_subquery_collection()?;
let right = self.sql_select_from_collection()?;
let join_constraint: Option<Box<SqlExpr>> = if self.match_next(skw!(On)) {
Some(self.sql_expression()?)
} else {
None
};

let left_popped = subquery_group.pop().unwrap();
let left_popped = from_group.pop().unwrap();

subquery_group.push(SqlFrom::Join {
from_group.push(SqlFrom::Join {
left: Box::new(left_popped),
right: Box::new(right),
join_type,
Expand All @@ -1168,7 +1168,7 @@ impl<'a> Parser<'a> {
}

Ok(SqlFrom::Group {
values: subquery_group,
values: from_group,
})
}

Expand Down Expand Up @@ -1197,7 +1197,7 @@ impl<'a> Parser<'a> {
}
}

fn sql_select_subquery_collection(&mut self) -> ParseResult<SqlFrom> {
fn sql_select_from_collection(&mut self) -> ParseResult<SqlFrom> {
if self.match_next(sym!(LeftParen)) {
if self.cmp_tok(&skw!(Select)) {
let expr = self.sql_select()?;
Expand All @@ -1209,8 +1209,8 @@ impl<'a> Parser<'a> {
alias: alias.map(|t| t.extract_identifier().unwrap()),
});
}
// If the next token is a left paren, then it must be either a select statement or a recursive subquery
let parsed = self.sql_select_subquery_join()?; // TODO(vck): Check if using _collection variant makes sense.
// If the next token is a left paren, then it must be either a select statement or a recursive from
let parsed = self.sql_select_from_join()?; // TODO(vck): Check if using _collection variant makes sense.
self.expected(sym!(RightParen))?; // closing paren
Ok(parsed)
} else if let Some(collection) = self.sql_collection_identifier()? {
Expand Down

0 comments on commit 84a8a31

Please sign in to comment.