Skip to content

Commit

Permalink
fix: Correct name for SqlSubquery
Browse files Browse the repository at this point in the history
  • Loading branch information
can-keklik committed Aug 24, 2024
1 parent 70e0a53 commit a7700d6
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 88 deletions.
18 changes: 9 additions & 9 deletions lykiadb-lang/src/ast/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,21 @@ pub struct SqlSelectCompound {

#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, Clone)]
#[serde(tag = "@type")]
pub enum SqlCollectionSubquery {
#[serde(rename = "SqlCollectionSubquery::Group")]
Group { values: Vec<SqlCollectionSubquery> },
#[serde(rename = "SqlCollectionSubquery::Collection")]
pub enum SqlFrom {
#[serde(rename = "SqlFrom::Group")]
Group { values: Vec<SqlFrom> },
#[serde(rename = "SqlFrom::Collection")]
Collection(SqlCollectionIdentifier),
#[serde(rename = "SqlCollectionSubquery::Select")]
#[serde(rename = "SqlFrom::Select")]
Select {
expr: Box<Expr>,
alias: Option<Identifier>,
},
#[serde(rename = "SqlCollectionSubquery::Join")]
#[serde(rename = "SqlFrom::Join")]
Join {
left: Box<SqlCollectionSubquery>,
left: Box<SqlFrom>,
join_type: SqlJoinType,
right: Box<SqlCollectionSubquery>,
right: Box<SqlFrom>,
constraint: Option<Box<SqlExpr>>,
},
}
Expand All @@ -168,7 +168,7 @@ pub enum SqlCollectionSubquery {
pub struct SqlSelectCore {
pub distinct: SqlDistinct,
pub projection: Vec<SqlProjection>,
pub from: Option<SqlCollectionSubquery>,
pub from: Option<SqlFrom>,
pub r#where: Option<Box<SqlExpr>>,
pub group_by: Option<Vec<SqlExpr>>,
pub having: Option<Box<SqlExpr>>,
Expand Down
6 changes: 3 additions & 3 deletions lykiadb-lang/src/ast/visitor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{
expr::Expr,
sql::{
SqlCollectionSubquery, SqlDelete, SqlExpr, SqlInsert, SqlSelect, SqlSelectCore, SqlUpdate,
SqlFrom, SqlDelete, SqlExpr, SqlInsert, SqlSelect, SqlSelectCore, SqlUpdate,
},
stmt::Stmt,
};
Expand All @@ -26,7 +26,7 @@ pub trait SqlVisitor<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: &SqlCollectionSubquery) -> Result<T, Q>;
fn visit_sql_subquery(&self, subquery: &SqlFrom) -> Result<T, Q>;
fn visit_sql_expr(&self, sql_expr: &SqlExpr) -> Result<T, Q>;
}

Expand All @@ -37,6 +37,6 @@ pub trait SqlVisitorMut<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: &SqlCollectionSubquery) -> 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>;
}
18 changes: 9 additions & 9 deletions lykiadb-lang/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ impl<'a> Parser<'a> {
}

use crate::ast::sql::{
SqlCollectionIdentifier, SqlCollectionSubquery, SqlCompoundOperator, SqlDelete, SqlDistinct,
SqlCollectionIdentifier, SqlFrom, SqlCompoundOperator, SqlDelete, SqlDistinct,
SqlExpr, SqlInsert, SqlJoinType, SqlLimitClause, SqlOrderByClause, SqlOrdering, SqlProjection,
SqlSelect, SqlSelectCompound, SqlSelectCore, SqlUpdate, SqlValues,
};
Expand Down Expand Up @@ -1114,15 +1114,15 @@ impl<'a> Parser<'a> {
Ok(projections)
}

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

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

