-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix(parser): pass modifier to ExceptOp/MinusOp constructors (#2419) #2420
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
Merged
manticore-projects
merged 2 commits into
JSQLParser:master
from
queelius:fix/except-minus-all-modifier-lost
Mar 25, 2026
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
132 changes: 132 additions & 0 deletions
132
src/test/java/net/sf/jsqlparser/statement/select/SetOperationModifierTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| /*- | ||
| * #%L | ||
| * JSQLParser library | ||
| * %% | ||
| * Copyright (C) 2004 - 2019 JSQLParser | ||
| * %% | ||
| * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 | ||
| * #L% | ||
| */ | ||
| package net.sf.jsqlparser.statement.select; | ||
|
|
||
| import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed; | ||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| import net.sf.jsqlparser.JSQLParserException; | ||
| import net.sf.jsqlparser.parser.CCJSqlParserUtil; | ||
| import net.sf.jsqlparser.statement.Statement; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.parallel.Execution; | ||
| import org.junit.jupiter.api.parallel.ExecutionMode; | ||
|
|
||
| /** | ||
| * Regression tests for EXCEPT/MINUS ALL/DISTINCT modifier handling. | ||
| * <p> | ||
| * Verifies that the ALL and DISTINCT modifiers are correctly preserved during | ||
| * parse-toString round-trips for all set operation types: UNION, INTERSECT, | ||
| * EXCEPT, and MINUS. | ||
| * | ||
| * @see <a href="https://github.com/JSQLParser/JSqlParser/issues/2080">#2080</a> | ||
| */ | ||
| @Execution(ExecutionMode.CONCURRENT) | ||
| public class SetOperationModifierTest { | ||
|
|
||
| // ── EXCEPT modifier tests ───────────────────────────────────── | ||
|
|
||
| @Test | ||
| public void testExceptAllRoundTrip() throws JSQLParserException { | ||
| assertSqlCanBeParsedAndDeparsed("SELECT a FROM t1 EXCEPT ALL SELECT a FROM t2"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testExceptDistinctRoundTrip() throws JSQLParserException { | ||
| assertSqlCanBeParsedAndDeparsed("SELECT a FROM t1 EXCEPT DISTINCT SELECT a FROM t2"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testPlainExceptRoundTrip() throws JSQLParserException { | ||
| assertSqlCanBeParsedAndDeparsed("SELECT a FROM t1 EXCEPT SELECT a FROM t2"); | ||
| } | ||
|
|
||
| // ── MINUS modifier tests ───────────────────────────────────── | ||
|
|
||
| @Test | ||
| public void testMinusAllRoundTrip() throws JSQLParserException { | ||
| assertSqlCanBeParsedAndDeparsed("SELECT a FROM t1 MINUS ALL SELECT a FROM t2"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMinusDistinctRoundTrip() throws JSQLParserException { | ||
| assertSqlCanBeParsedAndDeparsed("SELECT a FROM t1 MINUS DISTINCT SELECT a FROM t2"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testPlainMinusRoundTrip() throws JSQLParserException { | ||
| assertSqlCanBeParsedAndDeparsed("SELECT a FROM t1 MINUS SELECT a FROM t2"); | ||
| } | ||
|
|
||
| // ── Cross-check: UNION and INTERSECT still work ────────────── | ||
|
|
||
| @Test | ||
| public void testUnionAllRoundTrip() throws JSQLParserException { | ||
| assertSqlCanBeParsedAndDeparsed("SELECT a FROM t1 UNION ALL SELECT a FROM t2"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIntersectAllRoundTrip() throws JSQLParserException { | ||
| assertSqlCanBeParsedAndDeparsed("SELECT a FROM t1 INTERSECT ALL SELECT a FROM t2"); | ||
| } | ||
|
|
||
| // ── Modifier leak prevention: modifiers must not bleed across operators ── | ||
|
|
||
| @Test | ||
| public void testModifierDoesNotLeakFromUnionAllToExcept() throws JSQLParserException { | ||
| String sql = "SELECT a FROM t1 UNION ALL SELECT b FROM t2 EXCEPT SELECT c FROM t3"; | ||
| Statement stmt = CCJSqlParserUtil.parse(sql); | ||
| String result = stmt.toString(); | ||
| // EXCEPT must NOT inherit ALL from the preceding UNION ALL | ||
| assertFalse(result.contains("EXCEPT ALL"), | ||
| "Modifier should not leak from UNION ALL to a subsequent plain EXCEPT: " + result); | ||
| } | ||
|
|
||
| @Test | ||
| public void testModifierDoesNotLeakFromIntersectAllToUnion() throws JSQLParserException { | ||
| String sql = "SELECT a FROM t1 INTERSECT ALL SELECT b FROM t2 UNION SELECT c FROM t3"; | ||
| Statement stmt = CCJSqlParserUtil.parse(sql); | ||
| String result = stmt.toString(); | ||
| assertFalse(result.contains("UNION ALL"), | ||
| "Modifier should not leak from INTERSECT ALL to a subsequent plain UNION: " + result); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMixedModifiersPreserved() throws JSQLParserException { | ||
| // UNION ALL followed by EXCEPT DISTINCT | ||
| assertSqlCanBeParsedAndDeparsed( | ||
| "SELECT a FROM t1 UNION ALL SELECT b FROM t2 EXCEPT DISTINCT SELECT c FROM t3"); | ||
| } | ||
|
|
||
| // ── SetOperation object state verification ────────────────── | ||
|
|
||
| @Test | ||
| public void testExceptAllSetOperationObject() throws JSQLParserException { | ||
| String sql = "SELECT a FROM t1 EXCEPT ALL SELECT a FROM t2"; | ||
| Statement stmt = CCJSqlParserUtil.parse(sql); | ||
| SetOperationList setOpList = (SetOperationList) stmt; | ||
| SetOperation op = setOpList.getOperation(0); | ||
|
|
||
| assertInstanceOf(ExceptOp.class, op); | ||
| assertTrue(op.isAll(), "ExceptOp should report isAll() == true"); | ||
| assertFalse(op.isDistinct(), "ExceptOp should report isDistinct() == false"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMinusAllSetOperationObject() throws JSQLParserException { | ||
| String sql = "SELECT a FROM t1 MINUS ALL SELECT a FROM t2"; | ||
| Statement stmt = CCJSqlParserUtil.parse(sql); | ||
| SetOperationList setOpList = (SetOperationList) stmt; | ||
| SetOperation op = setOpList.getOperation(0); | ||
|
|
||
| assertInstanceOf(MinusOp.class, op); | ||
| assertTrue(op.isAll(), "MinusOp should report isAll() == true"); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Javadoc references issue #2080, but this PR (and the described regression) is for #2419. Please update the link so future readers can trace the correct bug report.