Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
Signed-off-by: shuming.li <[email protected]>
  • Loading branch information
LiShuMing committed Oct 9, 2024
1 parent 5205fd6 commit 9318ddd
Show file tree
Hide file tree
Showing 6 changed files with 459 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,6 @@ private MVColumnItem buildAggColumnItem(ConnectContext context,
String mvColumnName = MVUtils.getMVColumnName(selectListItem.getAlias());
AggStateDesc aggStateDesc = aggFunction.getAggStateDesc();
Type type = aggFunction.getIntermediateTypeOrReturnType();
Type finalType = AnalyzerUtils.transformTableColumnType(type, false);
if (type.isWildcardDecimal()) {
throw new UnsupportedMVException("Unsupported wildcard decimal type in materialized view:" + type + ", " +
"function:" + node);
Expand All @@ -584,7 +583,7 @@ private MVColumnItem buildAggColumnItem(ConnectContext context,
Set<String> baseColumnNames = baseSlotRefs.stream().map(slot -> slot.getColumnName())
.collect(Collectors.toSet());
AggregateType mvAggregateType = AggregateType.AGG_STATE_UNION;

Type finalType = AnalyzerUtils.transformTableColumnType(type, false);
return new MVColumnItem(mvColumnName, finalType, mvAggregateType, aggStateDesc, false,
defineExpr, aggStateDesc.getResultNullable(), baseColumnNames);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1046,8 +1046,6 @@ public void testGenerateCreateSyncMVWithArrayUniqueAgg() throws Exception {
starRocksAssert.dropTable("t1");
}



@Test
public void testGenerateCreateSyncMVWithAggState() throws Exception {
List<String> funcNames = Lists.newArrayList();
Expand Down Expand Up @@ -1076,7 +1074,6 @@ public void testGenerateCreateSyncMVWithAggState() throws Exception {
}

// TODO(lism): Fixme
connectContext.getSessionVariable().setCboCteReuse(false);
// create sync mv with all agg functions
String sql1 = "CREATE MATERIALIZED VIEW test_mv1 as select k1, " +
Joiner.on(", ").join(stateColumns) + " from t1 group by k1;";
Expand All @@ -1099,5 +1096,54 @@ public void testGenerateCreateSyncMVWithAggState() throws Exception {
}
starRocksAssert.dropTable("t1");
}

@Test
public void testGenerateCreateAsyncMVWithAggState() throws Exception {
List<String> funcNames = Lists.newArrayList();
Map<String, String> colTypes = Maps.newLinkedHashMap();
List<List<String>> aggArgTypes = Lists.newArrayList();
List<String> columns = Lists.newArrayList();
List<String> colNames = Lists.newArrayList();
buildTableT1(funcNames, colTypes, aggArgTypes, columns, colNames);
List<String> stateColumns = Lists.newArrayList();

List<String> queryColumns = Lists.newArrayList();
for (int i = 0; i < funcNames.size(); i++) {
String fnName = funcNames.get(i);
if (fnName.equalsIgnoreCase(FunctionSet.ARRAY_AGG_DISTINCT)) {
continue;
}
List<String> argTypes = aggArgTypes.get(i);
String arg = buildAggFuncArgs(fnName, argTypes, colTypes);
String col = String.format("%s(%s(%s)) as agg%s",
FunctionSet.getAggStateUnionName(fnName), FunctionSet.getAggStateName(fnName), arg, i);
stateColumns.add(col);
String qCol = String.format("%s(%s) as agg%s",
fnName, arg, i);
queryColumns.add(qCol);
}

// create async mv with all agg functions
String sql1 = "CREATE MATERIALIZED VIEW test_mv1 REFRESH MANUAL as select k1, " +
Joiner.on(", ").join(stateColumns) + " from t1 group by k1;";
System.out.println(sql1);
starRocksAssert.withRefreshedMaterializedView(sql1);

// no rollup
{
String query = String.format("select k1, %s from t1 group by k1;", Joiner.on(", ").join(queryColumns));
System.out.println(query);
String plan = getFragmentPlan(query);
PlanTestBase.assertContains(plan, "test_mv1");
}
// rollup
{
String query = String.format("select %s from t1;", Joiner.on(", ").join(queryColumns));
System.out.println(query);
String plan = getFragmentPlan(query);
PlanTestBase.assertContains(plan, "test_mv1");
}
starRocksAssert.dropTable("t1");
}
}

164 changes: 164 additions & 0 deletions test/sql/test_agg_state/R/test_agg_state_with_async_mv.sql

Large diffs are not rendered by default.

84 changes: 84 additions & 0 deletions test/sql/test_agg_state/R/test_agg_state_with_sync_mv.sql

Large diffs are not rendered by default.

94 changes: 86 additions & 8 deletions test/sql/test_agg_state/T/test_agg_state_with_async_mv.sql

Large diffs are not rendered by default.

75 changes: 75 additions & 0 deletions test/sql/test_agg_state/T/test_agg_state_with_sync_mv.sql

Large diffs are not rendered by default.

0 comments on commit 9318ddd

Please sign in to comment.