Skip to content

Commit

Permalink
feat(planner): support table reference type: subquery for new planner
Browse files Browse the repository at this point in the history
  • Loading branch information
xudong963 committed May 10, 2022
1 parent be038af commit 496cf2e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions query/src/sql/planner/binder/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use common_ast::ast::Indirection;
use common_ast::ast::SelectTarget;
use common_ast::ast::TableAlias;
use common_exception::ErrorCode;
use common_exception::Result;

Expand Down
22 changes: 18 additions & 4 deletions query/src/sql/planner/binder/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use common_ast::ast::Query;
use common_ast::ast::SelectStmt;
use common_ast::ast::SelectTarget;
use common_ast::ast::SetExpr;
use common_ast::ast::TableAlias;
use common_ast::ast::TableReference;
use common_datavalues::DataTypeImpl;
use common_exception::ErrorCode;
Expand All @@ -43,22 +44,31 @@ use crate::storages::ToReadDataSourcePlan;
use crate::table_functions::TableFunction;

impl Binder {
#[async_recursion]
pub(super) async fn bind_query(
&mut self,
query: &Query,
bind_context: &BindContext,
) -> Result<BindContext> {
self.bind_query_with_alias(query, &None, bind_context).await
}

#[async_recursion]
async fn bind_query_with_alias(
&mut self,
query: &Query,
alias: &Option<TableAlias>,
bind_context: &BindContext,
) -> Result<BindContext> {
let mut has_order_by = false;
if !query.order_by.is_empty() {
has_order_by = true;
};
let mut bind_context = match &query.body {
SetExpr::Select(stmt) => {
self.bind_select_stmt(stmt, has_order_by, bind_context)
self.bind_select_stmt(stmt, has_order_by, alias, bind_context)
.await
}
SetExpr::Query(stmt) => self.bind_query(stmt, bind_context).await,
SetExpr::Query(stmt) => self.bind_query_with_alias(stmt, alias, bind_context).await,
_ => Err(ErrorCode::UnImplement("Unsupported query type")),
}?;

Expand All @@ -84,6 +94,7 @@ impl Binder {
&mut self,
stmt: &SelectStmt,
has_order_by: bool,
_alias: &Option<TableAlias>,
bind_context: &BindContext,
) -> Result<BindContext> {
let mut input_context = if let Some(from) = &stmt.from {
Expand Down Expand Up @@ -221,7 +232,10 @@ impl Binder {
Ok(result)
}
TableReference::Join(join) => self.bind_join(bind_context, join).await,
_ => Err(ErrorCode::UnImplement("Unsupported table reference type")),
TableReference::Subquery { subquery, alias } => {
self.bind_query_with_alias(subquery, alias, bind_context)
.await
}
}
}

Expand Down

0 comments on commit 496cf2e

Please sign in to comment.