From 96ca3c2d3be7ef0aa60e4e357d6503e233dfc463 Mon Sep 17 00:00:00 2001 From: lichi <12095047@qq.com> Date: Fri, 6 Dec 2024 21:59:33 +0800 Subject: [PATCH] fix case --- .../plans/commands/info/AddColumnOp.java | 6 ++-- .../plans/commands/info/AddColumnsOp.java | 20 ------------- .../plans/commands/info/ColumnDefinition.java | 15 ++++++++++ .../plans/commands/info/ModifyColumnOp.java | 29 +------------------ 4 files changed, 19 insertions(+), 51 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AddColumnOp.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AddColumnOp.java index 7442fc524a17b88..2a1e1059bea5b69 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AddColumnOp.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AddColumnOp.java @@ -81,7 +81,7 @@ public void validate(ConnectContext ctx) throws UserException { colPos.analyze(); } validateColumnDef(tableName, columnDef, colPos, rollupName); - column = columnDef.translateToCatalogStyle(); + column = columnDef.translateToCatalogStyleForSchemaChange(); } @Override @@ -211,8 +211,8 @@ public static void validateColumnDef(TableNameInfo tableName, ColumnDefinition c } } } else { - // throw new AnalysisException( - // String.format("Column[%s] does not exist", colPos.getLastCol())); + // do nothing for now, because previous command may add a new column, but it can only be seen + // after previous command finished, we should not report error only by check the currect schema } } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AddColumnsOp.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AddColumnsOp.java index 58e106a884f0db3..20cb2e98a94dd38 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AddColumnsOp.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/AddColumnsOp.java @@ -79,26 +79,6 @@ public void validate(ConnectContext ctx) throws UserException { } seeValueColumn = seeValueColumn || !colDef.isKey(); } - // OlapTable olapTable = (OlapTable) table; - // boolean lastColumnIsKey = olapTable.getFullSchema().get(olapTable.getFullSchema().size() - 1).isKey(); - // if (lastColumnIsKey) { - // boolean seeValueColumn = false; - // for (ColumnDefinition colDef : columnDefs) { - // if (seeValueColumn && colDef.isKey()) { - // throw new AnalysisException(String.format("Cannot add key column %s after value column", - // colDef.getName())); - // } - // seeValueColumn = seeValueColumn || !colDef.isKey(); - // } - // } else { - // for (ColumnDefinition colDef : columnDefs) { - // if (colDef.isKey()) { - // throw new AnalysisException( - // String.format("Cannot add key column %s after %s's last column", colDef.getName(), - // tableName.getTbl())); - // } - // } - // } } columns = Lists.newArrayList(); 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 74052124ecfb9f8..531bee015d9b6c8 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 @@ -719,6 +719,21 @@ private void validateNestedType(Type parent, Type child) throws AnalysisExceptio * translate to catalog create table stmt */ public Column translateToCatalogStyle() { + Column column = new Column(name, type.toCatalogDataType(), isKey, aggType, isNullable, + autoIncInitValue, defaultValue.map(DefaultValue::getValue).orElse(null), comment, isVisible, + defaultValue.map(DefaultValue::getDefaultValueExprDef).orElse(null), Column.COLUMN_UNIQUE_ID_INIT_VALUE, + defaultValue.map(DefaultValue::getValue).orElse(null), onUpdateDefaultValue.isPresent(), + onUpdateDefaultValue.map(DefaultValue::getDefaultValueExprDef).orElse(null), clusterKeyId, + generatedColumnDesc.map(GeneratedColumnDesc::translateToInfo).orElse(null), + generatedColumnsThatReferToThis); + column.setAggregationTypeImplicit(aggTypeImplicit); + return column; + } + + /** + * translate to catalog column for schema change + */ + public Column translateToCatalogStyleForSchemaChange() { Column column = new Column(name, type.toCatalogDataType(), isKey, aggType, isNullable, autoIncInitValue, defaultValue.map(DefaultValue::getValue).orElse(null), comment, isVisible, defaultValue.map(DefaultValue::getDefaultValueExprDef).orElse(null), Column.COLUMN_UNIQUE_ID_INIT_VALUE, diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ModifyColumnOp.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ModifyColumnOp.java index 9a7222c0549ea42..f1afdcf85640a55 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ModifyColumnOp.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ModifyColumnOp.java @@ -98,33 +98,6 @@ public void validate(ConnectContext ctx) throws UserException { isEnableMergeOnWrite = olapTable.getEnableUniqueKeyMergeOnWrite(); if (!Strings.isNullOrEmpty(rollupName)) { throw new AnalysisException("Cannot modify column in rollup " + rollupName); - // Long indexId = olapTable.getIndexIdByName(rollupName); - // if (indexId != null) { - // MaterializedIndexMeta indexMeta = olapTable.getIndexMetaByIndexId(indexId); - // schemaColumns = indexMeta.getSchema(false); - // if (indexMeta.getDefineStmt() == null) { - // originalColumn = indexMeta.getColumnByName(colName); - // if (originalColumn != null) { - // columnDef.setIsKey(originalColumn.isKey()); - // if (originalColumn.isKey()) { - // if (indexMeta.getSchema(false).stream() - // .anyMatch(col -> col.getAggregationType() != null - // && col.getAggregationType().isReplaceFamily())) { - // throw new AnalysisException(String.format( - // "Can not modify key column %s when rollup has value column " - // + "with REPLACE aggregation method", - // colName)); - // } - // } - // } else { - // throw new AnalysisException(String.format("Column[%s] does not exist", colName)); - // } - // } else { - // throw new AnalysisException("Can not modify column in mv " + rollupName); - // } - // } else { - // throw new AnalysisException(String.format("rollup[%s] does not exist", rollupName)); - // } } else { originalColumn = olapTable.getColumn(colName); if (originalColumn != null) { @@ -186,7 +159,7 @@ public void validate(ConnectContext ctx) throws UserException { } } } - column = columnDef.translateToCatalogStyle(); + column = columnDef.translateToCatalogStyleForSchemaChange(); if (originalColumn != null) { originalColumn.checkSchemaChangeAllowed(column); }