Skip to content

Commit

Permalink
[Enhancement] Support mv rewrite with function array_agg_distinct whe…
Browse files Browse the repository at this point in the history
…n aggregate rollup (StarRocks#39344)

Signed-off-by: Youngwb <[email protected]>
  • Loading branch information
Youngwb authored Jan 18, 2024
1 parent 0e18d6f commit f3b2bb4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class AggregatedMaterializedViewRewriter extends MaterializedViewRewriter
private static final Map<String, String> REWRITE_ROLLUP_FUNCTION_MAP = ImmutableMap.<String, String>builder()
.put(FunctionSet.COUNT, FunctionSet.SUM)
.put(FunctionSet.BITMAP_AGG, FunctionSet.BITMAP_UNION)
.put(FunctionSet.ARRAY_AGG_DISTINCT, FunctionSet.ARRAY_UNIQUE_AGG)
.build();

private static final Set<String> SUPPORTED_ROLLUP_FUNCTIONS = ImmutableSet.<String>builder()
Expand All @@ -88,6 +89,7 @@ public class AggregatedMaterializedViewRewriter extends MaterializedViewRewriter
.add(FunctionSet.BITMAP_AGG)
.add(FunctionSet.HLL_UNION)
.add(FunctionSet.PERCENTILE_UNION)
.add(FunctionSet.ARRAY_AGG_DISTINCT)
.build();

public AggregatedMaterializedViewRewriter(MvRewriteContext mvRewriteContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2718,6 +2718,17 @@ public void testCountWithRollup() {
.contains("coalesce");
}

@Test
public void testArrayAggDistinctWithRollup() {
String mv = "select user_id, array_agg_distinct(tag_id) from user_tags group by user_id, time;";
testRewriteOK(mv, "select user_id, array_agg_distinct(tag_id) from user_tags group by user_id, time;")
.notContain("array_unique_agg");
testRewriteOK(mv, "select user_id, array_agg_distinct(tag_id) from user_tags group by user_id")
.contains("array_unique_agg");
testRewriteOK(mv, "select array_agg_distinct(tag_id) from user_tags")
.contains("array_unique_agg");
}

@Test
public void testCountDistinctToBitmapCount1() {
String mv = "select user_id, bitmap_union(to_bitmap(tag_id)) from user_tags group by user_id;";
Expand Down

0 comments on commit f3b2bb4

Please sign in to comment.