Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions fe/fe-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,11 @@ under the License.
<artifactId>lombok</artifactId>
</dependency>

<dependency>
<groupId>hu.webarticum</groupId>
<artifactId>tree-printer</artifactId>
</dependency>

</dependencies>

<build>
Expand Down
30 changes: 21 additions & 9 deletions fe/fe-core/src/main/cup/sql_parser.cup
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ terminal String KW_ADD, KW_ADMIN, KW_AFTER, KW_AGGREGATE, KW_ALL, KW_ALTER, KW_A
KW_ELSE, KW_ENABLE, KW_END, KW_ENGINE, KW_ENGINES, KW_ENTER, KW_ERRORS, KW_EVENTS, KW_EXCEPT, KW_EXCLUDE,
KW_EXISTS, KW_EXPORT, KW_EXTERNAL, KW_EXTRACT,
KW_FALSE, KW_FEATURE, KW_FOLLOWER, KW_FOLLOWING, KW_FREE, KW_FROM, KW_FILE, KW_FILTER, KW_FIRST, KW_FLOAT, KW_FOR, KW_FORCE, KW_FORMAT, KW_FRONTEND, KW_FRONTENDS, KW_FULL, KW_FUNCTION, KW_FUNCTIONS,
KW_GLOBAL, KW_GRANT, KW_GRANTS, KW_GROUP, KW_GROUPING,
KW_GLOBAL, KW_GRANT, KW_GRANTS, KW_GRAPH, KW_GROUP, KW_GROUPING,
KW_HASH, KW_HAVING, KW_HDFS, KW_HELP,KW_HLL, KW_HLL_UNION, KW_HOUR, KW_HUB,
KW_IDENTIFIED, KW_IF, KW_IN, KW_INDEX, KW_INDEXES, KW_INFILE, KW_INSTALL,
KW_INNER, KW_INSERT, KW_INT, KW_INTERMEDIATE, KW_INTERSECT, KW_INTERVAL, KW_INTO, KW_IS, KW_ISNULL, KW_ISOLATION,
Expand All @@ -252,7 +252,7 @@ terminal String KW_ADD, KW_ADMIN, KW_AFTER, KW_AGGREGATE, KW_ALL, KW_ALTER, KW_A
KW_PARTITION, KW_PARTITIONS, KW_PASSWORD, KW_PATH, KW_PAUSE, KW_PIPE, KW_PRECEDING,
KW_PLUGIN, KW_PLUGINS,
KW_PRIMARY,
KW_PROC, KW_PROCEDURE, KW_PROCESSLIST, KW_PROPERTIES, KW_PROPERTY,
KW_PROC, KW_PROCEDURE, KW_PROCESSLIST, KW_PROFILE, KW_PROPERTIES, KW_PROPERTY,
KW_QUERY, KW_QUOTA,
KW_RANDOM, KW_RANGE, KW_READ, KW_RECOVER, KW_REGEXP, KW_RELEASE, KW_RENAME,
KW_REPAIR, KW_REPEATABLE, KW_REPOSITORY, KW_REPOSITORIES, KW_REPLACE, KW_REPLACE_IF_NOT_NULL, KW_REPLICA, KW_RESOURCE, KW_RESOURCES, KW_RESTORE, KW_RETURNS, KW_RESUME, KW_REVOKE,
Expand Down Expand Up @@ -478,7 +478,7 @@ nonterminal IndexDef.IndexType opt_index_type;

nonterminal ShowAlterStmt.AlterType opt_alter_type;
nonterminal Boolean opt_builtin;
nonterminal Boolean opt_verbose;
nonterminal ExplainOptions opt_explain_options;

nonterminal Boolean opt_tmp;

Expand Down Expand Up @@ -2494,6 +2494,10 @@ show_param ::=
{:
RESULT = new ShowTransactionStmt(dbName, parser.where);
:}
| KW_QUERY KW_PROFILE STRING_LITERAL:queryIdPath
{:
RESULT = new ShowQueryProfileStmt(queryIdPath);
:}
;

opt_tmp ::=
Expand Down Expand Up @@ -2633,13 +2637,17 @@ opt_builtin ::=
:}
;

opt_verbose ::=
opt_explain_options ::=
{:
RESULT = false;
RESULT = new ExplainOptions(false, false);
:}
| KW_VERBOSE
{:
RESULT = true;
RESULT = new ExplainOptions(true, false);
:}
| KW_GRAPH
{:
RESULT = new ExplainOptions(false, true);
:}
;

