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

Using expression as default when declaring variable in procedure fails

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Done
    • Icon: Minor Minor
    • 1.3.0.Final
    • 1.3.0.CR1
    • mysql-connector
    • None

      Running the following statement in MySql would fail the connector task:

      use db;
      DROP PROCEDURE IF EXISTS p;
      DELIMITER #
      CREATE PROCEDURE p()
      BEGIN
        DECLARE a INT unsigned default 1;
        DECLARE b INT unsigned default 1 + a;
      END #
      DELIMITER ;
      

       

      The error trace: 

      [2020-10-01 07:52:36,599] ERROR Failed due to error: Error processing binlog event (io.debezium.connector.mysql.BinlogReader)[2020-10-01 07:52:36,599] ERROR Failed due to error: Error processing binlog event (io.debezium.connector.mysql.BinlogReader)org.apache.kafka.connect.errors.ConnectException: no viable alternative at input 'CREATE DEFINER=`root`@`%` PROCEDURE `p`()\nBEGIN\n  DECLARE a INT unsigned default 1;\n  DECLARE b INT unsigned default 1 +' at io.debezium.connector.mysql.AbstractReader.wrap(AbstractReader.java:230) at io.debezium.connector.mysql.AbstractReader.failed(AbstractReader.java:207) at io.debezium.connector.mysql.BinlogReader.handleEvent(BinlogReader.java:600) at com.github.shyiko.mysql.binlog.BinaryLogClient.notifyEventListeners(BinaryLogClient.java:1130) at com.github.shyiko.mysql.binlog.BinaryLogClient.listenForEventPackets(BinaryLogClient.java:978) at com.github.shyiko.mysql.binlog.BinaryLogClient.connect(BinaryLogClient.java:581) at com.github.shyiko.mysql.binlog.BinaryLogClient$7.run(BinaryLogClient.java:860) at java.lang.Thread.run(Thread.java:748)Caused by: io.debezium.text.ParsingException: no viable alternative at input 'CREATE DEFINER=`root`@`%` PROCEDURE `p`()\nBEGIN\n  DECLARE a INT unsigned default 1;\n  DECLARE b INT unsigned default 1 +' at io.debezium.antlr.ParsingErrorListener.syntaxError(ParsingErrorListener.java:40) at org.antlr.v4.runtime.ProxyErrorListener.syntaxError(ProxyErrorListener.java:41) at org.antlr.v4.runtime.Parser.notifyErrorListeners(Parser.java:544) at org.antlr.v4.runtime.DefaultErrorStrategy.reportNoViableAlternative(DefaultErrorStrategy.java:310) at org.antlr.v4.runtime.DefaultErrorStrategy.reportError(DefaultErrorStrategy.java:136) at io.debezium.ddl.parser.mysql.generated.MySqlParser.sqlStatements(MySqlParser.java:1124) at io.debezium.ddl.parser.mysql.generated.MySqlParser.root(MySqlParser.java:852) at io.debezium.connector.mysql.antlr.MySqlAntlrDdlParser.parseTree(MySqlAntlrDdlParser.java:68) at io.debezium.connector.mysql.antlr.MySqlAntlrDdlParser.parseTree(MySqlAntlrDdlParser.java:41) at io.debezium.antlr.AntlrDdlParser.parse(AntlrDdlParser.java:80) at io.debezium.connector.mysql.MySqlSchema.applyDdl(MySqlSchema.java:314) at io.debezium.connector.mysql.BinlogReader.handleQueryEvent(BinlogReader.java:793) at io.debezium.connector.mysql.BinlogReader.handleEvent(BinlogReader.java:583) ... 5 moreCaused by: org.antlr.v4.runtime.NoViableAltException at org.antlr.v4.runtime.atn.ParserATNSimulator.noViableAlt(ParserATNSimulator.java:2026) 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:926) ... 12 more
      

       

      The part in the statement that caused the error is:

      DECLARE b INT unsigned default 1 + a;
      

       

      Currently, the MySql query parser doesn't support using an expression as the default value in a variable declaration in CREATE PROCEDURE.

       

      Proposed solution:

      Upgrade MySqlParser.g4 to use an expression as default value in variable declaration.

       

      From MySQL documentation:

      To provide a default value for a variable, include a DEFAULT clause. The value can be specified as an expression; it need not be a constant.

              kewei.shang kewei shang (Inactive)
              kewei.shang kewei shang (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: