starrocks
starrocks copied to clipboard
[Feature] support map[key] operator
support map[key]
What type of PR is this:
- [ ] BugFix
- [x] Feature
- [ ] Enhancement
- [ ] Refactor
- [ ] UT
- [ ] Doc
- [ ] Tool
Which issues of this PR fixes :
Fixes #10677
Problem Summary(Required) :
map [] operator is used to access the value of the specified key, used just like map[key], the "map" is the column whose type is MapType and the "key" is the same type as MapType->keyType. The design of map []operator is very similar to arraysubscriptExpr, so I rename arraysubscript to collectionsubscript which can be used by both array and map. There are serveral main differences:
- In the analyse phase, the arraysubscript will check the subscriptor if it's an int or can cast to int, the mapsubscript will check the subscriptor if it's an keyType or can cast to keyType. In the phase the return type is set as the MapType->valueType.
- To transfer to be, the CollectionSubscriptExpr will check the child's type and than use ARRAY_ELEMENT_EXPR for array or MAP_SUBSCRIPT_EXPR for map.
- In be, the ARRAY_ELEMENT_EXPR and MAP_SUBSCRIPT_EXPR are dealed separately.
- In be, when the MAP_SUBSCRIPT_EXPR evaluates, check the keys one by one and get the key_match, use the key_match's index generate the final result.
Checklist:
- [x] I have added test cases for my bug fix or my new feature
- [ ] I have added user document for my new feature or new function
run starrocks_be_unittest
run starrocks_fe_unittest
starrocks_be_unittest succeeded.
starrocks_be_unittest succeeded.
run starrocks_fe_unittest
run starrocks_admit_test
run starrocks_admit_test
run starrocks_admit_test
run starrocks_admit_test
[FE PR Coverage Check]
:heart_eyes: pass : 32 / 37 (86.49%)
file detail
| path | covered_line | new_line | coverage | not_covered_line_detail | |
|---|---|---|---|---|---|
| :large_blue_circle: | com/starrocks/sql/Explain.java | 0 | 1 | 00.00% | [684] |
| :large_blue_circle: | com/starrocks/sql/optimizer/rewrite/BaseScalarOperatorShuttle.java | 2 | 3 | 66.67% | [64] |
| :large_blue_circle: | com/starrocks/analysis/CollectionElementExpr.java | 6 | 7 | 85.71% | [68] |
| :large_blue_circle: | com/starrocks/sql/analyzer/ExpressionAnalyzer.java | 14 | 16 | 87.50% | [269, 270] |
| :large_blue_circle: | com/starrocks/sql/parser/AstBuilder.java | 1 | 1 | 100.00% | [] |
| :large_blue_circle: | com/starrocks/sql/optimizer/operator/scalar/ScalarOperatorVisitor.java | 1 | 1 | 100.00% | [] |
| :large_blue_circle: | com/starrocks/sql/optimizer/operator/scalar/CollectionElementOperator.java | 4 | 4 | 100.00% | [] |
| :large_blue_circle: | com/starrocks/sql/plan/ScalarOperatorToExpr.java | 1 | 1 | 100.00% | [] |
| :large_blue_circle: | com/starrocks/sql/optimizer/operator/OperatorType.java | 1 | 1 | 100.00% | [] |
| :large_blue_circle: | com/starrocks/sql/optimizer/transformer/SqlToScalarOperatorTranslator.java | 2 | 2 | 100.00% | [] |
run starrocks_be_unittest
run starrocks_admit_test
starrocks_be_unittest succeeded.
run starrocks_admit_test
run starrocks_admit_test
run starrocks_admit_test
run starrocks_admit_test







