Skip to content

Commit f2cf736

Browse files
committed
init
1 parent d202753 commit f2cf736

File tree

16 files changed

+1303
-1
lines changed

16 files changed

+1303
-1
lines changed

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

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

758760
createOrReplaceTagClause
@@ -799,6 +801,12 @@ dropTagClause
799801
: DROP TAG (IF EXISTS)? name=identifier
800802
;
801803

804+
partitionTransform
805+
: identifier LEFT_PAREN INTEGER_VALUE COMMA identifier RIGHT_PAREN #partitionTransformWithArgs
806+
| identifier LEFT_PAREN identifier RIGHT_PAREN #partitionTransformWithColumn
807+
| identifier #partitionTransformIdentity
808+
;
809+
802810
columnPosition
803811
: FIRST
804812
| AFTER position=identifier

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.apache.doris.analysis.AddColumnClause;
2121
import org.apache.doris.analysis.AddColumnsClause;
2222
import org.apache.doris.analysis.AddPartitionClause;
23+
import org.apache.doris.analysis.AddPartitionFieldClause;
2324
import org.apache.doris.analysis.AddPartitionLikeClause;
2425
import org.apache.doris.analysis.AlterClause;
2526
import org.apache.doris.analysis.AlterMultiPartitionClause;
@@ -29,6 +30,7 @@
2930
import org.apache.doris.analysis.DropBranchClause;
3031
import org.apache.doris.analysis.DropColumnClause;
3132
import org.apache.doris.analysis.DropPartitionClause;
33+
import org.apache.doris.analysis.DropPartitionFieldClause;
3234
import org.apache.doris.analysis.DropPartitionFromIndexClause;
3335
import org.apache.doris.analysis.DropTagClause;
3436
import org.apache.doris.analysis.ModifyColumnClause;
@@ -75,6 +77,8 @@
7577
import org.apache.doris.common.util.PropertyAnalyzer;
7678
import org.apache.doris.common.util.PropertyAnalyzer.RewriteProperty;
7779
import org.apache.doris.datasource.ExternalTable;
80+
import org.apache.doris.datasource.iceberg.IcebergExternalCatalog;
81+
import org.apache.doris.datasource.iceberg.IcebergExternalTable;
7882
import org.apache.doris.info.TableNameInfo;
7983
import org.apache.doris.mtmv.BaseTableInfo;
8084
import org.apache.doris.nereids.trees.plans.commands.AlterSystemCommand;
@@ -181,6 +185,16 @@ private boolean processAlterOlapTableInternal(List<AlterClause> alterClauses, Ol
181185
AlterOperations currentAlterOps = new AlterOperations();
182186
currentAlterOps.checkConflict(alterClauses);
183187

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+
184198
for (AlterClause clause : alterClauses) {
185199
Map<String, String> properties = null;
186200
try {
@@ -415,6 +429,22 @@ private void processAlterTableForExternalTable(
415429
} else if (alterClause instanceof ReorderColumnsClause) {
416430
ReorderColumnsClause reorderColumns = (ReorderColumnsClause) alterClause;
417431
table.getCatalog().reorderColumns(table, reorderColumns.getColumnsByPos());
432+
} else if (alterClause instanceof AddPartitionFieldClause) {
433+
AddPartitionFieldClause addPartitionField = (AddPartitionFieldClause) alterClause;
434+
if (table instanceof IcebergExternalTable) {
435+
((IcebergExternalCatalog) table.getCatalog()).addPartitionField(
436+
(IcebergExternalTable) table, addPartitionField);
437+
} else {
438+
throw new UserException("ADD PARTITION KEY is only supported for Iceberg tables");
439+
}
440+
} else if (alterClause instanceof DropPartitionFieldClause) {
441+
DropPartitionFieldClause dropPartitionField = (DropPartitionFieldClause) alterClause;
442+
if (table instanceof IcebergExternalTable) {
443+
((IcebergExternalCatalog) table.getCatalog()).dropPartitionField(
444+
(IcebergExternalTable) table, dropPartitionField);
445+
} else {
446+
throw new UserException("DROP PARTITION KEY is only supported for Iceberg tables");
447+
}
418448
} else {
419449
throw new UserException("Invalid alter operations for external table: " + alterClauses);
420450
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.doris.analysis;
19+
20+
import org.apache.doris.alter.AlterOpType;
21+
import org.apache.doris.common.AnalysisException;
22+
23+
import java.util.Collections;
24+
import java.util.Map;
25+
26+
/**
27+
* AddPartitionFieldClause for Iceberg partition evolution
28+
*/
29+
public class AddPartitionFieldClause extends AlterTableClause {
30+
private final String transformName;
31+
private final Integer transformArg;
32+
private final String columnName;
33+
34+
public AddPartitionFieldClause(String transformName, Integer transformArg, String columnName) {
35+
super(AlterOpType.SCHEMA_CHANGE);
36+
this.transformName = transformName;
37+
this.transformArg = transformArg;
38+
this.columnName = columnName;
39+
}
40+
41+
public String getTransformName() {
42+
return transformName;
43+
}
44+
45+
public Integer getTransformArg() {
46+
return transformArg;
47+
}
48+
49+
public String getColumnName() {
50+
return columnName;
51+
}
52+
53+
@Override
54+
public void analyze() throws AnalysisException {
55+
// Validation will be done in IcebergMetadataOps
56+
}
57+
58+
@Override
59+
public String toSql() {
60+
StringBuilder sb = new StringBuilder();
61+
sb.append("ADD PARTITION KEY ");
62+
if (transformName != null) {
63+
sb.append(transformName);
64+
if (transformArg != null) {
65+
sb.append("(").append(transformArg);
66+
if (columnName != null) {
67+
sb.append(", ").append(columnName);
68+
}
69+
sb.append(")");
70+
} else if (columnName != null) {
71+
sb.append("(").append(columnName).append(")");
72+
}
73+
} else if (columnName != null) {
74+
sb.append(columnName);
75+
}
76+
return sb.toString();
77+
}
78+
79+
@Override
80+
public String toString() {
81+
return toSql();
82+
}
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+
}
98+
}
99+

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
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.doris.analysis;
19+
20+
import org.apache.doris.alter.AlterOpType;
21+
import org.apache.doris.common.AnalysisException;
22+
23+
import java.util.Collections;
24+
import java.util.Map;
25+
26+
/**
27+
* DropPartitionFieldClause for Iceberg partition evolution
28+
*/
29+
public class DropPartitionFieldClause extends AlterTableClause {
30+
private final String transformName;
31+
private final Integer transformArg;
32+
private final String columnName;
33+
34+
public DropPartitionFieldClause(String transformName, Integer transformArg, String columnName) {
35+
super(AlterOpType.SCHEMA_CHANGE);
36+
this.transformName = transformName;
37+
this.transformArg = transformArg;
38+
this.columnName = columnName;
39+
}
40+
41+
public String getTransformName() {
42+
return transformName;
43+
}
44+
45+
public Integer getTransformArg() {
46+
return transformArg;
47+
}
48+
49+
public String getColumnName() {
50+
return columnName;
51+
}
52+
53+
@Override
54+
public void analyze() throws AnalysisException {
55+
// Validation will be done in IcebergMetadataOps
56+
}
57+
58+
@Override
59+
public String toSql() {
60+
StringBuilder sb = new StringBuilder();
61+
sb.append("DROP PARTITION KEY ");
62+
if (transformName != null) {
63+
sb.append(transformName);
64+
if (transformArg != null) {
65+
sb.append("(").append(transformArg);
66+
if (columnName != null) {
67+
sb.append(", ").append(columnName);
68+
}
69+
sb.append(")");
70+
} else if (columnName != null) {
71+
sb.append("(").append(columnName).append(")");
72+
}
73+
} else if (columnName != null) {
74+
sb.append(columnName);
75+
}
76+
return sb.toString();
77+
}
78+
79+
@Override
80+
public String toString() {
81+
return toSql();
82+
}
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+
}
98+
}
99+

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

Lines changed: 44 additions & 0 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;
@@ -144,4 +148,44 @@ public void onClose() {
144148
public boolean viewExists(String dbName, String viewName) {
145149
return metadataOps.viewExists(dbName, viewName);
146150
}
151+
152+
/**
153+
* Add partition field to Iceberg table for partition evolution
154+
*/
155+
public void addPartitionField(IcebergExternalTable table, AddPartitionFieldClause clause) throws DdlException {
156+
makeSureInitialized();
157+
if (metadataOps == null) {
158+
throw new DdlException("Add partition field operation is not supported for catalog: " + getName());
159+
}
160+
try {
161+
((IcebergMetadataOps) metadataOps).addPartitionField(table, clause);
162+
Env.getCurrentEnv().getEditLog()
163+
.logRefreshExternalTable(
164+
ExternalObjectLog.createForRefreshTable(table.getCatalog().getId(),
165+
table.getDbName(), table.getName()));
166+
} catch (Exception e) {
167+
throw new DdlException("Failed to add partition field to table: "
168+
+ table.getName() + ", error message is: " + e.getMessage(), e);
169+
}
170+
}
171+
172+
/**
173+
* Drop partition field from Iceberg table for partition evolution
174+
*/
175+
public void dropPartitionField(IcebergExternalTable table, DropPartitionFieldClause clause) throws DdlException {
176+
makeSureInitialized();
177+
if (metadataOps == null) {
178+
throw new DdlException("Drop partition field operation is not supported for catalog: " + getName());
179+
}
180+
try {
181+
((IcebergMetadataOps) metadataOps).dropPartitionField(table, clause);
182+
Env.getCurrentEnv().getEditLog()
183+
.logRefreshExternalTable(
184+
ExternalObjectLog.createForRefreshTable(table.getCatalog().getId(),
185+
table.getDbName(), table.getName()));
186+
} catch (Exception e) {
187+
throw new DdlException("Failed to drop partition field from table: "
188+
+ table.getName() + ", error message is: " + e.getMessage(), e);
189+
}
190+
}
147191
}

0 commit comments

Comments
 (0)