prestodb / presto

The official home of the Presto distributed SQL query engine for big data
http://prestodb.io
Apache License 2.0
16.06k stars 5.38k forks source link

Make Presto-Parser compatible with Hibernate 6.0.1 and above #22174

Open apoorvam opened 8 months ago

apoorvam commented 8 months ago

With Spring boot 3.x, Hibernate v6.4.4 uses antlr4-runtime version 4.13.0 as dependency. Since presto-parser v0.285 uses antlr4-runtime 4.7.1, when presto-parser maven dependency is used in a spring project with hibernate, it is not compatible.

I'm unable to work around this problem by forcing specific dependency versions. When I remove antlr4-runtime dep from presto and use the one from hibernate, I get error as below:

    private static com.facebook.presto.sql.tree.Statement getStatementBySql(String sql) {
        SqlParser parser = new SqlParser();
        return parser.createStatement(sql, new ParsingOptions(DecimalLiteralTreatment.AS_DECIMAL));
    }
Caused by: java.lang.ExceptionInInitializerError: null
    at com.facebook.presto.sql.parser.SqlParser.invokeParser(SqlParser.java:133)
    at com.facebook.presto.sql.parser.SqlParser.createStatement(SqlParser.java:108)
..
Caused by: java.lang.UnsupportedOperationException: java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with version 3 (expected 4).
    at org.antlr.v4.runtime.atn.ATNDeserializer.deserialize(ATNDeserializer.java:56)
    at org.antlr.v4.runtime.atn.ATNDeserializer.deserialize(ATNDeserializer.java:48)
    at com.facebook.presto.sql.parser.SqlBaseLexer.<clinit>(SqlBaseLexer.java:1066)
    ... 184 common frames omitted
Caused by: java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with version 3 (expected 4).

And when I use antlr4-runtime v4.7.1 that presto-parser uses, hibernate fails to initialize.

Expected Behavior or Use Case

Presto-parser is usable in projects along with Spring/Hibernate 6. A new version of presto-parser released with antl4-runtime 4.13.0 thats compatible with Hibernate 6. (Is this already planned?)

Presto Component, Service, or Connector

Parser

This seems similar to issues in these other unrelated tools like: https://github.com/graphql-java-kickstart/graphql-java-tools/issues/767 https://github.com/espertechinc/esper/issues/278. It also makes sense to upgrade to keep them up-to-date and also for its better performance.

pratyakshsharma commented 8 months ago

cc @imjalpreet

pratyakshsharma commented 8 months ago

Slack thread - https://prestodb.slack.com/archives/C07JH9WMQ/p1710214369690629

apoorvam commented 8 months ago

@pratyakshsharma @imjalpreet Can you please let me know if antlr4-runtime library upgrade will be planned soon? This would unblock all the users using presto along with Spring Boot 3.x.

I compiled presto-parser locally with antlr4-runtime version v4.13.0 and it works fine without issues.

tdcmeehan commented 8 months ago

@apoorvam this is not planned. Would you like to raise a PR which bumps the version?

apoorvam commented 8 months ago

Will send in a PR

apoorvam commented 8 months ago

@tdcmeehan It looks like this new version of antlr has a minimum version of jdk 11 and that's causing the CI checks to fail. Do you think there is a way I can get around this(updating only in parser)? Locally I have higher version of java and building presto-parser module works fine with it. https://github.com/antlr/antlr4/releases/tag/4.10