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 b2e3eca37e006b..93bf6050970930 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 3b570fff8e7584..34f760ff4f524e 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.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.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 LogicalPlan visitShowLoadProfile(ShowLoadProfileContext ctx) { 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 f58a6bf139d2fe..8eeac54a853e0f 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 00000000000000..6ce9b781bd37f1 --- /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 getTypes() { + return PrimitiveType.getSupportedTypes(); + } + + /** + * getTypesAvailableInDdl(). + */ + public static List> getTypesAvailableInDdl() { + ArrayList supportedTypes = getTypes(); + List> rows = Lists.newArrayList(); + for (PrimitiveType type : supportedTypes) { + List 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> rows) { + Collections.sort(rows, new Comparator>() { + @Override + public int compare(List row1, List row2) { + return row1.get(0).compareTo(row2.get(0)); + } + }); + } + + @Override + public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) throws Exception { + List> rows = getTypesAvailableInDdl(); + sortMetaData(rows); + return new ShowResultSet(getMetaData(), rows); + } + + @Override + public R accept(PlanVisitor 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 9c2839b3784093..cce1f41e071531 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.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 @@ default R visitCleanAllProfileCommand(CleanAllProfileCommand cleanAllProfileComm 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 00000000000000..de1d757cbf80cd --- /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 00000000000000..4316fd5545f47f --- /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 + } +} +