Repository navigation
Support SIGNED INTEGER and reject unrecognized CAST targets - #573
Conversation
perNyfelt
left a comment
There was a problem hiding this comment.
Reviewed the diff against main and verified every claim in the PR description with runtime probes on both main and the PR head, plus a full mvn -o verify. (Comment review: GitHub does not allow approving my own PR.)
Verified behavior (probed on main vs head):
CAST('123' AS SIGNED INTEGER)/SIGNED_INTEGER: main returned String/OTHER; head returns Integer/INTEGERp=10, column operands convert, 22003 overflow identical toSIGNED.CAST('123' AS UNSIGNED)/UNSIGNED INTEGER/FOOBAR/JSON/INTERVAL DAY: main was a silent no-op (e.g.CAST(cyl AS FOOBAR)returned 6/Integer,CONVERT(UNSIGNED INTEGER, model)returned the row value); head rejects with 42000 "Invalid data type for CAST".- Temporal pass-throughs are sound:
CAST(... AS DATETIME),TIME [WITHOUT] TIME ZONE,TIMESTAMP [WITHOUT] TIME ZONEstill convert correctly (conversion is applied by the declared-type coercion path aftercastLiteral; e.g.CAST('2023-01-01T10:00:00Z' AS DATETIME)→ Timestamp in local zone; theTIMESTAMP WITH TIME ZONEregression guard holds). CONVERTdisambiguation:CONVERT(SIGNED INTEGER, '123')→ Integer 123,CONVERT(model, UNSIGNED)andCONVERT(UNSIGNED, '123')→ 42000; underscored names keep their column role (only the exact unsigned spellings are type-positioned), consistent with the pre-existing type-beats-column precedence for e.g.int.- The
navigationDefault(LAG/LEAD default) andLiteralConverterfolding call sites cannot reach the new throw with unhandled names: navigation defaults are rejected at prepare time ("LAG default type X is not assignable to Y") beforecastLiteral, and verifiedLAG(ARRAY[model], 1, 5)/LAG(model, 1, 5)/LAG(NULL, 1, 'a')behave as before.
Existing feedback check: the PR has no prior review threads, reviews, or comments (GraphQL reviewThreads/reviews/comments all empty), so nothing outstanding to re-check.
Build: full mvn -o verify green on this head — 4051 tests, 0 failures/errors, 0 Checkstyle/PMD/Spotless violations, JaCoCo coverage check passed.
Out-of-scope findings (tracked, no new issue created):
- Value-first CONVERT with space-joined or parameterized targets is still a parse error (e.g.
CONVERT(model, SIGNED INTEGER),CONVERT(model, VARCHAR(10)),CONVERT('123', SIGNED)). Verified identical on main, so pre-existing and out of scope here; it is the same JSqlParser source-first CONVERT grammar gap already tracked in #465.
Observations (non-blocking, no action requested):
2. Minor DRY note: NumericCastTarget.normalize duplicates DateTimeFunctions.normalizeTypeName (equivalent: lowercase, trim, strip parameters/spaces/underscores). Keeping the enum self-contained is defensible, but a shared helper could collapse the two.
|
Addressed observation #2 in 41b54a0: removed the private |
perNyfelt
left a comment
There was a problem hiding this comment.
Re-review of the updated head (new commit 41b54a0). Comment review: GitHub does not allow approving my own PR.
Status of existing feedback:
- My earlier review observation #2 (DRY:
NumericCastTarget.normalizeduplicatedDateTimeFunctions.normalizeTypeName) — fixed in 41b54a0: the privatenormalizeis removed andfromNamenow delegates to the canonicalDateTimeFunctions.normalizeTypeName. I verified the delegation is functionally identical (both lowercase, trim, strip parameters, spaces, and underscores; the paren-strip/trim ordering difference is unobservable) and re-probed the head:CAST('123' AS SIGNED INTEGER)→ Integer 123,CAST(cyl AS SIGNED_INTEGER)→ 6/Integer,CAST('123' AS UNSIGNED)andCONVERT(model, UNSIGNED)→ 42000,CONVERT(SIGNED INTEGER, '123')→ Integer 123,CAST(... AS TIMESTAMP WITH TIME ZONE)→ OffsetDateTime — all unchanged from the previously reviewed head.isUnsupportedAliascorrectly keeps its inline normalization since it deliberately retains underscores. - My earlier review observation #1 (value-first CONVERT parse gap, e.g.
CONVERT(model, SIGNED INTEGER)) — still open, not applicable to this PR: pre-existing JSqlParser grammar limitation, unchanged on this head, tracked in #465. - Your PR comment (16:32) claiming observation #2 addressed and full verify green — confirmed: the commit matches the description and I re-ran the full build.
- No review threads exist (GraphQL
reviewThreadsempty), and there are no Copilot or bot (nordnet-claude-app) reviews or comments on this PR, so nothing else outstanding.
Build: full mvn -o verify green on the new head — 4048 tests + 20 integration tests, 0 failures/errors, 0 Checkstyle violations, PMD and Spotless passed.
The follow-up commit is minimal and surgical (one file, +2/−7); the engine → engine.function class reference already exists in both directions (e.g. ScalarExpressionSchemas → DateTimeFunctions, DateTimeFunctions → NumericCastTarget) with no static-initialization cycle, so the refactor introduces no new coupling concerns.
No remaining issues found in the PR.
Problem
CAST(... AS SIGNED INTEGER)andCAST(... AS UNSIGNED)were silent no-ops: the value came back unchanged withOTHERmetadata. Space normalization turns the targets intosignedinteger/unsigned, which match noNumericCastTargetalias and fall throughDateTimeFunctions.castLiteral'sdefault -> value. Any unrecognized target (e.g.FOOBAR,JSON,INTERVAL DAY) is a no-op the same way.Reproduction (verified on main)
SELECT CAST('123' AS SIGNED INTEGER)123/java.lang.String,OTHER123/java.lang.Integer,INTEGERp=10SELECT CAST(cyl AS SIGNED INTEGER) FROM mtcarsOTHER6/java.lang.Integer,INTEGERSELECT CAST('3000000000' AS SIGNED INTEGER)"3000000000"/ String,OTHERSIGNED)SELECT CAST('3000000000' AS SIGNED)SELECT CAST('123' AS UNSIGNED)"123"/ String,OTHERSELECT CAST(cyl AS UNSIGNED INTEGER) FROM mtcarsOTHERSELECT CAST('x' AS FOOBAR)"x"/ String,OTHERSELECT CONVERT(SIGNED INTEGER, '123')"123"/ String,OTHER123/java.lang.Integer,INTEGERSELECT CONVERT(UNSIGNED, '123')"123"/ String,OTHERSELECT CAST(t AS TIMESTAMP WITH TIME ZONE) …(regression guard)OffsetDateTimeSIGNEDsemantics are intentionally kept at the established 32-bitINTEGER(tested since #238) rather than MySQL's 64-bitBIGINT;SIGNED INTEGERis a synonym ofSIGNED.UNSIGNED [INTEGER]names no JParq target (there is no unsigned integer type), so it is rejected with 42000 instead of being accepted as a no-op.Root cause
NumericCastTargetlists no alias for the space-joinedSIGNED INTEGERspelling, andcastLiteral's switchdefaultreturned the input for every name it does not convert, so both the value and the metadata (which resolves through the same name lists) silently reported the operand.SqlParser.isConvertTypeNamelikewise did not recognize the multi-word or unsigned spellings for CONVERT argument disambiguation.Fix (metadata and value side share the name lists)
NumericCastTarget:INTEGERgains thesignedintegeralias, soSIGNED INTEGER/SIGNED_INTEGERconvert likeSIGNEDin CAST and CONVERT, numeric metadata, and set operations. A newisUnsupportedAliasnames the unsigned spellings (underscores retained so column names likebig_intkeep their value role).DateTimeFunctions.castLiteral: thedefaultbranch now throws SQLState 42000 (Invalid data type for CAST: <type>) for unrecognized targets, except the temporal aliases (DATETIME,TIME [WITHOUT] TIME ZONE,TIMESTAMP [WITHOUT] TIME ZONE) whose conversion the temporal promotion path applies; their pass-through is preserved and regression-tested.SqlParser.isConvertTypeName: recognizes space-joined numeric spellings (spaces stripped, underscores not) and the unsigned spellings, so type-firstCONVERTresolves them to a CAST that fails with 42000 instead of silently returning the operand.Tests
jparq.SignedUnsignedCastTest(13 tests):SIGNED/SIGNED INTEGER/SIGNED_INTEGERdeclareINTEGER/Integerand convert literals and columns; truncation and 22003 overflow for oversized values, identical toSIGNED;UNSIGNED/UNSIGNED INTEGERrejected with 42000 for literal and column operands;FOOBAR/JSON/INTERVAL DAYrejected with 42000; a NULL operand keeps the signed declaration; unsigned inside a scalar subquery is rejected; cast-style CONVERT shares the signed declaration and the unsigned rejection for both argument orders; set operations see the declaredINTEGERbranch (empty signed branch + character peer rejected, numeric peer merges).Verified: full
mvn -o verifygreen (4048 tests, 0 failures), 0 Checkstyle/PMD/Spotless violations.Fixes #322.