Skip to content

Commit 57da735

Browse files
committed
add ut and case
fix build flush out change field to key fix
1 parent 4f1353d commit 57da735

File tree

16 files changed

+917
-104
lines changed

16 files changed

+917
-104
lines changed

fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,8 +753,8 @@ alterTableClause
753753
| createOrReplaceBranchClause #createOrReplaceBranchClauses
754754
| dropBranchClause #dropBranchClauses
755755
| dropTagClause #dropTagClauses
756-
| ADD PARTITION FIELD partitionTransform #addPartitionFieldClause
757-
| DROP PARTITION FIELD partitionTransform #dropPartitionFieldClause
756+
| ADD PARTITION KEY partitionTransform #addPartitionFieldClause
757+
| DROP PARTITION KEY partitionTransform #dropPartitionFieldClause
758758
;
759759

760760
createOrReplaceTagClause

fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
package org.apache.doris.alter;
1919

2020
import org.apache.doris.analysis.AddColumnClause;
21-
import org.apache.doris.analysis.AddPartitionFieldClause;
2221
import org.apache.doris.analysis.AddColumnsClause;
2322
import org.apache.doris.analysis.AddPartitionClause;
23+
import org.apache.doris.analysis.AddPartitionFieldClause;
2424
import org.apache.doris.analysis.AddPartitionLikeClause;
2525
import org.apache.doris.analysis.AlterClause;
2626
import org.apache.doris.analysis.AlterMultiPartitionClause;
@@ -30,6 +30,7 @@
3030
import org.apache.doris.analysis.DropBranchClause;
3131
import org.apache.doris.analysis.DropColumnClause;
3232
import org.apache.doris.analysis.DropPartitionClause;
33+
import org.apache.doris.analysis.DropPartitionFieldClause;
3334
import org.apache.doris.analysis.DropPartitionFromIndexClause;
3435
import org.apache.doris.analysis.DropTagClause;
3536
import org.apache.doris.analysis.ModifyColumnClause;
@@ -41,7 +42,6 @@
4142
import org.apache.doris.analysis.ModifyTablePropertiesClause;
4243
import org.apache.doris.analysis.PartitionRenameClause;
4344
import org.apache.doris.analysis.ReorderColumnsClause;
44-
import org.apache.doris.analysis.DropPartitionFieldClause;
4545
import org.apache.doris.analysis.ReplacePartitionClause;
4646
import org.apache.doris.analysis.ReplaceTableClause;
4747
import org.apache.doris.analysis.RollupRenameClause;
@@ -77,6 +77,8 @@
7777
import org.apache.doris.common.util.PropertyAnalyzer;
7878
import org.apache.doris.common.util.PropertyAnalyzer.RewriteProperty;
7979
import org.apache.doris.datasource.ExternalTable;
80+
import org.apache.doris.datasource.iceberg.IcebergExternalCatalog;
81+
import org.apache.doris.datasource.iceberg.IcebergExternalTable;
8082
import org.apache.doris.info.TableNameInfo;
8183
import org.apache.doris.mtmv.BaseTableInfo;
8284
import org.apache.doris.nereids.trees.plans.commands.AlterSystemCommand;
@@ -183,6 +185,16 @@ private boolean processAlterOlapTableInternal(List<AlterClause> alterClauses, Ol
183185
AlterOperations currentAlterOps = new AlterOperations();
184186
currentAlterOps.checkConflict(alterClauses);
185187

188+
// Check for unsupported operations on internal tables
189+
for (AlterClause clause : alterClauses) {
190+
if (clause instanceof AddPartitionFieldClause) {
191+
throw new UserException("ADD PARTITION KEY is only supported for Iceberg tables");
192+
}
193+
if (clause instanceof DropPartitionFieldClause) {
194+
throw new UserException("DROP PARTITION KEY is only supported for Iceberg tables");
195+
}
196+
}
197+
186198
for (AlterClause clause : alterClauses) {
187199
Map<String, String> properties = null;
188200
try {
@@ -423,15 +435,15 @@ private void processAlterTableForExternalTable(
423435
((IcebergExternalCatalog) table.getCatalog()).addPartitionField(
424436
(IcebergExternalTable) table, addPartitionField);
425437
} else {
426-
throw new UserException("ADD PARTITION FIELD is only supported for Iceberg tables");
438+
throw new UserException("ADD PARTITION KEY is only supported for Iceberg tables");
427439
}
428440
} else if (alterClause instanceof DropPartitionFieldClause) {
429441
DropPartitionFieldClause dropPartitionField = (DropPartitionFieldClause) alterClause;
430442
if (table instanceof IcebergExternalTable) {
431443
((IcebergExternalCatalog) table.getCatalog()).dropPartitionField(
432444
(IcebergExternalTable) table, dropPartitionField);
433445
} else {
434-
throw new UserException("DROP PARTITION FIELD is only supported for Iceberg tables");
446+
throw new UserException("DROP PARTITION KEY is only supported for Iceberg tables");
435447
}
436448
} else {
437449
throw new UserException("Invalid alter operations for external table: " + alterClauses);

fe/fe-core/src/main/java/org/apache/doris/analysis/AddPartitionFieldClause.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
package org.apache.doris.analysis;
1919

2020
import org.apache.doris.alter.AlterOpType;
21+
import org.apache.doris.common.AnalysisException;
22+
23+
import java.util.Collections;
24+
import java.util.Map;
2125

2226
/**
2327
* AddPartitionFieldClause for Iceberg partition evolution
@@ -46,10 +50,15 @@ public String getColumnName() {
4650
return columnName;
4751
}
4852

53+
@Override
54+
public void analyze() throws AnalysisException {
55+
// Validation will be done in IcebergMetadataOps
56+
}
57+
4958
@Override
5059
public String toSql() {
5160
StringBuilder sb = new StringBuilder();
52-
sb.append("ADD PARTITION FIELD ");
61+
sb.append("ADD PARTITION KEY ");
5362
if (transformName != null) {
5463
sb.append(transformName);
5564
if (transformArg != null) {
@@ -71,5 +80,20 @@ public String toSql() {
7180
public String toString() {
7281
return toSql();
7382
}
83+
84+
@Override
85+
public boolean allowOpMTMV() {
86+
return false;
87+
}
88+
89+
@Override
90+
public boolean needChangeMTMVState() {
91+
return false;
92+
}
93+
94+
@Override
95+
public Map<String, String> getProperties() {
96+
return Collections.emptyMap();
97+
}
7498
}
7599

fe/fe-core/src/main/java/org/apache/doris/analysis/AlterTableClause.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,21 @@ public void setTableNameInfo(TableNameInfo tableNameInfo) {
4040
this.tableNameInfo = tableNameInfo;
4141
}
4242

43+
/**
44+
* Check if this alter operation is allowed on Materialized View (MTMV).
45+
* This method is declared as abstract to force each table operation to explicitly
46+
* declare its MTMV support, as different operations have different MTMV compatibility.
47+
*
48+
* @return true if this operation is allowed on MTMV, false otherwise
49+
*/
4350
public abstract boolean allowOpMTMV();
4451

52+
/**
53+
* Check if this alter operation requires changing the MTMV state.
54+
* This method is declared as abstract to force each table operation to explicitly
55+
* declare whether it affects MTMV state (e.g., schema changes that require MTMV rebuild).
56+
*
57+
* @return true if this operation requires changing MTMV state, false otherwise
58+
*/
4559
public abstract boolean needChangeMTMVState();
4660
}

fe/fe-core/src/main/java/org/apache/doris/analysis/DropPartitionFieldClause.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
package org.apache.doris.analysis;
1919

2020
import org.apache.doris.alter.AlterOpType;
21+
import org.apache.doris.common.AnalysisException;
22+
23+
import java.util.Collections;
24+
import java.util.Map;
2125

2226
/**
2327
* DropPartitionFieldClause for Iceberg partition evolution
@@ -46,10 +50,15 @@ public String getColumnName() {
4650
return columnName;
4751
}
4852

53+
@Override
54+
public void analyze() throws AnalysisException {
55+
// Validation will be done in IcebergMetadataOps
56+
}
57+
4958
@Override
5059
public String toSql() {
5160
StringBuilder sb = new StringBuilder();
52-
sb.append("DROP PARTITION FIELD ");
61+
sb.append("DROP PARTITION KEY ");
5362
if (transformName != null) {
5463
sb.append(transformName);
5564
if (transformArg != null) {
@@ -71,5 +80,20 @@ public String toSql() {
7180
public String toString() {
7281
return toSql();
7382
}
83+
84+
@Override
85+
public boolean allowOpMTMV() {
86+
return false;
87+
}
88+
89+
@Override
90+
public boolean needChangeMTMVState() {
91+
return false;
92+
}
93+
94+
@Override
95+
public Map<String, String> getProperties() {
96+
return Collections.emptyMap();
97+
}
7498
}
7599

fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergExternalCatalog.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717

1818
package org.apache.doris.datasource.iceberg;
1919

20+
import org.apache.doris.analysis.AddPartitionFieldClause;
21+
import org.apache.doris.analysis.DropPartitionFieldClause;
22+
import org.apache.doris.catalog.Env;
2023
import org.apache.doris.common.DdlException;
2124
import org.apache.doris.common.ThreadPoolManager;
2225
import org.apache.doris.datasource.ExternalCatalog;
26+
import org.apache.doris.datasource.ExternalObjectLog;
2327
import org.apache.doris.datasource.InitCatalogLog;
2428
import org.apache.doris.datasource.SessionContext;
2529
import org.apache.doris.datasource.operations.ExternalMetadataOperations;
@@ -148,35 +152,39 @@ public boolean viewExists(String dbName, String viewName) {
148152
/**
149153
* Add partition field to Iceberg table for partition evolution
150154
*/
151-
public void addPartitionField(IcebergExternalTable table,
152-
org.apache.doris.analysis.AddPartitionFieldClause clause) throws org.apache.doris.common.UserException {
155+
public void addPartitionField(IcebergExternalTable table, AddPartitionFieldClause clause) throws DdlException {
153156
makeSureInitialized();
154157
if (metadataOps == null) {
155158
throw new DdlException("Add partition field operation is not supported for catalog: " + getName());
156159
}
157160
try {
158161
((IcebergMetadataOps) metadataOps).addPartitionField(table, clause);
159-
logRefreshExternalTable(table);
162+
Env.getCurrentEnv().getEditLog()
163+
.logRefreshExternalTable(
164+
ExternalObjectLog.createForRefreshTable(table.getCatalog().getId(),
165+
table.getDbName(), table.getName()));
160166
} catch (Exception e) {
161-
throw new org.apache.doris.common.UserException("Failed to add partition field to table: "
167+
throw new DdlException("Failed to add partition field to table: "
162168
+ table.getName() + ", error message is: " + e.getMessage(), e);
163169
}
164170
}
165171

166172
/**
167173
* Drop partition field from Iceberg table for partition evolution
168174
*/
169-
public void dropPartitionField(IcebergExternalTable table,
170-
org.apache.doris.analysis.DropPartitionFieldClause clause) throws org.apache.doris.common.UserException {
175+
public void dropPartitionField(IcebergExternalTable table, DropPartitionFieldClause clause) throws DdlException {
171176
makeSureInitialized();
172177
if (metadataOps == null) {
173178
throw new DdlException("Drop partition field operation is not supported for catalog: " + getName());
174179
}
175180
try {
176181
((IcebergMetadataOps) metadataOps).dropPartitionField(table, clause);
177-
logRefreshExternalTable(table);
182+
Env.getCurrentEnv().getEditLog()
183+
.logRefreshExternalTable(
184+
ExternalObjectLog.createForRefreshTable(table.getCatalog().getId(),
185+
table.getDbName(), table.getName()));
178186
} catch (Exception e) {
179-
throw new org.apache.doris.common.UserException("Failed to drop partition field from table: "
187+
throw new DdlException("Failed to drop partition field from table: "
180188
+ table.getName() + ", error message is: " + e.getMessage(), e);
181189
}
182190
}

0 commit comments

Comments
 (0)