[BugFix] Fix type mismatch in map literal when explicit key/value types are declared#71316
[BugFix] Fix type mismatch in map literal when explicit key/value types are declared#71316stephen-shelby merged 11 commits intoStarRocks:mainfrom
Conversation
…clared Signed-off-by: trueeyu <[email protected]>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2ef6bb13e3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
fe/fe-core/src/test/java/com/starrocks/sql/analyzer/ExpressionAnalyzerTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
This PR fixes a FE analysis bug where map literals with an explicit MAP<k,v> type annotation did not cast their key/value child expressions to the declared types, which could lead to a BE heap-buffer-overflow due to mismatched serialized types.
Changes:
- Update
ExpressionAnalyzer.visitMapExprto cast map literal children to the inferred/common types (implicit) or declared key/value types (explicit). - Add a regression unit test covering
map<smallint, smallint>{1: 2, 3: 4}analysis behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
fe/fe-core/src/main/java/com/starrocks/sql/analyzer/ExpressionAnalyzer.java |
Cast map-literal children to key/value target types (handles explicit MapType as well as AnyMapType.ANY_MAP). |
fe/fe-core/src/test/java/com/starrocks/sql/analyzer/ExpressionAnalyzerTest.java |
Adds regression test to ensure map literal children are analyzed with the expected target types. |
fe/fe-core/src/test/java/com/starrocks/sql/analyzer/ExpressionAnalyzerTest.java
Outdated
Show resolved
Hide resolved
fe/fe-core/src/main/java/com/starrocks/sql/analyzer/ExpressionAnalyzer.java
Outdated
Show resolved
Hide resolved
Signed-off-by: trueeyu <[email protected]>
Signed-off-by: trueeyu <[email protected]>
Signed-off-by: trueeyu <[email protected]>
Signed-off-by: trueeyu <[email protected]>
Signed-off-by: trueeyu <[email protected]>
Signed-off-by: trueeyu <[email protected]>
Signed-off-by: trueeyu <[email protected]>
Signed-off-by: trueeyu <[email protected]>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 943ca1b270
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
fe/fe-core/src/main/java/com/starrocks/sql/analyzer/ExpressionAnalyzer.java
Outdated
Show resolved
Hide resolved
Signed-off-by: trueeyu <[email protected]>
Signed-off-by: trueeyu <[email protected]>
[Java-Extensions Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
[FE Incremental Coverage Report]✅ pass : 18 / 18 (100.00%) file detail
|
[BE Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
|
@Mergifyio backport branch-4.1 |
✅ Backports have been createdDetails
Cherry-pick of fdc3329 has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally |
…es are declared (#71316) Signed-off-by: trueeyu <[email protected]> (cherry picked from commit fdc3329) # Conflicts: # fe/fe-core/src/test/java/com/starrocks/sql/analyzer/ExpressionAnalyzerTest.java # test/sql/test_map/R/test_map
…es are declared (backport #71316) (#71345) Signed-off-by: trueeyu <[email protected]> Co-authored-by: trueeyu <[email protected]>
…es are declared (backport #71316) (#71345) Signed-off-by: trueeyu <[email protected]> Co-authored-by: trueeyu <[email protected]> (cherry picked from commit 329bb2f)
…es are declared (backport #71316) (backport #71345) (#71373) Signed-off-by: trueeyu <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: trueeyu <[email protected]>
Why I'm doing:
Fix https://github.com/StarRocks/StarRocksTest/issues/11202
When a map literal is written with an explicit type annotation (e.g., map<smallint, smallint>{1: 2, 3: 4}), the FE analyzer failed to cast the child expressions (key/value literals) to the declared key and value types.
Integer literals like 1, 2, 3, 4 are inferred as TINYINT by default. Because visitMapExpr only handled the implicit-type case (AnyMapType.ANY_MAP) and had no logic for the explicit-type case, the children retained their inferred TINYINT types. These mistyped expressions were then serialized and sent to the BE.
On the BE side, MapExpr::evaluate_checked cloned the key column as a FixedLengthColumn<int8_t> (1 byte), but later attempted to append it into a FixedLengthColumnBase<int16_t> (2 bytes), causing a heap-buffer-overflow detected by
AddressSanitizer.
A typical reproducer:
Root Cause
In ExpressionAnalyzer.visitMapExpr, when the map has an explicit MapType (not AnyMapType.ANY_MAP), no casting was applied to the child expressions. The declared key/value types were simply ignored, and children kept their own inferred types.
The same issue did not exist for ArrayExpr — visitArrayExpr already correctly casts children to the declared item type when an explicit array type is present.
Fix
When the map literal has an explicit type, extract the declared keyType and valueType from the MapType and cast each key/value child expression to the corresponding type if it doesn't already match — exactly mirroring the existing pattern in visitArrayExpr.
What I'm doing:
Fix type mismatch in map literal when explicit key/value types are declared
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check: