forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enhancement] (nereids)implement alterCatalogCommentCommand in nereids (
apache#45160) Issue Number: close apache#42790
- Loading branch information
1 parent
830b74c
commit b0ab7f1
Showing
9 changed files
with
206 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterCatalogCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.apache.doris.nereids.trees.plans.commands; | ||
|
||
import org.apache.doris.catalog.Env; | ||
import org.apache.doris.common.ErrorCode; | ||
import org.apache.doris.common.ErrorReport; | ||
import org.apache.doris.common.util.Util; | ||
import org.apache.doris.datasource.InternalCatalog; | ||
import org.apache.doris.mysql.privilege.PrivPredicate; | ||
import org.apache.doris.nereids.trees.plans.PlanType; | ||
import org.apache.doris.qe.ConnectContext; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Base class for AlterCatalog commands. | ||
*/ | ||
public abstract class AlterCatalogCommand extends AlterCommand { | ||
protected final String catalogName; | ||
|
||
public AlterCatalogCommand(PlanType type, String catalogName) { | ||
super(type); | ||
this.catalogName = Objects.requireNonNull(catalogName, "Catalog name cannot be null"); | ||
} | ||
|
||
protected void validate(ConnectContext ctx) throws Exception { | ||
Util.checkCatalogAllRules(catalogName); | ||
|
||
if (!Env.getCurrentEnv().getAccessManager().checkCtlPriv(ctx, catalogName, PrivPredicate.ALTER)) { | ||
ErrorReport.reportAnalysisException(ErrorCode.ERR_CATALOG_ACCESS_DENIED, | ||
ctx.getQualifiedUser(), catalogName); | ||
} | ||
|
||
if (catalogName.equals(InternalCatalog.INTERNAL_CATALOG_NAME)) { | ||
throw new Exception("Internal catalog cannot be altered."); | ||
} | ||
} | ||
|
||
public String getCatalogName() { | ||
return catalogName; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...c/main/java/org/apache/doris/nereids/trees/plans/commands/AlterCatalogCommentCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.apache.doris.nereids.trees.plans.commands; | ||
|
||
import org.apache.doris.catalog.Env; | ||
import org.apache.doris.common.AnalysisException; | ||
import org.apache.doris.nereids.trees.plans.PlanType; | ||
import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor; | ||
import org.apache.doris.qe.ConnectContext; | ||
import org.apache.doris.qe.StmtExecutor; | ||
|
||
import com.google.common.base.Strings; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Represents the command for ALTER CATALOG MODIFY COMMENT. | ||
*/ | ||
public class AlterCatalogCommentCommand extends AlterCatalogCommand { | ||
|
||
private final String comment; | ||
|
||
public AlterCatalogCommentCommand(String catalogName, String comment) { | ||
super(PlanType.ALTER_CATALOG_COMMENT_COMMAND, catalogName); | ||
this.comment = Objects.requireNonNull(comment, "Comment cannot be null"); | ||
} | ||
|
||
@Override | ||
public void doRun(ConnectContext ctx, StmtExecutor executor) throws Exception { | ||
// Validate the catalog name | ||
if (Strings.isNullOrEmpty(comment)) { | ||
throw new AnalysisException("New comment is not set."); | ||
} | ||
|
||
// Fetch and modify the catalog's comment | ||
Env.getCurrentEnv().getCatalogMgr().alterCatalogComment(catalogName, comment); | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(PlanVisitor<R, C> visitor, C context) { | ||
return visitor.visitAlterCatalogCommentCommand(this, context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
regression-test/data/nereids_p0/test_alter_catalog_comment_command.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- This file is automatically generated. You should know what you did if you want to edit this | ||
-- !cmd -- | ||
test_alter_catalog_comment \nCREATE CATALOG `test_alter_catalog_comment`\nCOMMENT "Initial catalog comment"\n PROPERTIES (\n"type" = "es",\n"hosts" = "http://127.0.0.1:9200"\n); | ||
|
||
-- !cmd -- | ||
test_alter_catalog_comment \nCREATE CATALOG `test_alter_catalog_comment`\nCOMMENT "Updated catalog comment"\n PROPERTIES (\n"type" = "es",\n"hosts" = "http://127.0.0.1:9200"\n); | ||
|
54 changes: 54 additions & 0 deletions
54
regression-test/suites/nereids_p0/test_alter_catalog_comment_command.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
suite("test_alter_catalog_comment_command", "nereids_p0") { | ||
def catalogName = "test_alter_catalog_comment" | ||
def catalogProperties = "\"type\"=\"es\", \"hosts\"=\"http://127.0.0.1:9200\"" | ||
|
||
try { | ||
// Drop catalog if it already exists | ||
sql("DROP CATALOG IF EXISTS ${catalogName}") | ||
|
||
// Create a new catalog | ||
sql( | ||
""" | ||
CREATE CATALOG ${catalogName} | ||
COMMENT 'Initial catalog comment' | ||
PROPERTIES (${catalogProperties}) | ||
""" | ||
) | ||
// Verify the catalog was created | ||
checkNereidsExecute("""show create catalog ${catalogName}""") | ||
qt_cmd("""show create catalog ${catalogName}""") | ||
|
||
|
||
// Alter the catalog comment | ||
checkNereidsExecute( | ||
""" | ||
ALTER CATALOG ${catalogName} MODIFY COMMENT 'Updated catalog comment' | ||
""" | ||
) | ||
// Verify the comment was changed | ||
checkNereidsExecute("""show create catalog ${catalogName}""") | ||
qt_cmd("""show create catalog ${catalogName}""") | ||
|
||
} finally { | ||
// Clean up | ||
sql("DROP CATALOG IF EXISTS ${catalogName}") | ||
} | ||
} |