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 CreateRepositoryCommand in nereids
- Loading branch information
Showing
7 changed files
with
216 additions
and
3 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
74 changes: 74 additions & 0 deletions
74
.../src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateRepositoryCommand.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,74 @@ | ||
// 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.analysis.StmtType; | ||
import org.apache.doris.analysis.StorageBackend; | ||
import org.apache.doris.catalog.Env; | ||
import org.apache.doris.common.ErrorCode; | ||
import org.apache.doris.common.ErrorReport; | ||
import org.apache.doris.common.FeNameFormat; | ||
import org.apache.doris.mysql.privilege.PrivPredicate; | ||
import org.apache.doris.nereids.DorisParser.StorageBackendContext; | ||
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 java.util.Map; | ||
|
||
/** CreateViewCommand */ | ||
public class CreateRepositoryCommand extends Command implements ForwardWithSync { | ||
private final boolean isReadOnly; | ||
private final String name; | ||
private final StorageBackendContext storage; | ||
private final StorageBackend.StorageType type; | ||
private final Map<String, String> properties; | ||
|
||
/** CreateRepositoryCommand */ | ||
public CreateRepositoryCommand(boolean isReadOnly, String name, StorageBackendContext storage, | ||
StorageBackend.StorageType type, Map<String, String> properties) { | ||
super(PlanType.CREATE_REPOSITORY_COMMAND); | ||
this.isReadOnly = isReadOnly; | ||
this.name = name; | ||
this.storage = storage; | ||
this.type = type; | ||
this.properties = properties; | ||
} | ||
|
||
@Override | ||
public void run(ConnectContext ctx, StmtExecutor executor) throws Exception { | ||
// check auth | ||
if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), PrivPredicate.ADMIN)) { | ||
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "ADMIN"); | ||
} | ||
FeNameFormat.checkCommonName("repository", name); | ||
|
||
Env.getCurrentEnv().getBackupHandler().createRepositoryInNereids(isReadOnly, name, storage, type, properties); | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(PlanVisitor<R, C> visitor, C context) { | ||
return visitor.visitCreateRepositoryCommand(this, context); | ||
} | ||
|
||
@Override | ||
public StmtType stmtType() { | ||
return StmtType.CREATE; | ||
} | ||
} |
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
79 changes: 79 additions & 0 deletions
79
...ssion-test/suites/nereids_p0/ddl/repository/test_nereids_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,79 @@ | ||
package ddl.repository | ||
// 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("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_create_repository" | ||
String readOnlyRepoName = "test_create_read_only_repository" | ||
|
||
//cloud-mode | ||
if (isCloudMode()) { | ||
return | ||
} | ||
|
||
try_sql "DROP REPOSITORY `${repoName}`" | ||
try_sql "DROP REPOSITORY `${readOnlyRepoName}`" | ||
|
||
def create_read_only_repo = checkNereidsExecute("""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 = checkNereidsExecute("""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}" | ||
)"""); | ||
|
||
def test_create_repo = checkNereidsExecuteWithResult("""SHOW CREATE REPOSITORY for `${repoName}`;""").toString(); | ||
assertTrue(test_create_repo.contains("${repoName}")) | ||
assertTrue(test_create_repo.contains("s3://${bucket}/${repoName}")) | ||
|
||
assertTrue(test_create_repo.contains("${repoName}")) | ||
assertTrue(test_create_repo.contains("s3://${bucket}/${repoName}")) | ||
|
||
def test_read_only_repo = checkNereidsExecuteWithResult("""SHOW CREATE REPOSITORY for `${readOnlyRepoName}`;""").toString(); | ||
assertTrue(test_read_only_repo.contains("${readOnlyRepoName}")) | ||
assertTrue(test_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.")) | ||
} | ||
} |