fix(parser): support CAST to an array type for MySQL multi-valued indexes - #2506
Merged
manticore-projects merged 1 commit intoAug 25, 2026
Conversation
…exes MySQL defines a multi-valued index key part by casting to an array, e.g. CAST(data->'$.zips' AS UNSIGNED ARRAY). The trailing ARRAY keyword was not reachable, so both the CREATE INDEX and the ALTER TABLE form failed to parse. ARRAY is accepted as a further word of the cast target type, the way INT UNSIGNED already is, so no model change is needed and the deparsed statement round trips. It is added to the CAST production only, where MySQL allows it, which leaves the ARRAY<type> constructor form untouched. Closes the last open group of JSQLParser#2490.
Contributor
CREATE INDEX i20 ON t ((CAST(data->'$.zips' AS UNSIGNED ARRAY)));
ALTER TABLE t ADD INDEX i31 ((CAST(data->'$.zips' AS UNSIGNED ARRAY)));They should have killed this when it was little still. |
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.
Refs #2490
Description
Fixes the last open group of #2490, group 6, multi-valued (functional) indexes:
Both failed at the
ARRAYkeyword inside the cast target type, because that keyword was not reachable from the type of aCAST.Approach
ARRAYis accepted as a further word of the cast target type, exactly the wayINT UNSIGNEDis already assembled byDataType(). The type therefore readsUNSIGNED ARRAY, so:ColDataTypemodel is needed, andCastExpression#toString()andExpressionDeParser, render it through the sameColDataType#toString(), so the statement round trips.It is added to the
CastExpression()production only, which is where MySQL permits it. TheARRAY<type>constructor form and the[]array suffix are untouched, and no other statement gains a trailingARRAY.If you would rather have this exposed as an explicit flag on
ColDataTypefor programmatic access, say the word and I will change it.Testing
./gradlew checkpasses: checkstyle, PMD, spotless, spotbugs, JaCoCo.0 errors and 13 warnings, unchanged from master, verified by regenerating the parser on both states.CREATE INDEXform, theALTER TABLEform, and the cast itself, includingCAST(x AS CHAR(10) ARRAY)to cover a type that carries a precision, plus an assertion that the parsed type isUNSIGNED ARRAY.CAST(x AS UNSIGNED)andARRAY<INT>[1, 2]still parse unchanged.All statements were verified against MySQL 8.4.11 while writing #2490.
PR Checklist