Skip to content

fix: parse MySQL simple-form CREATE FUNCTION in multi-statement scripts - #6707

Open
kalayciburak wants to merge 1 commit into
alibaba:masterfrom
kalayciburak:fix/mysql-simple-create-function-semi
Open

fix: parse MySQL simple-form CREATE FUNCTION in multi-statement scripts#6707
kalayciburak wants to merge 1 commit into
alibaba:masterfrom
kalayciburak:fix/mysql-simple-create-function-semi

Conversation

@kalayciburak

Copy link
Copy Markdown

What is wrong

MySQL simple-form CREATE FUNCTION (body is RETURN expr without BEGIN...END) failed to parse when another statement followed in the same script:

SQLUtils.parseStatements(
        "CREATE FUNCTION f() RETURNS INT RETURN 1;\nSELECT 1;", "mysql");
// ParserException: not supported. ... token SELECT

BEGIN...END bodies were already fine.

The function body was parsed with parseStatement(), which treats leftover tokens as an unexpected end of the statement. The trailing semicolon was also consumed on the RETURN body, so the outer statement list did not see a terminator on the CREATE FUNCTION itself.

How this PR fixes it

  • Parse the simple-form body with parseStatement0() so a following statement in the same script is left for the caller.
  • If the function/procedure body already consumed the terminator, treat the CREATE as complete in parseStatementList.

Fixes #6705

Tests

Executed:

mvn test -pl core -Dtest=MySqlCreateFunctionMultiStatementTest,SQLServerCreateFunctionTest

Results: Tests run: 10, Failures: 0, Errors: 0, Skipped: 0

Also mvn test -pl core -Dtest=*CreateFunction* (same 10 tests) and checkstyle: 0 violations.

Simple-form CREATE FUNCTION (RETURN expr without BEGIN...END) consumed
the trailing semicolon on the body and then treated leftover tokens as
an unexpected end of the function. A following SELECT or CREATE in the
same script therefore failed to parse.

Parse the body without requiring end-of-script, and treat a terminator
on the function body as completing the CREATE statement.

Fixes alibaba#6705
@CLAassistant

CLAassistant commented Aug 21, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MySQL: simple-form CREATE FUNCTION (RETURN expr without BEGIN...END) breaks subsequent statements in multi-statement script

2 participants