From 09cf7f20ce264a8c78306637b0123e19e9a8ac8e Mon Sep 17 00:00:00 2001 From: lichi <12095047@qq.com> Date: Mon, 18 Nov 2024 19:31:34 +0800 Subject: [PATCH] fix failed case --- .../plans/commands/info/ColumnDefinition.java | 45 +++++++++++++------ .../plans/commands/info/DefaultValue.java | 27 +++++++++++ .../info/ModifyTablePropertiesOp.java | 2 + 3 files changed, 60 insertions(+), 14 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ColumnDefinition.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ColumnDefinition.java index 82345e1cdaeea7..ffe16fdfb60ec5 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ColumnDefinition.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ColumnDefinition.java @@ -41,6 +41,7 @@ import org.apache.doris.nereids.types.coercion.CharacterType; import org.apache.doris.qe.SessionVariable; +import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import java.util.ArrayList; @@ -251,21 +252,20 @@ private void checkKeyColumnType(boolean isOlap) { } else if (type.isArrayType()) { throw new AnalysisException("Array can only be used in the non-key column of" + " the duplicate table at present."); + } else if (type.isBitmapType() || type.isHllType() || type.isQuantileStateType()) { + throw new AnalysisException("Key column can not set complex type:" + name); + } else if (type.isJsonType()) { + throw new AnalysisException("JsonType type should not be used in key column[" + getName() + "]."); + } else if (type.isVariantType()) { + throw new AnalysisException("Variant type should not be used in key column[" + getName() + "]."); + } else if (type.isMapType()) { + throw new AnalysisException("Map can only be used in the non-key column of" + + " the duplicate table at present."); + } else if (type.isStructType()) { + throw new AnalysisException("Struct can only be used in the non-key column of" + + " the duplicate table at present."); } } - if (type.isBitmapType() || type.isHllType() || type.isQuantileStateType()) { - throw new AnalysisException("Key column can not set complex type:" + name); - } else if (type.isJsonType()) { - throw new AnalysisException("JsonType type should not be used in key column[" + getName() + "]."); - } else if (type.isVariantType()) { - throw new AnalysisException("Variant type should not be used in key column[" + getName() + "]."); - } else if (type.isMapType()) { - throw new AnalysisException("Map can only be used in the non-key column of" - + " the duplicate table at present."); - } else if (type.isStructType()) { - throw new AnalysisException("Struct can only be used in the non-key column of" - + " the duplicate table at present."); - } } /** @@ -300,7 +300,13 @@ public void validate(boolean isOlap, Set keysSet, Set clusterKey throw new AnalysisException("complex type have to use aggregate function: " + name); } } - isNullable = false; + if (isNullable) { + throw new AnalysisException("complex type column must be not nullable, column:" + name); + } + } + + if (keysSet.contains(name)) { + isKey = true; } // check keys type @@ -324,6 +330,17 @@ public void validate(boolean isOlap, Set keysSet, Set clusterKey throw new AnalysisException("agg state not enable, need set enable_agg_state=true"); } } + } else if (isOlap && !isKey) { + Preconditions.checkState(keysType != null, "keysType is null"); + if (keysType.equals(KeysType.DUP_KEYS)) { + aggType = AggregateType.NONE; + } else if (keysType.equals(KeysType.UNIQUE_KEYS) && isEnableMergeOnWrite) { + aggType = AggregateType.NONE; + } else if (!keysType.equals(KeysType.AGG_KEYS)) { + aggType = AggregateType.REPLACE; + } else { + throw new AnalysisException("should set aggregation type to non-key column when in aggregate key"); + } } if (isOlap) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/DefaultValue.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/DefaultValue.java index 7f5a55c94b842c..64d284a43f3241 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/DefaultValue.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/DefaultValue.java @@ -19,6 +19,10 @@ import org.apache.doris.analysis.DefaultValueExprDef; import org.apache.doris.catalog.ScalarType; +import org.apache.doris.common.util.TimeUtils; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; /** * default value of a column. @@ -112,6 +116,29 @@ public String getRawValue() { * get string value of a default value expression. */ public String getValue() { + if (isCurrentTimeStamp()) { + return LocalDateTime.now(TimeUtils.getTimeZone().toZoneId()).toString().replace('T', ' '); + } else if (isCurrentTimeStampWithPrecision()) { + long precision = getCurrentTimeStampPrecision(); + String format = "yyyy-MM-dd HH:mm:ss"; + if (precision == 0) { + return LocalDateTime.now(TimeUtils.getTimeZone().toZoneId()).toString().replace('T', ' '); + } else if (precision == 1) { + format = "yyyy-MM-dd HH:mm:ss.S"; + } else if (precision == 2) { + format = "yyyy-MM-dd HH:mm:ss.SS"; + } else if (precision == 3) { + format = "yyyy-MM-dd HH:mm:ss.SSS"; + } else if (precision == 4) { + format = "yyyy-MM-dd HH:mm:ss.SSSS"; + } else if (precision == 5) { + format = "yyyy-MM-dd HH:mm:ss.SSSSS"; + } else if (precision == 6) { + format = "yyyy-MM-dd HH:mm:ss.SSSSSS"; + } + return LocalDateTime.now(TimeUtils.getTimeZone().toZoneId()) + .format(DateTimeFormatter.ofPattern(format)); + } return value; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ModifyTablePropertiesOp.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ModifyTablePropertiesOp.java index f6fa54e99b981a..85042fc9fdcbb8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ModifyTablePropertiesOp.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ModifyTablePropertiesOp.java @@ -369,6 +369,8 @@ public void validate(ConnectContext ctx) throws UserException { this.opType = AlterOpType.MODIFY_TABLE_PROPERTY_SYNC; } else if (properties.containsKey(PropertyAnalyzer.ENABLE_UNIQUE_KEY_SKIP_BITMAP_COLUMN)) { // do nothing, will be analyzed when creating alter job + } else if (properties.containsKey(PropertyAnalyzer.PROPERTIES_STORAGE_PAGE_SIZE)) { + throw new AnalysisException("You can not modify storage_page_size"); } else { throw new AnalysisException("Unknown table property: " + properties.keySet()); }