Skip to content

Commit

Permalink
[Enhancement] (nereids)implement showDataTypesCommand in nereids
Browse files Browse the repository at this point in the history
  • Loading branch information
msridhar78 committed Nov 19, 2024
1 parent b3cb480 commit 748e021
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ supportedShowStatement
| SHOW PROC path=STRING_LITERAL #showProc
| SHOW STORAGE? ENGINES #showStorageEngines
| SHOW SQL_BLOCK_RULE (FOR ruleName=identifier)? #showSqlBlockRule
| SHOW DATA TYPES #showDataTypes
| SHOW CREATE MATERIALIZED VIEW mvName=identifier
ON tableName=multipartIdentifier #showCreateMaterializedView
| SHOW BACKENDS #showBackends
Expand Down Expand Up @@ -273,7 +274,6 @@ unsupportedShowStatement
((FROM | IN) database=multipartIdentifier)? #showCreateFunction
| SHOW (DATABASES | SCHEMAS) (FROM catalog=identifier)? wildWhere? #showDatabases
| SHOW DATABASE databaseId=INTEGER_VALUE #showDatabaseId
| SHOW DATA TYPES #showDataTypes
| SHOW CATALOGS wildWhere? #showCatalogs
| SHOW CATALOG name=identifier #showCatalog
| SHOW DYNAMIC PARTITION TABLES ((FROM | IN) database=multipartIdentifier)? #showDynamicPartition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
import org.apache.doris.nereids.DorisParser.ShowCreateMTMVContext;
import org.apache.doris.nereids.DorisParser.ShowCreateMaterializedViewContext;
import org.apache.doris.nereids.DorisParser.ShowCreateProcedureContext;
import org.apache.doris.nereids.DorisParser.ShowDataTypesContext;
import org.apache.doris.nereids.DorisParser.ShowFrontendsContext;
import org.apache.doris.nereids.DorisParser.ShowGrantsContext;
import org.apache.doris.nereids.DorisParser.ShowGrantsForUserContext;
Expand Down Expand Up @@ -453,6 +454,7 @@
import org.apache.doris.nereids.trees.plans.commands.ShowCreateMTMVCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowCreateMaterializedViewCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowCreateProcedureCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowDataTypesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowFrontendsCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowGrantsCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowLastInsertCommand;
Expand Down Expand Up @@ -4059,7 +4061,6 @@ public SetDefaultStorageVaultCommand visitSetDefaultStorageVault(SetDefaultStora
}

@Override

public Object visitRefreshCatalog(RefreshCatalogContext ctx) {
if (ctx.name != null) {
String catalogName = ctx.name.getText();
Expand All @@ -4070,10 +4071,16 @@ public Object visitRefreshCatalog(RefreshCatalogContext ctx) {
throw new AnalysisException("catalog name can not be null");
}

@Override
public LogicalPlan visitShowLastInsert(ShowLastInsertContext ctx) {
return new ShowLastInsertCommand();
}

@Override
public LogicalPlan visitShowDataTypes(ShowDataTypesContext ctx) {
return new ShowDataTypesCommand();
}

@Override
public LogicalPlan visitShowGrants(ShowGrantsContext ctx) {
boolean all = (ctx.ALL() != null) ? true : false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public enum PlanType {
SHOW_BLOCK_RULE_COMMAND,
SHOW_CONFIG_COMMAND,
SHOW_CREATE_MATERIALIZED_VIEW_COMMAND,
SHOW_DATA_TYPES_COMMAND,
SHOW_FRONTENDS_COMMAND,
SHOW_GRANTS_COMMAND,
SHOW_LAST_INSERT_COMMAND,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.apache.doris.nereids.trees.plans.commands.ShowCreateMTMVCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowCreateMaterializedViewCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowCreateProcedureCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowDataTypesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowFrontendsCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowGrantsCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowLastInsertCommand;
Expand Down Expand Up @@ -320,6 +321,10 @@ default R visitAlterRoleCommand(AlterRoleCommand alterRoleCommand, C context) {
return visitCommand(alterRoleCommand, context);
}

default R visitShowDataTypesCommand(ShowDataTypesCommand showDataTypesCommand, C context) {
return visitCommand(showDataTypesCommand, context);
}

default R visitShowFrontendsCommand(ShowFrontendsCommand showFrontendsCommand, C context) {
return visitCommand(showFrontendsCommand, context);
}
Expand Down
31 changes: 31 additions & 0 deletions regression-test/data/nereids_p0/show/test_show_data_types.out
Original file line number Diff line number Diff line change
@@ -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

29 changes: 29 additions & 0 deletions regression-test/suites/nereids_p0/show/test_show_data_types.groovy
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 748e021

Please sign in to comment.