Expand All @@ -2653,14 +2661,14 @@ describe_stmt ::=
{:
RESULT = new DescribeStmt(table, true);
:}
| describe_command opt_verbose:isVerbose query_stmt:query
| describe_command opt_explain_options:options query_stmt:query
{:
query.setIsExplain(true, isVerbose);
query.setIsExplain(options);
RESULT = query;
:}
| describe_command insert_stmt:stmt
{:
stmt.getQueryStmt().setIsExplain(true);
stmt.getQueryStmt().setIsExplain(new ExplainOptions(true, false));
RESULT = stmt;
:}
;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change KW_DESCRIBE to KW_EXPLAIN

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KW_DESCRIBE means both "desc" and "explain",
see fe/fe-core/src/main/jflex/sql_scanner.flex

Expand Down Expand Up @@ -4735,6 +4743,8 @@ keyword ::=
{: RESULT = id; :}
| KW_PATH:id
{: RESULT = id; :}
| KW_PROFILE:id
{: RESULT = id; :}
| KW_FUNCTION:id
{: RESULT = id; :}
| KW_END:id
Expand All @@ -4753,6 +4763,8 @@ keyword ::=
{: RESULT = id; :}
| KW_GLOBAL:id
{: RESULT = id; :}
| KW_GRAPH:id
{: RESULT = id; :}
| KW_HASH:id
{: RESULT = id; :}
| KW_HELP:id
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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;

