fix: seal JavaCC SQL parser escape hatches — ANTLR is always used now#3756
fix: seal JavaCC SQL parser escape hatches — ANTLR is always used now#3756
Conversation
Code ReviewThis is a solid, well-scoped cleanup that resolves the concrete bug from #3738 (parser tests silently testing the wrong parser). The core migration is correct and the grammar/AST fixes are legitimate gap-fills. A few items worth discussing: Issues to address before merging1. Overly broad exception catch in // Before (precise)
} catch (ParseException e) {
// IGNORE IT
// After (too broad)
} catch (Exception e) {
// IGNORE IT
2. - protected Identifier left;
- protected Expression key;
- protected Expression value;
+ public Identifier left;
+ public Expression key;
+ public Expression value;Widening access modifiers is a red flag — it enlarges the public API surface. If the ANTLR AST builder needs to set these, a package-private accessor or a constructor that accepts the fields would be preferable. What's the motivation for making them 3. Duplicate | identifier (IF NOT EXISTS)? indexType
(METADATA json)?
(ENGINE identifier)?
| identifier (IF NOT EXISTS)? indexType
(ENGINE identifier)?
(METADATA json)?These two alternatives exist only to allow ENGINE and METADATA in either order. ANTLR supports optional clauses in any combinator — consider something like: | identifier (IF NOT EXISTS)? indexType
( (METADATA json) | (ENGINE identifier) )*The duplicate alternatives will cause ambiguity warnings and are harder to maintain. 4. Users who have Minor observations5. Plan files committed to
6. Unused import added to +import org.antlr.v4.runtime.ParserRuleContext;This import was added but What's good
Overall this is good work. The 🤖 Generated with Claude Code |
There was a problem hiding this comment.
Code Review
This pull request implements the plan to "Seal JavaCC SQL Parser Escape Hatches" by removing the ability to invoke the legacy JavaCC parser. Key changes include deprecating the SQL_PARSER_IMPLEMENTATION configuration, migrating production code paths in AbstractProperty and SQLFunctionEval to SQLAntlrParser, and updating the ANTLR grammar and SQLASTBuilder to address syntax gaps. Additionally, numerous test files were refactored to extend AbstractParserTest. Feedback suggests adding the @deprecated tag to the configuration description for consistency and using protected fields with setters in UpdatePutItem to improve encapsulation.
| SQL parser implementation to use. 'antlr' (default) uses the new ANTLR4-based parser with improved error messages. \ | ||
| 'javacc' uses the legacy JavaCC-based parser for backward compatibility.""", | ||
| String.class, "antlr", Set.of("antlr", "javacc")), | ||
| "Deprecated, has no effect. The ANTLR4-based SQL parser is always used.", |
There was a problem hiding this comment.
There was a problem hiding this comment.
The description string is a user-facing runtime value, not a Javadoc comment — adding @Deprecated as literal text in the string does nothing for Java's deprecation mechanism. The codebase already shows the correct pattern: GREMLIN_COMMAND_TIMEOUT uses the actual @Deprecated Java annotation on the enum constant. Adding @Deprecated as a text prefix here would be misleading and inconsistent.
| public Identifier left; | ||
| public Expression key; | ||
| public Expression value; |
There was a problem hiding this comment.
For better encapsulation and consistency with other AST nodes like UpdateIncrementItem, it's preferable to keep these fields protected and provide public fluent setters instead of making them public.
You could add setters like this to UpdatePutItem:
public UpdatePutItem setLeft(Identifier left) {
this.left = left;
return this;
}
public UpdatePutItem setKey(Expression key) {
this.key = key;
return this;
}
public UpdatePutItem setValue(Expression value) {
this.value = value;
return this;
}Then, SQLASTBuilder.visitUpdatePutItem() can be updated to use these setters.
| public Identifier left; | |
| public Expression key; | |
| public Expression value; | |
| protected Identifier left; | |
| protected Expression key; | |
| protected Expression value; |
There was a problem hiding this comment.
Fixed. Reverted fields to protected and added fluent setters matching the UpdateIncrementItem pattern. Updated SQLASTBuilder.visitUpdatePutItem() to use them.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…arser Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…gaps - AbstractParserTest now uses SQLAntlrParser instead of SqlParser - SelectStatementTest.emptyCollection() migrated to use SQLAntlrParser directly - Fix SQLParser.g4: matchFilterItemKey restricted to valid keys only (was accepting any identifier) - Fix SQLParser.g4: named parameter :from now supported (FROM is a reserved keyword) - Fix SQLParser.g4: CREATE INDEX grammar for named vs unnamed index forms - Fix SQLParser.g4: UNWIND now supports multiple items separated by commas - Fix SQLParser.g4: TIMEOUT clause now supports EXCEPTION/RETURN options - Fix SQLParser.g4: array selectors improvements (range, IN, NOT IN) - Fix SQLParser.g4: RID_STRING as base expression - Fix SQLASTBuilder.java: UpdatePutItem, InCondition, Timeout, UpdateOperations, UpdateIncrementItem, CreateIndexStatement, StatementExpression, SubqueryExpression - PatternTestParserTest updated to work with ANTLR semantics This completes the JavaCC escape hatch sealing: grep for "new SqlParser" in src/main/java and src/test/java returns zero call-site results. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
- AbstractParserTest now uses SQLAntlrParser (the production parser) instead of the legacy JavaCC parser, which was silently hiding gaps - SQLParser.g4: make EXPORT DATABASE url optional; add FORCE to DROP PROPERTY; add INTEGER_LITERAL to DROP/TRUNCATE BUCKET; fix TRUNCATE RECORD to require brackets for multiple RIDs; fix COMMIT RETRY ELSE block to require AND and non-empty body; add STAR to ALTER BUCKET; add legacy quoted-name syntax to CREATE INDEX; add OVERWRITE as allowed identifier for use in WITH clause settings - SQLASTBuilder: fix ClassCastException in ALTER PROPERTY/BUCKET NAME handling; fix DROP/TRUNCATE BUCKET integer ID; fix CREATE INDEX legacy syntax visitor - SubqueryExpression, StatementExpression: add toString(Map,StringBuilder) override so LET subquery round-trips correctly - ImportDatabaseStatement: fix settings key serialization in toString() - ExportDatabaseStatementTestParserTest: add WITH clause test cases Closes #3738 Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
62205ce to
29c3c5a
Compare
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferencesFootnotes
|
- Remove FROM from identifier rule (was causing SELECT FROM to parse 'from' as a projection field); allow FROM only in inputParameter for :from named params - Fix createIndexBody ON-clause to accept NULL_STRATEGY/METADATA/ENGINE in any order matching toString() output order; fix positional visitor to check NULL_STRATEGY before ENGINE - Fix createVertexBody to accept BUCKET_IDENTIFIER/BUCKET_NUMBER_IDENTIFIER tokens (bucket:name syntax without a type name); fix visitCreateVertexStmt to handle both forms - Make DECR GT and ARROW_LEFT MINUS require matchProperties in matchMethod and nestedMatchMethod, preventing consecutive arrows without node filter - Add bucket value validation in visitMatchFilterItem to reject float literals (only integer ID or identifier name allowed) - Fix tryExtractIntegerLiteral to throw on FloatingPoint/PNumber values, rejecting foo[1....5] range selectors with float endpoints - Fix PInteger construction in BUCKET_NUMBER_IDENTIFIER handling (was passing value as node id; use setValue() instead) - Add PARALLEL keyword to lexer and selectStatement as optional trailing hint for legacy OrientDB compatibility Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
PR Review: Seal JavaCC SQL Parser Escape HatchesGood overall goal — removing the JavaCC escape hatches is an important correctness fix after #3738. The core migration in That said, I have several concerns worth addressing before merge. 🔴 Potential Breaking Change:
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3756 +/- ##
==========================================
+ Coverage 64.09% 64.84% +0.75%
==========================================
Files 1580 1580
Lines 115475 115571 +96
Branches 24445 24472 +27
==========================================
+ Hits 74010 74946 +936
+ Misses 31348 30464 -884
- Partials 10117 10161 +44 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Add RID_STRING token for quoted "@Rid" form in lexer - Allow RID_STRING in stringLiteral expression alternative - Fix COMMIT RETRY ELSE block to not require trailing AND FAIL/CONTINUE Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
- Restore (AS? identifier)? in fromIdentifier grammar rule - Fix visitFromIdentifier to use identifier(0) for the type name - Update SelectStatementTest: bare aliases without AS are valid SQL Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Code Review (supplemental)Good cleanup overall — the core goal of sealing JavaCC escape hatches is achieved cleanly. These are additional items not covered in the prior review. Issues to address before merging1. The comma-separated form 2. - | DECR GT matchProperties? // -->{as:x} anonymous outgoing
+ | DECR GT matchProperties // -->{as:x} anonymous outgoing (properties required)Any MATCH query using bare MATCH {class:Person, as:a} --> {class:Address, as:b} RETURN a, bThe 3.
4. The description text says "Deprecated" but there is no 5.
Minor6. The tests flip What looks good
|
Follow the same encapsulation pattern as UpdateIncrementItem: keep fields protected and expose public fluent setters. Update SQLASTBuilder to use the new setters instead of direct field assignment. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Review responseComment 1 (rejected) — Comment 2 (implemented) — |
|
Review Summary (follow-up): Three prior reviews have covered this PR thoroughly. Summarizing unresolved items after the author response. ADDRESSED: UpdatePutItem setters added (confirmed). The @deprecated annotation should also be placed on the enum constant, not just the description string. STILL UNRESOLVED:
The core parser migration (JavaCC to ANTLR everywhere) is correct and well-executed. Items 2 and 3 need explicit confirmation before merge. Generated with Claude Code |
lvca
left a comment
There was a problem hiding this comment.
Not sure if all the keywords added are not used, like PARALLEL in the query or FORCE in the drop statements.
Summary
SqlParser(JavaCC) from production code and tests —grep -r "new SqlParser("returns zero resultsStatementCachenow always callsSQLAntlrParser,parseWithJavaCC()removedSQLScriptQueryEngine.parseScript()JavaCC branch removedGlobalConfiguration.SQL_PARSER_IMPLEMENTATIONmarked deprecated (no effect — ANTLR is always used)AbstractProperty.getDefaultValue()andSQLFunctionEval.execute()migrated toSQLAntlrParserSqlParsertoSQLAntlrParser(viaAbstractParserTestrefactor)matchFilterItemKeyrestricted to valid keys only:from(reserved keyword) now supportedCREATE INDEXgrammar for named vs unnamed formsUNWINDwith multiple items,TIMEOUTwithEXCEPTION/RETURNIN,NOT INRID_STRINGas base expressionUpdatePutItem,InCondition,Timeout,UpdateOperations,UpdateIncrementItem,CreateIndexStatementAST fixesTest plan
grep -r "new SqlParser(" engine/src/main/java/ engine/src/test/java/→ zero resultsmvn test -Dtest="*ParserTest*,*StatementTest*,*ScriptTest*"→ 272 tests, 0 failures🤖 Generated with Claude Code