Skip to content

Commit

Permalink
feat(frontend): support alias for window table function (#2633)
Browse files Browse the repository at this point in the history
Signed-off-by: TennyZhuang <[email protected]>
  • Loading branch information
TennyZhuang authored May 18, 2022
1 parent 7b01d0e commit 5c295db
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/frontend/src/binder/relation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl Binder {
)
})?;
Ok(Relation::WindowTableFunction(Box::new(
self.bind_window_table_function(kind, args)?,
self.bind_window_table_function(alias, kind, args)?,
)))
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/frontend/src/binder/relation/window_table_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use itertools::Itertools;
use risingwave_common::catalog::Field;
use risingwave_common::error::{ErrorCode, RwError};
use risingwave_common::types::DataType;
use risingwave_sqlparser::ast::{Expr, FunctionArg, FunctionArgExpr, ObjectName};
use risingwave_sqlparser::ast::{Expr, FunctionArg, FunctionArgExpr, ObjectName, TableAlias};

use super::{Binder, Relation, Result};
use crate::expr::{ExprImpl, InputRef};
Expand Down Expand Up @@ -54,6 +54,7 @@ pub struct BoundWindowTableFunction {
impl Binder {
pub(super) fn bind_window_table_function(
&mut self,
alias: Option<TableAlias>,
kind: WindowTableFunctionKind,
args: Vec<FunctionArg>,
) -> Result<BoundWindowTableFunction> {
Expand All @@ -77,7 +78,6 @@ impl Binder {
}?;
let (schema_name, table_name) = Self::resolve_table_name(table_name)?;

// TODO: support alias.
let base = self.bind_table_or_source(&schema_name, &table_name, None)?;

let Some(time_col_arg) = args.next() else {
Expand Down Expand Up @@ -136,8 +136,8 @@ impl Binder {
]
.into_iter(),
);
// TODO: support alias.
self.bind_context(columns, table_name.clone(), None)?;

self.bind_context(columns, table_name.clone(), alias)?;

let exprs: Vec<_> = args
.map(|arg| self.bind_function_arg(arg))
Expand Down
17 changes: 17 additions & 0 deletions src/frontend/test_runner/tests/testdata/time_window.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,20 @@
StreamProject { exprs: [$0, $1, $2, $3] }
StreamHopWindow { time_col: $1 slide: 1 day 00:00:00 size: 3 days 00:00:00 }
StreamTableScan { table: t1, columns: [id, created_at, _row_id#0], pk_indices: [2] }
- sql: |
create table t1 (id int, created_at date);
select t_hop.id, t_hop.created_at from hop(t1, created_at, interval '1' day, interval '3' day) as t_hop;
logical_plan: |
LogicalProject { exprs: [$1, $2] }
LogicalHopWindow { time_col: $2 slide: 1 day 00:00:00 size: 3 days 00:00:00 }
LogicalScan { table: t1, columns: [_row_id#0, id, created_at] }
batch_plan: |
BatchExchange { order: [], dist: Single }
BatchProject { exprs: [$0, $1] }
BatchHopWindow { time_col: $1 slide: 1 day 00:00:00 size: 3 days 00:00:00 }
BatchScan { table: t1, columns: [id, created_at] }
stream_plan: |
StreamMaterialize { columns: [id, created_at, _row_id#0(hidden), window_start(hidden)], pk_columns: [_row_id#0, window_start] }
StreamProject { exprs: [$0, $1, $2, $3] }
StreamHopWindow { time_col: $1 slide: 1 day 00:00:00 size: 3 days 00:00:00 }
StreamTableScan { table: t1, columns: [id, created_at, _row_id#0], pk_indices: [2] }

0 comments on commit 5c295db

Please sign in to comment.