Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat](nereids) implement showConvertLscCommand in nereids #45631

Merged
merged 16 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ supportedShowStatement
(LIKE STRING_LITERAL)? #showTableCreation
| SHOW TABLET STORAGE FORMAT VERBOSE? #showTabletStorageFormat
| SHOW QUERY PROFILE queryIdPath=STRING_LITERAL #showQueryProfile
| SHOW CONVERT_LSC ((FROM | IN) database=multipartIdentifier)? #showConvertLsc
;

supportedLoadStatement
Expand Down Expand Up @@ -374,7 +375,6 @@ unsupportedShowStatement
| SHOW BUILD INDEX ((FROM | IN) database=multipartIdentifier)?
wildWhere? sortClause? limitClause? #showBuildIndex
| SHOW (CLUSTERS | (COMPUTE GROUPS)) #showClusters
| SHOW CONVERT_LSC ((FROM | IN) database=multipartIdentifier)? #showConvertLsc
| SHOW REPLICA STATUS FROM baseTableRef wildWhere? #showReplicaStatus
| SHOW COPY ((FROM | IN) database=multipartIdentifier)?
whereClause? sortClause? limitClause? #showCopy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@
import org.apache.doris.nereids.DorisParser.ShowCollationContext;
import org.apache.doris.nereids.DorisParser.ShowConfigContext;
import org.apache.doris.nereids.DorisParser.ShowConstraintContext;
import org.apache.doris.nereids.DorisParser.ShowConvertLscContext;
import org.apache.doris.nereids.DorisParser.ShowCreateCatalogContext;
import org.apache.doris.nereids.DorisParser.ShowCreateDatabaseContext;
import org.apache.doris.nereids.DorisParser.ShowCreateMTMVContext;
Expand Down Expand Up @@ -569,6 +570,7 @@
import org.apache.doris.nereids.trees.plans.commands.ShowCollationCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowConfigCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowConstraintsCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowConvertLSCCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowCreateCatalogCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowCreateDatabaseCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowCreateMTMVCommand;
Expand Down Expand Up @@ -5195,5 +5197,11 @@ public LogicalPlan visitUseDatabase(UseDatabaseContext ctx) {
return ctx.catalog != null ? new UseCommand(ctx.catalog.getText(), ctx.database.getText())
: new UseCommand(ctx.database.getText());
}

@Override
public LogicalPlan visitShowConvertLsc(ShowConvertLscContext ctx) {
MultipartIdentifierContext database = ctx.database;
return database == null ? new ShowConvertLSCCommand(null) : new ShowConvertLSCCommand(database.getText());
vinlee19 marked this conversation as resolved.
Show resolved Hide resolved
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ public enum PlanType {
SHOW_WARNING_ERRORS_COMMAND,
SHOW_WHITE_LIST_COMMAND,
SHOW_TABLETS_BELONG_COMMAND,
SHOW_CONVERT_LSC_COMMAND,
SYNC_COMMAND,
RECOVER_DATABASE_COMMAND,
RECOVER_TABLE_COMMAND,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// 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.RedirectStatus;
import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.ColumnIdFlushDaemon;
import org.apache.doris.catalog.ColumnIdFlushDaemon.FlushStatus;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
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 java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
* Represents the command for SHOW CONVERT LIGHT SCHEMA CHANGE PROCESS .
*/
public class ShowConvertLSCCommand extends ShowCommand {

vinlee19 marked this conversation as resolved.
Show resolved Hide resolved
private static final int COLUMN_LENGTH = 30;
private final String dbName;

public ShowConvertLSCCommand(String dbName) {
super(PlanType.SHOW_CONVERT_LSC_COMMAND);
this.dbName = dbName;
}

@Override
public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) throws Exception {
// Check if the user has ADMIN or OPERATOR privileges
if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), PrivPredicate.ADMIN)
&& !Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(),
PrivPredicate.OPERATOR)) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "ADMIN/OPERATOR");
}
return handleShowConvertLSC();
}

@Override
public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
return visitor.visitShowConvertLscCommand(this, context);
}

/**
* get show result set metadata.
*/
public ShowResultSetMetaData getMetaData() {
ShowResultSetMetaData.Builder builder = ShowResultSetMetaData.builder();
Column databaseColumn = new Column("database", ScalarType.createVarcharType(COLUMN_LENGTH));
Column tableNameColumn = new Column("table", ScalarType.createVarcharType(COLUMN_LENGTH));
Column statusColumn = new Column("status", ScalarType.createVarcharType(COLUMN_LENGTH));
builder.addColumn(databaseColumn);
builder.addColumn(tableNameColumn);
builder.addColumn(statusColumn);
return builder.build();
}

private ShowResultSet handleShowConvertLSC() {
ColumnIdFlushDaemon columnIdFlusher = Env.getCurrentEnv().getColumnIdFlusher();
columnIdFlusher.readLock();
List<List<String>> rows;
try {
Map<String, Map<String, FlushStatus>> resultCollector =
columnIdFlusher.getResultCollector();
rows = new ArrayList<>();
if (dbName != null) {
Map<String, ColumnIdFlushDaemon.FlushStatus> tblNameToStatus = resultCollector.get(dbName);
if (tblNameToStatus != null) {
tblNameToStatus.forEach((tblName, status) -> {
List<String> row = Arrays.asList(dbName, tblName, status.getMsg());
rows.add(row);
});
}
} else {
resultCollector.forEach((dbName, tblNameToStatus) ->
tblNameToStatus.forEach((tblName, status) -> {
List<String> row = Arrays.asList(dbName, tblName, status.getMsg());
rows.add(row);
}));
}
} finally {
columnIdFlusher.readUnlock();
}
return new ShowResultSet(getMetaData(), rows);
}

@Override
public RedirectStatus toRedirectStatus() {
return RedirectStatus.FORWARD_NO_SYNC;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
import org.apache.doris.nereids.trees.plans.commands.ShowCollationCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowConfigCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowConstraintsCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowConvertLSCCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowCreateCatalogCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowCreateDatabaseCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowCreateMTMVCommand;
Expand Down Expand Up @@ -695,6 +696,10 @@ default R visitShowQueryProfileCommand(ShowQueryProfileCommand showQueryProfileC
return visitCommand(showQueryProfileCommand, context);
}

default R visitShowConvertLscCommand(ShowConvertLSCCommand showConvertLSCCommand, C context) {
return visitCommand(showConvertLSCCommand, context);
}

default R visitSwitchCommand(SwitchCommand switchCommand, C context) {
return visitCommand(switchCommand, context);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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("show_light_schema_change_process_nereids") {
// can not use qt command since the output change based on cluster and backend ip
sql """drop database if exists testdb;""
sql """create database testdb;"""
checkNereidsExecute("""SHOW CONVERT_LIGHT_SCHEMA_CHANGE_PROCESS FROM testdb;""")
checkNereidsExecute("""SHOW CONVERT_LIGHT_SCHEMA_CHANGE_PROCESS;""")
sql """drop database if exists testdb;""
}
Loading