-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enhancement] (nereids)implement showDataTypesCommand in nereids (#44299
) Issue Number: close #42743
- Loading branch information
1 parent
0e2de34
commit a9de07b
Showing
7 changed files
with
176 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...ore/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowDataTypesCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
regression-test/data/nereids_p0/show/test_show_data_types.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
29
regression-test/suites/nereids_p0/show/test_show_data_types.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
|