Skip to content

Commit

Permalink
[fix](nereids)need validate auto partition columns in DDL (apache#29985)
Browse files Browse the repository at this point in the history
  • Loading branch information
starocean999 authored Jan 16, 2024
1 parent 29b8c84 commit 6d8567c
Showing 1 changed file with 7 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ public CreateTableInfo(boolean ifNotExists, boolean isExternal, String ctlName,
this.autoPartitionExprs = autoPartitionExprs;
this.partitionType = partitionType;
this.partitionColumns = partitionColumns;
appendColumnFromExprs();
this.partitions = partitions;
this.distribution = distribution;
this.rollups = Utils.copyRequiredList(rollups);
Expand Down Expand Up @@ -175,7 +174,6 @@ public CreateTableInfo(boolean ifNotExists, boolean isExternal, String ctlName,
this.autoPartitionExprs = autoPartitionExprs;
this.partitionType = partitionType;
this.partitionColumns = partitionColumns;
appendColumnFromExprs();
this.partitions = partitions;
this.distribution = distribution;
this.rollups = Utils.copyRequiredList(rollups);
Expand Down Expand Up @@ -459,6 +457,12 @@ public void validate(ConnectContext ctx) {
}
});

if (isAutoPartition) {
partitionColumns = ExpressionUtils
.collectAll(autoPartitionExprs, UnboundSlot.class::isInstance).stream()
.map(slot -> ((UnboundSlot) slot).getName()).collect(Collectors.toList());
}

if (partitionColumns != null) {
partitionColumns.forEach(p -> {
if (!columnMap.containsKey(p)) {
Expand Down Expand Up @@ -636,7 +640,7 @@ private void checkEngineName() {
throw new AnalysisException("odbc, mysql and broker table is no longer supported."
+ " For odbc and mysql external table, use jdbc table or jdbc catalog instead."
+ " For broker table, use table valued function instead."
+ ". Or you can temporarily set 'disable_odbc_mysql_broker_table=false'"
+ ". Or you can temporarily set 'enable_odbc_mysql_broker_table=true'"
+ " in fe.conf to reopen this feature.");
}
}
Expand Down Expand Up @@ -796,11 +800,6 @@ private void validateKeyColumns() {
* translate to catalog create table stmt
*/
public CreateTableStmt translateToLegacyStmt() {
if (isAutoPartition) {
partitionColumns = ExpressionUtils
.collectAll(autoPartitionExprs, UnboundSlot.class::isInstance).stream()
.map(slot -> ((UnboundSlot) slot).getName()).collect(Collectors.toList());
}
PartitionDesc partitionDesc = null;
if (partitionColumns != null || isAutoPartition) {
List<AllPartitionDesc> partitionDescs =
Expand Down Expand Up @@ -894,14 +893,4 @@ private static List<Expr> convertToLegacyArguments(List<Expression> children) {
}
}).collect(Collectors.toList());
}

private void appendColumnFromExprs() {
for (Expression autoExpr : autoPartitionExprs) {
for (Expression child : autoExpr.children()) {
if (child instanceof UnboundSlot) {
partitionColumns.add(((UnboundSlot) child).getName());
}
}
}
}
}

0 comments on commit 6d8567c

Please sign in to comment.