From 6a32e21fd162f52c6da40217161c8706c8ba9a66 Mon Sep 17 00:00:00 2001 From: Kanthi Subramanian Date: Tue, 5 Nov 2024 19:29:10 -0500 Subject: [PATCH 1/2] Added test to cover alter table rename without table keyword --- .../ddl/parser/MySqlDDLParserListenerImplTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sink-connector-lightweight/src/test/java/com/altinity/clickhouse/debezium/embedded/ddl/parser/MySqlDDLParserListenerImplTest.java b/sink-connector-lightweight/src/test/java/com/altinity/clickhouse/debezium/embedded/ddl/parser/MySqlDDLParserListenerImplTest.java index e4d479774..4dd1ac97a 100644 --- a/sink-connector-lightweight/src/test/java/com/altinity/clickhouse/debezium/embedded/ddl/parser/MySqlDDLParserListenerImplTest.java +++ b/sink-connector-lightweight/src/test/java/com/altinity/clickhouse/debezium/embedded/ddl/parser/MySqlDDLParserListenerImplTest.java @@ -612,6 +612,16 @@ public void dropMultipleTables() { Assert.assertTrue(clickHouseQuery.toString().equalsIgnoreCase("drop table add_test,add_test2")); } + @Test + public void renameTableWithoutTableKeyword() { + StringBuffer clickHouseQuery = new StringBuffer(); + + String sql = "ALTER TABLE old_table RENAME new_table"; + mySQLDDLParserService.parseSql(sql, "table1", clickHouseQuery); + + Assert.assertTrue(clickHouseQuery.toString().equalsIgnoreCase("rename table employees.old_table to employees.new_table")); + } + @Test public void renameTable() { StringBuffer clickHouseQuery = new StringBuffer(); From 055222bfa83f29bdb86106019722d875e5a233ef Mon Sep 17 00:00:00 2001 From: Kanthi Subramanian Date: Tue, 5 Nov 2024 19:57:14 -0500 Subject: [PATCH 2/2] Fixed handling of alter table rename without table keyword --- .../ddl/parser/MySqlDDLParserListenerImpl.java | 2 ++ .../ddl/parser/MySqlDDLParserListenerImplTest.java | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/sink-connector-lightweight/src/main/java/com/altinity/clickhouse/debezium/embedded/ddl/parser/MySqlDDLParserListenerImpl.java b/sink-connector-lightweight/src/main/java/com/altinity/clickhouse/debezium/embedded/ddl/parser/MySqlDDLParserListenerImpl.java index d068b8b6b..264bb7e6c 100644 --- a/sink-connector-lightweight/src/main/java/com/altinity/clickhouse/debezium/embedded/ddl/parser/MySqlDDLParserListenerImpl.java +++ b/sink-connector-lightweight/src/main/java/com/altinity/clickhouse/debezium/embedded/ddl/parser/MySqlDDLParserListenerImpl.java @@ -653,6 +653,8 @@ private void parseAlterTableByRename(String originalTableName, MySqlParser.Alter for(ParseTree alterByRenameChildren: tree.children) { if(alterByRenameChildren instanceof MySqlParser.UidContext) { newTableName = alterByRenameChildren.getText(); + } else if(alterByRenameChildren instanceof MySqlParser.FullIdContext) { + newTableName = alterByRenameChildren.getText(); } } diff --git a/sink-connector-lightweight/src/test/java/com/altinity/clickhouse/debezium/embedded/ddl/parser/MySqlDDLParserListenerImplTest.java b/sink-connector-lightweight/src/test/java/com/altinity/clickhouse/debezium/embedded/ddl/parser/MySqlDDLParserListenerImplTest.java index 4dd1ac97a..c2139a2dd 100644 --- a/sink-connector-lightweight/src/test/java/com/altinity/clickhouse/debezium/embedded/ddl/parser/MySqlDDLParserListenerImplTest.java +++ b/sink-connector-lightweight/src/test/java/com/altinity/clickhouse/debezium/embedded/ddl/parser/MySqlDDLParserListenerImplTest.java @@ -616,12 +616,20 @@ public void dropMultipleTables() { public void renameTableWithoutTableKeyword() { StringBuffer clickHouseQuery = new StringBuffer(); - String sql = "ALTER TABLE old_table RENAME new_table"; + String sql = "ALTER TABLE employees.old_table RENAME employees.new_table"; mySQLDDLParserService.parseSql(sql, "table1", clickHouseQuery); Assert.assertTrue(clickHouseQuery.toString().equalsIgnoreCase("rename table employees.old_table to employees.new_table")); } + @Test + public void renameTableWithTableKeyword() { + StringBuffer clickHouseQuery = new StringBuffer(); + String sql = "ALTER TABLE old_table RENAME new_table"; + mySQLDDLParserService.parseSql(sql, "table1", clickHouseQuery); + Assert.assertTrue(clickHouseQuery.toString().equalsIgnoreCase("rename table employees.old_table to employees.new_table")); + } + @Test public void renameTable() { StringBuffer clickHouseQuery = new StringBuffer();