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 a9de07b9ab2 [Enhancement] (nereids)implement showDataTypesCommand in
nereids (#44299)
a9de07b9ab2 is described below
commit a9de07b9ab2226b578821190e846ca4212fc7879
Author: Sridhar R Manikarnike <[email protected]>
AuthorDate: Thu Dec 19 15:01:22 2024 +0530
[Enhancement] (nereids)implement showDataTypesCommand in nereids (#44299)
Issue Number: close #42743
---
.../antlr4/org/apache/doris/nereids/DorisParser.g4 | 2 +-
.../doris/nereids/parser/LogicalPlanBuilder.java | 7 ++
.../apache/doris/nereids/trees/plans/PlanType.java | 1 +
.../trees/plans/commands/ShowDataTypesCommand.java | 102 +++++++++++++++++++++
.../trees/plans/visitor/CommandVisitor.java | 5 +
.../data/nereids_p0/show/test_show_data_types.out | 31 +++++++
.../nereids_p0/show/test_show_data_types.groovy | 29 ++++++
7 files changed, 176 insertions(+), 1 deletion(-)
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 b2e3eca37e0..93bf6050970 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
@@ -262,6 +262,7 @@ supportedShowStatement
| SHOW COLLATION wildWhere?
#showCollation
| SHOW SQL_BLOCK_RULE (FOR ruleName=identifier)?
#showSqlBlockRule
| SHOW CREATE VIEW name=multipartIdentifier
#showCreateView
+ | SHOW DATA TYPES
#showDataTypes
| SHOW CREATE MATERIALIZED VIEW mvName=identifier
ON tableName=multipartIdentifier
#showCreateMaterializedView
| SHOW (WARNINGS | ERRORS) limitClause?
#showWarningErrors
@@ -330,7 +331,6 @@ unsupportedShowStatement
LEFT_PAREN functionArguments? RIGHT_PAREN
((FROM | IN) database=multipartIdentifier)?
#showCreateFunction
| SHOW (DATABASES | SCHEMAS) (FROM catalog=identifier)? wildWhere?
#showDatabases
- | SHOW DATA TYPES
#showDataTypes
| SHOW CATALOGS wildWhere?
#showCatalogs
| SHOW CATALOG name=identifier
#showCatalog
| SHOW FULL? (COLUMNS | FIELDS) (FROM | IN) tableName=multipartIdentifier
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 3b570fff8e7..34f760ff4f5 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
@@ -257,6 +257,7 @@ import
org.apache.doris.nereids.DorisParser.ShowCreateRepositoryContext;
import org.apache.doris.nereids.DorisParser.ShowCreateTableContext;
import org.apache.doris.nereids.DorisParser.ShowCreateViewContext;
import org.apache.doris.nereids.DorisParser.ShowDataSkewContext;
+import org.apache.doris.nereids.DorisParser.ShowDataTypesContext;
import org.apache.doris.nereids.DorisParser.ShowDatabaseIdContext;
import org.apache.doris.nereids.DorisParser.ShowDeleteContext;
import org.apache.doris.nereids.DorisParser.ShowDiagnoseTabletContext;
@@ -575,6 +576,7 @@ import
org.apache.doris.nereids.trees.plans.commands.ShowCreateRepositoryCommand
import org.apache.doris.nereids.trees.plans.commands.ShowCreateTableCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowCreateViewCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowDataSkewCommand;
+import org.apache.doris.nereids.trees.plans.commands.ShowDataTypesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowDatabaseIdCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowDeleteCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowDiagnoseTabletCommand;
@@ -4498,6 +4500,11 @@ public class LogicalPlanBuilder extends
DorisParserBaseVisitor<Object> {
return new ShowLoadProfileCommand(ctx.loadIdPath.getText());
}
+ @Override
+ public LogicalPlan visitShowDataTypes(ShowDataTypesContext ctx) {
+ return new ShowDataTypesCommand();
+ }
+
@Override
public LogicalPlan visitShowGrants(ShowGrantsContext ctx) {
boolean all = (ctx.ALL() != null) ? true : false;
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 f58a6bf139d..8eeac54a853 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
@@ -224,6 +224,7 @@ public enum PlanType {
SHOW_DYNAMIC_PARTITION_COMMAND,
SHOW_ENCRYPT_KEYS_COMMAND,
SHOW_EVENTS_COMMAND,
+ SHOW_DATA_TYPES_COMMAND,
SHOW_FRONTENDS_COMMAND,
SHOW_GRANTS_COMMAND,
SHOW_LAST_INSERT_COMMAND,
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowDataTypesCommand.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowDataTypesCommand.java
new file mode 100644
index 00000000000..6ce9b781bd3
--- /dev/null
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowDataTypesCommand.java
@@ -0,0 +1,102 @@
+// 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.PrimitiveType;
+import org.apache.doris.catalog.ScalarType;
+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 com.google.common.collect.Lists;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * Represents the command for SHOW DATA TYPES.
+ */
+public class ShowDataTypesCommand extends ShowCommand {
+ private static final ShowResultSetMetaData META_DATA =
+ ShowResultSetMetaData.builder()
+ .addColumn(new Column("TypeName",
ScalarType.createVarchar(20)))
+ .addColumn(new Column("Size",
ScalarType.createVarchar(100)))
+ .build();
+
+ public ShowDataTypesCommand() {
+ super(PlanType.SHOW_DATA_TYPES_COMMAND);
+ }
+
+ /**
+ * getTypes().
+ */
+ public static ArrayList<PrimitiveType> getTypes() {
+ return PrimitiveType.getSupportedTypes();
+ }
+
+ /**
+ * getTypesAvailableInDdl().
+ */
+ public static List<List<String>> getTypesAvailableInDdl() {
+ ArrayList<PrimitiveType> supportedTypes = getTypes();
+ List<List<String>> rows = Lists.newArrayList();
+ for (PrimitiveType type : supportedTypes) {
+ List<String> row = new ArrayList<>();
+ if (type.isAvailableInDdl()) {
+ row.add(type.toString());
+ row.add(Integer.toString(type.getSlotSize()));
+ rows.add(row);
+ }
+ }
+ return rows;
+ }
+
+ /**
+ * sortMetaData().
+ */
+ public void sortMetaData(List<List<String>> rows) {
+ Collections.sort(rows, new Comparator<List<String>>() {
+ @Override
+ public int compare(List<String> row1, List<String> row2) {
+ return row1.get(0).compareTo(row2.get(0));
+ }
+ });
+ }
+
+ @Override
+ public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor)
throws Exception {
+ List<List<String>> rows = getTypesAvailableInDdl();
+ sortMetaData(rows);
+ return new ShowResultSet(getMetaData(), rows);
+ }
+
+ @Override
+ public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
+ return visitor.visitShowDataTypesCommand(this, context);
+ }
+
+ public ShowResultSetMetaData getMetaData() {
+ return META_DATA;
+ }
+}
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 9c2839b3784..cce1f41e071 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
@@ -102,6 +102,7 @@ import
org.apache.doris.nereids.trees.plans.commands.ShowCreateRepositoryCommand
import org.apache.doris.nereids.trees.plans.commands.ShowCreateTableCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowCreateViewCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowDataSkewCommand;
+import org.apache.doris.nereids.trees.plans.commands.ShowDataTypesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowDatabaseIdCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowDeleteCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowDiagnoseTabletCommand;
@@ -521,6 +522,10 @@ public interface CommandVisitor<R, C> {
return visitCommand(cleanAllProfileCommand, context);
}
+ default R visitShowDataTypesCommand(ShowDataTypesCommand
showDataTypesCommand, C context) {
+ return visitCommand(showDataTypesCommand, context);
+ }
+
default R visitShowFrontendsCommand(ShowFrontendsCommand
showFrontendsCommand, C context) {
return visitCommand(showFrontendsCommand, context);
}
diff --git a/regression-test/data/nereids_p0/show/test_show_data_types.out
b/regression-test/data/nereids_p0/show/test_show_data_types.out
new file mode 100644
index 00000000000..de1d757cbf8
--- /dev/null
+++ b/regression-test/data/nereids_p0/show/test_show_data_types.out
@@ -0,0 +1,31 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !cmd --
+AGG_STATE 16
+ARRAY 32
+BIGINT 8
+BITMAP 16
+BOOLEAN 1
+CHAR 16
+DATE 16
+DATETIME 16
+DATETIMEV2 8
+DATEV2 4
+DECIMAL128 16
+DECIMAL32 4
+DECIMAL64 8
+DECIMALV2 16
+DOUBLE 8
+FLOAT 4
+HLL 16
+INT 4
+IPV4 4
+IPV6 16
+JSON 16
+LARGEINT 16
+MAP 24
+QUANTILE_STATE 16
+SMALLINT 2
+STRING 16
+TINYINT 1
+VARCHAR 16
+
diff --git a/regression-test/suites/nereids_p0/show/test_show_data_types.groovy
b/regression-test/suites/nereids_p0/show/test_show_data_types.groovy
new file mode 100644
index 00000000000..4316fd5545f
--- /dev/null
+++ b/regression-test/suites/nereids_p0/show/test_show_data_types.groovy
@@ -0,0 +1,29 @@
+// 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("test_show_data_types_nereids", "query,datatype") {
+ try {
+ // Execute the SHOW DATA TYPES command and verify the output
+ checkNereidsExecute("SHOW DATA TYPES")
+ qt_cmd("SHOW DATA TYPES")
+ } catch (Exception e) {
+ // Log any exceptions that occur during testing
+ log.error("Failed to execute SHOW DATA TYPES command", e)
+ throw e
+ }
+}
+
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]