diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java index f8442a810e..4c7f80ab6c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java @@ -522,9 +522,9 @@ public class DateTimeExtractAndTransform { return new DateLiteral(date.getYear(), date.getMonth(), date.getDay()); } - @ExecFunction(name = "to_date", argTypes = {"DATETIMEV2"}, returnType = "DATE") + @ExecFunction(name = "to_date", argTypes = {"DATETIMEV2"}, returnType = "DATEV2") public static Expression toDate(DateTimeV2Literal date) { - return new DateLiteral(date.getYear(), date.getMonth(), date.getDay()); + return new DateV2Literal(date.getYear(), date.getMonth(), date.getDay()); } /** diff --git a/regression-test/data/external_table_emr_p2/hive/test_hive_to_date.out b/regression-test/data/external_table_emr_p2/hive/test_hive_to_date.out new file mode 100644 index 0000000000..97df022756 --- /dev/null +++ b/regression-test/data/external_table_emr_p2/hive/test_hive_to_date.out @@ -0,0 +1,25 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !1 -- +1 2000-01-01 + +-- !2 -- +1 2000-01-01 + +-- !3 -- +1 2000-01-01 + +-- !4 -- +1 2000-01-01 + +-- !5 -- +1 2000-01-01 + +-- !6 -- +1 2000-01-01 + +-- !7 -- + +-- !8 -- + +-- !9 -- + diff --git a/regression-test/suites/external_table_emr_p2/hive/test_hive_to_date.groovy b/regression-test/suites/external_table_emr_p2/hive/test_hive_to_date.groovy new file mode 100644 index 0000000000..cc2c7d58e2 --- /dev/null +++ b/regression-test/suites/external_table_emr_p2/hive/test_hive_to_date.groovy @@ -0,0 +1,49 @@ +// 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_hive_to_date", "p2") { + String enabled = context.config.otherConfigs.get("enableExternalHiveTest") + if (enabled != null && enabled.equalsIgnoreCase("true")) { + String extHiveHmsHost = context.config.otherConfigs.get("extHiveHmsHost") + String extHiveHmsPort = context.config.otherConfigs.get("extHiveHmsPort") + String catalog_name = "test_hive_to_date" + sql """drop catalog if exists ${catalog_name};""" + sql """ + create catalog if not exists ${catalog_name} properties ( + 'type'='hms', + 'hadoop.username' = 'hadoop', + 'hive.metastore.uris' = 'thrift://${extHiveHmsHost}:${extHiveHmsPort}' + ); + """ + logger.info("catalog " + catalog_name + " created") + sql """switch ${catalog_name};""" + logger.info("switched to catalog " + catalog_name) + sql """use multi_catalog;""" + sql """set enable_nereids_planner=true;""" + sql """set enable_fallback_to_original_planner=false""" + qt_1 "select * from datev2_csv" + qt_2 "select * from datev2_orc" + qt_3 "select * from datev2_parquet" + qt_4 "select * from datev2_csv where day>to_date(\"1999-01-01\")" + qt_5 "select * from datev2_orc where day>to_date(\"1999-01-01\")" + qt_6 "select * from datev2_parquet where day>to_date(\"1999-01-01\")" + qt_7 "select * from datev2_csv where day