Skip to content

Commit

Permalink
fix: changelog does not support fully qualified path (#18785)
Browse files Browse the repository at this point in the history
Signed-off-by: yihong0618 <[email protected]>
  • Loading branch information
yihong0618 authored Oct 18, 2024
1 parent 3b16130 commit 73a4bb9
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 @@ -10,8 +10,9 @@ create table t2 (v1 int, v2 int);
statement ok
create table t3 (v1 int primary key, v2 int);

# test public.t1 due to https://github.com/risingwavelabs/risingwave/issues/18747
statement ok
create materialized view mv1 as with sub as changelog from t1 select * from sub;
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 @@ -4141,7 +4141,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 73a4bb9

Please sign in to comment.