public class ExplainOptions {

private boolean isVerbose;
private boolean isGraph;

public ExplainOptions(boolean isVerbose, boolean isGraph) {
this.isVerbose = isVerbose;
this.isGraph = isGraph;
}

public boolean isVerbose() {
return isVerbose;
}

public boolean isGraph() {
return isGraph;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -509,12 +509,12 @@ public AssertNumRowsElement getAssertNumRowsElement() {
return assertNumRowsElement;
}

public void setIsExplain(boolean isExplain) {
this.isExplain = isExplain;
public void setIsExplain(ExplainOptions options) {
this.explainOptions = options;
}

public boolean isExplain() {
return isExplain;
return this.explainOptions != null;
}

public boolean hasLimitClause() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
// 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.common.UserException;
import org.apache.doris.qe.ShowResultSetMetaData;

import com.google.common.base.Strings;

// For stmt like:
// show query profile "/"; # list all saving query ids
// show query profile "/e0f7390f5363419e-b416a2a79996083e" # show graph of fragments of the query
// show query profile "/e0f7390f5363419e-b416a2a79996083e/0" # show instance list of the specified fragment
// show query profile "/e0f7390f5363419e-b416a2a79996083e/0/e0f7390f5363419e-b416a2a799960906" # show graph of the instance
public class ShowQueryProfileStmt extends ShowStmt {
// This should be same as ProfileManager.PROFILE_HEADERS
private static final ShowResultSetMetaData META_DATA_QUERYIDS =
ShowResultSetMetaData.builder()
.addColumn(new Column("QueryId", ScalarType.createVarchar(128)))
.addColumn(new Column("User", ScalarType.createVarchar(128)))
.addColumn(new Column("DefaultDb", ScalarType.createVarchar(128)))
.addColumn(new Column("SQL", ScalarType.createVarchar(65535)))
.addColumn(new Column("QueryType", ScalarType.createVarchar(128)))
.addColumn(new Column("StartTime", ScalarType.createVarchar(128)))
.addColumn(new Column("EndTime", ScalarType.createVarchar(128)))
.addColumn(new Column("TotalTime", ScalarType.createVarchar(128)))
.addColumn(new Column("QueryState", ScalarType.createVarchar(128)))
.build();

private static final ShowResultSetMetaData META_DATA_FRAGMENTS =
ShowResultSetMetaData.builder()
.addColumn(new Column("Fragments", ScalarType.createVarchar(65535)))
.build();
private static final ShowResultSetMetaData META_DATA_INSTANCES =
ShowResultSetMetaData.builder()
.addColumn(new Column("Instances", ScalarType.createVarchar(128)))
.addColumn(new Column("Host", ScalarType.createVarchar(64)))
.addColumn(new Column("ActiveTime", ScalarType.createVarchar(64)))
.build();
private static final ShowResultSetMetaData META_DATA_SINGLE_INSTANCE =
ShowResultSetMetaData.builder()
.addColumn(new Column("Instance", ScalarType.createVarchar(65535)))
.build();

public enum PathType {
QUERY_IDS,
FRAGMETNS,
INSTANCES,
SINGLE_INSTANCE
}

private String queryIdPath;
private PathType pathType;

private String queryId = "";
private String fragmentId = "";
private String instanceId = "";

public ShowQueryProfileStmt(String queryIdPath) {
this.queryIdPath = queryIdPath;
}

public PathType getPathType() {
return pathType;
}

public String getQueryId() {
return queryId;
}

public String getFragmentId() {
return fragmentId;
}

public String getInstanceId() {
return instanceId;
}

@Override
public void analyze(Analyzer analyzer) throws UserException {
super.analyze(analyzer);
if (Strings.isNullOrEmpty(queryIdPath)) {
// list all query ids
pathType = PathType.QUERY_IDS;
return;
}

if (!queryIdPath.startsWith("/")) {
throw new AnalysisException("Query path must starts with '/'");
}
pathType = PathType.QUERY_IDS;
String[] parts = queryIdPath.split("/");
if (parts.length > 4) {
throw new AnalysisException("Query path must in format '/queryId/fragmentId/instanceId'");
}

for (int i = 0; i < parts.length; i++) {
switch (i) {
case 0:
pathType = PathType.QUERY_IDS;
continue;
case 1:
queryId = parts[i];
pathType = PathType.FRAGMETNS;
break;
case 2:
fragmentId = parts[i];
pathType = PathType.INSTANCES;
break;
case 3:
instanceId = parts[i];
pathType = PathType.SINGLE_INSTANCE;
break;
default:
break;
}
}
}

@Override
public String toSql() {
StringBuilder sb = new StringBuilder("SHOW QUERY PROFILE ").append(queryIdPath);
return sb.toString();
}

@Override
public String toString() {
return toSql();
}

@Override
public ShowResultSetMetaData getMetaData() {
switch (pathType) {
case QUERY_IDS:
return META_DATA_QUERYIDS;
case FRAGMETNS:
return META_DATA_FRAGMENTS;
case INSTANCES:
return META_DATA_INSTANCES;
case SINGLE_INSTANCE:
return META_DATA_SINGLE_INSTANCE;
default:
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ public abstract class StatementBase implements ParseNode {

private String clusterName;

// True if this QueryStmt is the top level query from an EXPLAIN <query>
protected boolean isExplain = false;
// True if the describe_stmt print verbose information, if `isVerbose` is true, `isExplain` must be set to true.
protected boolean isVerbose = false;
// Set this variable if this QueryStmt is the top level query from an EXPLAIN <query>
protected ExplainOptions explainOptions = null;

/////////////////////////////////////////
// BEGIN: Members that need to be reset()
Expand All @@ -60,7 +58,7 @@ protected StatementBase() { }
*/
protected StatementBase(StatementBase other) {
analyzer = other.analyzer;
isExplain = other.isExplain;
explainOptions = other.explainOptions;
}

/**
Expand All @@ -72,22 +70,40 @@ protected StatementBase(StatementBase other) {
*/
public void analyze(Analyzer analyzer) throws AnalysisException, UserException {
if (isAnalyzed()) return;
if (isExplain) analyzer.setIsExplain();
this.analyzer = analyzer;
if (Strings.isNullOrEmpty(analyzer.getClusterName())) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_CLUSTER_NO_SELECT_CLUSTER);
}
this.clusterName = analyzer.getClusterName();
}

public Analyzer getAnalyzer() { return analyzer; }
public boolean isAnalyzed() { return analyzer != null; }
public void setIsExplain(boolean isExplain, boolean isVerbose) { this.isExplain = isExplain; this.isVerbose = isVerbose;}
public boolean isExplain() { return isExplain; }
public boolean isVerbose() { return isVerbose; }
public Analyzer getAnalyzer() {
return analyzer;
}

public boolean isAnalyzed() {
return analyzer != null;
}

public void setIsExplain(ExplainOptions options) {
this.explainOptions = options;
}

public boolean isExplain() {
return this.explainOptions != null;
}

public boolean isVerbose() {
return explainOptions != null && explainOptions.isVerbose();
}

public ExplainOptions getExplainOptions() {
return explainOptions;
}

/*
* Print SQL syntax corresponding to this node.
*
*
* @see org.apache.doris.parser.ParseNode#toSql()
*/
@Override
Expand Down
Loading