[fix](mtmv)mtmv support default key (#36221) (#36601)

pick : https://github.com/apache/doris/pull/36221
This commit is contained in:
zhangdong
2024-07-02 23:08:38 +08:00
committed by GitHub
parent fbca3196c5
commit 5bb6642b86
3 changed files with 43 additions and 6 deletions

View File

@ -30,8 +30,10 @@ import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.KeysType;
import org.apache.doris.catalog.PartitionType;
import org.apache.doris.catalog.TableIf;
import org.apache.doris.catalog.Type;
import org.apache.doris.catalog.View;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.FeConstants;
import org.apache.doris.common.FeNameFormat;
import org.apache.doris.common.util.DynamicPartitionUtil;
import org.apache.doris.common.util.PropertyAnalyzer;
@ -63,6 +65,7 @@ import org.apache.doris.nereids.trees.plans.logical.LogicalSink;
import org.apache.doris.nereids.trees.plans.logical.LogicalSubQueryAlias;
import org.apache.doris.nereids.trees.plans.visitor.NondeterministicFunctionCollector;
import org.apache.doris.nereids.types.AggStateType;
import org.apache.doris.nereids.types.DataType;
import org.apache.doris.nereids.util.Utils;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.SessionVariable;
@ -218,11 +221,50 @@ public class CreateMTMVInfo {
}
getRelation(planner);
getColumns(plan);
analyzeKeys();
this.mvPartitionInfo = mvPartitionDefinition
.analyzeAndTransferToMTMVPartitionInfo(planner, ctx, logicalQuery);
this.partitionDesc = generatePartitionDesc(ctx);
}
private void analyzeKeys() {
boolean enableDuplicateWithoutKeysByDefault = false;
try {
if (properties != null) {
enableDuplicateWithoutKeysByDefault =
PropertyAnalyzer.analyzeEnableDuplicateWithoutKeysByDefault(properties);
}
} catch (Exception e) {
throw new AnalysisException(e.getMessage(), e.getCause());
}
if (keys.isEmpty() && !enableDuplicateWithoutKeysByDefault) {
keys = Lists.newArrayList();
int keyLength = 0;
for (ColumnDefinition column : columns) {
DataType type = column.getType();
Type catalogType = column.getType().toCatalogDataType();
keyLength += catalogType.getIndexSize();
if (keys.size() >= FeConstants.shortkey_max_column_count
|| keyLength > FeConstants.shortkey_maxsize_bytes) {
if (keys.isEmpty() && type.isStringLikeType()) {
keys.add(column.getName());
}
break;
}
if (type.isFloatLikeType() || type.isStringType() || type.isJsonType()
|| catalogType.isComplexType() || type.isBitmapType() || type.isHllType()
|| type.isQuantileStateType() || type.isJsonType() || type.isStructType()
|| column.getAggType() != null) {
break;
}
keys.add(column.getName());
if (type.isVarcharType()) {
break;
}
}
}
}
private void getRelation(NereidsPlanner planner) {
// Should not make table without data to empty relation when analyze the related table,
// so add disable rules