[Enhancement](Backup) support show create repository (#17299)

support show create repository stmt.
This commit is contained in:
GoGoWen
2023-04-11 00:11:00 +08:00
committed by GitHub
parent 275d955762
commit a6d25ef8d0
5 changed files with 114 additions and 1 deletions

View File

@ -646,7 +646,7 @@ terminal String COMMENTED_PLAN_HINTS;
nonterminal List<StatementBase> stmts;
nonterminal StatementBase stmt, show_stmt, show_param, help_stmt, load_stmt,
create_routine_load_stmt, pause_routine_load_stmt, resume_routine_load_stmt, stop_routine_load_stmt,
show_routine_load_stmt, show_routine_load_task_stmt, show_create_routine_load_stmt, show_create_load_stmt,
show_routine_load_stmt, show_routine_load_task_stmt, show_create_routine_load_stmt, show_create_load_stmt, show_create_reporitory_stmt,
describe_stmt, alter_stmt,
use_stmt, kill_stmt, drop_stmt, recover_stmt, grant_stmt, revoke_stmt, create_stmt, set_stmt, sync_stmt, cancel_stmt, cancel_param, delete_stmt,
link_stmt, migrate_stmt, switch_stmt, enter_stmt, transaction_stmt, unsupported_stmt, export_stmt, admin_stmt, truncate_stmt,
@ -1109,6 +1109,8 @@ stmt ::=
{: RESULT = stmt; :}
| show_create_load_stmt : stmt
{: RESULT = stmt; :}
| show_create_reporitory_stmt : stmt
{: RESULT = stmt; :}
| cancel_stmt : stmt
{: RESULT = stmt; :}
| delete_stmt : stmt
@ -2798,6 +2800,13 @@ show_create_load_stmt ::=
:}
;
show_create_reporitory_stmt ::=
KW_SHOW KW_CREATE KW_REPOSITORY KW_FOR ident:repoName
{:
RESULT = new ShowCreateRepositoryStmt(repoName);
:}
;
// analyze statment
analyze_stmt ::=
KW_ANALYZE KW_TABLE table_name:tbl opt_col_list:cols opt_partition_names:partitionNames opt_properties:properties

View File

@ -0,0 +1,53 @@
// 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.analysis;
import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.qe.ShowResultSetMetaData;
// SHOW CREATE REPOSITORY statement
public class ShowCreateRepositoryStmt extends ShowStmt {
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 ShowCreateRepositoryStmt(String repoName) {
this.repoName = repoName;
}
public String getRepoName() {
return this.repoName;
}
@Override
public void analyze(Analyzer analyzer) throws AnalysisException {
}
@Override
public ShowResultSetMetaData getMetaData() {
return META_DATA;
}
}

View File

@ -26,6 +26,7 @@ import org.apache.doris.common.FeConstants;
import org.apache.doris.common.Pair;
import org.apache.doris.common.io.Text;
import org.apache.doris.common.io.Writable;
import org.apache.doris.common.util.PrintableMap;
import org.apache.doris.common.util.TimeUtils;
import org.apache.doris.system.Backend;
@ -630,6 +631,38 @@ public class Repository implements Writable {
return snapshotInfos;
}
public String getCreateStatement() {
StringBuilder stmtBuilder = new StringBuilder();
stmtBuilder.append("CREATE ");
if (this.isReadOnly) {
stmtBuilder.append("READ ONLY ");
}
stmtBuilder.append("REPOSITORY ");
stmtBuilder.append(this.name);
stmtBuilder.append(" \nWITH ");
StorageBackend.StorageType storageType = this.storage.getStorageType();
if (storageType == StorageBackend.StorageType.S3) {
stmtBuilder.append(" S3 ");
} else if (storageType == StorageBackend.StorageType.HDFS) {
stmtBuilder.append(" HDFS ");
} else if (storageType == StorageBackend.StorageType.BROKER) {
stmtBuilder.append(" BROKER ");
stmtBuilder.append(this.storage.getName());
} else {
// should never reach here
throw new UnsupportedOperationException(storageType.toString() + " backend is not implemented");
}
stmtBuilder.append(" \nON LOCATION \"");
stmtBuilder.append(this.location);
stmtBuilder.append("\"");
stmtBuilder.append("\nPROPERTIES\n(");
stmtBuilder.append(new PrintableMap<>(this.getStorage().getProperties(), " = ",
true, true));
stmtBuilder.append("\n)");
return stmtBuilder.toString();
}
private List<String> getSnapshotInfo(String snapshotName, String timestamp) {
List<String> info = Lists.newArrayList();
if (Strings.isNullOrEmpty(timestamp)) {

View File

@ -43,6 +43,7 @@ import org.apache.doris.analysis.ShowCreateDbStmt;
import org.apache.doris.analysis.ShowCreateFunctionStmt;
import org.apache.doris.analysis.ShowCreateLoadStmt;
import org.apache.doris.analysis.ShowCreateMaterializedViewStmt;
import org.apache.doris.analysis.ShowCreateRepositoryStmt;
import org.apache.doris.analysis.ShowCreateRoutineLoadStmt;
import org.apache.doris.analysis.ShowCreateTableStmt;
import org.apache.doris.analysis.ShowDataSkewStmt;
@ -297,6 +298,8 @@ public class ShowExecutor {
handleShowCreateRoutineLoad();
} else if (stmt instanceof ShowCreateLoadStmt) {
handleShowCreateLoad();
} else if (stmt instanceof ShowCreateRepositoryStmt) {
handleShowCreateRepository();
} else if (stmt instanceof ShowDeleteStmt) {
handleShowDelete();
} else if (stmt instanceof ShowAlterStmt) {
@ -2199,6 +2202,20 @@ public class ShowExecutor {
resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
}
private void handleShowCreateRepository() throws AnalysisException {
ShowCreateRepositoryStmt showCreateRepositoryStmt = (ShowCreateRepositoryStmt) stmt;
String repoName = showCreateRepositoryStmt.getRepoName();
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()));
resultSet = new ShowResultSet(showCreateRepositoryStmt.getMetaData(), rows);
}
private void handleShowCreateRoutineLoad() throws AnalysisException {
ShowCreateRoutineLoadStmt showCreateRoutineLoadStmt = (ShowCreateRoutineLoadStmt) stmt;
List<List<String>> rows = Lists.newArrayList();

View File

@ -392,6 +392,7 @@ import org.apache.doris.qe.SqlModeHelper;
keywordMap.put("revoke", new Integer(SqlParserSymbols.KW_REVOKE));
keywordMap.put("right", new Integer(SqlParserSymbols.KW_RIGHT));
keywordMap.put("rlike", new Integer(SqlParserSymbols.KW_REGEXP));
keywordMap.put("repository", new Integer(SqlParserSymbols.KW_REPOSITORY));
keywordMap.put("role", new Integer(SqlParserSymbols.KW_ROLE));
keywordMap.put("roles", new Integer(SqlParserSymbols.KW_ROLES));
keywordMap.put("rollback", new Integer(SqlParserSymbols.KW_ROLLBACK));