This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit d12a37044781c53b3e1edcf0e93d111cb1410ef9
Author: Gabriel <[email protected]>
AuthorDate: Fri Feb 3 20:50:16 2023 +0800

    [Bug](datev2) Fix bug when cast datev2 to date (#16394)
---
 be/src/vec/functions/function_cast.h               |  9 +++--
 .../data/datatype_p0/date/test_date_exprs.out      |  7 ++++
 .../suites/datatype_p0/date/test_date_exprs.groovy | 40 ++++++++++++++++++++++
 3 files changed, 51 insertions(+), 5 deletions(-)

diff --git a/be/src/vec/functions/function_cast.h 
b/be/src/vec/functions/function_cast.h
index a6817134ea..59f58be84c 100644
--- a/be/src/vec/functions/function_cast.h
+++ b/be/src/vec/functions/function_cast.h
@@ -194,17 +194,16 @@ struct ConvertImpl {
                     } else if constexpr (IsTimeType<ToDataType>) {
                         if constexpr (IsDateTimeType<ToDataType> && 
IsDateV2Type<FromDataType>) {
                             DataTypeDateV2::cast_to_date_time(vec_from[i], 
vec_to[i]);
-                        } else if constexpr (IsDateTimeV2Type<ToDataType> &&
-                                             IsDateV2Type<FromDataType>) {
+                        } else if constexpr (IsDateType<ToDataType> && 
IsDateV2Type<FromDataType>) {
                             DataTypeDateV2::cast_to_date(vec_from[i], 
vec_to[i]);
                         } else if constexpr (IsDateTimeType<ToDataType> &&
                                              IsDateTimeV2Type<FromDataType>) {
                             DataTypeDateTimeV2::cast_to_date_time(vec_from[i], 
vec_to[i]);
-                        } else if constexpr (IsDateTimeV2Type<ToDataType> &&
+                        } else if constexpr (IsDateType<ToDataType> &&
                                              IsDateTimeV2Type<FromDataType>) {
                             DataTypeDateTimeV2::cast_to_date(vec_from[i], 
vec_to[i]);
-                        } else if constexpr (IsDateType<ToDataType> && 
IsDateV2Type<FromDataType>) {
-                            DataTypeDateV2::cast_to_date(vec_from[i], 
vec_to[i]);
+                        } else {
+                            return Status::InvalidArgument("Wrong cast 
expression!");
                         }
                     } else {
                         if constexpr (IsDateTimeV2Type<FromDataType>) {
diff --git a/regression-test/data/datatype_p0/date/test_date_exprs.out 
b/regression-test/data/datatype_p0/date/test_date_exprs.out
new file mode 100644
index 0000000000..35c3b94ede
--- /dev/null
+++ b/regression-test/data/datatype_p0/date/test_date_exprs.out
@@ -0,0 +1,7 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !sql1 --
+2016-11-04
+
+-- !sql2 --
+2016-11-04
+
diff --git a/regression-test/suites/datatype_p0/date/test_date_exprs.groovy 
b/regression-test/suites/datatype_p0/date/test_date_exprs.groovy
new file mode 100644
index 0000000000..b77bb85bf5
--- /dev/null
+++ b/regression-test/suites/datatype_p0/date/test_date_exprs.groovy
@@ -0,0 +1,40 @@
+
+// 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_date_exprs") {
+    def tbName = "test_date_exprs"
+    sql "DROP TABLE IF EXISTS ${tbName}"
+    sql """
+            create table ${tbName}(k1 datetimev2, k2 int) distributed by 
hash(k1) buckets 1 properties("replication_num" = "1");
+        """
+    sql """ insert into ${tbName} values("2016-11-04 00:00:01", 1); """
+
+    qt_sql1 """ select dt
+             from
+             (
+             select cast(k1 as datev2) as dt
+             from ${tbName}
+             ) r; """
+    qt_sql2 """ select dt
+             from
+             (
+             select cast(k1 as datev2) as dt
+             from ${tbName}
+             ) r; """
+    sql "DROP TABLE ${tbName}"
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to