Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class DescribeStmt extends ShowStmt {
.addColumn(new Column("IndexKeysType", ScalarType.createVarchar(20)))
.addColumn(new Column("Field", ScalarType.createVarchar(20)))
.addColumn(new Column("Type", ScalarType.createVarchar(20)))
.addColumn(new Column("InternalType", ScalarType.createVarchar(20)))
.addColumn(new Column("Null", ScalarType.createVarchar(10)))
.addColumn(new Column("Key", ScalarType.createVarchar(10)))
.addColumn(new Column("Default", ScalarType.createVarchar(30)))
Expand Down Expand Up @@ -122,6 +123,11 @@ public void analyze(Analyzer analyzer) throws UserException {
? FeConstants.null_string : column.getDefaultValue(),
"NONE"
);
if (column.getOriginType().isDatetimeV2()) {
row.set(1, "DATETIME");
} else if (column.getOriginType().isDateV2()) {
row.set(1, "DATE");
}
totalRows.add(row);
}
return;
Expand Down Expand Up @@ -196,6 +202,7 @@ public void analyze(Analyzer analyzer) throws UserException {
"",
column.getDisplayName(),
column.getOriginType().toString(),
column.getOriginType().toString(),
column.isAllowNull() ? "Yes" : "No",
((Boolean) column.isKey()).toString(),
column.getDefaultValue() == null
Expand All @@ -204,6 +211,12 @@ public void analyze(Analyzer analyzer) throws UserException {
((Boolean) column.isVisible()).toString()
);

if (column.getOriginType().isDatetimeV2()) {
row.set(3, "DATETIME");
} else if (column.getOriginType().isDateV2()) {
row.set(3, "DATE");
}

if (j == 0) {
row.set(0, indexName);
row.set(1, indexMeta.getKeysType().name());
Expand Down
20 changes: 18 additions & 2 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java
Original file line number Diff line number Diff line change
Expand Up @@ -570,14 +570,30 @@ public SlotRef getRefColumn() {
}

public String toSql() {
return toSql(false);
return toSql(false, false);
}

public String toSql(boolean isUniqueTable) {
return toSql(isUniqueTable, false);
}

public String toSql(boolean isUniqueTable, boolean isCompatible) {
StringBuilder sb = new StringBuilder();
sb.append("`").append(name).append("` ");
String typeStr = type.toSql();
sb.append(typeStr);

// show change datetimeV2/dateV2 to datetime/date
if (isCompatible) {
if (type.isDatetimeV2()) {
sb.append("datetime");
} else if (type.isDateV2()) {
sb.append("date");
} else {
sb.append(typeStr);
}
} else {
sb.append(typeStr);
}
if (aggregationType != null && aggregationType != AggregateType.NONE && !isUniqueTable
&& !isAggregationTypeImplicit) {
sb.append(" ").append(aggregationType.name());
Expand Down
3 changes: 2 additions & 1 deletion fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
Original file line number Diff line number Diff line change
Expand Up @@ -2813,7 +2813,8 @@ public static void getDdlStmt(DdlStmt ddlStmt, String dbName, TableIf table, Lis
// There MUST BE 2 space in front of each column description line
// sqlalchemy requires this to parse SHOW CREATE TABLE stmt.
if (table.getType() == TableType.OLAP) {
sb.append(" ").append(column.toSql(((OlapTable) table).getKeysType() == KeysType.UNIQUE_KEYS));
sb.append(" ").append(
column.toSql(((OlapTable) table).getKeysType() == KeysType.UNIQUE_KEYS, true));
} else {
sb.append(" ").append(column.toSql());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ public ProcResult fetchResult() throws AnalysisException {
column.getDefaultValue() == null
? FeConstants.null_string : column.getDefaultValue(),
extraStr);

if (column.getOriginType().isDateV2()) {
rowList.set(1, "DATE");
}
if (column.getOriginType().isDatetimeV2()) {
rowList.set(1, "DATETIME");
}
result.addRow(rowList);
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ decimal64_key DECIMALV3(14,1) No true \N BLOOM_FILTER
decimal128_key DECIMALV3(38,1) No true \N BLOOM_FILTER
date_key DATE No true \N BLOOM_FILTER
datetime_key DATETIME No true \N BLOOM_FILTER
datev2_key DATEV2 No true \N BLOOM_FILTER
datetimev2_key_1 DATETIMEV2(0) No true \N BLOOM_FILTER
datetimev2_key_2 DATETIMEV2(3) No true \N BLOOM_FILTER
datetimev2_key_3 DATETIMEV2(6) No true \N BLOOM_FILTER
datev2_key DATE No true \N BLOOM_FILTER
datetimev2_key_1 DATETIME No true \N BLOOM_FILTER
datetimev2_key_2 DATETIME No true \N BLOOM_FILTER
datetimev2_key_3 DATETIME No true \N BLOOM_FILTER
tinyint_value TINYINT No false \N SUM
smallint_value SMALLINT No false \N SUM
int_value INT No false \N SUM
Expand All @@ -41,18 +41,18 @@ date_value_min DATE No false \N MIN
datetime_value_max DATETIME No false \N MAX
datetime_value_replace DATETIME No false \N REPLACE
datetime_value_min DATETIME No false \N MIN
datev2_value_max DATEV2 No false \N MAX
datev2_value_replace DATEV2 No false \N REPLACE
datev2_value_min DATEV2 No false \N MIN
datetimev2_value_1_max DATETIMEV2(0) No false \N MAX
datetimev2_value_1_replace DATETIMEV2(0) No false \N REPLACE
datetimev2_value_1_min DATETIMEV2(0) No false \N MIN
datetimev2_value_2_max DATETIMEV2(3) No false \N MAX
datetimev2_value_2_replace DATETIMEV2(3) No false \N REPLACE
datetimev2_value_2_min DATETIMEV2(3) No false \N MIN
datetimev2_value_3_max DATETIMEV2(6) No false \N MAX
datetimev2_value_3_replace DATETIMEV2(6) No false \N REPLACE
datetimev2_value_3_min DATETIMEV2(6) No false \N MIN
datev2_value_max DATE No false \N MAX
datev2_value_replace DATE No false \N REPLACE
datev2_value_min DATE No false \N MIN
datetimev2_value_1_max DATETIME No false \N MAX
datetimev2_value_1_replace DATETIME No false \N REPLACE
datetimev2_value_1_min DATETIME No false \N MIN
datetimev2_value_2_max DATETIME No false \N MAX
datetimev2_value_2_replace DATETIME No false \N REPLACE
datetimev2_value_2_min DATETIME No false \N MIN
datetimev2_value_3_max DATETIME No false \N MAX
datetimev2_value_3_replace DATETIME No false \N REPLACE
datetimev2_value_3_min DATETIME No false \N MIN
float_value FLOAT No false \N SUM
double_value DOUBLE No false \N SUM

Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ date_value_max DATE Yes false \N MAX
date_value_min DATE Yes false \N MIN
date_value_replace DATE Yes false \N REPLACE
date_value_replace_if_not_null DATE Yes false \N REPLACE_IF_NOT_NULL
datev2_value_max DATEV2 Yes false \N MAX
datev2_value_min DATEV2 Yes false \N MIN
datev2_value_replace DATEV2 Yes false \N REPLACE
datev2_value_replace_if_not_null DATEV2 Yes false \N REPLACE_IF_NOT_NULL
datetimev2_value_max DATETIMEV2(0) Yes false \N MAX
datetimev2_value_min DATETIMEV2(0) Yes false \N MIN
datetimev2_value_replace DATETIMEV2(0) Yes false \N REPLACE
datetimev2_value_replace_if_not_null DATETIMEV2(0) Yes false \N REPLACE_IF_NOT_NULL
datetimev2_value_max_1 DATETIMEV2(3) Yes false \N MAX
datetimev2_value_min_1 DATETIMEV2(3) Yes false \N MIN
datetimev2_value_replace_1 DATETIMEV2(3) Yes false \N REPLACE
datetimev2_value_replace_if_not_null_1 DATETIMEV2(3) Yes false \N REPLACE_IF_NOT_NULL
datetimev2_value_max_2 DATETIMEV2(6) Yes false \N MAX
datetimev2_value_min_2 DATETIMEV2(6) Yes false \N MIN
datetimev2_value_replace_2 DATETIMEV2(6) Yes false \N REPLACE
datetimev2_value_replace_if_not_null_2 DATETIMEV2(6) Yes false \N REPLACE_IF_NOT_NULL
datev2_value_max DATE Yes false \N MAX
datev2_value_min DATE Yes false \N MIN
datev2_value_replace DATE Yes false \N REPLACE
datev2_value_replace_if_not_null DATE Yes false \N REPLACE_IF_NOT_NULL
datetimev2_value_max DATETIME Yes false \N MAX
datetimev2_value_min DATETIME Yes false \N MIN
datetimev2_value_replace DATETIME Yes false \N REPLACE
datetimev2_value_replace_if_not_null DATETIME Yes false \N REPLACE_IF_NOT_NULL
datetimev2_value_max_1 DATETIME Yes false \N MAX
datetimev2_value_min_1 DATETIME Yes false \N MIN
datetimev2_value_replace_1 DATETIME Yes false \N REPLACE
datetimev2_value_replace_if_not_null_1 DATETIME Yes false \N REPLACE_IF_NOT_NULL
datetimev2_value_max_2 DATETIME Yes false \N MAX
datetimev2_value_min_2 DATETIME Yes false \N MIN
datetimev2_value_replace_2 DATETIME Yes false \N REPLACE
datetimev2_value_replace_if_not_null_2 DATETIME Yes false \N REPLACE_IF_NOT_NULL

Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ k INT Yes true \N
int_value INT Yes false \N NONE
char_value CHAR(10) Yes false \N NONE
date_value DATE Yes false \N NONE
date_value2 DATEV2 Yes false \N NONE
date_value3 DATETIMEV2(0) Yes false \N NONE
date_value4 DATETIMEV2(3) Yes false \N NONE
date_value5 DATETIMEV2(6) Yes false \N NONE
date_value2 DATE Yes false \N NONE
date_value3 DATETIME Yes false \N NONE
date_value4 DATETIME Yes false \N NONE
date_value5 DATETIME Yes false \N NONE

-- !select_dup_table --
0 1 2 3
Expand Down
24 changes: 12 additions & 12 deletions regression-test/data/index_p0/test_bitmap_index.out
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ k8 DATETIME Yes false \N NONE
k9 LARGEINT Yes false \N NONE
k10 DECIMAL(9,0) Yes false \N NONE
k11 BOOLEAN Yes false \N NONE
k12 DATEV2 Yes false \N NONE
k13 DATETIMEV2(0) Yes false \N NONE
k14 DATETIMEV2(3) Yes false \N NONE
k15 DATETIMEV2(6) Yes false \N NONE
k12 DATE Yes false \N NONE
k13 DATETIME Yes false \N NONE
k14 DATETIME Yes false \N NONE
k15 DATETIME Yes false \N NONE

-- !sql --
default_cluster:regression_test_index_p0.test_bitmap_index_dup index1 k1 BITMAP
Expand Down Expand Up @@ -48,10 +48,10 @@ k8 DATETIME Yes true \N
k9 LARGEINT Yes true \N
k10 DECIMAL(9,0) Yes true \N
k11 BOOLEAN Yes true \N
k12 DATEV2 Yes true \N
k13 DATETIMEV2(0) Yes true \N
k14 DATETIMEV2(3) Yes true \N
k15 DATETIMEV2(6) Yes true \N
k12 DATE Yes true \N
k13 DATETIME Yes true \N
k14 DATETIME Yes true \N
k15 DATETIME Yes true \N
v1 INT Yes false \N SUM

-- !sql --
Expand Down Expand Up @@ -86,10 +86,10 @@ k8 DATETIME Yes true \N
k9 LARGEINT Yes true \N
k10 DECIMAL(9,0) Yes true \N
k11 BOOLEAN Yes true \N
k12 DATEV2 Yes false \N REPLACE
k13 DATETIMEV2(0) Yes false \N REPLACE
k14 DATETIMEV2(3) Yes false \N REPLACE
k15 DATETIMEV2(6) Yes false \N REPLACE
k12 DATE Yes false \N REPLACE
k13 DATETIME Yes false \N REPLACE
k14 DATETIME Yes false \N REPLACE
k15 DATETIME Yes false \N REPLACE
v1 INT Yes false \N REPLACE

-- !sql --
Expand Down
4 changes: 4 additions & 0 deletions regression-test/data/query_p0/show/test_show_create_table.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !select --
tb_show_create_table CREATE TABLE `tb_show_create_table` (\n `datek1` date NULL COMMENT 'a',\n `datetimek1` datetime NULL COMMENT 'b',\n `datetimek2` datetime NULL COMMENT 'c',\n `datetimek3` datetime NULL COMMENT 'd',\n `datev1` date MAX NOT NULL COMMENT 'e',\n `datetimev1` datetime MAX NOT NULL COMMENT 'f',\n `datetimev2` datetime MAX NOT NULL COMMENT 'g',\n `datetimev3` datetime MAX NOT NULL COMMENT 'h'\n) ENGINE=OLAP\nAGGREGATE KEY(`datek1`, `datetimek1`, `datetimek2`, `datetimek3`)\nCOMMENT 'OLAP'\nDISTRIBUTED BY HASH(`datek1`) BUCKETS 5\nPROPERTIES (\n"replication_allocation" = "tag.location.default: 1",\n"in_memory" = "false",\n"storage_format" = "V2",\n"light_schema_change" = "true",\n"disable_auto_compaction" = "false"\n);

Binary file modified regression-test/data/rollup/test_materialized_view_hll.out
Binary file not shown.
Binary file not shown.
Binary file modified regression-test/data/rollup_p0/test_materialized_view.out
Binary file not shown.
20 changes: 10 additions & 10 deletions regression-test/data/rollup_p0/test_rollup_agg.out
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
test_rollup_agg AGG_KEYS siteid INT No true \N true
citycode SMALLINT No true \N true
username VARCHAR(32) No true \N true
pv BIGINT No false 0 SUM true
uv BIGINT No false 0 SUM true
vv BIGINT Yes false 0 SUM true

rollup_city AGG_KEYS citycode SMALLINT No true \N true
pv BIGINT No false 0 SUM true
vv BIGINT Yes false 0 SUM true
test_rollup_agg AGG_KEYS siteid INT INT No true \N true
citycode SMALLINT SMALLINT No true \N true
username VARCHAR(32) VARCHAR(32) No true \N true
pv BIGINT BIGINT No false 0 SUM true
uv BIGINT BIGINT No false 0 SUM true
vv BIGINT BIGINT Yes false 0 SUM true
rollup_city AGG_KEYS citycode SMALLINT SMALLINT No true \N true
pv BIGINT BIGINT No false 0 SUM true
vv BIGINT BIGINT Yes false 0 SUM true

-- !sql --
1 200
Expand Down
36 changes: 18 additions & 18 deletions regression-test/data/rollup_p0/test_rollup_agg_date.out
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
test_rollup_agg_date AGG_KEYS datek1 DATEV2 Yes true \N true
datetimek1 DATETIMEV2(0) Yes true \N true
datetimek2 DATETIMEV2(3) Yes true \N true
datetimek3 DATETIMEV2(6) Yes true \N true
datev1 DATEV2 No false \N MAX true
datetimev1 DATETIMEV2(0) No false \N MAX true
datetimev2 DATETIMEV2(3) No false \N MAX true
datetimev3 DATETIMEV2(6) No false \N MAX true
datetimev4 DATETIMEV2(3) Yes false \N MAX true

rollup_date AGG_KEYS datek1 DATEV2 Yes true \N true
datetimek2 DATETIMEV2(3) Yes true \N true
datetimek1 DATETIMEV2(0) Yes true \N true
datetimek3 DATETIMEV2(6) Yes true \N true
datev1 DATEV2 No false \N MAX true
datetimev1 DATETIMEV2(0) No false \N MAX true
datetimev2 DATETIMEV2(3) No false \N MAX true
datetimev3 DATETIMEV2(6) No false \N MAX true
test_rollup_agg_date AGG_KEYS datek1 DATE DATEV2 Yes true \N true
datetimek1 DATETIME DATETIMEV2(0) Yes true \N true
datetimek2 DATETIME DATETIMEV2(3) Yes true \N true
datetimek3 DATETIME DATETIMEV2(6) Yes true \N true
datev1 DATE DATEV2 No false \N MAX true
datetimev1 DATETIME DATETIMEV2(0) No false \N MAX true
datetimev2 DATETIME DATETIMEV2(3) No false \N MAX true
datetimev3 DATETIME DATETIMEV2(6) No false \N MAX true
datetimev4 DATETIME DATETIMEV2(3) Yes false \N MAX true
rollup_date AGG_KEYS datek1 DATE DATEV2 Yes true \N true
datetimek2 DATETIME DATETIMEV2(3) Yes true \N true
datetimek1 DATETIME DATETIMEV2(0) Yes true \N true
datetimek3 DATETIME DATETIMEV2(6) Yes true \N true
datev1 DATE DATEV2 No false \N MAX true
datetimev1 DATETIME DATETIMEV2(0) No false \N MAX true
datetimev2 DATETIME DATETIMEV2(3) No false \N MAX true
datetimev3 DATETIME DATETIMEV2(6) No false \N MAX true

-- !sql --
2022-08-23 2022-08-23T11:11:11 2022-08-23T11:11:11.111 2022-08-23T11:11:11.111111 2022-08-23 2022-08-23T11:11:11 2022-08-23T11:11:11.111 2022-08-23T11:11:11.111111
Expand Down
44 changes: 44 additions & 0 deletions regression-test/suites/query_p0/show/test_show_create_table.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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_create_table", "query") {
String tb_name = "tb_show_create_table";
try {
sql """drop table if exists ${tb_name} """
sql """
CREATE TABLE IF NOT EXISTS ${tb_name}(
datek1 datev2 COMMENT "a",
datetimek1 datetimev2 COMMENT "b",
datetimek2 datetimev2(3) COMMENT "c",
datetimek3 datetimev2(6) COMMENT "d",
datev1 datev2 MAX NOT NULL COMMENT "e",
datetimev1 datetimev2 MAX NOT NULL COMMENT "f",
datetimev2 datetimev2(3) MAX NOT NULL COMMENT "g",
datetimev3 datetimev2(6) MAX NOT NULL COMMENT "h"
)
AGGREGATE KEY (datek1, datetimek1, datetimek2, datetimek3)
DISTRIBUTED BY HASH(datek1) BUCKETS 5 properties("replication_num" = "1");
"""

qt_select "show create table `${tb_name}`"

} finally {

try_sql("DROP TABLE IF EXISTS `${tb_name}`")
}

}