fix(parser): parse Oracle outer join operator (+) after LIKE / SIMILAR TO operands (#2598) - #2600
Merged
Conversation
fudianchn
marked this pull request as draft
September 11, 2026 13:07
…R TO operands (JSQLParser#2598) Signed-off-by: 付典 <fudianchn@gmail.com>
fudianchn
force-pushed
the
like-oracle-join
branch
from
September 11, 2026 13:07
f695858 to
59aa40f
Compare
fudianchn
marked this pull request as ready for review
September 11, 2026 13:08
Contributor
|
Nice, thank you very much! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AI disclosure: this change was prepared with AI coding agents, reviewed and revised line by line by me.
What
JSqlParserCC.jjt: accept the Oracle outer join operator(+)after the right-hand operand ofLIKEconditions andSIMILAR TO, mirroring theBETWEENfix from #2564. 9 new cases inLikeExpressionTest.Why
WHERE t1.col1 LIKE t2.col2(+)fails to parse, although(+)already works on comparison operands (t1.c = t2.c(+),t1.c(+) = t2.c), onBETWEENoperands (#2564), and on the left operand ofLIKEitself. The same failure occurs forNOT LIKEandSIMILAR TO, and when anESCAPEclause follows. Fixes #2598.How
The grammar consumes
(+)atCondition()(left operand),RegularConditionRHS()(comparison right-hand side) andBetween()(#2564); the right operand ofLikeExpression()/SimilarToExpression()reaches none of them. The fix adds the same[ LOOKAHEAD("(" "+" ")") "(" "+" ")" ]block afterrightExpression = SimpleExpression()in both productions, placed before the optionalESCAPEclause, settingORACLE_JOIN_RIGHTon the operandColumnthrough the existingSupportsOldOracleJoinSyntaxinterface. No AST change, deparsing comes fromColumndirectly. The block lives in the shared production, so the other keywords it serves (ILIKE,RLIKE,REGEXP,MATCH_*) gain the same postfix. Oracle's documented(+)restrictions nameOR,IN, subqueries and non-column expressions, notLIKE(rules and restrictions in the Joins chapter of the Oracle SQL Reference).Root cause
LikeExpression()andSimilarToExpression()parse their right operand viaSimpleExpression()and never consume a(+)postfix on that path, soLIKE t2.col2(+)fails on the(token.Testing
net.sf.jsqlparser.expression.operators.relational.LikeExpressionTest(right-operand forms:LIKE,NOT LIKE,SIMILAR TOsingle token,SIMILAR TOon separate tokens,LIKE+ESCAPE,SIMILAR TO+ESCAPE,ILIKE,LIKEinside a joinONclause, left-operand guard): the 8 encoder cases fail on master7cc86386withParseExceptionat(and nothing else fails, all pass with this change (mvn clean test -Dtest=LikeExpressionTest;./gradlew checkandmvn verifyare green).ORACLE_JOIN_RIGHT, the other operandNO_ORACLE_JOIN.LikeExpression()block turns its path tests red; marking the left operand instead in theSimilarToExpression()block turns only the separate-token test red; disabling the marker of the pre-existingCondition()left-operand block turns only the left-operand guard red (round-trip loses the(+)), proving the guard pins the pre-existing route.Columnright operand followed by(+)the token is consumed and not recorded, matching the existingCondition()left-operand andBetween()semantics.JSQLParserBenchmark.parseSQLStatements,version=latest, 10 forks x 10 iterations (100 samples) per run, interleaved master -> branch -> master -> branch on a 32-core host (JDK 17):7cc86386The first master window has a wide interval (±0.227, background load on the shared host) and sits high; the remaining three windows agree within overlapping intervals (11.912-11.953), the mean delta is 0.1%, no regression. The new lookahead only executes inside the
LIKEfamily productions.Note on the corpus: the stock
performance.sqlcontains@Promptmacros JSQLParser cannot parse (long-standing, both builds fail that statement identically; tracked in #2599, which also documents thatparseStatementsused to hide this by returningnulluntil #2568 / #2594 made it fail fast). Its onlyLIKE-bearing statement is that one. Both builds therefore ran on an identical corpus consisting of the 48 statements that master parses plus one synthetic statement carrying 381LIKE-family predicates (LIKE/NOT LIKE/SIMILAR TO/ESCAPE, modeled on the excluded statement'sCASE WHEN ... LIKEcascades), so the changed productions are actually exercised on both sides.Verification of the original issue
SELECT * FROM table1 t1, table2 t2 WHERE t1.col1 LIKE t2.col2(+)7cc86386:ParseException: Encountered: <OPENING_BRACKET> / "(", at line 1, column 62ORACLE_JOIN_RIGHT, deparse is identical to the input.Fixes #2598