Skip to content

Commit

Permalink
fix case
Browse files Browse the repository at this point in the history
  • Loading branch information
starocean999 committed Dec 6, 2024
1 parent 922404c commit a6bf845
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -186,7 +159,7 @@ public void validate(ConnectContext ctx) throws UserException {
}
}
}
column = columnDef.translateToCatalogStyle();
column = columnDef.translateToCatalogStyleForSchemaChange();
if (originalColumn != null) {
originalColumn.checkSchemaChangeAllowed(column);
}
Expand Down

0 comments on commit a6bf845

Please sign in to comment.