This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 6e6de1853c [Bug](ctas): Ctas use default DEFAULT CURRENT_TIMESTAMP insert error (#12056) 6e6de1853c is described below commit 6e6de1853cee9faa49057aa055e776c5e24ae251 Author: Stalary <stal...@163.com> AuthorDate: Thu Aug 25 09:00:00 2022 +0800 [Bug](ctas): Ctas use default DEFAULT CURRENT_TIMESTAMP insert error (#12056) --- .../apache/doris/datasource/InternalCatalog.java | 7 ++- .../java/org/apache/doris/qe/StmtExecutor.java | 4 +- regression-test/data/ddl_p0/test_ctas.out | 7 +++ regression-test/data/ddl_p0/test_ctl.out | 4 ++ regression-test/suites/ddl_p0/test_ctas.groovy | 53 ++++++++++++++++++++++ regression-test/suites/ddl_p0/test_ctl.groovy | 44 ++++++++++++++++++ 6 files changed, 116 insertions(+), 3 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java index 175160be9d..921e9713ef 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java @@ -59,6 +59,7 @@ import org.apache.doris.analysis.TruncateTableStmt; import org.apache.doris.analysis.TypeDef; import org.apache.doris.analysis.UserDesc; import org.apache.doris.analysis.UserIdentity; +import org.apache.doris.catalog.AggregateType; import org.apache.doris.catalog.BrokerTable; import org.apache.doris.catalog.ColocateGroupSchema; import org.apache.doris.catalog.ColocateTableIndex; @@ -1153,7 +1154,11 @@ public class InternalCatalog implements CatalogIf<Database> { } else { defaultValue = new DefaultValue(setDefault, column.getDefaultValue()); } - columnDef = new ColumnDef(name, typeDef, column.isKey(), column.getAggregationType(), + // AggregateType.NONE cause the table to change to the AGGREGATE KEY when analyze is used, + // cause CURRENT_TIMESTAMP to report an error. + columnDef = new ColumnDef(name, typeDef, column.isKey(), + AggregateType.NONE.equals(column.getAggregationType()) + ? null : column.getAggregationType(), column.isAllowNull(), defaultValue, column.getComment()); } createTableStmt.addColumnDef(columnDef); diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java index 2dd7aa501f..fd4e28dd52 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java @@ -1679,10 +1679,10 @@ public class StmtExecutor implements ProfileWriter { // after success create table insert data if (MysqlStateType.OK.equals(context.getState().getStateType())) { try { - parsedStmt = setParsedStmt(ctasStmt.getInsertStmt()); + parsedStmt = ctasStmt.getInsertStmt(); execute(); } catch (Exception e) { - LOG.warn("CTAS insert data error, stmt={}", parsedStmt.toSql(), e); + LOG.warn("CTAS insert data error, stmt={}", ctasStmt.toSql(), e); // insert error drop table DropTableStmt dropTableStmt = new DropTableStmt(true, ctasStmt.getCreateTableStmt().getDbTbl(), true); try { diff --git a/regression-test/data/ddl_p0/test_ctas.out b/regression-test/data/ddl_p0/test_ctas.out new file mode 100644 index 0000000000..fb4247f3d3 --- /dev/null +++ b/regression-test/data/ddl_p0/test_ctas.out @@ -0,0 +1,7 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select -- +test_ctas1 CREATE TABLE `test_ctas1` (\n `test_varchar` varchar(150) NULL,\n `test_datetime` datetime REPLACE NULL,\n `test_default_timestamp` datetime REPLACE NULL DEFAULT CURRENT_TIMESTAMP\n) ENGINE=OLAP\nAGGREGATE KEY(`test_varchar`)\nCOMMENT 'OLAP'\nDISTRIBUTED BY HASH(`test_varchar`) BUCKETS 10\nPROPERTIES (\n"replication_allocation" = "tag.location.default: 1",\n"in_memory" = "false",\n"storage_format" = "V2",\n"disable_auto_compaction" = "false"\n) + +-- !select -- +2 + diff --git a/regression-test/data/ddl_p0/test_ctl.out b/regression-test/data/ddl_p0/test_ctl.out new file mode 100644 index 0000000000..3a2783ce1c --- /dev/null +++ b/regression-test/data/ddl_p0/test_ctl.out @@ -0,0 +1,4 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select -- +test_ctl1 CREATE TABLE `test_ctl1` (\n `test_varchar` varchar(150) NULL,\n `test_datetime` datetime NULL,\n `test_default_timestamp` datetime NULL DEFAULT CURRENT_TIMESTAMP\n) ENGINE=OLAP\nUNIQUE KEY(`test_varchar`)\nCOMMENT 'OLAP'\nDISTRIBUTED BY HASH(`test_varchar`) BUCKETS 3\nPROPERTIES (\n"replication_allocation" = "tag.location.default: 1",\n"in_memory" = "false",\n"storage_format" = "V2",\n"disable_auto_compaction" = "false"\n) + diff --git a/regression-test/suites/ddl_p0/test_ctas.groovy b/regression-test/suites/ddl_p0/test_ctas.groovy new file mode 100644 index 0000000000..cfd7e825c9 --- /dev/null +++ b/regression-test/suites/ddl_p0/test_ctas.groovy @@ -0,0 +1,53 @@ +// 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_ctas") { + sql """ + CREATE TABLE IF NOT EXISTS `test_ctas` ( + `test_varchar` varchar(150) NULL, + `test_datetime` datetime NULL, + `test_default_timestamp` datetime DEFAULT CURRENT_TIMESTAMP + ) ENGINE=OLAP + UNIQUE KEY(`test_varchar`) + DISTRIBUTED BY HASH(`test_varchar`) BUCKETS 3 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "in_memory" = "false", + "storage_format" = "V2" + ) + """ + + sql """ INSERT INTO test_ctas(test_varchar, test_datetime) VALUES ('test1','2022-04-27 16:00:33'),('test2','2022-04-27 16:00:54') """ + + sql """ + CREATE TABLE IF NOT EXISTS `test_ctas1` + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "in_memory" = "false", + "storage_format" = "V2" + ) as select * from test_ctas; + """ + + qt_select """SHOW CREATE TABLE `test_ctas1`""" + + qt_select """select count(*) from test_ctas1""" + + sql """ DROP TABLE IF EXISTS test_ctas """ + + sql """ DROP TABLE IF EXISTS test_ctas1 """ + +} diff --git a/regression-test/suites/ddl_p0/test_ctl.groovy b/regression-test/suites/ddl_p0/test_ctl.groovy new file mode 100644 index 0000000000..ef1735c167 --- /dev/null +++ b/regression-test/suites/ddl_p0/test_ctl.groovy @@ -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_ctl") { + sql """ + CREATE TABLE IF NOT EXISTS `test_ctl` ( + `test_varchar` varchar(150) NULL, + `test_datetime` datetime NULL, + `test_default_timestamp` datetime DEFAULT CURRENT_TIMESTAMP + ) ENGINE=OLAP + UNIQUE KEY(`test_varchar`) + DISTRIBUTED BY HASH(`test_varchar`) BUCKETS 3 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "in_memory" = "false", + "storage_format" = "V2" + ) + """ + + sql """ + CREATE TABLE IF NOT EXISTS `test_ctl1` LIKE `test_ctl` + """ + + qt_select """SHOW CREATE TABLE `test_ctl1`""" + + sql """ DROP TABLE IF EXISTS test_ctl """ + + sql """ DROP TABLE IF EXISTS test_ctl1 """ + +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org