From 0919d1460623ecfba6cdadc3b1462639fc0aa35d Mon Sep 17 00:00:00 2001 From: starocean999 <12095047@qq.com> Date: Tue, 5 Nov 2024 17:47:10 +0800 Subject: [PATCH] [Feat](Nereids) support show variables and show view command --- .../org/apache/doris/nereids/DorisParser.g4 | 14 +- .../org/apache/doris/catalog/Database.java | 13 ++ .../nereids/parser/LogicalPlanBuilder.java | 43 +++++ .../doris/nereids/trees/plans/PlanType.java | 2 + .../trees/plans/commands/ShowCommand.java | 53 +++++++ .../plans/commands/ShowVariablesCommand.java | 73 +++++++++ .../trees/plans/commands/ShowViewCommand.java | 148 ++++++++++++++++++ .../plans/commands/info/TableNameInfo.java | 31 ++++ .../trees/plans/visitor/CommandVisitor.java | 10 ++ .../org/apache/doris/qe/StmtExecutor.java | 4 + .../show_variables/show_variables_command.out | 10 ++ .../ddl/show_view/show_view_command.out | 17 ++ .../show_variables_command.groovy | 26 +++ .../ddl/show_view/show_view_command.groovy | 94 +++++++++++ 14 files changed, 533 insertions(+), 5 deletions(-) create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCommand.java create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowVariablesCommand.java create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowViewCommand.java create mode 100644 regression-test/data/nereids_p0/ddl/show_variables/show_variables_command.out create mode 100644 regression-test/data/nereids_p0/ddl/show_view/show_view_command.out create mode 100644 regression-test/suites/nereids_p0/ddl/show_variables/show_variables_command.groovy create mode 100644 regression-test/suites/nereids_p0/ddl/show_view/show_view_command.groovy 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 6cd4010bdcb7688..b7fa04c2ef796fb 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 11a60360426bf1d..61023caf5466139 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 List getViews() { return views; } + public List
getViewsOnIdOrder() { + List
tables = idToTable.values().stream() + .sorted(Comparator.comparing(Table::getId)) + .collect(Collectors.toList()); + List
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 1af48c8a5971c38..56c26557c1d83d3 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.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.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.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,41 @@ public SetUserPropertiesCommand visitSetUserProperties(SetUserPropertiesContext 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().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(InternalCatalog.INTERNAL_CATALOG_NAME); + sb.append("."); + sb.append(InfoSchemaDb.DATABASE_NAME); + 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()); + } + } + + @Override + public ShowViewCommand visitShowView(ShowViewContext ctx) { + List 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 d7a219cc7e45193..b9fb9e96f879272 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/ShowCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCommand.java new file mode 100644 index 000000000000000..3ce40cdd04d607f --- /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 000000000000000..1e8625b0a283183 --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowVariablesCommand.java @@ -0,0 +1,73 @@ +// 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 SetType type; + private 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 accept(PlanVisitor 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> 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 000000000000000..2074783e079eea8 --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowViewCommand.java @@ -0,0 +1,148 @@ +// 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 String db; + private TableNameInfo tbl; + private List matchViews = Lists.newArrayList(); + + public ShowViewCommand(String db, TableNameInfo tbl) { + super(PlanType.SHOW_VIEW_COMMAND); + this.db = db; + this.tbl = tbl; + } + + @Override + public R accept(PlanVisitor visitor, C context) { + return visitor.visitShowViewCommand(this, context); + } + + private void validate(ConnectContext ctx) throws Exception { + if (tbl == null) { + ErrorReport.reportAnalysisException(ErrorCode.ERR_NO_TABLES_USED); + } + 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 tableNameInfos = getTableNames(ctx, view.getInlineViewDef()); + for (TableNameInfo tableNameInfo : tableNameInfos) { + tableNameInfo.analyze(ctx); + if (tableNameInfo.equals(tbl)) { + matchViews.add(view); + } + } + } + } + + private List 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> rows = Lists.newArrayList(); + for (View view : matchViews) { + view.readLock(); + try { + List 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 79afb2d1fba476f..5d0a42e9807191e 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 String getDb() { 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 void readFields(DataInput in) throws IOException { 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 814596bca31a91e..e89c9a3a5c5f1c6 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.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 @@ default R visitSetUserPropertiesCommand(SetUserPropertiesCommand setUserProperti 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 f4c33d75cdcc51a..dd278734c4278f5 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 StmtExecutor(ConnectContext ctx, StatementBase parsedStmt) { context.getSessionVariable().getAutoProfileThresholdMs()); } + public boolean isProxy() { + return isProxy; + } + public static InternalService.PDataRow getRowStringValue(List cols, FormatOptions options) throws UserException { if (cols.isEmpty()) { 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 000000000000000..dc009a38e77678a --- /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 000000000000000..33e1f8315bfe1a1 --- /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 000000000000000..77caf22cacd40c2 --- /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 000000000000000..6054625e8fe1039 --- /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