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 790c3313d5f [Chore](nereids) Remove DescribeStmt (#51712)
790c3313d5f is described below
commit 790c3313d5f73915738fc005634cc18825843bd3
Author: Jensen <[email protected]>
AuthorDate: Tue Jun 17 12:36:13 2025 +0800
[Chore](nereids) Remove DescribeStmt (#51712)
---
fe/fe-core/src/main/cup/sql_parser.cup | 26 --
.../org/apache/doris/analysis/DescribeStmt.java | 419 ---------------------
.../java/org/apache/doris/qe/ShowExecutor.java | 9 -
.../java/org/apache/doris/qe/ShowExecutorTest.java | 21 +-
4 files changed, 6 insertions(+), 469 deletions(-)
diff --git a/fe/fe-core/src/main/cup/sql_parser.cup
b/fe/fe-core/src/main/cup/sql_parser.cup
index c1db51927b8..f39a485d4a0 100644
--- a/fe/fe-core/src/main/cup/sql_parser.cup
+++ b/fe/fe-core/src/main/cup/sql_parser.cup
@@ -4793,32 +4793,6 @@ opt_explain_options ::=
:}
;
-// Describe statement
-describe_stmt ::=
- describe_command table_name:table opt_partition_names:partitionNames
- {:
- RESULT = new DescribeStmt(table, false, partitionNames);
- :}
- | describe_command KW_FUNCTION table_valued_function_ref:tvf
- {:
- RESULT = new DescribeStmt(tvf);
- :}
- | describe_command table_name:table KW_ALL
- {:
- RESULT = new DescribeStmt(table, true);
- :}
- | describe_command opt_explain_options:options query_stmt:query
- {:
- query.setIsExplain(options);
- RESULT = query;
- :}
- | describe_command opt_explain_options:options insert_stmt:stmt
- {:
- stmt.getQueryStmt().setIsExplain(options);
- RESULT = stmt;
- :}
- ;
-
describe_command ::=
KW_DESCRIBE
| KW_DESC
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/DescribeStmt.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/DescribeStmt.java
deleted file mode 100644
index 29ade962cfa..00000000000
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/DescribeStmt.java
+++ /dev/null
@@ -1,419 +0,0 @@
-// 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.DatabaseIf;
-import org.apache.doris.catalog.Env;
-import org.apache.doris.catalog.JdbcTable;
-import org.apache.doris.catalog.MaterializedIndexMeta;
-import org.apache.doris.catalog.MysqlTable;
-import org.apache.doris.catalog.OdbcTable;
-import org.apache.doris.catalog.OlapTable;
-import org.apache.doris.catalog.ScalarType;
-import org.apache.doris.catalog.TableIf;
-import org.apache.doris.catalog.TableIf.TableType;
-import org.apache.doris.common.AnalysisException;
-import org.apache.doris.common.ErrorCode;
-import org.apache.doris.common.ErrorReport;
-import org.apache.doris.common.FeConstants;
-import org.apache.doris.common.Pair;
-import org.apache.doris.common.UserException;
-import org.apache.doris.common.proc.IndexSchemaProcNode;
-import org.apache.doris.common.proc.ProcNodeInterface;
-import org.apache.doris.common.proc.ProcService;
-import org.apache.doris.common.proc.TableProcDir;
-import org.apache.doris.common.util.Util;
-import org.apache.doris.datasource.CatalogIf;
-import org.apache.doris.datasource.systable.SysTable;
-import org.apache.doris.mysql.privilege.PrivPredicate;
-import org.apache.doris.qe.ConnectContext;
-import org.apache.doris.qe.ShowResultSetMetaData;
-
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-
-public class DescribeStmt extends ShowStmt implements NotFallbackInParser {
- private static final Logger LOG = LogManager.getLogger(DescribeStmt.class);
- private static final ShowResultSetMetaData DESC_OLAP_TABLE_ALL_META_DATA =
- ShowResultSetMetaData.builder()
- .addColumn(new Column("IndexName",
ScalarType.createVarchar(20)))
- .addColumn(new Column("IndexKeysType",
ScalarType.createVarchar(20)))
- .addColumn(new Column("Field",
ScalarType.createVarchar(20)))
- .addColumn(new Column("Type",
ScalarType.createVarchar(20)))
- .addColumn(new Column("InternalType",
ScalarType.createVarchar(20)))
- .addColumn(new Column("Null",
ScalarType.createVarchar(10)))
- .addColumn(new Column("Key", ScalarType.createVarchar(10)))
- .addColumn(new Column("Default",
ScalarType.createVarchar(30)))
- .addColumn(new Column("Extra",
ScalarType.createVarchar(30)))
- .addColumn(new Column("Visible",
ScalarType.createVarchar(10)))
- .addColumn(new Column("DefineExpr",
ScalarType.createVarchar(30)))
- .addColumn(new Column("WhereClause",
ScalarType.createVarchar(30)))
- .build();
-
- private static final ShowResultSetMetaData DESC_MYSQL_TABLE_ALL_META_DATA =
- ShowResultSetMetaData.builder()
- .addColumn(new Column("Host",
ScalarType.createVarchar(30)))
- .addColumn(new Column("Port",
ScalarType.createVarchar(10)))
- .addColumn(new Column("User",
ScalarType.createVarchar(30)))
- .addColumn(new Column("Password",
ScalarType.createVarchar(30)))
- .addColumn(new Column("Database",
ScalarType.createVarchar(30)))
- .addColumn(new Column("Table",
ScalarType.createVarchar(30)))
- .build();
-
- // empty col num equals to DESC_OLAP_TABLE_ALL_META_DATA.size()
- private static final List<String> EMPTY_ROW = initEmptyRow();
-
- private TableName dbTableName;
- private ProcNodeInterface node;
- private PartitionNames partitionNames;
-
- List<List<String>> totalRows = new LinkedList<List<String>>();
-
- private boolean isAllTables;
- private boolean isOlapTable = false;
- private boolean showComment = false;
-
- TableValuedFunctionRef tableValuedFunctionRef;
- boolean isTableValuedFunction;
-
- public DescribeStmt(TableName dbTableName, boolean isAllTables) {
- this.dbTableName = dbTableName;
- this.isAllTables = isAllTables;
- }
-
- public DescribeStmt(TableName dbTableName, boolean isAllTables,
PartitionNames partitionNames) {
- this.dbTableName = dbTableName;
- this.isAllTables = isAllTables;
- this.partitionNames = partitionNames;
- }
-
- public DescribeStmt(TableValuedFunctionRef tableValuedFunctionRef) {
- this.tableValuedFunctionRef = tableValuedFunctionRef;
- this.isTableValuedFunction = true;
- this.isAllTables = false;
- }
-
- public boolean isAllTables() {
- return isAllTables;
- }
-
- @Override
- public void analyze(Analyzer analyzer) throws UserException {
- // First handle meta table.
- // It will convert this to corresponding table valued functions
- // eg: DESC table$partitions -> partition_values(...)
- if (dbTableName != null) {
- // if this is isTableValuedFunction, eg: desc function s3(),
- // the dbTableName is null.
- dbTableName.analyze(analyzer);
- CatalogIf catalog =
Env.getCurrentEnv().getCatalogMgr().getCatalogOrAnalysisException(dbTableName.getCtl());
- DatabaseIf db =
catalog.getDbOrAnalysisException(dbTableName.getDb());
- Pair<String, String> tableNameWithSysTableName
- =
SysTable.getTableNameWithSysTableName(dbTableName.getTbl());
- if (!Strings.isNullOrEmpty(tableNameWithSysTableName.second)) {
- TableIf table =
db.getTableOrDdlException(tableNameWithSysTableName.first);
- isTableValuedFunction = true;
- Optional<TableValuedFunctionRef> optTvfRef =
table.getSysTableFunctionRef(dbTableName.getCtl(),
- dbTableName.getDb(), dbTableName.getTbl());
- if (!optTvfRef.isPresent()) {
- throw new AnalysisException("sys table not found: " +
tableNameWithSysTableName.second);
- }
- tableValuedFunctionRef = optTvfRef.get();
- }
- }
-
- if (!isAllTables && isTableValuedFunction) {
- tableValuedFunctionRef.analyze(analyzer);
- List<Column> columns =
tableValuedFunctionRef.getTable().getBaseSchema();
- for (Column column : columns) {
- List<String> row = Arrays.asList(
- column.getName(),
-
column.getOriginType().hideVersionForVersionColumn(true),
- column.isAllowNull() ? "Yes" : "No",
- ((Boolean) column.isKey()).toString(),
- column.getDefaultValue() == null
- ? FeConstants.null_string :
column.getDefaultValue(),
- "NONE"
- );
- totalRows.add(row);
- }
- return;
- }
-
- if (partitionNames != null) {
- partitionNames.analyze(analyzer);
- if (partitionNames.isTemp()) {
- throw new AnalysisException("Do not support temp partitions");
- }
- }
-
- if (!Env.getCurrentEnv().getAccessManager()
- .checkTblPriv(ConnectContext.get(), dbTableName,
PrivPredicate.SHOW)) {
-
ErrorReport.reportAnalysisException(ErrorCode.ERR_TABLEACCESS_DENIED_ERROR,
"DESCRIBE",
- ConnectContext.get().getQualifiedUser(),
ConnectContext.get().getRemoteIP(),
- dbTableName.toString());
- }
-
- CatalogIf catalog =
Env.getCurrentEnv().getCatalogMgr().getCatalogOrAnalysisException(dbTableName.getCtl());
- DatabaseIf db = catalog.getDbOrAnalysisException(dbTableName.getDb());
- TableIf table = db.getTableOrDdlException(dbTableName.getTbl());
- table.readLock();
- try {
- if (!isAllTables) {
- // show base table schema only
- String procString = "/catalogs/" + catalog.getId() + "/" +
db.getId() + "/" + table.getId() + "/"
- + TableProcDir.INDEX_SCHEMA + "/";
- if (table instanceof OlapTable) {
- procString += ((OlapTable) table).getBaseIndexId();
- } else {
- if (partitionNames != null) {
- throw new AnalysisException(dbTableName.getTbl()
- + " is not a OLAP table, describe
table failed");
- }
- procString += table.getId();
- }
- if (partitionNames != null) {
- procString += "/";
- StringBuilder builder = new StringBuilder();
- for (String str : partitionNames.getPartitionNames()) {
- builder.append(str);
- builder.append(",");
- }
- builder.deleteCharAt(builder.length() - 1);
- procString += builder.toString();
- }
- node = ProcService.getInstance().open(procString);
- if (node == null) {
- throw new AnalysisException("Describe table[" +
dbTableName.getTbl() + "] failed");
- }
- } else {
- Util.prohibitExternalCatalog(dbTableName.getCtl(),
this.getClass().getSimpleName() + " ALL");
- if (table instanceof OlapTable) {
- isOlapTable = true;
- OlapTable olapTable = (OlapTable) table;
- Set<String> bfColumns = olapTable.getCopiedBfColumns();
- Map<Long, List<Column>> indexIdToSchema =
olapTable.getIndexIdToSchema();
-
- // indices order
- List<Long> indices = Lists.newArrayList();
- indices.add(olapTable.getBaseIndexId());
- for (Long indexId : indexIdToSchema.keySet()) {
- if (indexId != olapTable.getBaseIndexId()) {
- indices.add(indexId);
- }
- }
-
- // add all indices
- for (int i = 0; i < indices.size(); ++i) {
- long indexId = indices.get(i);
- List<Column> columns = indexIdToSchema.get(indexId);
- String indexName = olapTable.getIndexNameById(indexId);
- MaterializedIndexMeta indexMeta =
olapTable.getIndexMetaByIndexId(indexId);
- for (int j = 0; j < columns.size(); ++j) {
- Column column = columns.get(j);
-
- // Extra string (aggregation and bloom filter)
- List<String> extras = Lists.newArrayList();
- if (column.getAggregationType() != null) {
- extras.add(column.getAggregationString());
- }
- if (bfColumns != null &&
bfColumns.contains(column.getName())) {
- extras.add("BLOOM_FILTER");
- }
- String extraStr = StringUtils.join(extras, ",");
-
- List<String> row = Arrays.asList(
- "",
- "",
- column.getName(),
- column.getOriginType().toString(),
- column.getOriginType().toString(),
- column.isAllowNull() ? "Yes" : "No",
- ((Boolean) column.isKey()).toString(),
- column.getDefaultValue() == null
- ? FeConstants.null_string
- : column.getDefaultValue(),
- extraStr,
- ((Boolean) column.isVisible()).toString(),
- column.getDefineExpr() == null ? "" :
column.getDefineExpr().toSql(),
- "");
-
- if (column.getOriginType().isDatetimeV2()) {
- StringBuilder typeStr = new
StringBuilder("DATETIME");
- if (((ScalarType)
column.getOriginType()).getScalarScale() > 0) {
- typeStr.append("(").append(((ScalarType)
column.getOriginType()).getScalarScale())
- .append(")");
- }
- row.set(3, typeStr.toString());
- } else if (column.getOriginType().isDateV2()) {
- row.set(3, "DATE");
- } else if (column.getOriginType().isDecimalV3()) {
- StringBuilder typeStr = new
StringBuilder("DECIMAL");
- ScalarType sType = (ScalarType)
column.getOriginType();
- int scale = sType.getScalarScale();
- int precision = sType.getScalarPrecision();
- // not default
- if (scale > 0 && precision != 9) {
-
typeStr.append("(").append(precision).append(", ").append(scale)
- .append(")");
- }
- row.set(3, typeStr.toString());
- }
-
- if (j == 0) {
- row.set(0, indexName);
- row.set(1, indexMeta.getKeysType().name());
- Expr where = indexMeta.getWhereClause();
-
row.set(DESC_OLAP_TABLE_ALL_META_DATA.getColumns().size() - 1,
- where == null ? "" :
where.toSqlWithoutTbl());
- }
-
- totalRows.add(row);
- } // end for columns
-
- if (i != indices.size() - 1) {
- totalRows.add(EMPTY_ROW);
- }
- } // end for indices
- } else if (table.getType() == TableType.ODBC) {
- isOlapTable = false;
- OdbcTable odbcTable = (OdbcTable) table;
- List<String> row = Arrays.asList(odbcTable.getHost(),
- odbcTable.getPort(),
- odbcTable.getUserName(),
- odbcTable.getPasswd(),
- odbcTable.getOdbcDatabaseName(),
- odbcTable.getOdbcTableName(),
- odbcTable.getOdbcDriver(),
- odbcTable.getOdbcTableTypeName());
- totalRows.add(row);
- } else if (table.getType() == TableType.JDBC) {
- isOlapTable = false;
- JdbcTable jdbcTable = (JdbcTable) table;
- List<String> row = Arrays.asList(jdbcTable.getJdbcUrl(),
jdbcTable.getJdbcUser(),
- jdbcTable.getJdbcPasswd(),
jdbcTable.getDriverClass(), jdbcTable.getDriverUrl(),
- jdbcTable.getExternalTableName(),
jdbcTable.getResourceName(), jdbcTable.getJdbcTypeName());
- totalRows.add(row);
- } else if (table.getType() == TableType.MYSQL) {
- isOlapTable = false;
- MysqlTable mysqlTable = (MysqlTable) table;
- List<String> row = Arrays.asList(mysqlTable.getHost(),
- mysqlTable.getPort(),
- mysqlTable.getUserName(),
- mysqlTable.getPasswd(),
-
mysqlTable.getMysqlDatabaseName(),
-
mysqlTable.getMysqlTableName(),
- mysqlTable.getCharset());
- totalRows.add(row);
- } else {
-
ErrorReport.reportAnalysisException(ErrorCode.ERR_UNKNOWN_STORAGE_ENGINE,
table.getType());
- }
- }
- } finally {
- table.readUnlock();
- }
- }
-
- public String getTableName() {
- return dbTableName.getTbl();
- }
-
- public String getDb() {
- return dbTableName.getDb();
- }
-
- public List<List<String>> getResultRows() throws AnalysisException {
- if (isAllTables) {
- return totalRows;
- } else {
- if (isTableValuedFunction) {
- return totalRows;
- }
- showComment =
ConnectContext.get().getSessionVariable().showColumnCommentInDescribe;
- Preconditions.checkNotNull(node);
- List<List<String>> rows = node.fetchResult().getRows();
- List<List<String>> res = new ArrayList<>();
- for (List<String> row : rows) {
- try {
- Env.getCurrentEnv().getAccessManager()
-
.checkColumnsPriv(ConnectContext.get().getCurrentUserIdentity(),
dbTableName.getCtl(),
- getDb(), getTableName(),
Sets.newHashSet(row.get(0)), PrivPredicate.SHOW);
- res.add(row);
- } catch (UserException e) {
- if (LOG.isDebugEnabled()) {
- LOG.debug(e.getMessage());
- }
- }
- }
- return res;
- }
- }
-
- @Override
- public ShowResultSetMetaData getMetaData() {
- if (!isAllTables) {
- ShowResultSetMetaData.Builder builder =
ShowResultSetMetaData.builder();
- for (String col : IndexSchemaProcNode.TITLE_NAMES) {
- builder.addColumn(new Column(col,
ScalarType.createVarchar(30)));
- }
- if (showComment) {
- builder.addColumn(new
Column(IndexSchemaProcNode.COMMENT_COLUMN_TITLE,
ScalarType.createStringType()));
- }
- return builder.build();
- } else {
- if (isOlapTable) {
- return DESC_OLAP_TABLE_ALL_META_DATA;
- } else {
- return DESC_MYSQL_TABLE_ALL_META_DATA;
- }
- }
- }
-
- @Override
- public String toSql() {
- return "DESCRIBE `" + dbTableName + "`" + (isAllTables ? " ALL" : "");
- }
-
- @Override
- public String toString() {
- return toSql();
- }
-
- private static List<String> initEmptyRow() {
- List<String> emptyRow = new
ArrayList<>(DESC_OLAP_TABLE_ALL_META_DATA.getColumns().size());
- for (int i = 0; i < DESC_OLAP_TABLE_ALL_META_DATA.getColumns().size();
i++) {
- emptyRow.add("");
- }
- return emptyRow;
- }
-}
-
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
b/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
index 282faaade97..07a5db7f3d0 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
@@ -19,7 +19,6 @@ package org.apache.doris.qe;
import org.apache.doris.analysis.AdminCopyTabletStmt;
import org.apache.doris.analysis.CompoundPredicate.Operator;
-import org.apache.doris.analysis.DescribeStmt;
import org.apache.doris.analysis.DiagnoseTabletStmt;
import org.apache.doris.analysis.Expr;
import org.apache.doris.analysis.HelpStmt;
@@ -306,8 +305,6 @@ public class ShowExecutor {
handleShowDbId();
} else if (stmt instanceof ShowTableIdStmt) {
handleShowTableId();
- } else if (stmt instanceof DescribeStmt) {
- handleDescribe();
} else if (stmt instanceof ShowCreateTableStmt) {
handleShowCreateTable();
} else if (stmt instanceof ShowCreateMTMVStmt) {
@@ -1007,12 +1004,6 @@ public class ShowExecutor {
resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
}
- // Describe statement
- private void handleDescribe() throws AnalysisException {
- DescribeStmt describeStmt = (DescribeStmt) stmt;
- resultSet = new ShowResultSet(describeStmt.getMetaData(),
describeStmt.getResultRows());
- }
-
// Show column statement.
private void handleShowColumn() throws AnalysisException {
ShowColumnStmt showStmt = (ShowColumnStmt) stmt;
diff --git a/fe/fe-core/src/test/java/org/apache/doris/qe/ShowExecutorTest.java
b/fe/fe-core/src/test/java/org/apache/doris/qe/ShowExecutorTest.java
index 7dc52087288..9c349b8156c 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/qe/ShowExecutorTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/qe/ShowExecutorTest.java
@@ -18,9 +18,7 @@
package org.apache.doris.qe;
import org.apache.doris.analysis.AccessTestUtil;
-import org.apache.doris.analysis.Analyzer;
import org.apache.doris.analysis.DbName;
-import org.apache.doris.analysis.DescribeStmt;
import org.apache.doris.analysis.HelpStmt;
import org.apache.doris.analysis.SetType;
import org.apache.doris.analysis.ShowAuthorStmt;
@@ -55,6 +53,7 @@ import org.apache.doris.datasource.InternalCatalog;
import org.apache.doris.mysql.MysqlCommand;
import org.apache.doris.mysql.privilege.AccessControllerManager;
import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.nereids.trees.plans.commands.DescribeCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowDatabasesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowTableCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowViewCommand;
@@ -370,7 +369,6 @@ public class ShowExecutorTest {
@Test
public void testDescribe() {
SystemInfoService clusterInfo =
AccessTestUtil.fetchSystemInfoService();
- Analyzer analyzer = AccessTestUtil.fetchAdminAnalyzer(false);
Env env = AccessTestUtil.fetchAdminCatalog();
new MockUp<Env>() {
@@ -385,20 +383,13 @@ public class ShowExecutorTest {
}
};
- DescribeStmt stmt = new DescribeStmt(new TableName(internalCtl,
"testDb", "testTbl"), false);
- try {
- stmt.analyze(analyzer);
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail();
- }
-
- ShowExecutor executor = new ShowExecutor(ctx, stmt);
- ShowResultSet resultSet;
+ TableNameInfo tableNameInfo = new TableNameInfo(internalCtl, "testDb",
"testTbl");
+ DescribeCommand command = new DescribeCommand(tableNameInfo, false,
null);
+ ShowResultSet resultSet = null;
try {
- resultSet = executor.execute();
+ resultSet = command.doRun(ctx, new StmtExecutor(ctx, ""));
Assert.assertFalse(resultSet.next());
- } catch (AnalysisException e) {
+ } catch (Exception e) {
e.printStackTrace();
Assert.fail();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]