-
Notifications
You must be signed in to change notification settings - Fork 706
feat(frontend): bind project #615
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
Changes from all commits
fe31cf1
82d10cf
3ca98aa
088ae33
c15800f
6566f98
c011a0a
7cac54f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| use std::collections::HashMap; | ||
|
|
||
| use risingwave_common::types::DataType; | ||
|
|
||
| pub struct ColumnBinding { | ||
| pub table_name: String, | ||
| pub index: usize, | ||
| pub data_type: DataType, | ||
| } | ||
|
|
||
| impl ColumnBinding { | ||
| pub fn new(table_name: String, index: usize, data_type: DataType) -> Self { | ||
| ColumnBinding { | ||
| table_name, | ||
| index, | ||
| data_type, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub struct BindContext { | ||
| // Mapping column name to `ColumnBinding` | ||
| pub columns: HashMap<String, Vec<ColumnBinding>>, | ||
| } | ||
|
|
||
| impl BindContext { | ||
| #[allow(clippy::new_without_default)] | ||
| pub fn new() -> Self { | ||
| BindContext { | ||
| // tables: HashMap::new(), | ||
| columns: HashMap::new(), | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| use risingwave_common::array::RwError; | ||
| use risingwave_common::error::{ErrorCode, Result}; | ||
| use risingwave_sqlparser::ast::Ident; | ||
|
|
||
| use crate::binder::Binder; | ||
| use crate::expr::{ExprImpl, InputRef}; | ||
|
|
||
| impl Binder { | ||
| pub fn bind_column(&mut self, idents: &[Ident]) -> Result<ExprImpl> { | ||
| // TODO: check quote style of `ident`. | ||
| let (_schema_name, table_name, column_name) = match idents { | ||
| [column] => (None, None, &column.value), | ||
| [table, column] => (None, Some(&table.value), &column.value), | ||
| [schema, table, column] => (Some(&schema.value), Some(&table.value), &column.value), | ||
| _ => { | ||
| return Err( | ||
| ErrorCode::InternalError(format!("Too many idents: {:?}", idents)).into(), | ||
| ) | ||
| } | ||
| }; | ||
| let columns = self.context.columns.get(column_name).ok_or_else(|| { | ||
| RwError::from(ErrorCode::ItemNotFound(format!( | ||
| "Invalid column: {}", | ||
| column_name | ||
| ))) | ||
| })?; | ||
| match table_name { | ||
| Some(table_name) => { | ||
| match columns | ||
| .iter() | ||
| .find(|column| column.table_name == *table_name) | ||
| { | ||
| Some(column) => Ok(ExprImpl::InputRef(Box::new(InputRef::new( | ||
| column.index, | ||
| column.data_type.clone(), | ||
| )))), | ||
| None => Err( | ||
| ErrorCode::ItemNotFound(format!("Invalid table: {}", table_name)).into(), | ||
| ), | ||
| } | ||
| } | ||
| None => { | ||
|
||
| if columns.len() > 1 { | ||
| Err(ErrorCode::InternalError("Ambiguous column name".into()).into()) | ||
| } else { | ||
| Ok(ExprImpl::InputRef(Box::new(InputRef::new( | ||
| columns[0].index, | ||
| columns[0].data_type.clone(), | ||
| )))) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub fn bind_all_columns(&mut self) -> Result<Vec<ExprImpl>> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feels like this has closer relationship with |
||
| let mut bound_columns = vec![]; | ||
| self.context.columns.values().for_each(|columns| { | ||
| columns.iter().for_each(|column| { | ||
| bound_columns.push(ExprImpl::InputRef(Box::new(InputRef::new( | ||
| column.index, | ||
| column.data_type.clone(), | ||
| )))); | ||
| }); | ||
| }); | ||
| Ok(bound_columns) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,25 @@ | ||||||
| use risingwave_common::error::Result; | ||||||
| use risingwave_sqlparser::ast::SelectItem; | ||||||
|
|
||||||
| use crate::binder::Binder; | ||||||
| use crate::expr::ExprImpl; | ||||||
|
|
||||||
| impl Binder { | ||||||
| pub fn bind_projection(&mut self, projection: Vec<SelectItem>) -> Result<Vec<ExprImpl>> { | ||||||
|
||||||
| pub fn bind_projection(&mut self, projection: Vec<SelectItem>) -> Result<Vec<ExprImpl>> { | |
| pub fn bind_select_items(&mut self, projection: Vec<SelectItem>) -> Result<Vec<ExprImpl>> { |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,8 +95,11 @@ impl PlanTreeNodeUnary for LogicalProject { | |
| impl_plan_tree_node_for_unary! {LogicalProject} | ||
|
|
||
| impl fmt::Display for LogicalProject { | ||
| fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result { | ||
| todo!() | ||
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
| f.debug_struct("LogicalProject") | ||
| .field("exprs", self.exprs()) | ||
| .field("expr_alias", &format_args!("{:?}", self.expr_alias())) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ignore the schema field which is useless to display and the input field which is redundant.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was asking about the field
|
||
| .finish() | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
ExprImpl::InputRef(Box::new(a))->a.to_expl_impl()