Skip to content

Commit

Permalink
[Enhancement] (nereids)implement showSmallFilesCommand in nereids (#4…
Browse files Browse the repository at this point in the history
…4453)

Issue Number: close #42770
  • Loading branch information
Vallishp authored Nov 26, 2024
1 parent 3358156 commit 8b9809e
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ supportedShowStatement
| SHOW ROLES #showRoles
| SHOW PARTITION partitionId=INTEGER_VALUE #showPartitionId
| SHOW PRIVILEGES #showPrivileges
| SHOW PROC path=STRING_LITERAL #showProc
| SHOW PROC path=STRING_LITERAL #showProc
| SHOW FILE ((FROM | IN) database=multipartIdentifier)? #showSmallFiles
| SHOW STORAGE? ENGINES #showStorageEngines
| SHOW CREATE CATALOG name=identifier #showCreateCatalog
| SHOW SQL_BLOCK_RULE (FOR ruleName=identifier)? #showSqlBlockRule
Expand Down Expand Up @@ -325,7 +326,6 @@ unsupportedShowStatement
((FROM | IN) database=multipartIdentifier)? wildWhere? #showFunctions
| SHOW GLOBAL FULL? FUNCTIONS wildWhere? #showGlobalFunctions
| SHOW TYPECAST ((FROM | IN) database=multipartIdentifier)? #showTypeCast
| SHOW FILE ((FROM | IN) database=multipartIdentifier)? #showSmallFiles
| SHOW (KEY | KEYS | INDEX | INDEXES)
(FROM |IN) tableName=multipartIdentifier
((FROM | IN) database=multipartIdentifier)? #showIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@
import org.apache.doris.nereids.DorisParser.ShowProcedureStatusContext;
import org.apache.doris.nereids.DorisParser.ShowRepositoriesContext;
import org.apache.doris.nereids.DorisParser.ShowRolesContext;
import org.apache.doris.nereids.DorisParser.ShowSmallFilesContext;
import org.apache.doris.nereids.DorisParser.ShowSqlBlockRuleContext;
import org.apache.doris.nereids.DorisParser.ShowStorageEnginesContext;
import org.apache.doris.nereids.DorisParser.ShowTableIdContext;
Expand Down Expand Up @@ -492,6 +493,7 @@
import org.apache.doris.nereids.trees.plans.commands.ShowProcedureStatusCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowRepositoriesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowRolesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowSmallFilesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowSqlBlockRuleCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowStorageEnginesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowTableIdCommand;
Expand Down Expand Up @@ -4232,6 +4234,16 @@ public LogicalPlan visitShowPlugins(ShowPluginsContext ctx) {
return new ShowPluginsCommand();
}

@Override
public LogicalPlan visitShowSmallFiles(ShowSmallFilesContext ctx) {
String dbName = null;
if (ctx.database != null) {
List<String> nameParts = visitMultipartIdentifier(ctx.database);
dbName = nameParts.get(0); // only one entry possible
}
return new ShowSmallFilesCommand(dbName);
}

@Override
public LogicalPlan visitShowSqlBlockRule(ShowSqlBlockRuleContext ctx) {
String ruleName = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ public enum PlanType {
SHOW_PRIVILEGES_COMMAND,
SHOW_REPOSITORIES_COMMAND,
SHOW_ROLE_COMMAND,
SHOW_SMALL_FILES_COMMAND,
SHOW_STORAGE_ENGINES_COMMAND,
SHOW_TABLE_ID_COMMAND,
SHOW_TRIGGERS_COMMAND,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// 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.Column;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.DdlException;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
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.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.base.Strings;

import java.util.List;

/**
* show small file command
*/
public class ShowSmallFilesCommand extends ShowCommand {
private static final ShowResultSetMetaData META_DATA =
ShowResultSetMetaData.builder()
.addColumn(new Column("Id", ScalarType.createVarchar(32)))
.addColumn(new Column("DbName", ScalarType.createVarchar(256)))
.addColumn(new Column("Catalog", ScalarType.createVarchar(32)))
.addColumn(new Column("FileName", ScalarType.createVarchar(16)))
.addColumn(new Column("FileSize", ScalarType.createVarchar(16)))
.addColumn(new Column("IsContent", ScalarType.createVarchar(16)))
.addColumn(new Column("MD5", ScalarType.createVarchar(16)))
.build();
private String dbName; // if empty we will use current db;

/**
* constructor
*/
public ShowSmallFilesCommand(String dbName) {
super(PlanType.SHOW_SMALL_FILES_COMMAND);
this.dbName = dbName;
}

@Override
public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) throws Exception {
if (Strings.isNullOrEmpty(dbName)) {
dbName = ctx.getDatabase();
if (Strings.isNullOrEmpty(dbName)) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_NO_DB_ERROR);
}
}
if (!Env.getCurrentEnv().getAccessManager()
.checkDbPriv(ConnectContext.get(), InternalCatalog.INTERNAL_CATALOG_NAME, dbName, PrivPredicate.SHOW)) {
ErrorReport.reportAnalysisException(
ErrorCode.ERR_DBACCESS_DENIED_ERROR, ConnectContext.get().getQualifiedUser(), dbName);
}

List<List<String>> results;
try {
results = Env.getCurrentEnv().getSmallFileMgr().getInfo(dbName);
} catch (DdlException e) {
throw new AnalysisException(e.getMessage());
}
return new ShowResultSet(META_DATA, results);
}

@Override
public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
return visitor.visitShowSmallFilesCommand(this, context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
import org.apache.doris.nereids.trees.plans.commands.ShowProcedureStatusCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowRepositoriesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowRolesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowSmallFilesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowSqlBlockRuleCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowStorageEnginesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowTableIdCommand;
Expand Down Expand Up @@ -330,6 +331,10 @@ default R visitShowCreateTableCommand(ShowCreateTableCommand showCreateTableComm
return visitCommand(showCreateTableCommand, context);
}

default R visitShowSmallFilesCommand(ShowSmallFilesCommand showSmallFilesCommand, C context) {
return visitCommand(showSmallFilesCommand, context);
}

default R visitShowSqlBlockRuleCommand(ShowSqlBlockRuleCommand showblockruleCommand, C context) {
return visitCommand(showblockruleCommand, context);
}
Expand Down
2 changes: 2 additions & 0 deletions regression-test/suites/auth_call/test_ddl_file_auth.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ suite("test_ddl_file_auth","p0,auth_call") {
"catalog" = "internal"
);"""
sql """use ${dbName}"""
checkNereidsExecute("SHOW FILE;")
checkNereidsExecute("SHOW FILE FROM ${dbName};")
def res = sql """SHOW FILE FROM ${dbName};"""
assertTrue(res.size() == 1)

Expand Down

0 comments on commit 8b9809e

Please sign in to comment.