loop {
let left = self.sql_select_subquery_collection()?;
Expand Down Expand Up @@ -1155,7 +1155,7 @@ impl<'a> Parser<'a> {

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

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

Ok(SqlCollectionSubquery::Group {
Ok(SqlFrom::Group {
values: subquery_group,
})
}
Expand Down Expand Up @@ -1197,14 +1197,14 @@ impl<'a> Parser<'a> {
}
}

fn sql_select_subquery_collection(&mut self) -> ParseResult<SqlCollectionSubquery> {
fn sql_select_subquery_collection(&mut self) -> ParseResult<SqlFrom> {
if self.match_next(sym!(LeftParen)) {
if self.cmp_tok(&skw!(Select)) {
let expr = self.sql_select()?;
self.expected(sym!(RightParen))?; // closing paren
let alias: Option<Token> =
optional_with_expected!(self, skw!(As), Identifier { dollar: false });
return Ok(SqlCollectionSubquery::Select {
return Ok(SqlFrom::Select {
expr,
alias: alias.map(|t| t.extract_identifier().unwrap()),
});
Expand All @@ -1214,7 +1214,7 @@ impl<'a> Parser<'a> {
self.expected(sym!(RightParen))?; // closing paren
Ok(parsed)
} else if let Some(collection) = self.sql_collection_identifier()? {
return Ok(SqlCollectionSubquery::Collection(collection));
return Ok(SqlFrom::Collection(collection));
} else {
Err(ParseError::UnexpectedToken {
token: self.peek_bw(0).clone(),
Expand Down
18 changes: 9 additions & 9 deletions lykiadb-lang/tests/lang/sql/select_compound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ assert_parsing! {
"@type": "SqlDistinct::ImplicitAll"
},
"from": {
"@type": "SqlCollectionSubquery::Group",
"@type": "SqlFrom::Group",
"values": [
{
"@type": "SqlCollectionIdentifier",
Expand Down Expand Up @@ -56,7 +56,7 @@ assert_parsing! {
"@type": "SqlDistinct::ImplicitAll"
},
"from": {
"@type": "SqlCollectionSubquery::Group",
"@type": "SqlFrom::Group",
"values": [
{
"@type": "SqlCollectionIdentifier",
Expand Down Expand Up @@ -109,7 +109,7 @@ assert_parsing! {
"@type": "SqlDistinct::ImplicitAll"
},
"from": {
"@type": "SqlCollectionSubquery::Group",
"@type": "SqlFrom::Group",
"values": [
{
"@type": "SqlCollectionIdentifier",
Expand Down Expand Up @@ -141,7 +141,7 @@ assert_parsing! {
"@type": "SqlDistinct::ImplicitAll"
},
"from": {
"@type": "SqlCollectionSubquery::Group",
"@type": "SqlFrom::Group",
"values": [
{
"@type": "SqlCollectionIdentifier",
Expand Down Expand Up @@ -194,7 +194,7 @@ assert_parsing! {
"@type": "SqlDistinct::ImplicitAll"
},
"from": {
"@type": "SqlCollectionSubquery::Group",
"@type": "SqlFrom::Group",
"values": [
{
"@type": "SqlCollectionIdentifier",
Expand Down Expand Up @@ -226,7 +226,7 @@ assert_parsing! {
"@type": "SqlDistinct::ImplicitAll"
},
"from": {
"@type": "SqlCollectionSubquery::Group",
"@type": "SqlFrom::Group",
"values": [
{
"@type": "SqlCollectionIdentifier",
Expand Down Expand Up @@ -283,7 +283,7 @@ assert_parsing! {
"@type": "SqlDistinct::ImplicitAll"
},
"from": {
"@type": "SqlCollectionSubquery::Group",
"@type": "SqlFrom::Group",
"values": [
{
"@type": "SqlCollectionIdentifier",
Expand Down Expand Up @@ -315,7 +315,7 @@ assert_parsing! {
"@type": "SqlDistinct::ImplicitAll"
},
"from": {
"@type": "SqlCollectionSubquery::Group",
"@type": "SqlFrom::Group",
"values": [
{
"@type": "SqlCollectionIdentifier",
Expand Down Expand Up @@ -347,7 +347,7 @@ assert_parsing! {
"@type": "SqlDistinct::ImplicitAll"
},
"from": {
"@type": "SqlCollectionSubquery::Group",
"@type": "SqlFrom::Group",
"values": [
{
"@type": "SqlCollectionIdentifier",
Expand Down
6 changes: 3 additions & 3 deletions lykiadb-lang/tests/lang/sql/select_distinct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ assert_parsing! {
"@type": "SqlDistinct::ImplicitAll"
},
"from": {
"@type": "SqlCollectionSubquery::Group",
"@type": "SqlFrom::Group",
"values": [
{
"@type": "SqlCollectionIdentifier",
Expand Down Expand Up @@ -77,7 +77,7 @@ assert_parsing! {
"@type": "SqlDistinct::All"
},
"from": {
"@type": "SqlCollectionSubquery::Group",
"@type": "SqlFrom::Group",
"values": [
{
"@type": "SqlCollectionIdentifier",
Expand Down Expand Up @@ -134,7 +134,7 @@ assert_parsing! {
"@type": "SqlDistinct::Distinct"
},
"from": {
"@type": "SqlCollectionSubquery::Group",
"@type": "SqlFrom::Group",
"values": [
{
"@type": "SqlCollectionIdentifier",
Expand Down
12 changes: 6 additions & 6 deletions lykiadb-lang/tests/lang/sql/select_from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ assert_parsing! {
"@type": "SqlDistinct::ImplicitAll"
},
"from": {
"@type": "SqlCollectionSubquery::Group",
"@type": "SqlFrom::Group",
"values": [
{
"@type": "SqlCollectionIdentifier",
Expand Down Expand Up @@ -69,7 +69,7 @@ assert_parsing! {
"@type": "SqlDistinct::ImplicitAll"
},
"from": {
"@type": "SqlCollectionSubquery::Group",
"@type": "SqlFrom::Group",
"values": [
{
"@type": "SqlCollectionIdentifier",
Expand Down Expand Up @@ -128,7 +128,7 @@ assert_parsing! {
"@type": "SqlDistinct::ImplicitAll"
},
"from": {
"@type": "SqlCollectionSubquery::Group",
"@type": "SqlFrom::Group",
"values": [
{
"@type": "SqlCollectionIdentifier",
Expand Down Expand Up @@ -195,10 +195,10 @@ assert_parsing! {
"@type": "SqlDistinct::ImplicitAll"
},
"from": {
"@type": "SqlCollectionSubquery::Group",
"@type": "SqlFrom::Group",
"values": [
{
"@type": "SqlCollectionSubquery::Select",
"@type": "SqlFrom::Select",
"alias": {
"@type": "Identifier",
"dollar": false,
Expand All @@ -215,7 +215,7 @@ assert_parsing! {
"@type": "SqlDistinct::ImplicitAll"
},
"from": {
"@type": "SqlCollectionSubquery::Group",
"@type": "SqlFrom::Group",
"values": [
{
"@type": "SqlCollectionIdentifier",
Expand Down
6 changes: 3 additions & 3 deletions lykiadb-lang/tests/lang/sql/select_group_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ assert_parsing! {
"@type": "SqlDistinct::ImplicitAll"
},
"from": {
"@type": "SqlCollectionSubquery::Group",
"@type": "SqlFrom::Group",
"values": [
{
"@type": "SqlCollectionIdentifier",
Expand Down Expand Up @@ -99,7 +99,7 @@ assert_parsing! {
"@type": "SqlDistinct::ImplicitAll"
},
"from": {
"@type": "SqlCollectionSubquery::Group",
"@type": "SqlFrom::Group",
"values": [
{
"@type": "SqlCollectionIdentifier",
Expand Down Expand Up @@ -211,7 +211,7 @@ assert_parsing! {
"@type": "SqlDistinct::ImplicitAll"
},
"from": {
"@type": "SqlCollectionSubquery::Group",
"@type": "SqlFrom::Group",
"values": [
{
"@type": "SqlCollectionIdentifier",
Expand Down
Loading

0 comments on commit a7700d6

Please sign in to comment.