You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2023/06/30 13:43:06 UTC
[doris] branch master updated: [fix](nereids) to_date should return type datev2 for datetimev2 (#21375)
This is an automated email from the ASF dual-hosted git repository.
morrysnow 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 ed2cd4974e [fix](nereids) to_date should return type datev2 for datetimev2 (#21375)
ed2cd4974e is described below
commit ed2cd4974e4b8e45ffc4a9994cd51e515583108e
Author: Jibing-Li <64...@users.noreply.github.com>
AuthorDate: Fri Jun 30 21:42:59 2023 +0800
[fix](nereids) to_date should return type datev2 for datetimev2 (#21375)
To_date function in nereids return type should be DATEV2 if the arg type is DATETIMEV2.
Before the return type was DATE which would cause BE get wrong query result.
---
.../executable/DateTimeExtractAndTransform.java | 4 +-
.../hive/test_hive_to_date.out | 25 +++++++++++
.../hive/test_hive_to_date.groovy | 49 ++++++++++++++++++++++
3 files changed, 76 insertions(+), 2 deletions(-)
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<to_date(\"1999-01-01\")"
+ qt_8 "select * from datev2_orc where day<to_date(\"1999-01-01\")"
+ qt_9 "select * from datev2_parquet where day<to_date(\"1999-01-01\")"
+ }
+}
+
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org