[feature](datatype) add show data types stmt (#18111)

This commit is contained in:
ZashJie
2023-03-26 12:37:06 +08:00
committed by GitHub
parent 45ad297a1d
commit 2a0890d803
8 changed files with 303 additions and 0 deletions

View File

@ -0,0 +1,52 @@
---
{
"title": "SHOW-DATA-TYPES",
"language": "en"
}
---
<!--
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.
-->
## SHOW-DATA-TYPES
### Name
SHOW DATA TYPES
### Description
This statement is used to view all supported data types.
grammar:
```sql
SHOW DATA TYPES;
```
### Example
1. Display all supported data types
SHOW DATA TYPES;
### Keywords
SHOW,DATA,TYPES
### Best Practice

View File

@ -0,0 +1,52 @@
---
{
"title": "SHOW-DATA-TYPES",
"language": "zh-CN"
}
---
<!--
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.
-->
## SHOW-DATA-TYPES
### Name
SHOW DATA TYPES
### Description
该语句用于查看DORIS支持的所有数据类型。
语法:
```sql
SHOW DATA TYPES;
```
### Example
1. 查看Doris支持的所有数据类型
SHOW DATA TYPES;
### Keywords
SHOW,DATA,TYPES
### Best Practice

View File

@ -3672,6 +3672,11 @@ show_param ::=
{:
RESULT = new ShowDbIdStmt(dbId);
:}
/* show all data types */
| KW_DATA KW_TYPES
{:
RESULT = new ShowDataTypesStmt();
:}
| KW_SCHEMAS opt_wild_where
{:
RESULT = new ShowDbStmt(parser.wild, parser.where);

View File

@ -0,0 +1,75 @@
// 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.PrimitiveType;
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.UserException;
import org.apache.doris.qe.ShowResultSetMetaData;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class ShowDataTypesStmt extends ShowStmt {
private static final ShowResultSetMetaData META_DATA =
ShowResultSetMetaData.builder()
.addColumn(new Column("TypeName", ScalarType.createVarchar(20)))
.addColumn(new Column("Size", ScalarType.createVarchar(20)))
.build();
public static ArrayList<PrimitiveType> getTypes() {
return PrimitiveType.getSupportedTypes();
}
@Override
public void analyze(Analyzer analyzer) throws AnalysisException, UserException {
super.analyze(analyzer);
}
@Override
public String toSql() {
StringBuilder sb = new StringBuilder();
sb.append("SHOW ");
sb.append("DATA TYPES");
return sb.toString();
}
@Override
public String toString() {
return toSql();
}
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 ShowResultSetMetaData getMetaData() {
return META_DATA;
}
}

View File

@ -47,6 +47,7 @@ import org.apache.doris.analysis.ShowCreateRoutineLoadStmt;
import org.apache.doris.analysis.ShowCreateTableStmt;
import org.apache.doris.analysis.ShowDataSkewStmt;
import org.apache.doris.analysis.ShowDataStmt;
import org.apache.doris.analysis.ShowDataTypesStmt;
import org.apache.doris.analysis.ShowDbIdStmt;
import org.apache.doris.analysis.ShowDbStmt;
import org.apache.doris.analysis.ShowDeleteStmt;
@ -270,6 +271,8 @@ public class ShowExecutor {
handleShowEngines();
} else if (stmt instanceof ShowFunctionsStmt) {
handleShowFunctions();
} else if (stmt instanceof ShowDataTypesStmt) {
handleShowDataTypes();
} else if (stmt instanceof ShowCreateFunctionStmt) {
handleShowCreateFunction();
} else if (stmt instanceof ShowEncryptKeysStmt) {
@ -469,6 +472,20 @@ public class ShowExecutor {
resultSet = new ShowResultSet(showMetaData, resultRowSet);
}
private void handleShowDataTypes() throws AnalysisException {
ShowDataTypesStmt showStmt = (ShowDataTypesStmt) stmt;
ArrayList<PrimitiveType> supportedTypes = showStmt.getTypes();
List<List<String>> rows = Lists.newArrayList();
for (PrimitiveType type : supportedTypes) {
List<String> row = new ArrayList<>();
row.add(type.toString());
row.add(Integer.toString(type.getSlotSize()));
rows.add(row);
}
showStmt.sortMetaData(rows);
resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
}
/***
* get resultRowSet by showFunctionsStmt
* @param showStmt

View File

@ -0,0 +1,48 @@
// 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.common.AnalysisException;
import org.apache.doris.common.UserException;
import org.apache.doris.mysql.privilege.MockedAuth;
import org.apache.doris.qe.ConnectContext;
import mockit.Mocked;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class ShowDataTypesStmtTest {
private Analyzer analyzer;
@Mocked
private ConnectContext ctx;
@Before
public void setUp() {
analyzer = AccessTestUtil.fetchAdminAnalyzer(true);
MockedAuth.mockedConnectContext(ctx, "root", "192.168.1.1");
}
@Test
public void testNormal() throws UserException, AnalysisException {
ShowDataTypesStmt stmt = new ShowDataTypesStmt();
stmt.analyze(analyzer);
Assert.assertEquals("SHOW DATA TYPES", stmt.toString());
}
}

View File

@ -0,0 +1,32 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
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
JSONB 16
LARGEINT 16
MAP 24
NULL_TYPE 1
QUANTILE_STATE 16
SMALLINT 2
STRING 16
TIME 8
TIMEV2 8
TINYINT 1
VARCHAR 16
VARIANT 24

View File

@ -0,0 +1,22 @@
// 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", "types") {
qt_sql """show data types"""
}