Uploaded image for project: 'Debezium'
  1. Debezium
  2. DBZ-780

Support RENAME column syntax from MySQL 8.0

    • Icon: Task Task
    • Resolution: Done
    • Icon: Major Major
    • 0.9.0.Beta1
    • None
    • mysql-connector
    • None

      There are new DDL constructs as of 8.0. E.g. it's now possible to rename a column without repeating its definition:

      ALTER TABLE foo RENAME COLUMN old TO new;
      

      We should check with the upstream grammar provided by Antlr, whether it has already been updated and if not look into collaborating with them. 8.0 support should only be provided for the new Antlr-based parser and not the legacy one.

            [DBZ-780] Support RENAME column syntax from MySQL 8.0

            Released

            Jiri Pechanec added a comment - Released

            Sagar Rao (Inactive) added a comment - https://github.com/debezium/debezium/pull/655/

            Sagar Rao (Inactive) added a comment - - edited

            gunnar.morlingjpechane I created the following test case to test the Alter column:

            @Test
            public void shouldRenameColumnWithoutDefinition()

            { parser = new MysqlDdlParserWithSimpleTestListener(listener, TableFilter.fromPredicate(x -> !x.table().contains("ignored"))); final String ddl = "CREATE TABLE foo (id int primary key, old INT);" + System.lineSeparator() + "ALTER TABLE ok RENAME COLUMN old to new "; parser.parse(ddl, tables); assertThat(((MysqlDdlParserWithSimpleTestListener)parser).getParsingExceptionsFromWalker()).isEmpty(); assertThat(tables.size()).isEqualTo(1); final Table t1 = tables.forTable(null, null, "foo"); assertThat(t1.columns()).hasSize(2); final Column c1 = t1.columns().get(0); final Column c2 = t1.columns().get(1); assertThat(c1.name()).isEqualTo("id"); assertThat(c1.typeName()).isEqualTo("INT"); assertThat(c2.name()).isEqualTo("new"); assertThat(c2.typeName()).isEqualTo("INT"); }

            When I ran the test case, got this exception:

            shouldRenameColumnWithoutDefinition(io.debezium.connector.mysql.MySqlAntlrDdlParserTest) Time elapsed: 0.009 sec <<< ERROR!
            io.debezium.text.ParsingException: no viable alternative at input 'ALTER TABLE foo RENAME COLUMN'
            at org.antlr.v4.runtime.atn.ParserATNSimulator.noViableAlt(ParserATNSimulator.java:2023)
            at org.antlr.v4.runtime.atn.ParserATNSimulator.execATN(ParserATNSimulator.java:467)
            at org.antlr.v4.runtime.atn.ParserATNSimulator.adaptivePredict(ParserATNSimulator.java:393)
            at io.debezium.ddl.parser.mysql.generated.MySqlParser.sqlStatements(MySqlParser.java:977)
            at io.debezium.ddl.parser.mysql.generated.MySqlParser.root(MySqlParser.java:806)
            at io.debezium.connector.mysql.antlr.MySqlAntlrDdlParser.parseTree(MySqlAntlrDdlParser.java:71)
            at io.debezium.connector.mysql.antlr.MySqlAntlrDdlParser.parseTree(MySqlAntlrDdlParser.java:44)
            at io.debezium.antlr.AntlrDdlParser.parse(AntlrDdlParser.java:80)
            at io.debezium.connector.mysql.MySqlAntlrDdlParserTest.shouldRenameColumnWithoutDefinition(MySqlAntlrDdlParserTest.java:290)

            My Mysql server version is 5.7 and this RENAME option was added in 8.0. That seems to be a problem here.

            Sagar Rao (Inactive) added a comment - - edited gunnar.morling jpechane I created the following test case to test the Alter column: @Test public void shouldRenameColumnWithoutDefinition() { parser = new MysqlDdlParserWithSimpleTestListener(listener, TableFilter.fromPredicate(x -> !x.table().contains("ignored"))); final String ddl = "CREATE TABLE foo (id int primary key, old INT);" + System.lineSeparator() + "ALTER TABLE ok RENAME COLUMN old to new "; parser.parse(ddl, tables); assertThat(((MysqlDdlParserWithSimpleTestListener)parser).getParsingExceptionsFromWalker()).isEmpty(); assertThat(tables.size()).isEqualTo(1); final Table t1 = tables.forTable(null, null, "foo"); assertThat(t1.columns()).hasSize(2); final Column c1 = t1.columns().get(0); final Column c2 = t1.columns().get(1); assertThat(c1.name()).isEqualTo("id"); assertThat(c1.typeName()).isEqualTo("INT"); assertThat(c2.name()).isEqualTo("new"); assertThat(c2.typeName()).isEqualTo("INT"); } When I ran the test case, got this exception: shouldRenameColumnWithoutDefinition(io.debezium.connector.mysql.MySqlAntlrDdlParserTest) Time elapsed: 0.009 sec <<< ERROR! io.debezium.text.ParsingException: no viable alternative at input 'ALTER TABLE foo RENAME COLUMN' at org.antlr.v4.runtime.atn.ParserATNSimulator.noViableAlt(ParserATNSimulator.java:2023) at org.antlr.v4.runtime.atn.ParserATNSimulator.execATN(ParserATNSimulator.java:467) at org.antlr.v4.runtime.atn.ParserATNSimulator.adaptivePredict(ParserATNSimulator.java:393) at io.debezium.ddl.parser.mysql.generated.MySqlParser.sqlStatements(MySqlParser.java:977) at io.debezium.ddl.parser.mysql.generated.MySqlParser.root(MySqlParser.java:806) at io.debezium.connector.mysql.antlr.MySqlAntlrDdlParser.parseTree(MySqlAntlrDdlParser.java:71) at io.debezium.connector.mysql.antlr.MySqlAntlrDdlParser.parseTree(MySqlAntlrDdlParser.java:44) at io.debezium.antlr.AntlrDdlParser.parse(AntlrDdlParser.java:80) at io.debezium.connector.mysql.MySqlAntlrDdlParserTest.shouldRenameColumnWithoutDefinition(MySqlAntlrDdlParserTest.java:290) My Mysql server version is 5.7 and this RENAME option was added in 8.0. That seems to be a problem here.

              Unassigned Unassigned
              gunnar.morling Gunnar Morling
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: