fix: allow UNIQUE INDEX in CREATE TABLE - #2457
Open
fudianchn wants to merge 1 commit into
Open
Conversation
Accept an optional UNIQUE prefix on the INDEX branch of CreateTableConstraint, so MySQL-style CREATE TABLE ... UNIQUE INDEX name (cols) ... parses and round-trips. UNIQUE INDEX is disambiguated from UNIQUE KEY and the bare UNIQUE constraint by the LOOKAHEAD. Fixes JSQLParser#1893 Signed-off-by: 付典 <fudianchn@gmail.com>
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.
What
Allow an optional
UNIQUEprefix onINDEXinsideCREATE TABLE, so MySQL-styleUNIQUE INDEX name (cols) ...parses and round-trips.Why
MySQL accepts
UNIQUE INDEX name (cols) ...as an inline table constraint (it is produced by tooling and appears in real schemas). JSQLParser currently rejects it:Only
INDEX name (...)and[UNIQUE] KEY name (...)were accepted; theUNIQUE INDEXcombination fell through everyCreateTableConstraintalternative.How
The
INDEXbranch ofCreateTableConstraintnow accepts an optional leadingUNIQUE, and the indextypeis rendered asUNIQUE INDEXwhen present (mirroring the existing[UNIQUE] KEYbranch).LOOKAHEAD(3)becomesLOOKAHEAD(4)to cover the extra token. The branches remain unambiguous:UNIQUE INDEX name (matches this branch,UNIQUE KEY name (still matches the[UNIQUE] ... KEYbranch, andUNIQUE (still matches the[CONSTRAINT] UNIQUEbranch.Testing
CreateTableTest#testUniqueIndexIssue1893—UNIQUE INDEX idx (a, b) USING BTREE COMMENT '...'round-trips (fails before the grammar change), and a plainINDEX idx (a)still parses../gradlew test --tests net.sf.jsqlparser.statement.create.CreateTableTest— green../gradlew test— no regressions introduced by this change. The 33 unrelated failures observed locally are pre-existing environmental issues (Mockito inlineMockMakerdoes not initialise under the local JDK 17 / Windows toolchain, andParserKeywordsUtilsTestresolves its temp file toC:\WINDOWS); both reproduce on unmodifiedmaster.Fixes #1893