starrocks icon indicating copy to clipboard operation
starrocks copied to clipboard

[Feature] support map[key] operator

Open zombee0 opened this issue 3 years ago • 4 comments
trafficstars

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:

  1. 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.
  2. 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.
  3. In be, the ARRAY_ELEMENT_EXPR and MAP_SUBSCRIPT_EXPR are dealed separately.
  4. 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

zombee0 avatar Sep 16 '22 03:09 zombee0

run starrocks_be_unittest

zombee0 avatar Sep 16 '22 10:09 zombee0

run starrocks_fe_unittest

zombee0 avatar Sep 16 '22 10:09 zombee0

starrocks_be_unittest succeeded.

wanpengfei-git avatar Oct 25 '22 14:10 wanpengfei-git

starrocks_be_unittest succeeded.

wanpengfei-git avatar Oct 26 '22 13:10 wanpengfei-git

run starrocks_fe_unittest

Youngwb avatar Oct 27 '22 02:10 Youngwb

run starrocks_admit_test

Youngwb avatar Oct 27 '22 02:10 Youngwb

run starrocks_admit_test

wanpengfei-git avatar Oct 27 '22 03:10 wanpengfei-git

run starrocks_admit_test

zombee0 avatar Oct 27 '22 05:10 zombee0

run starrocks_admit_test

wanpengfei-git avatar Oct 27 '22 07:10 wanpengfei-git

[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% []

wanpengfei-git avatar Oct 27 '22 07:10 wanpengfei-git

run starrocks_be_unittest

zombee0 avatar Oct 27 '22 09:10 zombee0

run starrocks_admit_test

zombee0 avatar Oct 27 '22 09:10 zombee0

starrocks_be_unittest succeeded.

wanpengfei-git avatar Oct 27 '22 11:10 wanpengfei-git

run starrocks_admit_test

zombee0 avatar Oct 27 '22 12:10 zombee0

run starrocks_admit_test

zombee0 avatar Oct 28 '22 00:10 zombee0

run starrocks_admit_test

satanson avatar Oct 28 '22 01:10 satanson

run starrocks_admit_test

zombee0 avatar Oct 28 '22 02:10 zombee0