Skip to content

Commit

Permalink
[Enhancement] (nereids)implement showQueryProfileCommand in nereids
Browse files Browse the repository at this point in the history
  • Loading branch information
rijeshkp committed Dec 11, 2024
1 parent 71f96e6 commit 80f20f8
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ supportedShowStatement
| SHOW TABLE CREATION ((FROM | IN) database=multipartIdentifier)?
(LIKE STRING_LITERAL)? #showTableCreation
| SHOW TABLET STORAGE FORMAT VERBOSE? #showTabletStorageFormat
| SHOW QUERY PROFILE queryIdPath=STRING_LITERAL #showQueryProfile
;

supportedLoadStatement
Expand Down Expand Up @@ -359,7 +360,6 @@ unsupportedShowStatement
(FROM |IN) tableName=multipartIdentifier
((FROM | IN) database=multipartIdentifier)? #showIndex
| SHOW TRANSACTION ((FROM | IN) database=multipartIdentifier)? wildWhere? #showTransaction
| SHOW QUERY PROFILE queryIdPath=STRING_LITERAL #showQueryProfile
| SHOW CACHE HOTSPOT tablePath=STRING_LITERAL #showCacheHotSpot
| SHOW SYNC JOB ((FROM | IN) database=multipartIdentifier)? #showSyncJob
| SHOW CATALOG RECYCLE BIN wildWhere? #showCatalogRecycleBin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@
import org.apache.doris.nereids.DorisParser.ShowProcContext;
import org.apache.doris.nereids.DorisParser.ShowProcedureStatusContext;
import org.apache.doris.nereids.DorisParser.ShowProcessListContext;
import org.apache.doris.nereids.DorisParser.ShowQueryProfileContext;
import org.apache.doris.nereids.DorisParser.ShowReplicaDistributionContext;
import org.apache.doris.nereids.DorisParser.ShowRepositoriesContext;
import org.apache.doris.nereids.DorisParser.ShowRolesContext;
Expand Down Expand Up @@ -571,6 +572,7 @@
import org.apache.doris.nereids.trees.plans.commands.ShowProcCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowProcedureStatusCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowProcessListCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowQueryProfileCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowReplicaDistributionCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowRepositoriesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowRolesCommand;
Expand Down Expand Up @@ -5014,5 +5016,11 @@ public LogicalPlan visitAdminShowTabletStorageFormat(AdminShowTabletStorageForma
public LogicalPlan visitShowTabletStorageFormat(ShowTabletStorageFormatContext ctx) {
return new ShowTabletStorageFormatCommand(ctx.VERBOSE() != null);
}

@Override
public LogicalPlan visitShowQueryProfile(ShowQueryProfileContext ctx) {
String queryIdPath = stripQuotes(ctx.queryIdPath.getText());
return new ShowQueryProfileCommand(queryIdPath);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -251,5 +251,6 @@ public enum PlanType {
CREATE_WORKLOAD_GROUP_COMMAND,
CREATE_FILE_COMMAND,
CREATE_ROUTINE_LOAD_COMMAND,
SHOW_TABLE_CREATION_COMMAND
SHOW_TABLE_CREATION_COMMAND,
SHOW_QUERY_PROFILE_COMMAND
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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.Env;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.Config;
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.StmtExecutor;

/**
* Represents the command for SHOW COLLATION
*/
public class ShowQueryProfileCommand extends ShowCommand {
String queryIdPath;

public ShowQueryProfileCommand(String queryIdPath) {
super(PlanType.SHOW_QUERY_PROFILE_COMMAND);
this.queryIdPath = queryIdPath;
}

@Override
public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) throws Exception {
String selfHost = Env.getCurrentEnv().getSelfNode().getHost();
int httpPort = Config.http_port;
String terminalMsg = String.format(
"try visit http://%s:%d/QueryProfile, show query/load profile syntax is a deprecated feature",
selfHost, httpPort);
throw new AnalysisException(terminalMsg);
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
import org.apache.doris.nereids.trees.plans.commands.ShowProcCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowProcedureStatusCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowProcessListCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowQueryProfileCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowReplicaDistributionCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowRepositoriesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowRolesCommand;
Expand Down Expand Up @@ -621,4 +622,9 @@ default R visitShowTabletStorageFormatCommand(ShowTabletStorageFormatCommand sho
C context) {
return visitCommand(showTabletStorageFormatCommand, context);
}

default R visitShowQueryProfileCommand(ShowQueryProfileCommand showQueryProfileCommand,
C context) {
return visitCommand(showQueryProfileCommand, context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ suite("test_show_commands_nereids") {
checkNereidsExecute("""show triggers;""")
checkNereidsExecute("""show events;""")
checkNereidsExecute("""show load profile "/";""")
checkNereidsExecute("""show query profile "/";""")
}

0 comments on commit 80f20f8

Please sign in to comment.