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

Calling function UTC_TIMESTAMP without parenthesis causes a parsing error

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 1.2.0.CR1
    • 1.2.0.Beta2
    • mysql-connector
    • None
    • Hide

      Connect Debezium to an empty MySQL database and run the CREATE FUNCTION in the description.

      Show
      Connect Debezium to an empty MySQL database and run the CREATE FUNCTION in the description.

      Connecting Debezium to an empty MySQL database and executing this:

      CREATE FUNCTION myfunc(a INT) RETURNS INT
      BEGIN
          DECLARE result INT;
          SET result = UTC_TIMESTAMP;
          RETURN result;
      END;
      

      causes Debezium to fail with this error:

      org.apache.kafka.connect.errors.ConnectException: io.debezium.text.ParsingException: no viable alternative at input 'CREATE DEFINER=`root`@`%` FUNCTION `myfunc`(a INT) RETURNS int(11)\nBEGIN\n    DECLARE result INT;\n    SET result = UTC_TIMESTAMP;'
      	at io.debezium.connector.mysql.MySqlConnectorTask.start(MySqlConnectorTask.java:298)
      	at io.debezium.connector.common.BaseSourceTask.start(BaseSourceTask.java:101)
          ...
      

      The function works fine in MySQL. Adding parenthesis at the end of the function name makes it work for Debezium, but MySQL also accepts the function name without the parenthesis. Try, for instance `SELECT UTC_TIMESTAMP;`.

      The following patch fixes the problem for me, but again (as in DBZ-2153), I'm not sure this is the proper place to do this fix:

      diff --git a/debezium-ddl-parser/src/main/antlr4/io/debezium/ddl/parser/mysql/generated/MySqlParser.g4 b/debezium-ddl-parser/src/main/antlr4/io/debezium/ddl/parser/mysql/generated/MySqlParser.g4
      index 3aaf1ab4..0cbf0b57 100644
      --- a/debezium-ddl-parser/src/main/antlr4/io/debezium/ddl/parser/mysql/generated/MySqlParser.g4
      +++ b/debezium-ddl-parser/src/main/antlr4/io/debezium/ddl/parser/mysql/generated/MySqlParser.g4
      @@ -2188,7 +2188,7 @@ functionCall
       specificFunction
           : (
             CURRENT_DATE | CURRENT_TIME | CURRENT_TIMESTAMP
      -      | CURRENT_USER | LOCALTIME
      +      | CURRENT_USER | LOCALTIME | UTC_TIMESTAMP
             )                                                             #simpleFunctionCall
           | CONVERT '(' expression separator=',' convertedDataType ')'    #dataTypeFunctionCall
           | CONVERT '(' expression USING charsetName ')'                  #dataTypeFunctionCall
      

              Unassigned Unassigned
              ateijelo Andy Teijelo (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: