From a0b8a05333d348d0d1831d7f88e6190eccf059e9 Mon Sep 17 00:00:00 2001 From: Kanthi Subramanian Date: Mon, 26 Aug 2024 13:48:23 -0400 Subject: [PATCH 1/2] Added test case for parsing ghost SQL statements --- .../parser/MySqlDDLParserListenerImplTest.java | 17 +++++++++++++++++ 1 file changed, 17 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 7e1d5b56f..c2a22a03b 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 @@ -819,6 +819,23 @@ public void testRenameIsDeletedColumn() { Assert.assertTrue(clickHouseQuery2.toString().equalsIgnoreCase( "CREATE TABLE employees.city(id Int32 NOT NULL ,Name Nullable(String),is_deleted Nullable(Int16),`_version` UInt64,`__is_deleted` UInt8) Engine=ReplacingMergeTree(_version,__is_deleted) ORDER BY (id)")); } + + @Test + public void testGhostSQL() { + String sql = " alter /* gh-ost */ table `p_prod`.`_j_failed_s_g` REMOVE PARTITIONING;\n"; + StringBuffer clickHouseQuery = new StringBuffer(); + mySQLDDLParserService.parseSql(sql, "employees", clickHouseQuery); + + //Assert.assertTrue(clickHouseQuery.toString().equalsIgnoreCase("alter table `p_prod`.`_j_failed_s_g` REMOVE PARTITIONING")); + + String createTableQuery = "create /* gh-ost */ table `p_prod`.`_j_failed_s_g` (\\n\\t\\t\\tid int auto_increment primary key\\n\\t\\t) engine=InnoDB comment='ghost-cut-over'"; + + StringBuffer clickHouseQuery2 = new StringBuffer(); + mySQLDDLParserService.parseSql(createTableQuery, "employees", clickHouseQuery2); + + Assert.assertTrue(clickHouseQuery2.toString().equalsIgnoreCase("CREATE TABLE employees.`p_prod`.`_j_failed_s_g`(`id` Int32 NOT NULL ,`_version` UInt64,`is_deleted` UInt8) Engine=ReplacingMergeTree(_version,is_deleted) ORDER BY (`id`)")); + + } // @Test // public void deleteData() { // String sql = "DELETE FROM Customers WHERE CustomerName='Alfreds Futterkiste'"; From b006ffad4a20bc051eaa502766e07190680fbe7d Mon Sep 17 00:00:00 2001 From: Kanthi Subramanian Date: Mon, 16 Sep 2024 15:36:15 -0400 Subject: [PATCH 2/2] Fixed assert ghost --- .../embedded/ddl/parser/MySqlDDLParserListenerImplTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 c2a22a03b..a9eaf4f0d 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 @@ -828,12 +828,12 @@ public void testGhostSQL() { //Assert.assertTrue(clickHouseQuery.toString().equalsIgnoreCase("alter table `p_prod`.`_j_failed_s_g` REMOVE PARTITIONING")); - String createTableQuery = "create /* gh-ost */ table `p_prod`.`_j_failed_s_g` (\\n\\t\\t\\tid int auto_increment primary key\\n\\t\\t) engine=InnoDB comment='ghost-cut-over'"; + String createTableQuery = "create /* gh-ost */ table `p_prod`.`_j_failed_s_g`(id int auto_increment primary key)engine=InnoDB comment='ghost-cut-over'"; StringBuffer clickHouseQuery2 = new StringBuffer(); mySQLDDLParserService.parseSql(createTableQuery, "employees", clickHouseQuery2); - Assert.assertTrue(clickHouseQuery2.toString().equalsIgnoreCase("CREATE TABLE employees.`p_prod`.`_j_failed_s_g`(`id` Int32 NOT NULL ,`_version` UInt64,`is_deleted` UInt8) Engine=ReplacingMergeTree(_version,is_deleted) ORDER BY (`id`)")); + Assert.assertTrue(clickHouseQuery2.toString().equalsIgnoreCase("CREATE TABLE `p_prod`.`_j_failed_s_g`(id Nullable(Int32),`_version` UInt64,`is_deleted` UInt8) Engine=ReplacingMergeTree(_version,is_deleted) ORDER BY id")); } // @Test