This is an automated email from the ASF dual-hosted git repository.
starocean999 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 854512ff5aa [Feat](Nereids) support show variables and show view
command (#43271)
854512ff5aa is described below
commit 854512ff5aa078fc3e7fdf9610abc366e920accb
Author: starocean999 <[email protected]>
AuthorDate: Fri Nov 8 09:31:21 2024 +0800
[Feat](Nereids) support show variables and show view command (#43271)
migrate ShowVariablesStmt and ShowViewStmt to nereids
---
.../antlr4/org/apache/doris/nereids/DorisParser.g4 | 14 +-
.../java/org/apache/doris/catalog/Database.java | 13 ++
.../doris/nereids/parser/LogicalPlanBuilder.java | 47 +++++++
.../apache/doris/nereids/trees/plans/PlanType.java | 2 +
.../nereids/trees/plans/commands/Command.java | 14 ++
.../nereids/trees/plans/commands/ShowCommand.java | 53 ++++++++
.../trees/plans/commands/ShowVariablesCommand.java | 74 +++++++++++
.../trees/plans/commands/ShowViewCommand.java | 146 +++++++++++++++++++++
.../trees/plans/commands/info/TableNameInfo.java | 31 +++++
.../trees/plans/visitor/CommandVisitor.java | 10 ++
.../java/org/apache/doris/qe/StmtExecutor.java | 5 +
.../ddl/show_variables/show_variables_command.out | 10 ++
.../nereids_p0/ddl/show_view/show_view_command.out | 17 +++
.../show_variables/show_variables_command.groovy | 26 ++++
.../ddl/show_view/show_view_command.groovy | 94 +++++++++++++
15 files changed, 551 insertions(+), 5 deletions(-)
diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
index 6cd4010bdcb..b7fa04c2ef7 100644
--- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
+++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
@@ -50,11 +50,12 @@ statementBase
| supportedCreateStatement #supportedCreateStatementAlias
| supportedAlterStatement #supportedAlterStatementAlias
| materializedViewStatement #materializedViewStatementAlias
- | supportedJobStatement #supportedJobStatementAlias
+ | supportedJobStatement #supportedJobStatementAlias
| constraintStatement #constraintStatementAlias
| supportedDropStatement #supportedDropStatementAlias
| supportedSetStatement #supportedSetStatementAlias
| supportedUnsetStatement #supportedUnsetStatementAlias
+ | supportedShowStatement #supportedShowStatementAlias
| unsupportedStatement #unsupported
;
@@ -189,6 +190,13 @@ supportedDropStatement
: DROP CATALOG RECYCLE BIN WHERE idType=STRING_LITERAL EQ id=INTEGER_VALUE
#dropCatalogRecycleBin
;
+supportedShowStatement
+ : SHOW (GLOBAL | SESSION | LOCAL)? VARIABLES wildWhere?
#showVariables
+ | SHOW VIEW
+ (FROM |IN) tableName=multipartIdentifier
+ ((FROM | IN) database=identifier)?
#showView
+ ;
+
unsupportedOtherStatement
: HELP mark=identifierOrText
#help
| INSTALL PLUGIN FROM source=identifierOrText properties=propertyClause?
#installPlugin
@@ -224,7 +232,6 @@ unsupportedShowStatement
| SHOW STORAGE (VAULT | VAULTS)
#showStorageVault
| SHOW CREATE REPOSITORY FOR identifier
#showCreateRepository
| SHOW WHITELIST
#showWhitelist
- | SHOW (GLOBAL | SESSION | LOCAL)? VARIABLES wildWhere?
#showVariables
| SHOW OPEN TABLES ((FROM | IN) database=multipartIdentifier)? wildWhere?
#showOpenTables
| SHOW TABLE STATUS ((FROM | IN) database=multipartIdentifier)? wildWhere?
#showTableStatus
| SHOW FULL? TABLES ((FROM | IN) database=multipartIdentifier)? wildWhere?
#showTables
@@ -302,9 +309,6 @@ unsupportedShowStatement
| SHOW (KEY | KEYS | INDEX | INDEXES)
(FROM |IN) tableName=multipartIdentifier
((FROM | IN) database=multipartIdentifier)?
#showIndex
- | SHOW VIEW
- (FROM |IN) tableName=multipartIdentifier
- ((FROM | IN) database=multipartIdentifier)?
#showView
| SHOW TRANSACTION ((FROM | IN) database=multipartIdentifier)? wildWhere?
#showTransaction
| SHOW QUERY PROFILE queryIdPath=STRING_LITERAL
#showQueryProfile
| SHOW LOAD PROFILE loadIdPath=STRING_LITERAL
#showLoadProfile
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java
index 11a60360426..61023caf546 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java
@@ -497,6 +497,19 @@ public class Database extends MetaObject implements
Writable, DatabaseIf<Table>,
return views;
}
+ public List<Table> getViewsOnIdOrder() {
+ List<Table> tables = idToTable.values().stream()
+ .sorted(Comparator.comparing(Table::getId))
+ .collect(Collectors.toList());
+ List<Table> views = new ArrayList<>();
+ for (Table table : tables) {
+ if (table.getType() == TableType.VIEW) {
+ views.add(table);
+ }
+ }
+ return views;
+ }
+
/**
* this method is used for get existed table list by table id list, if
table not exist, just ignore it.
*/
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
index 1af48c8a597..8362d002d2b 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
@@ -30,11 +30,13 @@ import org.apache.doris.analysis.UserIdentity;
import org.apache.doris.catalog.AggregateType;
import org.apache.doris.catalog.BuiltinAggregateFunctions;
import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.InfoSchemaDb;
import org.apache.doris.catalog.KeysType;
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.common.Config;
import org.apache.doris.common.FeConstants;
import org.apache.doris.common.Pair;
+import org.apache.doris.datasource.InternalCatalog;
import org.apache.doris.job.common.IntervalUnit;
import org.apache.doris.load.loadv2.LoadTask;
import org.apache.doris.mtmv.MTMVPartitionInfo.MTMVPartitionType;
@@ -194,6 +196,8 @@ import
org.apache.doris.nereids.DorisParser.ShowConstraintContext;
import org.apache.doris.nereids.DorisParser.ShowCreateMTMVContext;
import org.apache.doris.nereids.DorisParser.ShowCreateProcedureContext;
import org.apache.doris.nereids.DorisParser.ShowProcedureStatusContext;
+import org.apache.doris.nereids.DorisParser.ShowVariablesContext;
+import org.apache.doris.nereids.DorisParser.ShowViewContext;
import org.apache.doris.nereids.DorisParser.SimpleColumnDefContext;
import org.apache.doris.nereids.DorisParser.SimpleColumnDefsContext;
import org.apache.doris.nereids.DorisParser.SingleStatementContext;
@@ -423,6 +427,8 @@ import
org.apache.doris.nereids.trees.plans.commands.ShowConstraintsCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowCreateMTMVCommand;
import
org.apache.doris.nereids.trees.plans.commands.ShowCreateProcedureCommand;
import
org.apache.doris.nereids.trees.plans.commands.ShowProcedureStatusCommand;
+import org.apache.doris.nereids.trees.plans.commands.ShowVariablesCommand;
+import org.apache.doris.nereids.trees.plans.commands.ShowViewCommand;
import
org.apache.doris.nereids.trees.plans.commands.UnsetDefaultStorageVaultCommand;
import org.apache.doris.nereids.trees.plans.commands.UnsetVariableCommand;
import org.apache.doris.nereids.trees.plans.commands.UnsupportedCommand;
@@ -3999,4 +4005,45 @@ public class LogicalPlanBuilder extends
DorisParserBaseVisitor<Object> {
public SetDefaultStorageVaultCommand
visitSetDefaultStorageVault(SetDefaultStorageVaultContext ctx) {
return new
SetDefaultStorageVaultCommand(stripQuotes(ctx.identifier().getText()));
}
+
+ @Override
+ public LogicalPlan visitShowVariables(ShowVariablesContext ctx) {
+ SetType type = SetType.DEFAULT;
+ if (ctx.GLOBAL() != null) {
+ type = SetType.GLOBAL;
+ } else if (ctx.LOCAL() != null || ctx.SESSION() != null) {
+ type = SetType.SESSION;
+ }
+ if (ctx.wildWhere() != null) {
+ if (ctx.wildWhere().LIKE() != null) {
+ return new ShowVariablesCommand(type,
stripQuotes(ctx.wildWhere().STRING_LITERAL().getText()));
+ } else {
+ StringBuilder sb = new StringBuilder();
+ sb.append("SELECT `VARIABLE_NAME` AS `Variable_name`,
`VARIABLE_VALUE` AS `Value` FROM ");
+
sb.append("`").append(InternalCatalog.INTERNAL_CATALOG_NAME).append("`");
+ sb.append(".");
+ sb.append("`").append(InfoSchemaDb.DATABASE_NAME).append("`");
+ sb.append(".");
+ if (type == SetType.GLOBAL) {
+ sb.append("`global_variables` ");
+ } else {
+ sb.append("`session_variables` ");
+ }
+ sb.append(getOriginSql(ctx.wildWhere()));
+ return new NereidsParser().parseSingle(sb.toString());
+ }
+ } else {
+ return new ShowVariablesCommand(type, null);
+ }
+ }
+
+ @Override
+ public ShowViewCommand visitShowView(ShowViewContext ctx) {
+ List<String> tableNameParts = visitMultipartIdentifier(ctx.tableName);
+ String databaseName = null;
+ if (ctx.database != null) {
+ databaseName = stripQuotes(ctx.database.getText());
+ }
+ return new ShowViewCommand(databaseName, new
TableNameInfo(tableNameParts));
+ }
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java
index d7a219cc7e4..b9fb9e96f87 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java
@@ -176,5 +176,7 @@ public enum PlanType {
PREPARED_COMMAND,
EXECUTE_COMMAND,
SHOW_CONFIG_COMMAND,
+ SHOW_VARIABLES_COMMAND,
+ SHOW_VIEW_COMMAND,
REPLAY_COMMAND
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/Command.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/Command.java
index 4dcf3017097..d1b8e5a263c 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/Command.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/Command.java
@@ -17,6 +17,8 @@
package org.apache.doris.nereids.trees.plans.commands;
+import org.apache.doris.common.Config;
+import org.apache.doris.common.DdlException;
import org.apache.doris.nereids.memo.GroupExpression;
import org.apache.doris.nereids.properties.LogicalProperties;
import org.apache.doris.nereids.trees.expressions.Expression;
@@ -116,4 +118,16 @@ public abstract class Command extends AbstractPlan
implements LogicalPlan, Block
public Plan withGroupExpression(Optional<GroupExpression> groupExpression)
{
throw new RuntimeException("Command do not implement
withGroupExpression");
}
+
+ public void verifyCommandSupported() throws DdlException {
+ // check command has been supported in cloud mode
+ if (Config.isCloudMode()) {
+ checkSupportedInCloudMode();
+ }
+ }
+
+ // check if the command is supported in cloud mode
+ // see checkStmtSupported() in
fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
+ // override this method if the command is not supported in cloud mode
+ protected void checkSupportedInCloudMode() throws DdlException {}
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCommand.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCommand.java
new file mode 100644
index 00000000000..3ce40cdd04d
--- /dev/null
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCommand.java
@@ -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.nereids.trees.plans.commands;
+
+import org.apache.doris.analysis.StmtType;
+import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.ShowResultSet;
+import org.apache.doris.qe.StmtExecutor;
+
+/**
+ * base class for all show commands
+ */
+public abstract class ShowCommand extends Command implements NoForward {
+ public ShowCommand(PlanType type) {
+ super(type);
+ }
+
+ @Override
+ public StmtType stmtType() {
+ return StmtType.SHOW;
+ }
+
+ @Override
+ public void run(ConnectContext ctx, StmtExecutor executor) throws
Exception {
+ ShowResultSet resultSet = doRun(ctx, executor);
+ if (resultSet != null) {
+ if (executor.isProxy()) {
+ executor.setProxyShowResultSet(resultSet);
+ } else {
+ executor.sendResultSet(resultSet);
+ }
+ }
+ }
+
+ public abstract ShowResultSet doRun(ConnectContext ctx, StmtExecutor
executor) throws Exception;
+
+}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowVariablesCommand.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowVariablesCommand.java
new file mode 100644
index 00000000000..0a24167a2a8
--- /dev/null
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowVariablesCommand.java
@@ -0,0 +1,74 @@
+// 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.SetType;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.common.CaseSensibility;
+import org.apache.doris.common.PatternMatcher;
+import org.apache.doris.common.PatternMatcherWrapper;
+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 org.apache.doris.qe.VariableMgr;
+
+import java.util.List;
+
+/**
+ * ShowVariablesCommand
+ */
+public class ShowVariablesCommand extends ShowCommand {
+ private static final String NAME_COL = "Variable_name";
+ private static final String VALUE_COL = "Value";
+ private static final String DEFAULT_VALUE_COL = "Default_Value";
+ private static final String CHANGED_COL = "Changed";
+ private static final ShowResultSetMetaData META_DATA =
ShowResultSetMetaData.builder()
+ .addColumn(new Column(NAME_COL, ScalarType.createVarchar(20)))
+ .addColumn(new Column(VALUE_COL, ScalarType.createVarchar(20)))
+ .addColumn(new Column(DEFAULT_VALUE_COL,
ScalarType.createVarchar(20)))
+ .addColumn(new Column(CHANGED_COL, ScalarType.createVarchar(20)))
+ .build();
+
+ private final SetType type;
+ private final String pattern;
+
+ public ShowVariablesCommand(SetType type, String pattern) {
+ super(PlanType.SHOW_VARIABLES_COMMAND);
+ this.type = type == null ? SetType.DEFAULT : type;
+ this.pattern = pattern;
+ }
+
+ @Override
+ public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
+ return visitor.visitShowVariablesCommand(this, context);
+ }
+
+ @Override
+ public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor)
throws Exception {
+ PatternMatcher matcher = null;
+ if (pattern != null) {
+ matcher = PatternMatcherWrapper.createMysqlPattern(pattern,
CaseSensibility.VARIABLES.getCaseSensibility());
+ }
+ List<List<String>> rows = VariableMgr.dump(type,
ctx.getSessionVariable(), matcher);
+ return new ShowResultSet(META_DATA, rows);
+ }
+}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowViewCommand.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowViewCommand.java
new file mode 100644
index 00000000000..08a2d3baae4
--- /dev/null
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowViewCommand.java
@@ -0,0 +1,146 @@
+// 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.Database;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.catalog.Table;
+import org.apache.doris.catalog.View;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+import org.apache.doris.common.util.Util;
+import org.apache.doris.mysql.privilege.PrivPredicate;
+import org.apache.doris.nereids.NereidsPlanner;
+import org.apache.doris.nereids.StatementContext;
+import org.apache.doris.nereids.parser.NereidsParser;
+import org.apache.doris.nereids.properties.PhysicalProperties;
+import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.nereids.trees.plans.commands.info.TableNameInfo;
+import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
+import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
+import org.apache.doris.nereids.util.PlanUtils;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.OriginStatement;
+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 com.google.common.collect.Lists;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * ShowViewCommand
+ */
+public class ShowViewCommand extends ShowCommand {
+ private static final ShowResultSetMetaData META_DATA =
ShowResultSetMetaData.builder()
+ .addColumn(new Column("View", ScalarType.createVarchar(30)))
+ .addColumn(new Column("Create View",
ScalarType.createVarchar(65535)))
+ .build();
+
+ private final String db;
+ private final TableNameInfo tbl;
+ private List<View> matchViews = Lists.newArrayList();
+
+ public ShowViewCommand(String db, TableNameInfo tbl) {
+ super(PlanType.SHOW_VIEW_COMMAND);
+ this.db = db;
+ this.tbl = tbl;
+ }
+
+ @Override
+ public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
+ return visitor.visitShowViewCommand(this, context);
+ }
+
+ private void validate(ConnectContext ctx) throws Exception {
+ if (!Strings.isNullOrEmpty(db)) {
+ // if user specify the `from db`, overwrite the db in `tbl` with
this db.
+ // for example:
+ // show view from db1.tbl1 from db2;
+ // will be rewrote to:
+ // show view from db2.tbl1;
+ // this act same as in MySQL
+ tbl.setDb(db);
+ }
+ tbl.analyze(ctx);
+ // disallow external catalog
+ Util.prohibitExternalCatalog(tbl.getCtl(),
this.getClass().getSimpleName());
+
+ String dbName = tbl.getDb();
+ if (!Env.getCurrentEnv().getAccessManager().checkTblPriv(
+ ConnectContext.get(), tbl.getCtl(), dbName, tbl.getTbl(),
PrivPredicate.SHOW)) {
+
ErrorReport.reportAnalysisException(ErrorCode.ERR_TABLEACCESS_DENIED_ERROR,
"SHOW VIEW",
+ ConnectContext.get().getQualifiedUser(),
+ ConnectContext.get().getRemoteIP(),
+ dbName + ": " + tbl.getTbl());
+ }
+
+ Database database =
Env.getCurrentInternalCatalog().getDbOrAnalysisException(dbName);
+ database.getOlapTableOrAnalysisException(tbl.getTbl());
+ for (Table table : database.getViewsOnIdOrder()) {
+ View view = (View) table;
+ // get table refs instead of get tables because it don't need to
check table's validity
+ List<TableNameInfo> tableNameInfos = getTableNames(ctx,
view.getInlineViewDef());
+ for (TableNameInfo tableNameInfo : tableNameInfos) {
+ tableNameInfo.analyze(ctx);
+ if (tableNameInfo.equals(tbl)) {
+ matchViews.add(view);
+ }
+ }
+ }
+ }
+
+ private List<TableNameInfo> getTableNames(ConnectContext ctx, String sql) {
+ LogicalPlan unboundMvPlan = new NereidsParser().parseSingle(sql);
+ StatementContext statementContext = new StatementContext(ctx,
+ new OriginStatement(sql, 0));
+ NereidsPlanner planner = new NereidsPlanner(statementContext);
+ if (ctx.getStatementContext() == null) {
+ ctx.setStatementContext(statementContext);
+ }
+ planner.planWithLock(unboundMvPlan, PhysicalProperties.ANY,
ExplainCommand.ExplainLevel.ANALYZED_PLAN);
+ LogicalPlan logicalPlan = (LogicalPlan)
planner.getCascadesContext().getRewritePlan();
+
+ return PlanUtils.getLogicalScanFromRootPlan(logicalPlan).stream()
+ .map(plan -> new
TableNameInfo(plan.getTable().getFullQualifiers())).collect(Collectors.toList());
+ }
+
+ @Override
+ public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor)
throws Exception {
+ validate(ctx);
+ List<List<String>> rows = Lists.newArrayList();
+ for (View view : matchViews) {
+ view.readLock();
+ try {
+ List<String> createViewStmt = Lists.newArrayList();
+ Env.getDdlStmt(view, createViewStmt, null, null, false, true
/* hide password */, -1L);
+ if (!createViewStmt.isEmpty()) {
+ rows.add(Lists.newArrayList(view.getName(),
createViewStmt.get(0)));
+ }
+ } finally {
+ view.readUnlock();
+ }
+ }
+ return new ShowResultSet(META_DATA, rows);
+ }
+}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/TableNameInfo.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/TableNameInfo.java
index 79afb2d1fba..5d0a42e9807 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/TableNameInfo.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/TableNameInfo.java
@@ -129,6 +129,14 @@ public class TableNameInfo implements Writable {
return db;
}
+ /**
+ * set a new database name
+ * @param db new database name
+ */
+ public void setDb(String db) {
+ this.db = db;
+ }
+
/**
* get table name
* @return tableName
@@ -162,4 +170,27 @@ public class TableNameInfo implements Writable {
db = fromJson.db;
tbl = fromJson.tbl;
}
+
+ /**
+ * equals
+ */
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ TableNameInfo that = (TableNameInfo) o;
+ return tbl.equals(that.tbl) && db.equals(that.db) &&
ctl.equals(that.ctl);
+ }
+
+ /**
+ * hashCode
+ */
+ @Override
+ public int hashCode() {
+ return Objects.hash(tbl, db, ctl);
+ }
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
index 814596bca31..e89c9a3a5c5 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
@@ -52,6 +52,8 @@ import
org.apache.doris.nereids.trees.plans.commands.ShowConstraintsCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowCreateMTMVCommand;
import
org.apache.doris.nereids.trees.plans.commands.ShowCreateProcedureCommand;
import
org.apache.doris.nereids.trees.plans.commands.ShowProcedureStatusCommand;
+import org.apache.doris.nereids.trees.plans.commands.ShowVariablesCommand;
+import org.apache.doris.nereids.trees.plans.commands.ShowViewCommand;
import
org.apache.doris.nereids.trees.plans.commands.UnsetDefaultStorageVaultCommand;
import org.apache.doris.nereids.trees.plans.commands.UnsetVariableCommand;
import org.apache.doris.nereids.trees.plans.commands.UnsupportedCommand;
@@ -232,4 +234,12 @@ public interface CommandVisitor<R, C> {
default R visitSetDefaultStorageVault(SetDefaultStorageVaultCommand
setDefaultStorageVaultCommand, C context) {
return visitCommand(setDefaultStorageVaultCommand, context);
}
+
+ default R visitShowVariablesCommand(ShowVariablesCommand
showVariablesCommand, C context) {
+ return visitCommand(showVariablesCommand, context);
+ }
+
+ default R visitShowViewCommand(ShowViewCommand showViewCommand, C context)
{
+ return visitCommand(showViewCommand, context);
+ }
}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
index 0b4f26cadb1..9fa50afa702 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
@@ -338,6 +338,10 @@ public class StmtExecutor {
context.getSessionVariable().getAutoProfileThresholdMs());
}
+ public boolean isProxy() {
+ return isProxy;
+ }
+
public static InternalService.PDataRow getRowStringValue(List<Expr> cols,
FormatOptions options) throws UserException {
if (cols.isEmpty()) {
@@ -746,6 +750,7 @@ public class StmtExecutor {
// t3: observer fe receive editlog creating the table from the
master fe
syncJournalIfNeeded();
try {
+ ((Command) logicalPlan).verifyCommandSupported();
((Command) logicalPlan).run(context, this);
} catch (MustFallbackException e) {
if (LOG.isDebugEnabled()) {
diff --git
a/regression-test/data/nereids_p0/ddl/show_variables/show_variables_command.out
b/regression-test/data/nereids_p0/ddl/show_variables/show_variables_command.out
new file mode 100644
index 00000000000..dc009a38e77
--- /dev/null
+++
b/regression-test/data/nereids_p0/ddl/show_variables/show_variables_command.out
@@ -0,0 +1,10 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !cmd --
+license Apache License, Version 2.0 Apache License, Version 2.0 0
+
+-- !cmd --
+license Apache License, Version 2.0
+
+-- !cmd --
+license Apache License, Version 2.0
+
diff --git
a/regression-test/data/nereids_p0/ddl/show_view/show_view_command.out
b/regression-test/data/nereids_p0/ddl/show_view/show_view_command.out
new file mode 100644
index 00000000000..33e1f8315bf
--- /dev/null
+++ b/regression-test/data/nereids_p0/ddl/show_view/show_view_command.out
@@ -0,0 +1,17 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !cmd --
+ttv1 CREATE VIEW `ttv1` AS select `internal`.`test_show_view_db2`.`t1`.`c1`,
`internal`.`test_show_view_db2`.`t2`.`c2` from
`internal`.`test_show_view_db2`.`t1` join `internal`.`test_show_view_db2`.`t2`
on `internal`.`test_show_view_db2`.`t1`.`c2` =
`internal`.`test_show_view_db2`.`t2`.`c2`;
+ttv2 CREATE VIEW `ttv2` AS select `internal`.`test_show_view_db2`.`t1`.`c1`
from `internal`.`test_show_view_db2`.`t1` where
`internal`.`test_show_view_db2`.`t1`.`c2` = 1;
+
+-- !cmd --
+tv1 CREATE VIEW `tv1` AS select `internal`.`test_show_view_db1`.`t1`.`c1`,
`internal`.`test_show_view_db1`.`t2`.`c2` from
`internal`.`test_show_view_db1`.`t1` join `internal`.`test_show_view_db1`.`t2`
on `internal`.`test_show_view_db1`.`t1`.`c2` =
`internal`.`test_show_view_db1`.`t2`.`c2`;
+tv2 CREATE VIEW `tv2` AS select `internal`.`test_show_view_db1`.`t1`.`c1`
from `internal`.`test_show_view_db1`.`t1` where
`internal`.`test_show_view_db1`.`t1`.`c2` = 1;
+
+-- !cmd --
+ttv1 CREATE VIEW `ttv1` AS select `internal`.`test_show_view_db2`.`t1`.`c1`,
`internal`.`test_show_view_db2`.`t2`.`c2` from
`internal`.`test_show_view_db2`.`t1` join `internal`.`test_show_view_db2`.`t2`
on `internal`.`test_show_view_db2`.`t1`.`c2` =
`internal`.`test_show_view_db2`.`t2`.`c2`;
+ttv2 CREATE VIEW `ttv2` AS select `internal`.`test_show_view_db2`.`t1`.`c1`
from `internal`.`test_show_view_db2`.`t1` where
`internal`.`test_show_view_db2`.`t1`.`c2` = 1;
+
+-- !cmd --
+ttv1 CREATE VIEW `ttv1` AS select `internal`.`test_show_view_db2`.`t1`.`c1`,
`internal`.`test_show_view_db2`.`t2`.`c2` from
`internal`.`test_show_view_db2`.`t1` join `internal`.`test_show_view_db2`.`t2`
on `internal`.`test_show_view_db2`.`t1`.`c2` =
`internal`.`test_show_view_db2`.`t2`.`c2`;
+ttv2 CREATE VIEW `ttv2` AS select `internal`.`test_show_view_db2`.`t1`.`c1`
from `internal`.`test_show_view_db2`.`t1` where
`internal`.`test_show_view_db2`.`t1`.`c2` = 1;
+
diff --git
a/regression-test/suites/nereids_p0/ddl/show_variables/show_variables_command.groovy
b/regression-test/suites/nereids_p0/ddl/show_variables/show_variables_command.groovy
new file mode 100644
index 00000000000..77caf22cacd
--- /dev/null
+++
b/regression-test/suites/nereids_p0/ddl/show_variables/show_variables_command.groovy
@@ -0,0 +1,26 @@
+// 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_variables_command") {
+ sql "UNSET VARIABLE ALL"
+ checkNereidsExecute("""show variables like 'li_ense'""")
+ checkNereidsExecute("""show variables where variable_name like
'li_ense'""")
+ checkNereidsExecute("""show variables where variable_name = 'license'""")
+ qt_cmd("""show variables like 'li_ense'""")
+ qt_cmd("""show variables where variable_name like 'li_ense'""")
+ qt_cmd("""show variables where variable_name = 'license'""")
+}
diff --git
a/regression-test/suites/nereids_p0/ddl/show_view/show_view_command.groovy
b/regression-test/suites/nereids_p0/ddl/show_view/show_view_command.groovy
new file mode 100644
index 00000000000..6054625e8fe
--- /dev/null
+++ b/regression-test/suites/nereids_p0/ddl/show_view/show_view_command.groovy
@@ -0,0 +1,94 @@
+// 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_view_command") {
+ multi_sql """
+ drop database if exists test_show_view_db1;
+ create database test_show_view_db1;
+ use test_show_view_db1;
+
+ drop table if exists t1;
+ drop table if exists t2;
+
+ create table t1
+ (c1 bigint, c2 bigint)
+ ENGINE=OLAP
+ DUPLICATE KEY(c1, c2)
+ COMMENT 'OLAP'
+ DISTRIBUTED BY HASH(c1) BUCKETS 1
+ PROPERTIES (
+ "replication_num" = "1"
+ );
+
+ create table t2
+ (c1 bigint, c2 bigint)
+ ENGINE=OLAP
+ DUPLICATE KEY(c1, c2)
+ COMMENT 'OLAP'
+ DISTRIBUTED BY HASH(c1) BUCKETS 1
+ PROPERTIES (
+ "replication_num" = "1"
+ );
+
+ drop view if exists tv1;
+ drop view if exists tv2;
+
+ create view tv1 as select t1.c1, t2.c2 from t1 join t2 on t1.c2 =
t2.c2;
+ create view tv2 as select t1.c1 from t1 where t1.c2 = 1;
+
+ drop database if exists test_show_view_db2;
+ create database test_show_view_db2;
+ use test_show_view_db2;
+
+ drop table if exists t1;
+ drop table if exists t2;
+
+ create table t1
+ (c1 bigint, c2 bigint)
+ ENGINE=OLAP
+ DUPLICATE KEY(c1, c2)
+ COMMENT 'OLAP'
+ DISTRIBUTED BY HASH(c1) BUCKETS 1
+ PROPERTIES (
+ "replication_num" = "1"
+ );
+
+ create table t2
+ (c1 bigint, c2 bigint)
+ ENGINE=OLAP
+ DUPLICATE KEY(c1, c2)
+ COMMENT 'OLAP'
+ DISTRIBUTED BY HASH(c1) BUCKETS 1
+ PROPERTIES (
+ "replication_num" = "1"
+ );
+
+ drop view if exists ttv1;
+ drop view if exists ttv2;
+
+ create view ttv1 as select t1.c1, t2.c2 from t1 join t2 on t1.c2 =
t2.c2;
+ create view ttv2 as select t1.c1 from t1 where t1.c2 = 1;
+ """
+ checkNereidsExecute("""show view from t1;""")
+ checkNereidsExecute("""show view from test_show_view_db1.t1;""")
+ checkNereidsExecute("""show view from test_show_view_db2.t1;""")
+ checkNereidsExecute("""show view from test_show_view_db1.t1 from
test_show_view_db2;""")
+ qt_cmd("""show view from t1;""")
+ qt_cmd("""show view from test_show_view_db1.t1;""")
+ qt_cmd("""show view from test_show_view_db2.t1;""")
+ qt_cmd("""show view from test_show_view_db1.t1 from test_show_view_db2;""")
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]