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.
[Feat](Nereids) support show create repository command (apache#43902)
Issue Number: close apache#42724 migrate show create repository command to nereids
- Loading branch information
1 parent
78bd61e
commit 7836e93
Showing
6 changed files
with
172 additions
and
1 deletion.
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
81 changes: 81 additions & 0 deletions
81
.../main/java/org/apache/doris/nereids/trees/plans/commands/ShowCreateRepositoryCommand.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,81 @@ | ||
// 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.backup.Repository; | ||
import org.apache.doris.catalog.Column; | ||
import org.apache.doris.catalog.Env; | ||
import org.apache.doris.catalog.ScalarType; | ||
import org.apache.doris.common.AnalysisException; | ||
import org.apache.doris.common.ErrorCode; | ||
import org.apache.doris.common.ErrorReport; | ||
import org.apache.doris.common.UserException; | ||
import org.apache.doris.mysql.privilege.PrivPredicate; | ||
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.ShowResultSet; | ||
import org.apache.doris.qe.ShowResultSetMetaData; | ||
import org.apache.doris.qe.StmtExecutor; | ||
|
||
import com.google.common.collect.Lists; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* ShowCreateRepositoryCommand | ||
*/ | ||
public class ShowCreateRepositoryCommand extends ShowCommand { | ||
private static final ShowResultSetMetaData META_DATA = | ||
ShowResultSetMetaData.builder() | ||
.addColumn(new Column("RepoName", ScalarType.createVarchar(128))) | ||
.addColumn(new Column("CreateStmt", ScalarType.createVarchar(65535))) | ||
.build(); | ||
|
||
private final String repoName; | ||
|
||
public ShowCreateRepositoryCommand(String repoName) { | ||
super(PlanType.SHOW_CREATE_REPOSITORY_COMMAND); | ||
this.repoName = repoName; | ||
} | ||
|
||
private void validate() throws UserException { | ||
// check auth | ||
if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), PrivPredicate.ADMIN)) { | ||
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, | ||
PrivPredicate.ADMIN.getPrivs().toString()); | ||
} | ||
} | ||
|
||
@Override | ||
public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) throws Exception { | ||
validate(); | ||
List<List<String>> rows = Lists.newArrayList(); | ||
Repository repo = Env.getCurrentEnv().getBackupHandler().getRepoMgr().getRepo(repoName); | ||
if (repo == null) { | ||
throw new AnalysisException("repository not exist."); | ||
} | ||
rows.add(Lists.newArrayList(repoName, repo.getCreateStatement())); | ||
return new ShowResultSet(META_DATA, rows); | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(PlanVisitor<R, C> visitor, C context) { | ||
return visitor.visitShowCreateRepositoryCommand(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
77 changes: 77 additions & 0 deletions
77
regression-test/suites/nereids_p0/ddl/repository/show_create_repository_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,77 @@ | ||
// 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. | ||
|
||
import org.junit.Assert; | ||
|
||
suite("show_create_repository_command") { | ||
String ak = getS3AK() | ||
String sk = getS3SK() | ||
String endpoint = getS3Endpoint() | ||
String region = getS3Region() | ||
String bucket = context.config.otherConfigs.get("s3BucketName"); | ||
String repoName = "test_show_create_repository" | ||
String readOnlyRepoName = "test_show_create_read_only_repository" | ||
|
||
//cloud-mode | ||
if (isCloudMode()) { | ||
return | ||
} | ||
|
||
try_sql "DROP REPOSITORY `${repoName}`" | ||
try_sql "DROP REPOSITORY `${readOnlyRepoName}`" | ||
|
||
// create S3 repo | ||
sql """CREATE REPOSITORY `${repoName}` | ||
WITH S3 | ||
ON LOCATION "s3://${bucket}/${repoName}" | ||
PROPERTIES | ||
( | ||
"s3.endpoint" = "http://${endpoint}", | ||
"s3.region" = "${region}", | ||
"s3.access_key" = "${ak}", | ||
"s3.secret_key" = "${sk}" | ||
)""" | ||
|
||
// create S3 read only repo | ||
sql """CREATE READ ONLY REPOSITORY `${readOnlyRepoName}` | ||
WITH S3 | ||
ON LOCATION "s3://${bucket}/${readOnlyRepoName}" | ||
PROPERTIES | ||
( | ||
"s3.endpoint" = "http://${endpoint}", | ||
"s3.region" = "${region}", | ||
"s3.access_key" = "${ak}", | ||
"s3.secret_key" = "${sk}" | ||
)""" | ||
|
||
def create_repo = checkNereidsExecuteWithResult("""SHOW CREATE REPOSITORY for `${repoName}`;""").toString(); | ||
assertTrue(create_repo.contains("${repoName}")) | ||
assertTrue(create_repo.contains("s3://${bucket}/${repoName}")) | ||
|
||
def create_read_only_repo = checkNereidsExecuteWithResult("""SHOW CREATE REPOSITORY for `${readOnlyRepoName}`;""").toString(); | ||
assertTrue(create_read_only_repo.contains("${readOnlyRepoName}")) | ||
assertTrue(create_read_only_repo.contains("READ ONLY")) | ||
|
||
sql """DROP REPOSITORY `${repoName}`;""" | ||
sql """DROP REPOSITORY `${readOnlyRepoName}`;""" | ||
|
||
try { | ||
sql """SHOW CREATE REPOSITORY for `${repoName}`;""" | ||
} catch (Exception e) { | ||
assertTrue(e.getMessage().contains("repository not exist.")) | ||
} | ||
} |