You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "John Wright (Jira)" <ji...@apache.org> on 2023/02/23 19:22:00 UTC

[jira] [Created] (CALCITE-5541) Upgrade JavaCC

John Wright created CALCITE-5541:
------------------------------------

             Summary: Upgrade JavaCC
                 Key: CALCITE-5541
                 URL: https://issues.apache.org/jira/browse/CALCITE-5541
             Project: Calcite
          Issue Type: Improvement
          Components: core
            Reporter: John Wright


After [https://github.com/apache/calcite/commit/515f3356a6a1ab4bd570c1c20bec9a7e5d4aca5f#diff-e873041549333502af52ece8a1b34301ae5a059ff4719e9bddbaef48929e7047] there appears to be an issue with JavaCC codegen of the Parser.jj template in "newer" versions of JavaCC (6.1.2 was the version I tested).
{code:java}
 build/scala_2.10/generated-sources/java/com/redacted/query/sql/parser/impl/QuerySqlParserImpl.java:15266: error: variable startNum might not have been initialized
                    startNum.intValue(true) != endNum.intValue(true),
                    ^ 
redacted/build/scala_2.10/generated-sources/java/com/redacted/query/sql/parser/impl/QuerySqlParserImpl.java:15266: error: variable endNum might not have been initialized
                    startNum.intValue(true) != endNum.intValue(true),
                                               ^ redacted/build/scala_2.10/generated-sources/java/com/redacted/query/sql/parser/impl/QuerySqlParserImpl.java:15281: error: variable startNum might not have been initialized
            span().end(e), e, startNum, endNum, reluctant);}
                              ^ 
redacted/build/scala_2.10/generated-sources/java/com/redacted/query/sql/parser/impl/QuerySqlParserImpl.java:15281: error: variable endNum might not have been initialized
            span().end(e), e, startNum, endNum, reluctant);}
                                        ^ redacted/build/scala_2.10/generated-sources/java/com/redacted/query/sql/parser/impl/QuerySqlParserImpl.java:15281: error: variable reluctant might not have been initialized
            span().end(e), e, startNum, endNum, reluctant);}{code}
[~jbalint@gmail.com] helped me debug this, and he pointed out which generated code was incorrect:
{code:java}
final public SqlNode PatternFactor() throws ParseException {final SqlNode e;
    final SqlNode extra;
    final SqlLiteral startNum;
    final SqlLiteral endNum;
    final SqlLiteral reluctant;

...

    default:
      jj_la1[163] = jj_gen;
{if ("" != null) return e;}
    }
{if ("" != null) return SqlStdOperatorTable.PATTERN_QUANTIFIER.createCall(
            span().end(e), e, startNum, endNum, reluctant);}
    throw new Error("Missing return statement in function");
  }{code}
instead of
{code:java}
  default:
    jj_la1[163] = jj_gen;
        {if (true) return e;}
  }
      {if (true) return SqlStdOperatorTable.PATTERN_QUANTIFIER.createCall(
          span().end(e), e, startNum, endNum, reluctant);}
  throw new Error("Missing return statement in function");
} {code}
The misunderstood line in the template:
{code:java}
{if ("" != null) return SqlStdOperatorTable.PATTERN_CONCAT.createCall( {code}
 

I've worked around this by pinning to JavaCC 4.0, however the Gradle JavaCC plugin we use [https://github.com/javacc/javaccPlugin] defaults to 6.1.2.

It looks like JavaCC 4.0 was release in 2006, 6.1.2 in 2014, and current 7.0.12 in 2022 so it felt like it might be worth updating.

If this is intended / known, feel free to close - Thanks



--
This message was sent by Atlassian Jira
(v8.20.10#820010)