[Bug](materialized-view) fix create mv failed on unique table (#27971)
fix create mv failed on unique table
This commit is contained in:
@ -488,14 +488,10 @@ public class MaterializedViewHandler extends AlterHandler {
|
||||
// check b.1
|
||||
throw new DdlException("The materialized view of unique table must not has grouping columns");
|
||||
}
|
||||
addMVClause.setMVKeysType(olapTable.getKeysType());
|
||||
|
||||
for (MVColumnItem mvColumnItem : mvColumnItemList) {
|
||||
if (olapTable.getKeysType() == KeysType.UNIQUE_KEYS && !mvColumnItem.isKey()) {
|
||||
mvColumnItem.setAggregationType(AggregateType.REPLACE, true);
|
||||
}
|
||||
|
||||
if (olapTable.getKeysType() == KeysType.UNIQUE_KEYS) {
|
||||
mvColumnItem.setIsKey(false);
|
||||
for (String slotName : mvColumnItem.getBaseColumnNames()) {
|
||||
if (!addMVClause.isReplay()
|
||||
&& olapTable
|
||||
@ -505,6 +501,9 @@ public class MaterializedViewHandler extends AlterHandler {
|
||||
mvColumnItem.setIsKey(true);
|
||||
}
|
||||
}
|
||||
if (!mvColumnItem.isKey()) {
|
||||
mvColumnItem.setAggregationType(AggregateType.REPLACE, true);
|
||||
}
|
||||
}
|
||||
|
||||
// check a.2 and b.2
|
||||
|
||||
@ -146,10 +146,6 @@ public class CreateMaterializedViewStmt extends DdlStmt {
|
||||
return dbName;
|
||||
}
|
||||
|
||||
public void setMVKeysType(KeysType type) {
|
||||
mvKeysType = type;
|
||||
}
|
||||
|
||||
public KeysType getMVKeysType() {
|
||||
return mvKeysType;
|
||||
}
|
||||
@ -209,11 +205,11 @@ public class CreateMaterializedViewStmt extends DdlStmt {
|
||||
analyzer = new Analyzer(analyzer.getEnv(), analyzer.getContext());
|
||||
selectStmt.analyze(analyzer);
|
||||
|
||||
analyzeSelectClause(analyzer);
|
||||
analyzeFromClause();
|
||||
if (selectStmt.getAggInfo() != null) {
|
||||
mvKeysType = KeysType.AGG_KEYS;
|
||||
}
|
||||
analyzeSelectClause(analyzer);
|
||||
analyzeFromClause();
|
||||
if (selectStmt.getWhereClause() != null) {
|
||||
if (!isReplay && selectStmt.getWhereClause().hasAggregateSlot()) {
|
||||
throw new AnalysisException(
|
||||
@ -303,6 +299,12 @@ public class CreateMaterializedViewStmt extends DdlStmt {
|
||||
if (!isReplay && tableRefList.get(0).hasExplicitAlias()) {
|
||||
throw new AnalysisException("The materialized view not support table with alias.");
|
||||
}
|
||||
if (!isReplay && !(tableRefList.get(0).getTable() instanceof OlapTable)) {
|
||||
throw new AnalysisException("The materialized view only support olap table.");
|
||||
}
|
||||
OlapTable olapTable = (OlapTable) tableRefList.get(0).getTable();
|
||||
mvKeysType = olapTable.getKeysType();
|
||||
|
||||
TableName tableName = tableRefList.get(0).getName();
|
||||
if (tableName == null) {
|
||||
throw new AnalysisException("table in from clause is invalid, please check if it's single table "
|
||||
@ -412,14 +414,7 @@ public class CreateMaterializedViewStmt extends DdlStmt {
|
||||
* The keys type of Materialized view is aggregation.
|
||||
* All of group by columns are keys of materialized view.
|
||||
*/
|
||||
if (mvKeysType == KeysType.AGG_KEYS) {
|
||||
for (MVColumnItem mvColumnItem : mvColumnItemList) {
|
||||
if (mvColumnItem.getAggregationType() != null) {
|
||||
break;
|
||||
}
|
||||
mvColumnItem.setIsKey(true);
|
||||
}
|
||||
} else if (mvKeysType == KeysType.DUP_KEYS) {
|
||||
if (mvKeysType == KeysType.DUP_KEYS) {
|
||||
/**
|
||||
* There is no aggregation function in materialized view.
|
||||
* Supplement key of MV columns
|
||||
@ -463,6 +458,13 @@ public class CreateMaterializedViewStmt extends DdlStmt {
|
||||
MVColumnItem mvColumnItem = mvColumnItemList.get(theBeginIndexOfValue);
|
||||
mvColumnItem.setAggregationType(AggregateType.NONE, true);
|
||||
}
|
||||
} else {
|
||||
for (MVColumnItem mvColumnItem : mvColumnItemList) {
|
||||
if (mvColumnItem.getAggregationType() != null) {
|
||||
break;
|
||||
}
|
||||
mvColumnItem.setIsKey(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3979,8 +3979,8 @@ public class Env {
|
||||
}
|
||||
}
|
||||
LOG.debug("index column size: {}, cluster column size: {}", indexColumns.size(), clusterColumns.size());
|
||||
if (isKeysRequired) {
|
||||
Preconditions.checkArgument(indexColumns.size() > 0);
|
||||
if (isKeysRequired && indexColumns.isEmpty()) {
|
||||
throw new DdlException("The materialized view need key column");
|
||||
}
|
||||
// sort by cluster keys for mow if set, otherwise by index columns
|
||||
List<Column> sortKeyColumns = clusterColumns.isEmpty() ? indexColumns
|
||||
|
||||
Reference in New Issue
Block a user