Skip to content

Commit

Permalink
fix(meta): rename changelog shall check self.from (#19030)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangjinwu authored and xxhZs committed Oct 24, 2024
1 parent 51804b9 commit 1cdf3f3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
40 changes: 40 additions & 0 deletions e2e_test/ddl/alter_rename.slt
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,43 @@ DROP TABLE t2;

statement ok
DROP TABLE t_as_1;

# BEGIN references in changelog

statement ok
CREATE TABLE a (a0 int);

statement ok
CREATE TABLE b (b0 int);

statement ok
CREATE MATERIALIZED VIEW mv AS
WITH a_log AS changelog FROM a,
b_log AS changelog FROM b
SELECT 'a' AS tbl, * FROM a_log
UNION ALL
SELECT 'b', * FROM b_log;

query T
SELECT definition FROM rw_materialized_views WHERE name = 'mv';
----
CREATE MATERIALIZED VIEW mv AS WITH a_log AS changelog from a, b_log AS changelog from b SELECT 'a' AS tbl, * FROM a_log UNION ALL SELECT 'b', * FROM b_log

statement ok
ALTER TABLE a RENAME TO c;

query T
SELECT definition FROM rw_materialized_views WHERE name = 'mv';
----
CREATE MATERIALIZED VIEW mv AS WITH a_log AS changelog from "c", b_log AS changelog from b SELECT 'a' AS tbl, * FROM a_log UNION ALL SELECT 'b', * FROM b_log

statement ok
DROP MATERIALIZED VIEW mv;

statement ok
DROP TABLE b;

statement ok
DROP TABLE c;

# END references in changelog
7 changes: 5 additions & 2 deletions src/meta/src/controller/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,11 @@ impl QueryRewriter<'_> {
for cte_table in &mut with.cte_tables {
match &mut cte_table.cte_inner {
risingwave_sqlparser::ast::CteInner::Query(query) => self.visit_query(query),
risingwave_sqlparser::ast::CteInner::ChangeLog(from) => {
*from = ObjectName(vec![Ident::new_unchecked(self.to)])
risingwave_sqlparser::ast::CteInner::ChangeLog(name) => {
let idx = name.0.len() - 1;
if name.0[idx].real_value() == self.from {
name.0[idx] = Ident::with_quote_unchecked('"', self.to);
}
}
}
}
Expand Down

0 comments on commit 1cdf3f3

Please sign in to comment.