Skip to content

Commit

Permalink
fix: changelog does not support fully qualified path
Browse files Browse the repository at this point in the history
Close issue #18747 by using ObjectName for table instead of Ident.

Signed-off-by: yihong0618 <zouzou0208@gmail.com>
  • Loading branch information
yihong0618 committed Oct 2, 2024
1 parent ef8c50f commit 71a60e0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
3 changes: 2 additions & 1 deletion e2e_test/streaming/changelog.slt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ statement ok
create table t3 (v1 int primary key, v2 int);

statement ok
create materialized view mv1 as with sub as changelog from t1 select * from sub;
# test public.t1 due to https://github.com/risingwavelabs/risingwave/issues/18747
create materialized view mv1 as with sub as changelog from public.t1 select * from sub;

statement ok
create materialized view mv2 as with sub as changelog from t2 select * from sub;
Expand Down
9 changes: 3 additions & 6 deletions src/frontend/src/binder/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use risingwave_common::catalog::Schema;
use risingwave_common::types::DataType;
use risingwave_common::util::sort_util::{ColumnOrder, OrderType};
use risingwave_sqlparser::ast::{
Cte, CteInner, Expr, Fetch, ObjectName, OrderByExpr, Query, SetExpr, SetOperator, Value, With,
Cte, CteInner, Expr, Fetch, OrderByExpr, Query, SetExpr, SetOperator, Value, With,
};
use thiserror_ext::AsReport;

Expand Down Expand Up @@ -350,11 +350,8 @@ impl Binder {
}
CteInner::ChangeLog(from_table_name) => {
self.push_context();
let from_table_relation = self.bind_relation_by_name(
ObjectName::from(vec![from_table_name]),
None,
None,
)?;
let from_table_relation =
self.bind_relation_by_name(from_table_name.clone(), None, None)?;
self.pop_context()?;
self.context.cte_to_relation.insert(
table_name,
Expand Down
2 changes: 1 addition & 1 deletion src/meta/src/controller/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl QueryRewriter<'_> {
match &mut cte_table.cte_inner {
risingwave_sqlparser::ast::CteInner::Query(query) => self.visit_query(query),
risingwave_sqlparser::ast::CteInner::ChangeLog(from) => {
*from = Ident::new_unchecked(self.to)
*from = ObjectName(vec![Ident::new_unchecked(self.to)])
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/sqlparser/src/ast/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,12 @@ impl fmt::Display for Cte {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.cte_inner {
CteInner::Query(query) => write!(f, "{} AS ({})", self.alias, query)?,
CteInner::ChangeLog(ident) => {
write!(f, "{} AS changelog from {}", self.alias, ident.value)?
}
CteInner::ChangeLog(obj_name) => write!(
f,
"{} AS changelog from {}",
self.alias,
obj_name.real_value()
)?,
}
Ok(())
}
Expand All @@ -347,7 +350,7 @@ impl fmt::Display for Cte {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum CteInner {
Query(Query),
ChangeLog(Ident),
ChangeLog(ObjectName),
}

/// One item of the comma-separated list following `SELECT`
Expand Down
2 changes: 1 addition & 1 deletion src/sqlparser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4130,7 +4130,7 @@ impl Parser<'_> {
parser_err!("Expected 'changelog' but found '{}'", changelog);
}
self.expect_keyword(Keyword::FROM)?;
Ok(CteInner::ChangeLog(self.parse_identifier()?))
Ok(CteInner::ChangeLog(self.parse_object_name()?))
}
}

Expand Down

0 comments on commit 71a60e0

Please sign in to comment.