Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB2Parser struggles with block depth count #2379

Closed
wallenborn opened this issue May 8, 2019 · 5 comments

Comments

Projects
None yet
2 participants
@wallenborn
Copy link

commented May 8, 2019

Which version and edition of Flyway are you using?

Cloned from git, most recent commit is
51dc662

If this is not the latest version, can you reproduce the issue with the latest one as well?

(Many bugs are fixed in newer releases and upgrading will often resolve the issue)

Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin)

commandline

Which database are you using (type & version)?

DB2/LINUXX8664 10.5.5

Which operating system are you using?

Windows 10/cygwin

What did you do?

(Please include the content causing the issue, any relevant configuration settings, the SQL statement that failed (if relevant) and the command you ran.)

After upgrade to the current version i ran a
flyway -configFiles=/path/to/flyway-TEST.conf -locations=filesystem:TEST info
on a database that was setup with an earlier version of flyway

What did you expect to see?

The usual migration list with status success for the migrations applied before

What did you see instead?

Flyway Community Edition 5.2.3 by Boxfuse
Database: jdbc:db2://localhost:50000/test (DB2/LINUXX8664 10.5)
ERROR: Unable to parse statement in TEST\R__0.0.1_foo.sql at line 2 col 1: Flyway parsing bug: unable to decrease block depth below 0

Rerunning the command with the -X flag produced the following stacktrace:

org.flywaydb.core.api.FlywayException: Unable to parse statement in TEST\R__0.0.1_foo.sql at line 2 col 1: Flyway parsing bug: unable to decrease block depth below 0
at org.flywaydb.core.internal.parser.Parser.getNextStatement(Parser.java:271)
at org.flywaydb.core.internal.parser.Parser.access$000(Parser.java:41)
at org.flywaydb.core.internal.parser.Parser$ParserSqlStatementIterator.(Parser.java:586)
at org.flywaydb.core.internal.parser.Parser.parse(Parser.java:103)
at org.flywaydb.core.internal.sqlscript.ParserSqlScript.(ParserSqlScript.java:70)
at org.flywaydb.core.internal.database.db2.DB2Database.createSqlScript(DB2Database.java:88)
at org.flywaydb.core.internal.resolver.sql.SqlMigrationResolver.addMigrations(SqlMigrationResolver.java:140)
at org.flywaydb.core.internal.resolver.sql.SqlMigrationResolver.resolveMigrations(SqlMigrationResolver.java:110)
at org.flywaydb.core.internal.resolver.sql.SqlMigrationResolver.resolveMigrations(SqlMigrationResolver.java:47)
at org.flywaydb.core.internal.resolver.CompositeMigrationResolver.collectMigrations(CompositeMigrationResolver.java:130)
at org.flywaydb.core.internal.resolver.CompositeMigrationResolver.doFindAvailableMigrations(CompositeMigrationResolver.java:112)
at org.flywaydb.core.internal.resolver.CompositeMigrationResolver.resolveMigrations(CompositeMigrationResolver.java:98)
at org.flywaydb.core.internal.resolver.CompositeMigrationResolver.resolveMigrations(CompositeMigrationResolver.java:44)
at org.flywaydb.core.internal.info.MigrationInfoServiceImpl.refresh(MigrationInfoServiceImpl.java:133)
at org.flywaydb.core.internal.command.DbInfo.info(DbInfo.java:52)
at org.flywaydb.core.Flyway$4.execute(Flyway.java:308)
at org.flywaydb.core.Flyway$4.execute(Flyway.java:301)
at org.flywaydb.core.Flyway.execute(Flyway.java:453)
at org.flywaydb.core.Flyway.info(Flyway.java:301)
at org.flywaydb.commandline.Main.executeOperation(Main.java:171)
at org.flywaydb.commandline.Main.main(Main.java:112)
Caused by: org.flywaydb.core.api.FlywayException: Flyway parsing bug: unable to decrease block depth below 0
at org.flywaydb.core.internal.parser.ParserContext.decreaseBlockDepth(ParserContext.java:48)
at org.flywaydb.core.internal.database.db2.DB2Parser.adjustBlockDepth(DB2Parser.java:58)
at org.flywaydb.core.internal.parser.Parser.getNextStatement(Parser.java:189)
... 20 more

The migration in question is a stored procedure definition, one of many. Previous migrations with other stored procedures went through without a problem. One difference between the migration is that this one contains a construct like this:

INSERT INTO FOO(ID, X_CODE, Y_CODE)
    SELECT S.ID,
        CASE S.IS_X
            WHEN 1 THEN S.CODE
            ELSE NULL END,
        CASE S.IS_Y
            WHEN 1 THEN S.CODE
            ELSE NULL END
    FROM SOURCE S
    WHERE S.ID = IDENTIFIER;

In the source i see that DB2Parser increases the block depth counter on

"CASE".equals(token.getText()) && !"END".equals(previousToken.getText())

Wouldn't this break in the case above when a CASE is immediately preceeded by the END of the previous clause?

@axelfontaine

This comment has been minimized.

Copy link
Contributor

commented May 8, 2019

Please try again with 6.0.0-beta. The parser was rewritten from the ground up and this change eliminated entire classes of errors. Did this fix the issue?

@wallenborn

This comment has been minimized.

Copy link
Author

commented May 8, 2019

@axelfontaine

This comment has been minimized.

Copy link
Contributor

commented May 8, 2019

We just tested this internally and this statement parses correctly with the latest code.

@axelfontaine axelfontaine added this to the Flyway 6.0.0 milestone May 8, 2019

@axelfontaine axelfontaine reopened this May 10, 2019

@axelfontaine axelfontaine added m: Core and removed r: fixed labels May 10, 2019

@axelfontaine

This comment has been minimized.

Copy link
Contributor

commented May 10, 2019

Reopening as we now have managed to reproduce this.

axelfontaine pushed a commit to flyway/flywaydb.org that referenced this issue May 10, 2019

@wallenborn

This comment has been minimized.

Copy link
Author

commented May 14, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.