Skip to content

Commit

Permalink
[Enhancement] change default_replication_num of MV (#50931)
Browse files Browse the repository at this point in the history
Signed-off-by: Murphy <[email protected]>
(cherry picked from commit eb8fdb9)

# Conflicts:
#	fe/fe-core/src/test/java/com/starrocks/sql/analyzer/MaterializedViewAnalyzerTest.java
  • Loading branch information
murphyatwork authored and mergify[bot] committed Sep 20, 2024
1 parent fe137ea commit d0273a9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import com.starrocks.mv.analyzer.MVPartitionSlotRefResolver;
import com.starrocks.qe.ConnectContext;
import com.starrocks.server.GlobalStateMgr;
import com.starrocks.server.RunMode;
import com.starrocks.sql.ast.AlterMaterializedViewStmt;
import com.starrocks.sql.ast.AstVisitor;
import com.starrocks.sql.ast.CancelRefreshMaterializedViewStmt;
Expand Down Expand Up @@ -1091,17 +1092,17 @@ private void checkDistribution(CreateMaterializedViewStatement statement,

private Short autoInferReplicationNum(Map<TableName, Table> tableNameTableMap) {
// For replication_num, we select the maximum value of all tables replication_num
Short defaultReplicationNum = 1;
Optional<Short> maxReplicationFromTable = Optional.empty();
for (Table table : tableNameTableMap.values()) {
if (table instanceof OlapTable) {
OlapTable olapTable = (OlapTable) table;
Short replicationNum = olapTable.getDefaultReplicationNum();
if (replicationNum > defaultReplicationNum) {
defaultReplicationNum = replicationNum;
if (maxReplicationFromTable.isEmpty() || replicationNum > maxReplicationFromTable.get()) {
maxReplicationFromTable = Optional.of(replicationNum);
}
}
}
return defaultReplicationNum;
return maxReplicationFromTable.orElseGet(RunMode::defaultReplicationNum);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@
import com.starrocks.catalog.ScalarType;
import com.starrocks.catalog.Table;
import com.starrocks.catalog.Type;
import com.starrocks.common.Config;
import com.starrocks.common.DdlException;
import com.starrocks.common.Pair;
import com.starrocks.common.util.PropertyAnalyzer;
import com.starrocks.qe.ShowExecutor;
import com.starrocks.qe.ShowResultSet;
<<<<<<< HEAD
=======
import com.starrocks.server.GlobalStateMgr;
import com.starrocks.sql.ast.CreateMaterializedViewStatement;
>>>>>>> eb8fdb9a41 ([Enhancement] change default_replication_num of MV (#50931))
import com.starrocks.sql.ast.ShowStmt;
import com.starrocks.sql.plan.ConnectorPlanTestBase;
import com.starrocks.utframe.StarRocksAssert;
Expand All @@ -39,6 +46,7 @@
import org.apache.hadoop.util.Lists;
import org.junit.Assert;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -483,4 +491,32 @@ private void checkQueryOutputIndices(List<Integer> inputs, String expect, boolea
Assert.assertEquals(IntStream.range(0, queryOutputIndices.size()).anyMatch(i -> i != queryOutputIndices.get(i)),
isChanged);
}

@Test
public void testReplicationNum() throws Exception {
short defaultReplication = Config.default_replication_num;
final String sql = "create materialized view mv1 refresh manual as " +
"SELECT id, data, date FROM `iceberg0`.`partitioned_db`.`t1` as a;";

{
Config.default_replication_num = 1;
CreateMaterializedViewStatement statementBase =
(CreateMaterializedViewStatement) UtFrameUtils.parseStmtWithNewParser(sql,
starRocksAssert.getCtx());
MaterializedViewAnalyzer.analyze(statementBase, starRocksAssert.getCtx());
Assertions.assertEquals("1",
statementBase.getProperties().get(PropertyAnalyzer.PROPERTIES_REPLICATION_NUM));
}
{
Config.default_replication_num = 3;
CreateMaterializedViewStatement statementBase =
(CreateMaterializedViewStatement) UtFrameUtils.parseStmtWithNewParser(sql,
starRocksAssert.getCtx());
MaterializedViewAnalyzer.analyze(statementBase, starRocksAssert.getCtx());
Assertions.assertEquals("3",
statementBase.getProperties().get(PropertyAnalyzer.PROPERTIES_REPLICATION_NUM));
}

Config.default_replication_num = defaultReplication;
}
}

0 comments on commit d0273a9

Please sign in to comment.