Skip to content

Commit 5a93879

Browse files
authored
[Enhancement] (nereids)implement alterCatalogPropertiesCommand in nereids (#45164)
Issue Number: close #42789
1 parent d9dfd7f commit 5a93879

9 files changed

Lines changed: 149 additions & 9 deletions

File tree

‎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
@@ -229,6 +229,8 @@ supportedAlterStatement
229229
| ALTER ROLE role=identifier commentSpec #alterRole
230230
| ALTER WORKLOAD GROUP name=identifierOrText
231231
properties=propertyClause? #alterWorkloadGroup
232+
| ALTER CATALOG name=identifier SET PROPERTIES
233+
LEFT_PAREN propertyItemList RIGHT_PAREN #alterCatalogProperties
232234
| ALTER WORKLOAD POLICY name=identifierOrText
233235
properties=propertyClause? #alterWorkloadPolicy
234236
| ALTER SQL_BLOCK_RULE name=identifier properties=propertyClause? #alterSqlBlockRule
@@ -619,8 +621,6 @@ privilegeList
619621
unsupportedAlterStatement
620622
: ALTER DATABASE name=identifier SET PROPERTIES
621623
LEFT_PAREN propertyItemList RIGHT_PAREN #alterDatabaseProperties
622-
| ALTER CATALOG name=identifier SET PROPERTIES
623-
LEFT_PAREN propertyItemList RIGHT_PAREN #alterCatalogProperties
624624
| ALTER RESOURCE name=identifierOrText properties=propertyClause? #alterResource
625625
| ALTER COLOCATE GROUP name=multipartIdentifier
626626
SET LEFT_PAREN propertyItemList RIGHT_PAREN #alterColocateGroup

‎fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -377,26 +377,35 @@ public void alterCatalogComment(AlterCatalogCommentStmt stmt) throws UserExcepti
377377
/**
378378
* Modify the catalog property and write the meta log.
379379
*/
380-
public void alterCatalogProps(AlterCatalogPropertyStmt stmt) throws UserException {
380+
public void alterCatalogProps(String catalogName, Map<String, String> newProperties) throws UserException {
381381
writeLock();
382382
try {
383-
CatalogIf catalog = nameToCatalog.get(stmt.getCatalogName());
383+
CatalogIf catalog = nameToCatalog.get(catalogName);
384384
if (catalog == null) {
385-
throw new DdlException("No catalog found with name: " + stmt.getCatalogName());
385+
throw new DdlException("No catalog found with name: " + catalogName);
386386
}
387387
Map<String, String> oldProperties = catalog.getProperties();
388-
if (stmt.getNewProperties().containsKey("type") && !catalog.getType()
389-
.equalsIgnoreCase(stmt.getNewProperties().get("type"))) {
390-
throw new DdlException("Can't modify the type of catalog property with name: " + stmt.getCatalogName());
388+
if (newProperties.containsKey("type") && !catalog.getType()
389+
.equalsIgnoreCase(newProperties.get("type"))) {
390+
throw new DdlException("Can't modify the type of catalog property with name: " + catalogName);
391391
}
392-
CatalogLog log = CatalogFactory.createCatalogLog(catalog.getId(), stmt);
392+
CatalogLog log = new CatalogLog();
393+
log.setCatalogId(catalog.getId());
394+
log.setNewProps(newProperties);
393395
replayAlterCatalogProps(log, oldProperties, false);
394396
Env.getCurrentEnv().getEditLog().logCatalogLog(OperationType.OP_ALTER_CATALOG_PROPS, log);
395397
} finally {
396398
writeUnlock();
397399
}
398400
}
399401

402+
/**
403+
* Modify the catalog property and write the meta log.
404+
*/
405+
public void alterCatalogProps(AlterCatalogPropertyStmt stmt) throws UserException {
406+
alterCatalogProps(stmt.getCatalogName(), stmt.getNewProperties());
407+
}
408+
400409
/**
401410
* List all catalog or get the special catalog with a name.
402411
*/

‎fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import org.apache.doris.nereids.DorisParser.AliasQueryContext;
7777
import org.apache.doris.nereids.DorisParser.AliasedQueryContext;
7878
import org.apache.doris.nereids.DorisParser.AlterCatalogCommentContext;
79+
import org.apache.doris.nereids.DorisParser.AlterCatalogPropertiesContext;
7980
import org.apache.doris.nereids.DorisParser.AlterCatalogRenameContext;
8081
import org.apache.doris.nereids.DorisParser.AlterDatabaseRenameContext;
8182
import org.apache.doris.nereids.DorisParser.AlterDatabaseSetQuotaContext;
@@ -516,6 +517,7 @@
516517
import org.apache.doris.nereids.trees.plans.commands.AdminSetTableStatusCommand;
517518
import org.apache.doris.nereids.trees.plans.commands.AdminShowReplicaStatusCommand;
518519
import org.apache.doris.nereids.trees.plans.commands.AlterCatalogCommentCommand;
520+
import org.apache.doris.nereids.trees.plans.commands.AlterCatalogPropertiesCommand;
519521
import org.apache.doris.nereids.trees.plans.commands.AlterCatalogRenameCommand;
520522
import org.apache.doris.nereids.trees.plans.commands.AlterMTMVCommand;
521523
import org.apache.doris.nereids.trees.plans.commands.AlterRoleCommand;
@@ -5382,6 +5384,13 @@ public LogicalPlan visitShowWarningErrors(ShowWarningErrorsContext ctx) {
53825384
return new ShowWarningErrorsCommand(isWarning, limit);
53835385
}
53845386

5387+
@Override
5388+
public LogicalPlan visitAlterCatalogProperties(AlterCatalogPropertiesContext ctx) {
5389+
String catalogName = stripQuotes(ctx.name.getText());
5390+
Map<String, String> properties = visitPropertyItemList(ctx.propertyItemList());
5391+
return new AlterCatalogPropertiesCommand(catalogName, properties);
5392+
}
5393+
53855394
@Override
53865395
public RecoverTableCommand visitRecoverTable(RecoverTableContext ctx) {
53875396
List<String> dbTblNameParts = visitMultipartIdentifier(ctx.name);

‎fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ public enum PlanType {
158158
DROP_JOB_COMMAND,
159159
RESUME_JOB_COMMAND,
160160
ALTER_MTMV_COMMAND,
161+
ALTER_CATALOG_PROPERTIES_COMMAND,
161162
ADD_CONSTRAINT_COMMAND,
162163
ADMIN_COMPACT_TABLE_COMMAND,
163164
DROP_CONSTRAINT_COMMAND,

‎fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterCatalogCommentCommand.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public AlterCatalogCommentCommand(String catalogName, String comment) {
4242

4343
@Override
4444
public void doRun(ConnectContext ctx, StmtExecutor executor) throws Exception {
45+
validate(ctx);
4546
// Validate the catalog name
4647
if (Strings.isNullOrEmpty(comment)) {
4748
throw new AnalysisException("New comment is not set.");
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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.nereids.trees.plans.commands;
19+
20+
import org.apache.doris.catalog.Env;
21+
import org.apache.doris.common.util.PropertyAnalyzer;
22+
import org.apache.doris.nereids.trees.plans.PlanType;
23+
import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
24+
import org.apache.doris.qe.ConnectContext;
25+
import org.apache.doris.qe.StmtExecutor;
26+
27+
import java.util.Map;
28+
import java.util.Objects;
29+
30+
/**
31+
* Represents the command for ALTER CATALOG ... SET PROPERTIES.
32+
*/
33+
public class AlterCatalogPropertiesCommand extends AlterCatalogCommand {
34+
private final Map<String, String> newProperties;
35+
36+
public AlterCatalogPropertiesCommand(String catalogName, Map<String, String> properties) {
37+
super(PlanType.ALTER_CATALOG_PROPERTIES_COMMAND, catalogName);
38+
this.newProperties = Objects.requireNonNull(properties, "Properties cannot be null");
39+
}
40+
41+
@Override
42+
public void doRun(ConnectContext ctx, StmtExecutor executor) throws Exception {
43+
validate(ctx);
44+
PropertyAnalyzer.checkCatalogProperties(newProperties, true);
45+
46+
Env.getCurrentEnv().getCatalogMgr().alterCatalogProps(catalogName, newProperties);
47+
}
48+
49+
@Override
50+
public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
51+
return visitor.visitAlterCatalogPropertiesCommand(this, context);
52+
}
53+
}

‎fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.doris.nereids.trees.plans.commands.AdminSetTableStatusCommand;
2727
import org.apache.doris.nereids.trees.plans.commands.AdminShowReplicaStatusCommand;
2828
import org.apache.doris.nereids.trees.plans.commands.AlterCatalogCommentCommand;
29+
import org.apache.doris.nereids.trees.plans.commands.AlterCatalogPropertiesCommand;
2930
import org.apache.doris.nereids.trees.plans.commands.AlterCatalogRenameCommand;
3031
import org.apache.doris.nereids.trees.plans.commands.AlterJobStatusCommand;
3132
import org.apache.doris.nereids.trees.plans.commands.AlterMTMVCommand;
@@ -618,6 +619,10 @@ default R visitShowWhiteListCommand(ShowWhiteListCommand whiteListCommand, C con
618619
return visitCommand(whiteListCommand, context);
619620
}
620621

622+
default R visitAlterCatalogPropertiesCommand(AlterCatalogPropertiesCommand alterCatalogPropsCmd, C context) {
623+
return visitCommand(alterCatalogPropsCmd, context);
624+
}
625+
621626
default R visitRecoverDatabaseCommand(RecoverDatabaseCommand recoverDatabaseCommand, C context) {
622627
return visitCommand(recoverDatabaseCommand, context);
623628
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- This file is automatically generated. You should know what you did if you want to edit this
2+
-- !cmd --
3+
test_alter_catalog_properties \nCREATE CATALOG `test_alter_catalog_properties`\nCOMMENT "Catalog for property test"\n PROPERTIES (\n"type" = "es",\n"hosts" = "http://127.0.0.1:9200"\n);
4+
5+
-- !cmd --
6+
test_alter_catalog_properties \nCREATE CATALOG `test_alter_catalog_properties`\nCOMMENT "Catalog for property test"\n PROPERTIES (\n"type" = "es",\n"hosts" = "http://192.168.0.1:9200"\n);
7+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
suite("test_alter_catalog_properties_command", "nereids_p0") {
19+
def catalogName = "test_alter_catalog_properties"
20+
def catalogProperties = "\"type\"=\"es\", \"hosts\"=\"http://127.0.0.1:9200\""
21+
def newProperties = "\"type\"=\"es\", \"hosts\"=\"http://192.168.0.1:9200\""
22+
23+
try {
24+
// Drop catalog if it already exists
25+
sql("DROP CATALOG IF EXISTS ${catalogName}")
26+
27+
// Create a new catalog
28+
sql(
29+
"""
30+
CREATE CATALOG ${catalogName}
31+
COMMENT 'Catalog for property test'
32+
PROPERTIES (${catalogProperties})
33+
"""
34+
)
35+
// Verify the catalog was created
36+
checkNereidsExecute("""SHOW CREATE CATALOG ${catalogName}""")
37+
qt_cmd("""SHOW CREATE CATALOG ${catalogName}""")
38+
39+
// Alter the catalog properties
40+
checkNereidsExecute(
41+
"""
42+
ALTER CATALOG ${catalogName} SET PROPERTIES (${newProperties})
43+
"""
44+
)
45+
46+
// Verify the properties were changed
47+
checkNereidsExecute("""SHOW CREATE CATALOG ${catalogName}""")
48+
qt_cmd("""SHOW CREATE CATALOG ${catalogName}""")
49+
50+
} finally {
51+
// Clean up
52+
sql("DROP CATALOG IF EXISTS ${catalogName}")
53+
}
54+
}
55+

0 commit comments

Comments
 (0)