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

zclll 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 8ee6089278b [Refactor](util) Remove date_cast utils (#56343)
8ee6089278b is described below

commit 8ee6089278bf223de7118cd404f276e00b8dc1f5
Author: zclllyybb <[email protected]>
AuthorDate: Wed Sep 24 15:49:00 2025 +0800

    [Refactor](util) Remove date_cast utils (#56343)
    
    use PrimitiveTypeTraits uniformly
    
    btw, fix a always existed bug of regression `test_date_function` in
    query_p0/
---
 be/src/util/datetype_cast.hpp                      | 114 ------
 be/src/vec/functions/function.h                    |   4 +-
 be/src/vec/functions/function_convert_tz.cpp       | 123 ++-----
 .../vec/functions/function_datetime_floor_ceil.cpp |  66 ++--
 .../vec/functions/function_other_types_to_date.cpp | 398 ++++++++-------------
 be/src/vec/functions/simple_function_factory.h     |   5 +-
 be/test/vec/function/function_test_util.cpp        |  30 +-
 be/test/vec/function/function_time_test.cpp        |  45 +--
 .../executable/DateTimeExtractAndTransform.java    |  66 +---
 .../expressions/functions/scalar/ConvertTz.java    |   6 +-
 .../expressions/functions/scalar/DateTrunc.java    |  11 +-
 .../expressions/functions/scalar/LastDay.java      |   7 +-
 .../expressions/functions/scalar/MakeDate.java     |   4 +-
 .../expressions/functions/scalar/StrToDate.java    |  16 +-
 .../expressions/functions/scalar/ToMonday.java     |   6 +-
 .../org/apache/doris/nereids/types/DataType.java   |  14 +
 .../nereids/rules/expression/FoldConstantTest.java |  41 +--
 .../datetime_functions/test_date_function.out      |   4 +-
 .../datetime_functions/test_date_function.groovy   |   2 +-
 19 files changed, 280 insertions(+), 682 deletions(-)

diff --git a/be/src/util/datetype_cast.hpp b/be/src/util/datetype_cast.hpp
deleted file mode 100644
index 59d8589b004..00000000000
--- a/be/src/util/datetype_cast.hpp
+++ /dev/null
@@ -1,114 +0,0 @@
-// 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.
-
-#pragma once
-
-#include <type_traits>
-
-#include "vec/core/types.h"
-#include "vec/data_types/data_type_date.h"
-#include "vec/data_types/data_type_date_or_datetime_v2.h"
-#include "vec/data_types/data_type_date_time.h"
-#include "vec/runtime/vdatetime_value.h"
-
-/*
- * We use these function family to clarify our types of datelike type. for 
example:
- *      DataTypeDate -------------------> ColumnDate -----------------------> 
Int64
- *           |   |      TypeToColumn                    ValueTypeOfColumn      
 |
- *           |   
↘--------------------------------------------------------------↗
- *           |   |                       ::FieldType                           
 |
- *           |   
↖--------------------------------------------------------------↙
- *           |                       DateTraits<T>::DateType
- *           ↓ TypeToValueType
- *      VecDateTimeValue
- */
-namespace doris::date_cast {
-
-// e.g. DataTypeDate -> ColumnDate
-template <typename DataType>
-struct TypeToColumn {};
-template <>
-struct TypeToColumn<vectorized::DataTypeDate> {
-    using type = vectorized::ColumnDate;
-};
-template <>
-struct TypeToColumn<vectorized::DataTypeDateTime> {
-    using type = vectorized::ColumnDateTime;
-};
-template <>
-struct TypeToColumn<vectorized::DataTypeDateV2> {
-    using type = vectorized::ColumnDateV2;
-};
-template <>
-struct TypeToColumn<vectorized::DataTypeDateTimeV2> {
-    using type = vectorized::ColumnDateTimeV2;
-};
-
-template <typename DataType>
-using TypeToColumnV = TypeToColumn<DataType>::type;
-
-// e.g. DateTypeDate -> VecDateTimeValue
-template <typename DataType>
-struct TypeToValueType {};
-template <>
-struct TypeToValueType<vectorized::DataTypeDate> {
-    using type = VecDateTimeValue;
-};
-template <>
-struct TypeToValueType<vectorized::DataTypeDateTime> {
-    using type = VecDateTimeValue;
-};
-template <>
-struct TypeToValueType<vectorized::DataTypeDateV2> {
-    using type = DateV2Value<DateV2ValueType>;
-};
-template <>
-struct TypeToValueType<vectorized::DataTypeDateTimeV2> {
-    using type = DateV2Value<DateTimeV2ValueType>;
-};
-
-template <typename DataType>
-using TypeToValueTypeV = TypeToValueType<DataType>::type;
-
-// e.g. ColumnDate -> Int64 (see also columns_number.h)
-template <typename ColumnType>
-    requires requires { typename ColumnType::value_type; }
-struct ValueTypeOfColumn {
-    using type = ColumnType::value_type;
-};
-
-template <typename ColumnType>
-using ValueTypeOfColumnV = ValueTypeOfColumn<ColumnType>::type;
-
-// check V1 or V2 for both DateType/ColumnType/ValueType/ValueOfColumnType
-template <typename Type>
-constexpr bool IsV1() {
-    return static_cast<bool>(std::is_same_v<Type, vectorized::DataTypeDate> ||
-                             std::is_same_v<Type, 
vectorized::DataTypeDateTime> ||
-                             std::is_same_v<Type, VecDateTimeValue> ||
-                             std::is_same_v<Type, vectorized::ColumnDate> ||
-                             std::is_same_v<Type, vectorized::ColumnDateTime> 
||
-                             std::is_same_v<Type, vectorized::Int64>);
-}
-
-// only for datelike types.
-template <typename Type>
-constexpr bool IsV2() {
-    return !IsV1<Type>();
-}
-
-} // namespace doris::date_cast
diff --git a/be/src/vec/functions/function.h b/be/src/vec/functions/function.h
index 83215785801..600327a7418 100644
--- a/be/src/vec/functions/function.h
+++ b/be/src/vec/functions/function.h
@@ -31,7 +31,7 @@
 #include "common/exception.h"
 #include "common/logging.h"
 #include "common/status.h"
-#include "olap/rowset/segment_v2/inverted_index_iterator.h"
+#include "olap/rowset/segment_v2/inverted_index_iterator.h" // IWYU pragma: 
keep
 #include "udf/udf.h"
 #include "vec/core/block.h"
 #include "vec/core/column_numbers.h"
@@ -226,6 +226,8 @@ public:
     virtual String get_name() const = 0;
 
     /// Override and return true if function could take different number of 
arguments.
+    ///TODO: this function is not actually used now. but in 
check_number_of_arguments we still need it because for many
+    /// functions we didn't set the correct number of arguments.
     virtual bool is_variadic() const = 0;
 
     /// For non-variadic functions, return number of arguments; otherwise 
return zero (that should be ignored).
diff --git a/be/src/vec/functions/function_convert_tz.cpp 
b/be/src/vec/functions/function_convert_tz.cpp
index b60f20e7733..bd3648580f9 100644
--- a/be/src/vec/functions/function_convert_tz.cpp
+++ b/be/src/vec/functions/function_convert_tz.cpp
@@ -21,13 +21,13 @@
 #include <cstdint>
 #include <memory>
 #include <string>
-#include <type_traits>
 #include <utility>
 
 #include "common/status.h"
+#include "runtime/define_primitive_type.h"
+#include "runtime/primitive_type.h"
 #include "udf/udf.h"
 #include "util/binary_cast.hpp"
-#include "util/datetype_cast.hpp"
 #include "util/timezone_utils.h"
 #include "vec/aggregate_functions/aggregate_function.h"
 #include "vec/columns/column.h"
@@ -64,18 +64,11 @@ struct ConvertTzState {
     cctz::time_zone to_tz;
 };
 
-template <typename ArgDateType>
 class FunctionConvertTZ : public IFunction {
-    using DateValueType = date_cast::TypeToValueTypeV<ArgDateType>;
-    using ColumnType = date_cast::TypeToColumnV<ArgDateType>;
-    using NativeType = date_cast::ValueTypeOfColumnV<ColumnType>;
-    constexpr static bool is_v1 = date_cast::IsV1<ArgDateType>();
-    using ReturnDateType = ArgDateType;
-    using ReturnDateValueType = date_cast::TypeToValueTypeV<ReturnDateType>;
-    using ReturnColumnType = date_cast::TypeToColumnV<ReturnDateType>;
-    using ReturnNativeType = date_cast::ValueTypeOfColumnV<ReturnColumnType>;
-    using ArgDateValueType = DateValueType;
-    using ArgNativeType = NativeType;
+    constexpr static PrimitiveType PType = PrimitiveType::TYPE_DATETIMEV2;
+    using DateValueType = PrimitiveTypeTraits<PType>::CppType;
+    using ColumnType = PrimitiveTypeTraits<PType>::ColumnType;
+    using NativeType = PrimitiveTypeTraits<PType>::CppNativeType;
 
 public:
     static constexpr auto name = "convert_tz";
@@ -87,20 +80,8 @@ public:
     size_t get_number_of_arguments() const override { return 3; }
 
     DataTypePtr get_return_type_impl(const DataTypes& arguments) const 
override {
-        if constexpr (is_v1) {
-            return have_nullable(arguments) ? 
make_nullable(std::make_shared<DataTypeDateTime>())
-                                            : 
std::make_shared<DataTypeDateTime>();
-        } else {
-            return have_nullable(arguments) ? 
make_nullable(std::make_shared<DataTypeDateTimeV2>())
-                                            : 
std::make_shared<DataTypeDateTimeV2>();
-        }
-    }
-
-    bool is_variadic() const override { return true; }
-
-    DataTypes get_variadic_argument_types_impl() const override {
-        return {std::make_shared<ArgDateType>(), 
std::make_shared<DataTypeString>(),
-                std::make_shared<DataTypeString>()};
+        return have_nullable(arguments) ? 
make_nullable(std::make_shared<DataTypeDateTimeV2>())
+                                        : 
std::make_shared<DataTypeDateTimeV2>();
     }
 
     // default value of timezone is invalid, should skip to avoid wrong 
exception
@@ -194,20 +175,20 @@ public:
             // ignore argument columns, use cached timezone input in state
             execute_tz_const_with_state(convert_tz_state,
                                         assert_cast<const 
ColumnType*>(argument_columns[0].get()),
-                                        
assert_cast<ReturnColumnType*>(result_column.get()),
+                                        
assert_cast<ColumnType*>(result_column.get()),
                                         result_null_map, input_rows_count);
         } else if (col_const[1] && col_const[2]) {
             // arguments are const
             execute_tz_const(context, assert_cast<const 
ColumnType*>(argument_columns[0].get()),
                              assert_cast<const 
ColumnString*>(argument_columns[1].get()),
                              assert_cast<const 
ColumnString*>(argument_columns[2].get()),
-                             
assert_cast<ReturnColumnType*>(result_column.get()), result_null_map,
+                             assert_cast<ColumnType*>(result_column.get()), 
result_null_map,
                              input_rows_count);
         } else {
             _execute(context, assert_cast<const 
ColumnType*>(argument_columns[0].get()),
                      assert_cast<const 
ColumnString*>(argument_columns[1].get()),
                      assert_cast<const 
ColumnString*>(argument_columns[2].get()),
-                     assert_cast<ReturnColumnType*>(result_column.get()), 
result_null_map,
+                     assert_cast<ColumnType*>(result_column.get()), 
result_null_map,
                      input_rows_count);
         } //if const
 
@@ -223,7 +204,7 @@ public:
 private:
     static void _execute(FunctionContext* context, const ColumnType* 
date_column,
                          const ColumnString* from_tz_column, const 
ColumnString* to_tz_column,
-                         ReturnColumnType* result_column, NullMap& 
result_null_map,
+                         ColumnType* result_column, NullMap& result_null_map,
                          size_t input_rows_count) {
         for (size_t i = 0; i < input_rows_count; i++) {
             if (result_null_map[i]) {
@@ -238,8 +219,8 @@ private:
 
     static void execute_tz_const_with_state(ConvertTzState* convert_tz_state,
                                             const ColumnType* date_column,
-                                            ReturnColumnType* result_column,
-                                            NullMap& result_null_map, size_t 
input_rows_count) {
+                                            ColumnType* result_column, 
NullMap& result_null_map,
+                                            size_t input_rows_count) {
         cctz::time_zone& from_tz = convert_tz_state->from_tz;
         cctz::time_zone& to_tz = convert_tz_state->to_tz;
         auto push_null = [&](size_t row) {
@@ -262,46 +243,27 @@ private:
 
             DateValueType ts_value =
                     binary_cast<NativeType, 
DateValueType>(date_column->get_element(i));
-            ReturnDateValueType ts_value2;
-
-            if constexpr (std::is_same_v<ArgDateType, DataTypeDateTimeV2>) {
-                std::pair<int64_t, int64_t> timestamp;
-                if (!ts_value.unix_timestamp(&timestamp, from_tz)) 
[[unlikely]] {
-                    throw_invalid_string("convert_tz", from_tz.name());
-                }
-                ts_value2.from_unixtime(timestamp, to_tz);
-            } else {
-                int64_t timestamp;
-                if (!ts_value.unix_timestamp(&timestamp, from_tz)) 
[[unlikely]] {
-                    throw_invalid_string("convert_tz", from_tz.name());
-                }
-                ts_value2.from_unixtime(timestamp, to_tz);
+            DateValueType ts_value2;
+
+            std::pair<int64_t, int64_t> timestamp;
+            if (!ts_value.unix_timestamp(&timestamp, from_tz)) [[unlikely]] {
+                throw_invalid_string("convert_tz", from_tz.name());
             }
+            ts_value2.from_unixtime(timestamp, to_tz);
 
             if (!ts_value2.is_valid_date()) [[unlikely]] {
                 
throw_out_of_bound_convert_tz<DateValueType>(date_column->get_element(i),
                                                              from_tz.name(), 
to_tz.name());
             }
 
-            if constexpr (std::is_same_v<ArgDateType, DataTypeDateTimeV2>) {
-                result_column->insert(Field::create_field<TYPE_DATETIMEV2>(
-                        binary_cast<ReturnDateValueType, 
ReturnNativeType>(ts_value2)));
-            } else if constexpr (std::is_same_v<ArgDateType, DataTypeDateV2>) {
-                result_column->insert(Field::create_field<TYPE_DATEV2>(
-                        binary_cast<ReturnDateValueType, 
ReturnNativeType>(ts_value2)));
-            } else if constexpr (std::is_same_v<ArgDateType, 
DataTypeDateTime>) {
-                result_column->insert(Field::create_field<TYPE_DATETIME>(
-                        binary_cast<ReturnDateValueType, 
ReturnNativeType>(ts_value2)));
-            } else {
-                result_column->insert(Field::create_field<TYPE_DATE>(
-                        binary_cast<ReturnDateValueType, 
ReturnNativeType>(ts_value2)));
-            }
+            result_column->insert(Field::create_field<TYPE_DATETIMEV2>(
+                    binary_cast<DateValueType, NativeType>(ts_value2)));
         }
     }
 
     static void execute_tz_const(FunctionContext* context, const ColumnType* 
date_column,
                                  const ColumnString* from_tz_column,
-                                 const ColumnString* to_tz_column, 
ReturnColumnType* result_column,
+                                 const ColumnString* to_tz_column, ColumnType* 
result_column,
                                  NullMap& result_null_map, size_t 
input_rows_count) {
         auto from_tz = from_tz_column->get_data_at(0).to_string();
         auto to_tz = to_tz_column->get_data_at(0).to_string();
@@ -324,12 +286,12 @@ private:
     }
 
     static void execute_inner_loop(const ColumnType* date_column, const 
std::string& from_tz_name,
-                                   const std::string& to_tz_name, 
ReturnColumnType* result_column,
+                                   const std::string& to_tz_name, ColumnType* 
result_column,
                                    NullMap& result_null_map, const size_t 
index_now) {
         DateValueType ts_value =
                 binary_cast<NativeType, 
DateValueType>(date_column->get_element(index_now));
         cctz::time_zone from_tz {}, to_tz {};
-        ReturnDateValueType ts_value2;
+        DateValueType ts_value2;
 
         if (!TimezoneUtils::find_cctz_time_zone(from_tz_name, from_tz)) 
[[unlikely]] {
             throw Exception(ErrorCode::INVALID_ARGUMENT, "Operation {} invalid 
timezone: {}", name,
@@ -340,45 +302,24 @@ private:
                             to_tz_name);
         }
 
-        if constexpr (std::is_same_v<ArgDateType, DataTypeDateTimeV2>) {
-            std::pair<int64_t, int64_t> timestamp;
-            if (!ts_value.unix_timestamp(&timestamp, from_tz)) {
-                throw_invalid_string("convert_tz", from_tz.name());
-            }
-            ts_value2.from_unixtime(timestamp, to_tz);
-        } else {
-            int64_t timestamp;
-            if (!ts_value.unix_timestamp(&timestamp, from_tz)) {
-                throw_invalid_string("convert_tz", from_tz.name());
-            }
-
-            ts_value2.from_unixtime(timestamp, to_tz);
+        std::pair<int64_t, int64_t> timestamp;
+        if (!ts_value.unix_timestamp(&timestamp, from_tz)) {
+            throw_invalid_string("convert_tz", from_tz.name());
         }
+        ts_value2.from_unixtime(timestamp, to_tz);
 
         if (!ts_value2.is_valid_date()) [[unlikely]] {
             
throw_out_of_bound_convert_tz<DateValueType>(date_column->get_element(index_now),
                                                          from_tz.name(), 
to_tz.name());
         }
 
-        if constexpr (std::is_same_v<ArgDateType, DataTypeDateTimeV2>) {
-            result_column->insert(Field::create_field<TYPE_DATETIMEV2>(
-                    binary_cast<ReturnDateValueType, 
ReturnNativeType>(ts_value2)));
-        } else if constexpr (std::is_same_v<ArgDateType, DataTypeDateV2>) {
-            result_column->insert(Field::create_field<TYPE_DATEV2>(
-                    binary_cast<ReturnDateValueType, 
ReturnNativeType>(ts_value2)));
-        } else if constexpr (std::is_same_v<ArgDateType, DataTypeDateTime>) {
-            result_column->insert(Field::create_field<TYPE_DATETIME>(
-                    binary_cast<ReturnDateValueType, 
ReturnNativeType>(ts_value2)));
-        } else {
-            result_column->insert(Field::create_field<TYPE_DATE>(
-                    binary_cast<ReturnDateValueType, 
ReturnNativeType>(ts_value2)));
-        }
+        result_column->insert(Field::create_field<TYPE_DATETIMEV2>(
+                binary_cast<DateValueType, NativeType>(ts_value2)));
     }
 };
 
 void register_function_convert_tz(SimpleFunctionFactory& factory) {
-    factory.register_function<FunctionConvertTZ<DataTypeDateTime>>();
-    factory.register_function<FunctionConvertTZ<DataTypeDateTimeV2>>();
+    factory.register_function<FunctionConvertTZ>();
 }
 
 } // namespace doris::vectorized
diff --git a/be/src/vec/functions/function_datetime_floor_ceil.cpp 
b/be/src/vec/functions/function_datetime_floor_ceil.cpp
index 2f9074155b9..d8516763f5f 100644
--- a/be/src/vec/functions/function_datetime_floor_ceil.cpp
+++ b/be/src/vec/functions/function_datetime_floor_ceil.cpp
@@ -15,10 +15,6 @@
 // specific language governing permissions and limitations
 // under the License.
 
-#include "vec/common/assert_cast.h"
-#if !defined(__APPLE__)
-#include <experimental/bits/simd.h>
-#endif
 #include <glog/logging.h>
 
 #include <algorithm>
@@ -28,19 +24,23 @@
 #include <cstddef>
 #include <cstdint>
 #include <cstring>
+#if !defined(__APPLE__)
+#include <experimental/bits/simd.h>
+#endif
 #include <memory>
 #include <type_traits>
 #include <utility>
 
 #include "common/compiler_util.h"
 #include "common/status.h"
+#include "runtime/define_primitive_type.h"
 #include "util/binary_cast.hpp"
-#include "util/datetype_cast.hpp"
 #include "vec/aggregate_functions/aggregate_function.h"
 #include "vec/columns/column.h"
 #include "vec/columns/column_const.h"
 #include "vec/columns/column_nullable.h"
 #include "vec/columns/column_vector.h"
+#include "vec/common/assert_cast.h"
 #include "vec/common/pod_array_fwd.h"
 #include "vec/core/block.h"
 #include "vec/core/column_numbers.h"
@@ -95,12 +95,12 @@ struct YearFloor;
 #define CEIL 1
 #endif
 
-template <typename Flag, typename DateType, int ArgNum, bool UseDelta = false>
+template <typename Flag, PrimitiveType PType, int ArgNum, bool UseDelta = 
false>
 class FunctionDateTimeFloorCeil : public IFunction {
 public:
-    using DateValueType = date_cast::TypeToValueTypeV<DateType>;
-    using NativeType = DateType::FieldType;
-    static constexpr PrimitiveType PType = DateType::PType;
+    using DateType = PrimitiveTypeTraits<PType>::DataType;
+    using DateValueType = PrimitiveTypeTraits<PType>::CppType;
+    using NativeType = PrimitiveTypeTraits<PType>::CppNativeType;
     using DeltaDataType = DataTypeInt32;
     // return date type = DateType
     static constexpr auto name = Flag::name;
@@ -894,34 +894,32 @@ private:
 
 #define TIME_ROUND_WITH_DELTA_TYPE(IMPL, NAME, UNIT, TYPE, DELTA)              
                   \
     using FunctionOneArg##IMPL##DELTA =                                        
                   \
-            FunctionDateTimeFloorCeil<IMPL, DataTypeDateTime,                  
                   \
-                                      1>; /*DateTime and Date is same here*/   
                   \
-    using FunctionTwoArg##IMPL##DELTA = FunctionDateTimeFloorCeil<IMPL, 
DataTypeDateTime, 2>;     \
-    using FunctionThreeArg##IMPL##DELTA = FunctionDateTimeFloorCeil<IMPL, 
DataTypeDateTime, 3>;   \
-    using FunctionDateV2OneArg##IMPL##DELTA = FunctionDateTimeFloorCeil<IMPL, 
DataTypeDateV2, 1>; \
-    using FunctionDateV2TwoArg##IMPL##DELTA = FunctionDateTimeFloorCeil<IMPL, 
DataTypeDateV2, 2>; \
-    using FunctionDateV2ThreeArg##IMPL##DELTA =                                
                   \
-            FunctionDateTimeFloorCeil<IMPL, DataTypeDateV2, 3>;                
                   \
+            FunctionDateTimeFloorCeil<IMPL, TYPE_DATETIME, 1>; /*DateTime and 
Date is same here*/ \
+    using FunctionTwoArg##IMPL##DELTA = FunctionDateTimeFloorCeil<IMPL, 
TYPE_DATETIME, 2>;        \
+    using FunctionThreeArg##IMPL##DELTA = FunctionDateTimeFloorCeil<IMPL, 
TYPE_DATETIME, 3>;      \
+    using FunctionDateV2OneArg##IMPL##DELTA = FunctionDateTimeFloorCeil<IMPL, 
TYPE_DATEV2, 1>;    \
+    using FunctionDateV2TwoArg##IMPL##DELTA = FunctionDateTimeFloorCeil<IMPL, 
TYPE_DATEV2, 2>;    \
+    using FunctionDateV2ThreeArg##IMPL##DELTA = 
FunctionDateTimeFloorCeil<IMPL, TYPE_DATEV2, 3>;  \
     using FunctionDateTimeV2OneArg##IMPL##DELTA =                              
                   \
-            FunctionDateTimeFloorCeil<IMPL, DataTypeDateTimeV2, 1>;            
                   \
+            FunctionDateTimeFloorCeil<IMPL, TYPE_DATETIMEV2, 1>;               
                   \
     using FunctionDateTimeV2TwoArg##IMPL##DELTA =                              
                   \
-            FunctionDateTimeFloorCeil<IMPL, DataTypeDateTimeV2, 2>;            
                   \
+            FunctionDateTimeFloorCeil<IMPL, TYPE_DATETIMEV2, 2>;               
                   \
     using FunctionDateTimeV2ThreeArg##IMPL##DELTA =                            
                   \
-            FunctionDateTimeFloorCeil<IMPL, DataTypeDateTimeV2, 3>;
-
-#define TIME_ROUND_DECLARE(IMPL, NAME, UNIT, TYPE)                             
                  \
-    struct IMPL {                                                              
                  \
-        static constexpr auto name = #NAME;                                    
                  \
-        static constexpr TimeUnit Unit = UNIT;                                 
                  \
-        static constexpr auto Type = TYPE;                                     
                  \
-    };                                                                         
                  \
-                                                                               
                  \
-    TIME_ROUND_WITH_DELTA_TYPE(IMPL, NAME, UNIT, TYPE, Int32)                  
                  \
-    using FunctionDateV2TwoArg##IMPL = FunctionDateTimeFloorCeil<IMPL, 
DataTypeDateV2, 2, true>; \
-    using FunctionDateTimeV2TwoArg##IMPL =                                     
                  \
-            FunctionDateTimeFloorCeil<IMPL, DataTypeDateTimeV2, 2, true>;      
                  \
-    using FunctionDateTimeTwoArg##IMPL =                                       
                  \
-            FunctionDateTimeFloorCeil<IMPL, DataTypeDateTime, 2,               
                  \
+            FunctionDateTimeFloorCeil<IMPL, TYPE_DATETIMEV2, 3>;
+
+#define TIME_ROUND_DECLARE(IMPL, NAME, UNIT, TYPE)                             
               \
+    struct IMPL {                                                              
               \
+        static constexpr auto name = #NAME;                                    
               \
+        static constexpr TimeUnit Unit = UNIT;                                 
               \
+        static constexpr auto Type = TYPE;                                     
               \
+    };                                                                         
               \
+                                                                               
               \
+    TIME_ROUND_WITH_DELTA_TYPE(IMPL, NAME, UNIT, TYPE, Int32)                  
               \
+    using FunctionDateV2TwoArg##IMPL = FunctionDateTimeFloorCeil<IMPL, 
TYPE_DATEV2, 2, true>; \
+    using FunctionDateTimeV2TwoArg##IMPL =                                     
               \
+            FunctionDateTimeFloorCeil<IMPL, TYPE_DATETIMEV2, 2, true>;         
               \
+    using FunctionDateTimeTwoArg##IMPL =                                       
               \
+            FunctionDateTimeFloorCeil<IMPL, TYPE_DATETIME, 2,                  
               \
                                       true>; /*DateTime and Date is same here*/
 
 TIME_ROUND_DECLARE(YearFloor, year_floor, YEAR, FLOOR);
diff --git a/be/src/vec/functions/function_other_types_to_date.cpp 
b/be/src/vec/functions/function_other_types_to_date.cpp
index 3de4ee5e485..56b75d39cb8 100644
--- a/be/src/vec/functions/function_other_types_to_date.cpp
+++ b/be/src/vec/functions/function_other_types_to_date.cpp
@@ -32,10 +32,10 @@
 
 #include "common/status.h"
 #include "runtime/define_primitive_type.h"
+#include "runtime/primitive_type.h"
 #include "runtime/runtime_state.h"
 #include "udf/udf.h"
 #include "util/binary_cast.hpp"
-#include "util/datetype_cast.hpp"
 #include "util/time_lut.h"
 #include "vec/aggregate_functions/aggregate_function.h"
 #include "vec/columns/column.h"
@@ -67,11 +67,11 @@
 
 namespace doris::vectorized {
 #include "common/compile_check_avoid_begin.h"
-template <typename DateType>
+
 struct StrToDate {
     static constexpr auto name = "str_to_date";
 
-    static bool is_variadic() { return false; }
+    static bool is_variadic() { return true; }
 
     static size_t get_number_of_arguments() { return 2; }
 
@@ -79,12 +79,13 @@ struct StrToDate {
         return {std::make_shared<DataTypeString>(), 
std::make_shared<DataTypeString>()};
     }
 
+    //ATTN: because str_to_date may have different return type with same input 
types (for some inputs with special
+    // format, if skip FE fold or FE fold failed). in implementation, we use 
type of result column slot in block, so
+    // it's ok. just different with get_return_type_impl.
+    static bool skip_return_type_check() { return true; }
     static DataTypePtr get_return_type_impl(const DataTypes& arguments) {
-        if constexpr (IsDataTypeDateTimeV2<DateType>) {
-            // max scale
-            return std::make_shared<DataTypeDateTimeV2>(6);
-        }
-        return std::make_shared<DateType>();
+        // it's FAKE. takes no effect.
+        return std::make_shared<DataTypeDateTimeV2>(6);
     }
 
     // Handle nulls manually to prevent invalid default values from causing 
errors
@@ -146,52 +147,36 @@ struct StrToDate {
         const auto& rdata = specific_char_column->get_chars();
         const auto& roffsets = specific_char_column->get_offsets();
 
+        ColumnPtr res;
         // Because of we cant distinguish by return_type when we find 
function. so the return_type may NOT be same with real return type
-        // which decided by FE. that's found by which.
-        ColumnPtr res = nullptr;
-        switch (block.get_by_position(result).type->get_primitive_type()) {
-        case PrimitiveType::TYPE_DATETIMEV2: {
-            res = ColumnDateTimeV2::create();
-            if (col_const[1]) {
-                execute_impl_const_right<DataTypeDateTimeV2>(
-                        context, ldata, loffsets, 
specific_char_column->get_data_at(0),
-                        result_null_map,
-                        
static_cast<ColumnDateTimeV2*>(res->assume_mutable().get())->get_data());
-            } else {
-                execute_impl<DataTypeDateTimeV2>(
-                        context, ldata, loffsets, rdata, roffsets, 
result_null_map,
-                        
static_cast<ColumnDateTimeV2*>(res->assume_mutable().get())->get_data());
-            }
-            break;
-        }
-        case PrimitiveType::TYPE_DATEV2: {
-            res = ColumnDateV2::create();
+        // which decided by FE. we directly use block column's type which 
decided by FE.
+        if (block.get_by_position(result).type->get_primitive_type() == 
TYPE_DATEV2) {
+            res = ColumnDateV2::create(input_rows_count);
             if (col_const[1]) {
-                execute_impl_const_right<DataTypeDateV2>(
+                execute_impl_const_right<TYPE_DATEV2>(
                         context, ldata, loffsets, 
specific_char_column->get_data_at(0),
                         result_null_map,
                         
static_cast<ColumnDateV2*>(res->assume_mutable().get())->get_data());
             } else {
-                execute_impl<DataTypeDateV2>(
+                execute_impl<TYPE_DATEV2>(
                         context, ldata, loffsets, rdata, roffsets, 
result_null_map,
                         
static_cast<ColumnDateV2*>(res->assume_mutable().get())->get_data());
             }
-            break;
-        }
-        default: {
-            res = ColumnDateTime::create();
+        } else {
+            DCHECK(block.get_by_position(result).type->get_primitive_type() == 
TYPE_DATETIMEV2);
+
+            res = ColumnDateTimeV2::create(input_rows_count);
             if (col_const[1]) {
-                execute_impl_const_right<DataTypeDateTime>(
+                execute_impl_const_right<TYPE_DATETIMEV2>(
                         context, ldata, loffsets, 
specific_char_column->get_data_at(0),
                         result_null_map,
-                        
static_cast<ColumnDateTime*>(res->assume_mutable().get())->get_data());
+                        
static_cast<ColumnDateTimeV2*>(res->assume_mutable().get())->get_data());
             } else {
-                execute_impl<DataTypeDateTime>(
+                execute_impl<TYPE_DATETIMEV2>(
                         context, ldata, loffsets, rdata, roffsets, 
result_null_map,
-                        
static_cast<ColumnDateTime*>(res->assume_mutable().get())->get_data());
+                        
static_cast<ColumnDateTimeV2*>(res->assume_mutable().get())->get_data());
             }
         }
-        }
 
         // Wrap result in nullable column only if input has nullable arguments
         if (block.get_by_position(result).type->is_nullable()) {
@@ -205,14 +190,12 @@ struct StrToDate {
     }
 
 private:
-    template <typename ArgDateType,
-              typename DateValueType = 
date_cast::TypeToValueTypeV<ArgDateType>,
-              typename NativeType = date_cast::TypeToColumnV<ArgDateType>>
-    static void execute_impl(FunctionContext* context, const 
ColumnString::Chars& ldata,
-                             const ColumnString::Offsets& loffsets,
-                             const ColumnString::Chars& rdata,
-                             const ColumnString::Offsets& roffsets, const 
NullMap& result_null_map,
-                             PaddedPODArray<NativeType>& res) {
+    template <PrimitiveType PType>
+    static void execute_impl(
+            FunctionContext* context, const ColumnString::Chars& ldata,
+            const ColumnString::Offsets& loffsets, const ColumnString::Chars& 
rdata,
+            const ColumnString::Offsets& roffsets, const NullMap& 
result_null_map,
+            PaddedPODArray<typename 
PrimitiveTypeTraits<PType>::CppNativeType>& res) {
         size_t size = loffsets.size();
         res.resize(size);
         for (size_t i = 0; i < size; ++i) {
@@ -226,17 +209,17 @@ private:
             const char* r_raw_str = reinterpret_cast<const 
char*>(&rdata[roffsets[i - 1]]);
             size_t r_str_size = roffsets[i] - roffsets[i - 1];
             const StringRef format_str = rewrite_specific_format(r_raw_str, 
r_str_size);
-            _execute_inner_loop<DateValueType, NativeType>(l_raw_str, 
l_str_size, format_str.data,
-                                                           format_str.size, 
context, res, i);
+            _execute_inner_loop<PType>(l_raw_str, l_str_size, format_str.data, 
format_str.size,
+                                       context, res, i);
         }
     }
-    template <typename ArgDateType,
-              typename DateValueType = 
date_cast::TypeToValueTypeV<ArgDateType>,
-              typename NativeType = date_cast::TypeToColumnV<ArgDateType>>
-    static void execute_impl_const_right(FunctionContext* context, const 
ColumnString::Chars& ldata,
-                                         const ColumnString::Offsets& loffsets,
-                                         const StringRef& rdata, const 
NullMap& result_null_map,
-                                         PaddedPODArray<NativeType>& res) {
+
+    template <PrimitiveType PType>
+    static void execute_impl_const_right(
+            FunctionContext* context, const ColumnString::Chars& ldata,
+            const ColumnString::Offsets& loffsets, const StringRef& rdata,
+            const NullMap& result_null_map,
+            PaddedPODArray<typename 
PrimitiveTypeTraits<PType>::CppNativeType>& res) {
         size_t size = loffsets.size();
         res.resize(size);
         const StringRef format_str = rewrite_specific_format(rdata.data, 
rdata.size);
@@ -248,33 +231,30 @@ private:
             const char* l_raw_str = reinterpret_cast<const 
char*>(&ldata[loffsets[i - 1]]);
             size_t l_str_size = loffsets[i] - loffsets[i - 1];
 
-            _execute_inner_loop<DateValueType, NativeType>(l_raw_str, 
l_str_size, format_str.data,
-                                                           format_str.size, 
context, res, i);
+            _execute_inner_loop<PType>(l_raw_str, l_str_size, format_str.data, 
format_str.size,
+                                       context, res, i);
         }
     }
-    template <typename DateValueType, typename NativeType>
-    static void _execute_inner_loop(const char* l_raw_str, size_t l_str_size, 
const char* r_raw_str,
-                                    size_t r_str_size, FunctionContext* 
context,
-                                    PaddedPODArray<NativeType>& res, size_t 
index) {
-        auto& ts_val = *reinterpret_cast<DateValueType*>(&res[index]);
+
+    template <PrimitiveType PType>
+    static void _execute_inner_loop(
+            const char* l_raw_str, size_t l_str_size, const char* r_raw_str, 
size_t r_str_size,
+            FunctionContext* context,
+            PaddedPODArray<typename 
PrimitiveTypeTraits<PType>::CppNativeType>& res, size_t index) {
+        auto& ts_val =
+                *reinterpret_cast<typename 
PrimitiveTypeTraits<PType>::CppType*>(&res[index]);
         if (!ts_val.from_date_format_str(r_raw_str, r_str_size, l_raw_str, 
l_str_size))
                 [[unlikely]] {
             throw_invalid_strings("str_to_date", std::string_view(l_raw_str, 
l_str_size),
                                   std::string_view(r_raw_str, r_str_size));
         }
-        if constexpr (std::is_same_v<DateValueType, VecDateTimeValue>) {
-            if (context->get_return_type()->get_primitive_type() ==
-                doris::PrimitiveType::TYPE_DATETIME) {
-                ts_val.to_datetime();
-            } else {
-                ts_val.cast_to_date();
-            }
-        }
     }
 };
 
 struct MakeDateImpl {
     static constexpr auto name = "makedate";
+    using DateValueType = 
PrimitiveTypeTraits<PrimitiveType::TYPE_DATEV2>::CppType;
+    using NativeType = 
PrimitiveTypeTraits<PrimitiveType::TYPE_DATEV2>::CppNativeType;
 
     static bool is_variadic() { return false; }
 
@@ -283,7 +263,7 @@ struct MakeDateImpl {
     static DataTypes get_variadic_argument_types() { return {}; }
 
     static DataTypePtr get_return_type_impl(const DataTypes& arguments) {
-        return std::make_shared<DataTypeDate>();
+        return std::make_shared<DataTypeDateV2>();
     }
 
     // Handle nulls manually to prevent invalid default values from causing 
errors
@@ -294,8 +274,8 @@ struct MakeDateImpl {
         DCHECK_EQ(arguments.size(), 2);
 
         // Handle null map manually - update result null map from input null 
maps upfront
-        auto result_null_map_column = ColumnUInt8::create(input_rows_count, 0);
-        NullMap& result_null_map = 
assert_cast<ColumnUInt8&>(*result_null_map_column).get_data();
+        auto result_null_map_column = ColumnBool::create(input_rows_count, 0);
+        NullMap& result_null_map = 
assert_cast<ColumnBool&>(*result_null_map_column).get_data();
 
         ColumnPtr argument_columns[2];
         bool col_const[2];
@@ -325,47 +305,16 @@ struct MakeDateImpl {
         const auto* dayofyear_col = assert_cast<const 
ColumnInt32*>(argument_columns[1].get());
 
         ColumnPtr res_column;
-        switch (block.get_by_position(result).type->get_primitive_type()) {
-        case PrimitiveType::TYPE_DATEV2: {
-            res_column = ColumnDateV2::create(input_rows_count);
-            if (col_const[1]) {
-                execute_impl_right_const<DataTypeDateV2>(
-                        year_col->get_data(), dayofyear_col->get_element(0), 
result_null_map,
-                        
static_cast<ColumnDateV2*>(res_column->assume_mutable().get())->get_data());
-            } else {
-                execute_impl<DataTypeDateV2>(
-                        year_col->get_data(), dayofyear_col->get_data(), 
result_null_map,
-                        
static_cast<ColumnDateV2*>(res_column->assume_mutable().get())->get_data());
-            }
-            break;
-        }
-        case PrimitiveType::TYPE_DATETIMEV2: {
-            res_column = ColumnDateTimeV2::create(input_rows_count);
-            if (col_const[1]) {
-                execute_impl_right_const<DataTypeDateTimeV2>(
-                        year_col->get_data(), dayofyear_col->get_element(0), 
result_null_map,
-                        
static_cast<ColumnDateTimeV2*>(res_column->assume_mutable().get())
-                                ->get_data());
-            } else {
-                execute_impl<DataTypeDateTimeV2>(
-                        year_col->get_data(), dayofyear_col->get_data(), 
result_null_map,
-                        
static_cast<ColumnDateTimeV2*>(res_column->assume_mutable().get())
-                                ->get_data());
-            }
-            break;
-        }
-        default: {
-            res_column = ColumnDate::create(input_rows_count);
-            if (col_const[1]) {
-                execute_impl_right_const<DataTypeDate>(
-                        year_col->get_data(), dayofyear_col->get_element(0), 
result_null_map,
-                        
assert_cast<ColumnDate*>(res_column->assume_mutable().get())->get_data());
-            } else {
-                execute_impl<DataTypeDate>(
-                        year_col->get_data(), dayofyear_col->get_data(), 
result_null_map,
-                        
assert_cast<ColumnDate*>(res_column->assume_mutable().get())->get_data());
-            }
-        }
+
+        res_column = ColumnDateV2::create(input_rows_count);
+        if (col_const[1]) {
+            execute_impl_right_const(
+                    year_col->get_data(), dayofyear_col->get_element(0), 
result_null_map,
+                    
static_cast<ColumnDateV2*>(res_column->assume_mutable().get())->get_data());
+        } else {
+            execute_impl(
+                    year_col->get_data(), dayofyear_col->get_data(), 
result_null_map,
+                    
static_cast<ColumnDateV2*>(res_column->assume_mutable().get())->get_data());
         }
 
         // Wrap result in nullable column only if input has nullable arguments
@@ -380,11 +329,9 @@ struct MakeDateImpl {
     }
 
 private:
-    template <typename DateType, typename DateValueType = 
date_cast::TypeToValueTypeV<DateType>,
-              typename ReturnType = date_cast::TypeToColumnV<DateType>>
     static void execute_impl(const PaddedPODArray<Int32>& year_data,
                              const PaddedPODArray<Int32>& dayofyear_data,
-                             const NullMap& result_null_map, 
PaddedPODArray<ReturnType>& res) {
+                             const NullMap& result_null_map, 
PaddedPODArray<NativeType>& res) {
         auto len = year_data.size();
         res.resize(len);
 
@@ -398,14 +345,13 @@ private:
             if (dayofyear <= 0 || year < 0 || year > 9999) [[unlikely]] {
                 throw_out_of_bound_two_ints(name, year, dayofyear);
             }
-            _execute_inner_loop<DateValueType, ReturnType>(year, dayofyear, 
res, i);
+            _execute_inner_loop(year, dayofyear, res, i);
         }
     }
-    template <typename DateType, typename DateValueType = 
date_cast::TypeToValueTypeV<DateType>,
-              typename ReturnType = date_cast::TypeToColumnV<DateType>>
+
     static void execute_impl_right_const(const PaddedPODArray<Int32>& 
year_data, Int32 dayofyear,
                                          const NullMap& result_null_map,
-                                         PaddedPODArray<ReturnType>& res) {
+                                         PaddedPODArray<NativeType>& res) {
         auto len = year_data.size();
         res.resize(len);
 
@@ -418,29 +364,17 @@ private:
             if (dayofyear <= 0 || year < 0 || year > 9999) [[unlikely]] {
                 throw_out_of_bound_two_ints(name, year, dayofyear);
             }
-            _execute_inner_loop<DateValueType, ReturnType>(year, dayofyear, 
res, i);
+            _execute_inner_loop(year, dayofyear, res, i);
         }
     }
-    template <typename DateValueType, typename ReturnType>
+
     static void _execute_inner_loop(const int& year, const int& dayofyear,
-                                    PaddedPODArray<ReturnType>& res, size_t 
index) {
+                                    PaddedPODArray<NativeType>& res, size_t 
index) {
         auto& res_val = *reinterpret_cast<DateValueType*>(&res[index]);
-        if constexpr (std::is_same_v<DateValueType, VecDateTimeValue>) {
-            VecDateTimeValue ts_value = VecDateTimeValue();
-            ts_value.unchecked_set_time(year, 1, 1, 0, 0, 0);
-
-            TimeInterval interval(DAY, dayofyear - 1, false);
-            res_val = ts_value;
-            if (!res_val.template date_add_interval<DAY>(interval)) {
-                throw_out_of_bound_two_ints(name, year, dayofyear);
-            }
-            res_val.cast_to_date();
-        } else {
-            res_val.unchecked_set_time(year, 1, 1, 0, 0, 0, 0);
-            TimeInterval interval(DAY, dayofyear - 1, false);
-            if (!res_val.template date_add_interval<DAY>(interval)) {
-                throw_out_of_bound_two_ints(name, year, dayofyear);
-            }
+        res_val.unchecked_set_time(year, 1, 1, 0, 0, 0, 0);
+        TimeInterval interval(DAY, dayofyear - 1, false);
+        if (!res_val.template date_add_interval<DAY>(interval)) {
+            throw_out_of_bound_two_ints(name, year, dayofyear);
         }
     }
 };
@@ -450,13 +384,13 @@ struct DateTruncState {
     Callback_function callback_function;
 };
 
-template <typename DateType, bool DateArgIsFirst>
+template <PrimitiveType PType, bool DateArgIsFirst>
 struct DateTrunc {
     static constexpr auto name = "date_trunc";
-
-    using ColumnType = date_cast::TypeToColumnV<DateType>;
-    using DateValueType = date_cast::TypeToValueTypeV<DateType>;
-    using ArgType = date_cast::ValueTypeOfColumnV<ColumnType>;
+    using DateType = PrimitiveTypeTraits<PType>::DataType;
+    using ColumnType = PrimitiveTypeTraits<PType>::ColumnType;
+    using DateValueType = PrimitiveTypeTraits<PType>::CppType;
+    using NativeType = PrimitiveTypeTraits<PType>::CppNativeType;
 
     static bool is_variadic() { return true; }
 
@@ -536,11 +470,11 @@ private:
         auto& data = static_cast<const 
ColumnType*>(datetime_column.get())->get_data();
         auto& res = 
static_cast<ColumnType*>(result_column->assume_mutable().get())->get_data();
         for (size_t i = 0; i < input_rows_count; ++i) {
-            auto dt = binary_cast<ArgType, DateValueType>(data[i]);
+            auto dt = binary_cast<NativeType, DateValueType>(data[i]);
             if (!dt.template datetime_trunc<Unit>()) {
                 throw_out_of_bound_one_date<DateValueType>(name, data[i]);
             }
-            res[i] = binary_cast<DateValueType, ArgType>(dt);
+            res[i] = binary_cast<DateValueType, NativeType>(dt);
         }
     }
 };
@@ -936,12 +870,12 @@ public:
     }
 };
 
-template <template <typename> class Impl, typename DateType>
+template <template <PrimitiveType> class Impl, PrimitiveType PType>
 class FunctionDateOrDateTimeToDate : public IFunction {
 public:
-    static constexpr auto name = Impl<DateType>::name;
+    static constexpr auto name = Impl<PType>::name;
     static FunctionPtr create() {
-        return std::make_shared<FunctionDateOrDateTimeToDate<Impl, 
DateType>>();
+        return std::make_shared<FunctionDateOrDateTimeToDate<Impl, PType>>();
     }
 
     String get_name() const override { return name; }
@@ -951,37 +885,32 @@ public:
     bool is_variadic() const override { return true; }
 
     DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) 
const override {
-        //TODO: remove v1 types
-        if constexpr (date_cast::IsV1<DateType>()) {
-            return std::make_shared<DataTypeDate>();
-        } else {
-            return std::make_shared<DataTypeDateV2>();
-        }
+        return std::make_shared<DataTypeDateV2>();
     }
 
     DataTypes get_variadic_argument_types_impl() const override {
-        return {std::make_shared<DateType>()};
+        return {std::make_shared<typename 
PrimitiveTypeTraits<PType>::DataType>()};
     }
 
     //ATTN: no need to replace null value now because last_day and to_monday 
both process boundary case well.
     // may need to change if support more functions
     Status execute_impl(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
                         uint32_t result, size_t input_rows_count) const 
override {
-        return Impl<DateType>::execute_impl(context, block, arguments, result, 
input_rows_count);
+        return Impl<PType>::execute_impl(context, block, arguments, result, 
input_rows_count);
     }
 };
 
-template <typename DateType>
+template <PrimitiveType PType>
 struct LastDayImpl {
     static constexpr auto name = "last_day";
+    using DateType = PrimitiveTypeTraits<PType>::DataType;
+    using ColumnType = PrimitiveTypeTraits<PType>::ColumnType;
+    using DateValueType = PrimitiveTypeTraits<PType>::CppType;
+    using NativeType = PrimitiveTypeTraits<PType>::CppNativeType;
 
-    using DateValueType = date_cast::TypeToValueTypeV<DateType>;
-    using ColumnType = date_cast::TypeToColumnV<DateType>;
-    using NativeType = date_cast::ValueTypeOfColumnV<ColumnType>;
-    using ResultType =
-            std::conditional_t<date_cast::IsV1<DateType>(), DataTypeDate, 
DataTypeDateV2>;
-    using ResultColumnType = date_cast::TypeToColumnV<ResultType>;
-    using ResultNativeType = date_cast::ValueTypeOfColumnV<ResultColumnType>;
+    constexpr static PrimitiveType ResultPType = PrimitiveType::TYPE_DATEV2;
+    using ResultColumnType = PrimitiveTypeTraits<ResultPType>::ColumnType;
+    using ResultNativeType = PrimitiveTypeTraits<ResultPType>::CppNativeType;
 
     static Status execute_impl(FunctionContext* context, Block& block,
                                const ColumnNumbers& arguments, uint32_t result,
@@ -1000,14 +929,12 @@ struct LastDayImpl {
             block.replace_by_position(result,
                                       ColumnNullable::create(res_column, 
std::move(null_map)));
         } else {
-            if constexpr (date_cast::IsV2<DateType>()) {
-                auto data_col = assert_cast<const 
ColumnType*>(argument_column.get());
-                res_column = ResultColumnType::create(input_rows_count);
-                execute_straight(input_rows_count, data_col->get_data(),
-                                 
static_cast<ResultColumnType*>(res_column->assume_mutable().get())
-                                         ->get_data());
-                block.replace_by_position(result, std::move(res_column));
-            }
+            auto data_col = assert_cast<const 
ColumnType*>(argument_column.get());
+            res_column = ResultColumnType::create(input_rows_count);
+            execute_straight(
+                    input_rows_count, data_col->get_data(),
+                    
static_cast<ResultColumnType*>(res_column->assume_mutable().get())->get_data());
+            block.replace_by_position(result, std::move(res_column));
         }
         return Status::OK();
     }
@@ -1023,14 +950,10 @@ struct LastDayImpl {
             }
             int day = get_last_month_day(ts_value.year(), ts_value.month());
             // day is definitely legal
-            if constexpr (date_cast::IsV1<DateType>()) {
-                ts_value.unchecked_set_time(ts_value.year(), ts_value.month(), 
day, 0, 0, 0);
-                ts_value.set_type(TIME_DATE);
-                res_data[i] = binary_cast<VecDateTimeValue, Int64>(ts_value);
-            } else if constexpr (std::is_same_v<DateType, DataTypeDateV2>) {
+            if constexpr (std::is_same_v<DateType, DataTypeDateV2>) {
                 ts_value.template unchecked_set_time_unit<TimeUnit::DAY>(day);
                 res_data[i] = binary_cast<DateValueType, UInt32>(ts_value);
-            } else {
+            } else { // datetimev2
                 ts_value.template unchecked_set_time_unit<TimeUnit::DAY>(day);
                 ts_value.unchecked_set_time(ts_value.year(), ts_value.month(), 
day, 0, 0, 0, 0);
                 UInt64 cast_value = binary_cast<DateValueType, 
UInt64>(ts_value);
@@ -1054,17 +977,17 @@ struct LastDayImpl {
     }
 };
 
-template <typename DateType>
-struct MondayImpl {
+template <PrimitiveType PType>
+struct ToMondayImpl {
     static constexpr auto name = "to_monday";
+    using DateType = PrimitiveTypeTraits<PType>::DataType;
+    using ColumnType = PrimitiveTypeTraits<PType>::ColumnType;
+    using DateValueType = PrimitiveTypeTraits<PType>::CppType;
+    using NativeType = PrimitiveTypeTraits<PType>::CppNativeType;
 
-    using DateValueType = date_cast::TypeToValueTypeV<DateType>;
-    using ColumnType = date_cast::TypeToColumnV<DateType>;
-    using NativeType = date_cast::ValueTypeOfColumnV<ColumnType>;
-    using ResultType =
-            std::conditional_t<date_cast::IsV1<DateType>(), DataTypeDate, 
DataTypeDateV2>;
-    using ResultColumnType = date_cast::TypeToColumnV<ResultType>;
-    using ResultNativeType = date_cast::ValueTypeOfColumnV<ResultColumnType>;
+    constexpr static PrimitiveType ResultPType = PrimitiveType::TYPE_DATEV2;
+    using ResultColumnType = PrimitiveTypeTraits<ResultPType>::ColumnType;
+    using ResultNativeType = PrimitiveTypeTraits<ResultPType>::CppNativeType;
 
     static Status execute_impl(FunctionContext* context, Block& block,
                                const ColumnNumbers& arguments, uint32_t result,
@@ -1083,14 +1006,12 @@ struct MondayImpl {
             block.replace_by_position(result,
                                       ColumnNullable::create(res_column, 
std::move(null_map)));
         } else {
-            if constexpr (date_cast::IsV2<DateType>()) {
-                auto data_col = assert_cast<const 
ColumnType*>(argument_column.get());
-                res_column = ResultColumnType::create(input_rows_count);
-                execute_straight(input_rows_count, data_col->get_data(),
-                                 
static_cast<ResultColumnType*>(res_column->assume_mutable().get())
-                                         ->get_data());
-                block.replace_by_position(result, std::move(res_column));
-            }
+            auto data_col = assert_cast<const 
ColumnType*>(argument_column.get());
+            res_column = ResultColumnType::create(input_rows_count);
+            execute_straight(
+                    input_rows_count, data_col->get_data(),
+                    
static_cast<ResultColumnType*>(res_column->assume_mutable().get())->get_data());
+            block.replace_by_position(result, std::move(res_column));
         }
         return Status::OK();
     }
@@ -1105,23 +1026,7 @@ struct MondayImpl {
             if (!ts_value.is_valid_date()) [[unlikely]] {
                 throw_out_of_bound_one_date<DateValueType>("to_monday", 
cur_data);
             }
-            if constexpr (date_cast::IsV1<DateType>()) {
-                if (is_special_day(ts_value.year(), ts_value.month(), 
ts_value.day())) {
-                    ts_value.unchecked_set_time(ts_value.year(), 
ts_value.month(), 1, 0, 0, 0);
-                    ts_value.set_type(TIME_DATE);
-                    res_data[i] = binary_cast<VecDateTimeValue, 
Int64>(ts_value);
-                    continue;
-                }
-
-                // day_of_week, from 1(Mon) to 7(Sun)
-                int day_of_week = ts_value.weekday() + 1;
-                int gap_of_monday = day_of_week - 1;
-                TimeInterval interval(DAY, gap_of_monday, true);
-                ts_value.template date_add_interval<DAY>(interval);
-                ts_value.set_type(TIME_DATE);
-                res_data[i] = binary_cast<VecDateTimeValue, Int64>(ts_value);
-
-            } else if constexpr (std::is_same_v<DateType, DataTypeDateV2>) {
+            if constexpr (std::is_same_v<DateType, DataTypeDateV2>) {
                 if (is_special_day(ts_value.year(), ts_value.month(), 
ts_value.day())) {
                     ts_value.template 
unchecked_set_time_unit<TimeUnit::DAY>(1);
                     res_data[i] = binary_cast<DateValueType, UInt32>(ts_value);
@@ -1134,7 +1039,7 @@ struct MondayImpl {
                 TimeInterval interval(DAY, gap_of_monday, true);
                 ts_value.template date_add_interval<DAY>(interval);
                 res_data[i] = binary_cast<DateValueType, UInt32>(ts_value);
-            } else {
+            } else { // datetimev2
                 if (is_special_day(ts_value.year(), ts_value.month(), 
ts_value.day())) {
                     ts_value.unchecked_set_time(ts_value.year(), 
ts_value.month(), 1, 0, 0, 0, 0);
                     UInt64 cast_value = binary_cast<DateValueType, 
UInt64>(ts_value);
@@ -1180,6 +1085,15 @@ public:
         return Impl::get_return_type_impl(arguments);
     }
 
+    bool skip_return_type_check() const override {
+        if constexpr (requires { Impl::skip_return_type_check(); }) {
+            // for str_to_date now, it's very special
+            return Impl::skip_return_type_check();
+        } else {
+            return false;
+        }
+    }
+
     bool use_default_implementation_for_nulls() const override {
         if constexpr (requires { Impl::use_default_implementation_for_nulls(); 
}) {
             return Impl::use_default_implementation_for_nulls();
@@ -1189,14 +1103,10 @@ public:
     }
 
     Status open(FunctionContext* context, FunctionContext::FunctionStateScope 
scope) override {
-        if constexpr (std::is_same_v<Impl, DateTrunc<DataTypeDate, true>> ||
-                      std::is_same_v<Impl, DateTrunc<DataTypeDateV2, true>> ||
-                      std::is_same_v<Impl, DateTrunc<DataTypeDateTime, true>> 
||
-                      std::is_same_v<Impl, DateTrunc<DataTypeDateTimeV2, 
true>> ||
-                      std::is_same_v<Impl, DateTrunc<DataTypeDate, false>> ||
-                      std::is_same_v<Impl, DateTrunc<DataTypeDateV2, false>> ||
-                      std::is_same_v<Impl, DateTrunc<DataTypeDateTime, false>> 
||
-                      std::is_same_v<Impl, DateTrunc<DataTypeDateTimeV2, 
false>>) {
+        if constexpr (std::is_same_v<Impl, DateTrunc<TYPE_DATEV2, true>> ||
+                      std::is_same_v<Impl, DateTrunc<TYPE_DATETIMEV2, true>> ||
+                      std::is_same_v<Impl, DateTrunc<TYPE_DATEV2, false>> ||
+                      std::is_same_v<Impl, DateTrunc<TYPE_DATETIMEV2, false>>) 
{
             return Impl::open(context, scope);
         } else {
             return Status::OK();
@@ -1433,41 +1343,27 @@ private:
     }
 };
 
-using FunctionStrToDate = 
FunctionOtherTypesToDateType<StrToDate<DataTypeDate>>;
-using FunctionStrToDatetime = 
FunctionOtherTypesToDateType<StrToDate<DataTypeDateTime>>;
-using FunctionStrToDateV2 = 
FunctionOtherTypesToDateType<StrToDate<DataTypeDateV2>>;
-using FunctionStrToDatetimeV2 = 
FunctionOtherTypesToDateType<StrToDate<DataTypeDateTimeV2>>;
+using FunctionStrToDate = FunctionOtherTypesToDateType<StrToDate>;
+using FunctionStrToDatetime = FunctionOtherTypesToDateType<StrToDate>;
+
 using FunctionMakeDate = FunctionOtherTypesToDateType<MakeDateImpl>;
-using FunctionDateTruncDate = 
FunctionOtherTypesToDateType<DateTrunc<DataTypeDate, true>>;
-using FunctionDateTruncDateV2 = 
FunctionOtherTypesToDateType<DateTrunc<DataTypeDateV2, true>>;
-using FunctionDateTruncDatetime = 
FunctionOtherTypesToDateType<DateTrunc<DataTypeDateTime, true>>;
-using FunctionDateTruncDatetimeV2 =
-        FunctionOtherTypesToDateType<DateTrunc<DataTypeDateTimeV2, true>>;
-
-using FunctionDateTruncDateWithCommonOrder =
-        FunctionOtherTypesToDateType<DateTrunc<DataTypeDate, false>>;
+
+using FunctionDateTruncDateV2 = 
FunctionOtherTypesToDateType<DateTrunc<TYPE_DATEV2, true>>;
+using FunctionDateTruncDatetimeV2 = 
FunctionOtherTypesToDateType<DateTrunc<TYPE_DATETIMEV2, true>>;
 using FunctionDateTruncDateV2WithCommonOrder =
-        FunctionOtherTypesToDateType<DateTrunc<DataTypeDateV2, false>>;
-using FunctionDateTruncDatetimeWithCommonOrder =
-        FunctionOtherTypesToDateType<DateTrunc<DataTypeDateTime, false>>;
+        FunctionOtherTypesToDateType<DateTrunc<TYPE_DATEV2, false>>;
 using FunctionDateTruncDatetimeV2WithCommonOrder =
-        FunctionOtherTypesToDateType<DateTrunc<DataTypeDateTimeV2, false>>;
+        FunctionOtherTypesToDateType<DateTrunc<TYPE_DATETIMEV2, false>>;
 using FunctionFromIso8601DateV2 = 
FunctionOtherTypesToDateType<FromIso8601DateV2>;
 
 void register_function_timestamp(SimpleFunctionFactory& factory) {
     factory.register_function<FunctionStrToDate>();
     factory.register_function<FunctionStrToDatetime>();
-    factory.register_function<FunctionStrToDateV2>();
-    factory.register_function<FunctionStrToDatetimeV2>();
     factory.register_function<FunctionMakeDate>();
     factory.register_function<FromDays>();
-    factory.register_function<FunctionDateTruncDate>();
     factory.register_function<FunctionDateTruncDateV2>();
-    factory.register_function<FunctionDateTruncDatetime>();
     factory.register_function<FunctionDateTruncDatetimeV2>();
-    factory.register_function<FunctionDateTruncDateWithCommonOrder>();
     factory.register_function<FunctionDateTruncDateV2WithCommonOrder>();
-    factory.register_function<FunctionDateTruncDatetimeWithCommonOrder>();
     factory.register_function<FunctionDateTruncDatetimeV2WithCommonOrder>();
     factory.register_function<FunctionFromIso8601DateV2>();
 
@@ -1488,14 +1384,10 @@ void register_function_timestamp(SimpleFunctionFactory& 
factory) {
             FunctionUnixTimestampNew<UnixTimeStampDateImpl<DataTypeDateTimeV2, 
true>>>();
     
factory.register_function<FunctionUnixTimestampNew<UnixTimeStampStrImpl<true>>>();
 
-    factory.register_function<FunctionDateOrDateTimeToDate<LastDayImpl, 
DataTypeDateTime>>();
-    factory.register_function<FunctionDateOrDateTimeToDate<LastDayImpl, 
DataTypeDate>>();
-    factory.register_function<FunctionDateOrDateTimeToDate<LastDayImpl, 
DataTypeDateV2>>();
-    factory.register_function<FunctionDateOrDateTimeToDate<LastDayImpl, 
DataTypeDateTimeV2>>();
-    factory.register_function<FunctionDateOrDateTimeToDate<MondayImpl, 
DataTypeDateV2>>();
-    factory.register_function<FunctionDateOrDateTimeToDate<MondayImpl, 
DataTypeDateTimeV2>>();
-    factory.register_function<FunctionDateOrDateTimeToDate<MondayImpl, 
DataTypeDate>>();
-    factory.register_function<FunctionDateOrDateTimeToDate<MondayImpl, 
DataTypeDateTime>>();
+    factory.register_function<FunctionDateOrDateTimeToDate<LastDayImpl, 
TYPE_DATEV2>>();
+    factory.register_function<FunctionDateOrDateTimeToDate<LastDayImpl, 
TYPE_DATETIMEV2>>();
+    factory.register_function<FunctionDateOrDateTimeToDate<ToMondayImpl, 
TYPE_DATEV2>>();
+    factory.register_function<FunctionDateOrDateTimeToDate<ToMondayImpl, 
TYPE_DATETIMEV2>>();
 
     factory.register_function<DateTimeToTimestamp<MicroSec>>();
     factory.register_function<DateTimeToTimestamp<MilliSec>>();
diff --git a/be/src/vec/functions/simple_function_factory.h 
b/be/src/vec/functions/simple_function_factory.h
index f48deb4524e..3ddb84e6df9 100644
--- a/be/src/vec/functions/simple_function_factory.h
+++ b/be/src/vec/functions/simple_function_factory.h
@@ -139,6 +139,7 @@ class SimpleFunctionFactory {
 
 public:
     void register_function(const std::string& name, const Creator& ptr) {
+        //TODO: should add check of is_variadic. or just remove is_variadic is 
ok?
         DataTypes types = ptr()->get_variadic_argument_types();
         // types.empty() means function is not variadic
         if (!types.empty()) {
@@ -155,7 +156,7 @@ public:
 
     template <class Function>
     void register_function() {
-        if constexpr (std::is_base_of<IFunction, Function>::value) {
+        if constexpr (std::is_base_of_v<IFunction, Function>) {
             register_function(Function::name, 
&createDefaultFunction<Function>);
         } else {
             register_function(Function::name, &Function::create);
@@ -242,7 +243,7 @@ private:
     void temporary_function_update(int fe_version_now, std::string& name) {
         // replace if fe is old version.
         if (fe_version_now < NEWEST_VERSION_EXPLODE_MULTI_PARAM &&
-            function_to_replace.find(name) != function_to_replace.end()) {
+            function_to_replace.contains(name)) {
             name = function_to_replace[name];
         }
     }
diff --git a/be/test/vec/function/function_test_util.cpp 
b/be/test/vec/function/function_test_util.cpp
index f231d5d3580..a4844a83c4e 100644
--- a/be/test/vec/function/function_test_util.cpp
+++ b/be/test/vec/function/function_test_util.cpp
@@ -26,11 +26,11 @@
 #include "runtime/jsonb_value.h"
 #include "runtime/runtime_state.h"
 #include "util/bitmap_value.h"
-#include "util/datetype_cast.hpp"
 #include "vec/columns/column.h"
 #include "vec/columns/column_nullable.h"
 #include "vec/columns/column_struct.h"
 #include "vec/common/assert_cast.h"
+#include "vec/core/field.h"
 #include "vec/core/types.h"
 #include "vec/data_types/data_type.h"
 #include "vec/data_types/data_type_array.h"
@@ -293,29 +293,29 @@ bool parse_ut_data_type(const std::vector<AnyType>& 
input_types, ut_type::UTData
     return true;
 }
 
-template <typename DataType>
+template <PrimitiveType PType>
 bool insert_datetime_cell(MutableColumnPtr& column, DataTypePtr date_type_ptr, 
const AnyType& cell,
                           bool datetime_is_string_format) {
     bool result = true;
-    date_cast::TypeToValueTypeV<DataType> date_value;
+    typename PrimitiveTypeTraits<PType>::CppType date_value;
     //TODO: remove string format. only accept value input.
     if (datetime_is_string_format) {
         // accept cell of type string
         auto datetime_str = any_cast<std::string>(cell);
 
-        if constexpr (std::is_same_v<DataType, DataTypeDateTimeV2>) {
+        if constexpr (PType == PrimitiveType::TYPE_DATETIMEV2) {
             result = date_value.from_date_str(datetime_str.c_str(), 
datetime_str.size(),
                                               date_type_ptr->get_scale());
         } else {
             result = date_value.from_date_str(datetime_str.c_str(), 
datetime_str.size());
         }
     } else {
-        date_value = any_cast<date_cast::TypeToValueTypeV<DataType>>(cell);
+        date_value = any_cast<typename 
PrimitiveTypeTraits<PType>::CppType>(cell);
     }
     // deal for v1
-    if constexpr (std::is_same_v<DataType, DataTypeDate>) {
+    if constexpr (PType == PrimitiveType::TYPE_DATE) {
         date_value.cast_to_date();
-    } else if constexpr (std::is_same_v<DataType, DataTypeDateTime>) {
+    } else if constexpr (PType == PrimitiveType::TYPE_DATETIME) {
         date_value.to_datetime();
     }
 
@@ -473,23 +473,23 @@ bool insert_cell(MutableColumnPtr& column, DataTypePtr 
type_ptr, const AnyType&
             break;
         }
         case PrimitiveType::TYPE_DATE: {
-            RETURN_IF_FALSE((insert_datetime_cell<DataTypeDate>(column, 
type_ptr, cell,
-                                                                
datetime_is_string_format)));
+            RETURN_IF_FALSE((insert_datetime_cell<PrimitiveType::TYPE_DATE>(
+                    column, type_ptr, cell, datetime_is_string_format)));
             break;
         }
         case PrimitiveType::TYPE_DATEV2: {
-            RETURN_IF_FALSE((insert_datetime_cell<DataTypeDateV2>(column, 
type_ptr, cell,
-                                                                  
datetime_is_string_format)));
+            RETURN_IF_FALSE((insert_datetime_cell<PrimitiveType::TYPE_DATEV2>(
+                    column, type_ptr, cell, datetime_is_string_format)));
             break;
         }
         case PrimitiveType::TYPE_DATETIME: {
-            RETURN_IF_FALSE((insert_datetime_cell<DataTypeDateTime>(column, 
type_ptr, cell,
-                                                                    
datetime_is_string_format)));
+            
RETURN_IF_FALSE((insert_datetime_cell<PrimitiveType::TYPE_DATETIME>(
+                    column, type_ptr, cell, datetime_is_string_format)));
             break;
         }
         case PrimitiveType::TYPE_DATETIMEV2: {
-            RETURN_IF_FALSE((insert_datetime_cell<DataTypeDateTimeV2>(column, 
type_ptr, cell,
-                                                                      
datetime_is_string_format)));
+            
RETURN_IF_FALSE((insert_datetime_cell<PrimitiveType::TYPE_DATETIMEV2>(
+                    column, type_ptr, cell, datetime_is_string_format)));
             break;
         }
         case PrimitiveType::TYPE_TIMEV2: {
diff --git a/be/test/vec/function/function_time_test.cpp 
b/be/test/vec/function/function_time_test.cpp
index 88277a4e17f..6368859ab55 100644
--- a/be/test/vec/function/function_time_test.cpp
+++ b/be/test/vec/function/function_time_test.cpp
@@ -395,7 +395,7 @@ TEST(VTimestampFunctionsTest, makedate_test) {
             {{2021, 400}, std::string("2022-02-04")},
     };
 
-    static_cast<void>(check_function<DataTypeDate, true>(func_name, 
input_types, data_set));
+    static_cast<void>(check_function<DataTypeDateV2, true>(func_name, 
input_types, data_set));
 }
 
 TEST(VTimestampFunctionsTest, weekday_test) {
@@ -1255,49 +1255,6 @@ TEST(VTimestampFunctionsTest, dayname_test) {
 
 TEST(VTimestampFunctionsTest, datetrunc_test) {
     std::string func_name = "date_trunc";
-    {
-        InputTypeSet input_types = {PrimitiveType::TYPE_DATETIME,
-                                    Consted {PrimitiveType::TYPE_VARCHAR}};
-        DataSet data_set = {{{std::string("2022-10-08 11:44:23"), 
std::string("second")},
-                             std::string("2022-10-08 11:44:23")}};
-        static_cast<void>(check_function<DataTypeDateTime, true>(func_name, 
input_types, data_set));
-    }
-    {
-        InputTypeSet input_types = {PrimitiveType::TYPE_DATETIME,
-                                    Consted {PrimitiveType::TYPE_VARCHAR}};
-        DataSet data_set = {{{std::string("2022-10-08 11:44:23"), 
std::string("minute")},
-                             std::string("2022-10-08 11:44:00")}};
-        static_cast<void>(check_function<DataTypeDateTime, true>(func_name, 
input_types, data_set));
-    }
-    {
-        InputTypeSet input_types = {PrimitiveType::TYPE_DATETIME,
-                                    Consted {PrimitiveType::TYPE_VARCHAR}};
-        DataSet data_set = {{{std::string("2022-10-08 11:44:23"), 
std::string("hour")},
-                             std::string("2022-10-08 11:00:00")}};
-        static_cast<void>(check_function<DataTypeDateTime, true>(func_name, 
input_types, data_set));
-    }
-    {
-        InputTypeSet input_types = {PrimitiveType::TYPE_DATETIME,
-                                    Consted {PrimitiveType::TYPE_VARCHAR}};
-        DataSet data_set = {{{std::string("2022-10-08 11:44:23"), 
std::string("day")},
-                             std::string("2022-10-08 00:00:00")}};
-        static_cast<void>(check_function<DataTypeDateTime, true>(func_name, 
input_types, data_set));
-    }
-    {
-        InputTypeSet input_types = {PrimitiveType::TYPE_DATETIME,
-                                    Consted {PrimitiveType::TYPE_VARCHAR}};
-        DataSet data_set = {{{std::string("2022-10-08 11:44:23"), 
std::string("month")},
-                             std::string("2022-10-01 00:00:00")}};
-        static_cast<void>(check_function<DataTypeDateTime, true>(func_name, 
input_types, data_set));
-    }
-    {
-        InputTypeSet input_types = {PrimitiveType::TYPE_DATETIME,
-                                    Consted {PrimitiveType::TYPE_VARCHAR}};
-        DataSet data_set = {{{std::string("2022-10-08 11:44:23"), 
std::string("year")},
-                             std::string("2022-01-01 00:00:00")}};
-        static_cast<void>(check_function<DataTypeDateTime, true>(func_name, 
input_types, data_set));
-    }
-
     {
         InputTypeSet input_types = {PrimitiveType::TYPE_DATETIMEV2,
                                     Consted {PrimitiveType::TYPE_VARCHAR}};
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 bcf3ac6f7d1..a23826ca2e3 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
@@ -17,8 +17,6 @@
 
 package org.apache.doris.nereids.trees.expressions.functions.executable;
 
-import org.apache.doris.catalog.ScalarType;
-import org.apache.doris.catalog.Type;
 import org.apache.doris.nereids.exceptions.AnalysisException;
 import 
org.apache.doris.nereids.rules.expression.rules.SupportJavaDateFormatter;
 import org.apache.doris.nereids.trees.expressions.ExecFunction;
@@ -40,9 +38,7 @@ import 
org.apache.doris.nereids.trees.expressions.literal.StringLiteral;
 import org.apache.doris.nereids.trees.expressions.literal.TimeV2Literal;
 import org.apache.doris.nereids.trees.expressions.literal.TinyIntLiteral;
 import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral;
-import org.apache.doris.nereids.types.DataType;
 import org.apache.doris.nereids.types.DateTimeV2Type;
-import org.apache.doris.nereids.types.DateType;
 import org.apache.doris.nereids.types.DateV2Type;
 import org.apache.doris.nereids.types.DecimalV3Type;
 import org.apache.doris.nereids.util.DateUtils;
@@ -373,41 +369,21 @@ public class DateTimeExtractAndTransform {
     /**
      * datetime arithmetic function date-trunc
      */
-    @ExecFunction(name = "date_trunc")
-    public static Expression dateTrunc(DateTimeLiteral date, StringLikeLiteral 
trunc) {
-        return 
DateTimeLiteral.fromJavaDateType(dateTruncHelper(date.toJavaDateType(), 
trunc.getValue()));
-    }
-
     @ExecFunction(name = "date_trunc")
     public static Expression dateTrunc(DateTimeV2Literal date, 
StringLikeLiteral trunc) {
         return 
DateTimeV2Literal.fromJavaDateType(dateTruncHelper(date.toJavaDateType(), 
trunc.getValue()));
     }
 
-    @ExecFunction(name = "date_trunc")
-    public static Expression dateTrunc(DateLiteral date, StringLikeLiteral 
trunc) {
-        return 
DateLiteral.fromJavaDateType(dateTruncHelper(date.toJavaDateType(), 
trunc.getValue()));
-    }
-
     @ExecFunction(name = "date_trunc")
     public static Expression dateTrunc(DateV2Literal date, StringLikeLiteral 
trunc) {
         return 
DateV2Literal.fromJavaDateType(dateTruncHelper(date.toJavaDateType(), 
trunc.getValue()));
     }
 
-    @ExecFunction(name = "date_trunc")
-    public static Expression dateTrunc(StringLikeLiteral trunc, 
DateTimeLiteral date) {
-        return 
DateTimeLiteral.fromJavaDateType(dateTruncHelper(date.toJavaDateType(), 
trunc.getValue()));
-    }
-
     @ExecFunction(name = "date_trunc")
     public static Expression dateTrunc(StringLikeLiteral trunc, 
DateTimeV2Literal date) {
         return 
DateTimeV2Literal.fromJavaDateType(dateTruncHelper(date.toJavaDateType(), 
trunc.getValue()));
     }
 
-    @ExecFunction(name = "date_trunc")
-    public static Expression dateTrunc(StringLikeLiteral trunc, DateLiteral 
date) {
-        return 
DateLiteral.fromJavaDateType(dateTruncHelper(date.toJavaDateType(), 
trunc.getValue()));
-    }
-
     @ExecFunction(name = "date_trunc")
     public static Expression dateTrunc(StringLikeLiteral trunc, DateV2Literal 
date) {
         return 
DateV2Literal.fromJavaDateType(dateTruncHelper(date.toJavaDateType(), 
trunc.getValue()));
@@ -466,20 +442,6 @@ public class DateTimeExtractAndTransform {
         return DateV2Literal.fromJavaDateType(res);
     }
 
-    @ExecFunction(name = "last_day")
-    public static Expression lastDay(DateLiteral date) {
-        LocalDateTime nextMonthFirstDay = LocalDateTime.of((int) 
date.getYear(), (int) date.getMonth(), 1,
-                0, 0, 0).plusMonths(1);
-        return DateLiteral.fromJavaDateType(nextMonthFirstDay.minusDays(1));
-    }
-
-    @ExecFunction(name = "last_day")
-    public static Expression lastDay(DateTimeLiteral date) {
-        LocalDateTime nextMonthFirstDay = LocalDateTime.of((int) 
date.getYear(), (int) date.getMonth(), 1,
-                0, 0, 0).plusMonths(1);
-        return DateLiteral.fromJavaDateType(nextMonthFirstDay.minusDays(1));
-    }
-
     @ExecFunction(name = "last_day")
     public static Expression lastDay(DateV2Literal date) {
         LocalDateTime nextMonthFirstDay = LocalDateTime.of((int) 
date.getYear(), (int) date.getMonth(), 1,
@@ -705,8 +667,8 @@ public class DateTimeExtractAndTransform {
             throw new AnalysisException("Operation makedate of " + yearValue + 
", " + dayValue + " out of range");
         }
         return dayValue > 0
-                ? DateLiteral.fromJavaDateType(LocalDateTime.of(yearValue, 1, 
1, 0, 0, 0).plusDays(dayValue - 1))
-                : new NullLiteral(DateType.INSTANCE);
+                ? DateV2Literal.fromJavaDateType(LocalDateTime.of(yearValue, 
1, 1, 0, 0, 0).plusDays(dayValue - 1))
+                : new NullLiteral(DateV2Type.INSTANCE);
     }
 
     /**
@@ -716,25 +678,13 @@ public class DateTimeExtractAndTransform {
     public static Expression strToDate(StringLikeLiteral str, 
StringLikeLiteral format) {
         format = (StringLikeLiteral) 
SupportJavaDateFormatter.translateJavaFormatter(format);
         if 
(org.apache.doris.analysis.DateLiteral.hasTimePart(format.getStringValue())) {
-            DataType returnType = 
DataType.fromCatalogType(ScalarType.getDefaultDateType(Type.DATETIME));
-            if (returnType instanceof DateTimeV2Type) {
-                boolean hasMicroPart = org.apache.doris.analysis.DateLiteral
-                        .hasMicroSecondPart(format.getStringValue());
-                return 
DateTimeV2Literal.fromJavaDateType(DateUtils.getTime(DateUtils
-                        .dateTimeFormatter(format.getValue()), 
str.getValue()), hasMicroPart ? 6 : 0);
-            } else {
-                return 
DateTimeLiteral.fromJavaDateType(DateUtils.getTime(DateUtils
-                        .dateTimeFormatter(format.getValue()), 
str.getValue()));
-            }
+            boolean hasMicroPart = 
org.apache.doris.analysis.DateLiteral.hasMicroSecondPart(format.getStringValue());
+            return DateTimeV2Literal.fromJavaDateType(
+                    
DateUtils.getTime(DateUtils.dateTimeFormatter(format.getValue()), 
str.getValue()),
+                    hasMicroPart ? 6 : 0);
         } else {
-            DataType returnType = 
DataType.fromCatalogType(ScalarType.getDefaultDateType(Type.DATE));
-            if (returnType instanceof DateV2Type) {
-                return 
DateV2Literal.fromJavaDateType(DateUtils.getTime(DateUtils.dateTimeFormatter(format.getValue()),
-                        str.getValue()));
-            } else {
-                return 
DateLiteral.fromJavaDateType(DateUtils.getTime(DateUtils.dateTimeFormatter(format.getValue()),
-                        str.getValue()));
-            }
+            return DateV2Literal.fromJavaDateType(
+                    
DateUtils.getTime(DateUtils.dateTimeFormatter(format.getValue()), 
str.getValue()));
         }
     }
 
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ConvertTz.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ConvertTz.java
index 39f3145166a..15387474ce6 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ConvertTz.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ConvertTz.java
@@ -29,7 +29,6 @@ import 
org.apache.doris.nereids.trees.expressions.literal.NullLiteral;
 import org.apache.doris.nereids.trees.expressions.literal.StringLikeLiteral;
 import org.apache.doris.nereids.trees.expressions.shape.TernaryExpression;
 import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
-import org.apache.doris.nereids.types.DateTimeType;
 import org.apache.doris.nereids.types.DateTimeV2Type;
 import org.apache.doris.nereids.types.VarcharType;
 
@@ -46,16 +45,13 @@ public class ConvertTz extends ScalarFunction
 
     public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
             FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT)
-                    .args(DateTimeV2Type.SYSTEM_DEFAULT, 
VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT),
-            FunctionSignature.ret(DateTimeType.INSTANCE)
-                    .args(DateTimeType.INSTANCE, VarcharType.SYSTEM_DEFAULT, 
VarcharType.SYSTEM_DEFAULT)
+                    .args(DateTimeV2Type.SYSTEM_DEFAULT, 
VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT)
     );
 
     /**
      * constructor with 3 arguments.
      */
     public ConvertTz(Expression arg0, Expression arg1, Expression arg2) {
-        //TODO: maybe remove castDateTime with DateTimeType signature together 
is ok. it's of no use now.
         super("convert_tz", castDateTime(arg0), arg1, arg2);
     }
 
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DateTrunc.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DateTrunc.java
index 6f46a34af8e..5c969fd2100 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DateTrunc.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DateTrunc.java
@@ -27,6 +27,7 @@ import 
org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
 import org.apache.doris.nereids.trees.expressions.literal.StringLikeLiteral;
 import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression;
 import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
+import org.apache.doris.nereids.types.DataType;
 import org.apache.doris.nereids.types.DateTimeV2Type;
 import org.apache.doris.nereids.types.VarcharType;
 
@@ -92,13 +93,15 @@ public class DateTrunc extends ScalarFunction
 
     @Override
     public FunctionSignature customSignature() {
+        // should never return V1 Type
         if (getArgument(0).getDataType().isDateLikeType()) {
-            return FunctionSignature.ret(getArgument(0).getDataType())
-                    .args(getArgument(0).getDataType(), 
VarcharType.SYSTEM_DEFAULT);
+            DataType type = 
DataType.getCurrentType(getArgument(0).getDataType());
+            return FunctionSignature.ret(type).args(type, 
VarcharType.SYSTEM_DEFAULT);
         } else if (getArgument(1).getDataType().isDateLikeType()) {
-            return FunctionSignature.ret(getArgument(1).getDataType())
-                    .args(VarcharType.SYSTEM_DEFAULT, 
getArgument(1).getDataType());
+            DataType type = 
DataType.getCurrentType(getArgument(1).getDataType());
+            return 
FunctionSignature.ret(type).args(VarcharType.SYSTEM_DEFAULT, type);
         }
+
         boolean firstArgIsStringLiteral =
                 getArgument(0).isConstant() && getArgument(0) instanceof 
StringLikeLiteral;
         boolean secondArgIsStringLiteral =
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/LastDay.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/LastDay.java
index 9786609c314..1a9934db38b 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/LastDay.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/LastDay.java
@@ -24,9 +24,7 @@ import 
org.apache.doris.nereids.trees.expressions.functions.Monotonic;
 import 
org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateOrTimeLikeV2Args;
 import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression;
 import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
-import org.apache.doris.nereids.types.DateTimeType;
 import org.apache.doris.nereids.types.DateTimeV2Type;
-import org.apache.doris.nereids.types.DateType;
 import org.apache.doris.nereids.types.DateV2Type;
 
 import com.google.common.base.Preconditions;
@@ -42,10 +40,7 @@ public class LastDay extends ScalarFunction
 
     public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
             
FunctionSignature.ret(DateV2Type.INSTANCE).args(DateV2Type.INSTANCE),
-            
FunctionSignature.ret(DateV2Type.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT),
-            FunctionSignature.ret(DateType.INSTANCE).args(DateType.INSTANCE),
-            
FunctionSignature.ret(DateType.INSTANCE).args(DateTimeType.INSTANCE)
-    );
+            
FunctionSignature.ret(DateV2Type.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT));
 
     /**
      * constructor with 1 argument.
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MakeDate.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MakeDate.java
index e2b6385164a..9dbb4c8bf46 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MakeDate.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MakeDate.java
@@ -26,7 +26,7 @@ import 
org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
 import org.apache.doris.nereids.trees.expressions.literal.Literal;
 import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression;
 import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
-import org.apache.doris.nereids.types.DateType;
+import org.apache.doris.nereids.types.DateV2Type;
 import org.apache.doris.nereids.types.IntegerType;
 
 import com.google.common.base.Preconditions;
@@ -41,7 +41,7 @@ public class MakeDate extends ScalarFunction implements 
BinaryExpression, Explic
         PropagateNullLiteral, PropagateNullable, DateDiffMonotonic {
 
     public static final List<FunctionSignature> SIGNATURES = ImmutableList
-            
.of(FunctionSignature.ret(DateType.INSTANCE).args(IntegerType.INSTANCE, 
IntegerType.INSTANCE));
+            
.of(FunctionSignature.ret(DateV2Type.INSTANCE).args(IntegerType.INSTANCE, 
IntegerType.INSTANCE));
 
     /**
      * constructor with 2 arguments.
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/StrToDate.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/StrToDate.java
index 3febe3d0fb6..1c4ece2f599 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/StrToDate.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/StrToDate.java
@@ -19,8 +19,6 @@ package 
org.apache.doris.nereids.trees.expressions.functions.scalar;
 
 import org.apache.doris.analysis.DateLiteral;
 import org.apache.doris.catalog.FunctionSignature;
-import org.apache.doris.catalog.ScalarType;
-import org.apache.doris.catalog.Type;
 import org.apache.doris.nereids.trees.expressions.Expression;
 import 
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
 import 
org.apache.doris.nereids.trees.expressions.functions.PropagateNullLiteral;
@@ -30,6 +28,7 @@ import 
org.apache.doris.nereids.trees.expressions.shape.BinaryExpression;
 import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
 import org.apache.doris.nereids.types.DataType;
 import org.apache.doris.nereids.types.DateTimeV2Type;
+import org.apache.doris.nereids.types.DateV2Type;
 import org.apache.doris.nereids.types.StringType;
 import org.apache.doris.nereids.types.VarcharType;
 
@@ -44,6 +43,7 @@ import java.util.List;
 public class StrToDate extends ScalarFunction
         implements BinaryExpression, ExplicitlyCastableSignature, 
PropagateNullLiteral, PropagateNullable {
 
+    // not final signatures. see computeSignature()
     public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
             
FunctionSignature.ret(DateTimeV2Type.MAX).args(VarcharType.SYSTEM_DEFAULT,
                     VarcharType.SYSTEM_DEFAULT),
@@ -92,19 +92,17 @@ public class StrToDate extends ScalarFunction
         DataType returnType;
         if (getArgument(1) instanceof StringLikeLiteral) {
             if (DateLiteral.hasTimePart(((StringLikeLiteral) 
getArgument(1)).getStringValue())) {
-                returnType = 
DataType.fromCatalogType(ScalarType.getDefaultDateType(Type.DATETIME));
+                //FIXME: Here will pass different scale to BE with same input 
types. Need to be fixed.
+                returnType = DateTimeV2Type.SYSTEM_DEFAULT;
                 if (returnType.isDateTimeV2Type()
                         && DateLiteral.hasMicroSecondPart(((StringLikeLiteral) 
getArgument(1)).getStringValue())) {
-                    returnType = 
DataType.fromCatalogType(Type.DATETIMEV2_WITH_MAX_SCALAR);
+                    returnType = DateTimeV2Type.MAX;
                 }
             } else {
-                returnType = 
DataType.fromCatalogType(ScalarType.getDefaultDateType(Type.DATE));
+                returnType = DateV2Type.INSTANCE;
             }
         } else {
-            returnType = 
DataType.fromCatalogType(ScalarType.getDefaultDateType(Type.DATETIME));
-            if (returnType.isDateTimeV2Type()) {
-                returnType = 
DataType.fromCatalogType(Type.DATETIMEV2_WITH_MAX_SCALAR);
-            }
+            returnType = DateTimeV2Type.MAX;
         }
         return signature.withReturnType(returnType);
     }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ToMonday.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ToMonday.java
index f4d0dfc0c0c..1c149d657a4 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ToMonday.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ToMonday.java
@@ -24,9 +24,7 @@ import 
org.apache.doris.nereids.trees.expressions.functions.Monotonic;
 import 
org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateOrTimeLikeV2Args;
 import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression;
 import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
-import org.apache.doris.nereids.types.DateTimeType;
 import org.apache.doris.nereids.types.DateTimeV2Type;
-import org.apache.doris.nereids.types.DateType;
 import org.apache.doris.nereids.types.DateV2Type;
 
 import com.google.common.base.Preconditions;
@@ -42,9 +40,7 @@ public class ToMonday extends ScalarFunction
 
     private static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
             
FunctionSignature.ret(DateV2Type.INSTANCE).args(DateV2Type.INSTANCE),
-            FunctionSignature.ret(DateType.INSTANCE).args(DateType.INSTANCE),
-            
FunctionSignature.ret(DateV2Type.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT),
-            
FunctionSignature.ret(DateType.INSTANCE).args(DateTimeType.INSTANCE)
+            
FunctionSignature.ret(DateV2Type.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT)
     );
 
     /**
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java
index 59b393017b7..d1f919a951f 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java
@@ -142,6 +142,20 @@ public abstract class DataType {
         return null;
     }
 
+    /**
+     * Get the active types for the deprecated types. see also {@link 
ScalarType#getDefaultDateType()}
+     */
+    public static DataType getCurrentType(DataType dataType) {
+        if (dataType instanceof DateType) {
+            return DateV2Type.INSTANCE;
+        } else if (dataType instanceof DateTimeType) {
+            return DateTimeV2Type.SYSTEM_DEFAULT;
+        } else if (dataType instanceof DecimalV2Type) {
+            return DecimalV3Type.SYSTEM_DEFAULT;
+        }
+        return dataType;
+    }
+
     /**
      * Convert to data type in Nereids.
      * throw exception when cannot convert to Nereids type
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/FoldConstantTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/FoldConstantTest.java
index af299a36c0a..570534584ec 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/FoldConstantTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/FoldConstantTest.java
@@ -432,18 +432,10 @@ class FoldConstantTest extends 
ExpressionRewriteTestHelper {
         rewritten = executor.rewrite(d, context);
         Assertions.assertEquals(new VarcharLiteral("01 01 01"), rewritten);
 
-        DateTrunc t = new 
DateTrunc(DateTimeLiteral.fromJavaDateType(LocalDateTime.of(1, 1, 1, 1, 1, 1)),
-                StringLiteral.of("week"));
-        rewritten = executor.rewrite(t, context);
-        Assertions.assertEquals(new DateTimeLiteral("0001-01-01 00:00:00"), 
rewritten);
-        t = new 
DateTrunc(DateTimeV2Literal.fromJavaDateType(LocalDateTime.of(1, 1, 1, 1, 1, 
1)),
+        DateTrunc t = new 
DateTrunc(DateTimeV2Literal.fromJavaDateType(LocalDateTime.of(1, 1, 1, 1, 1, 
1)),
                 StringLiteral.of("week"));
         rewritten = executor.rewrite(t, context);
         Assertions.assertTrue(((ComparableLiteral) rewritten).compareTo(new 
DateTimeV2Literal("0001-01-01 00:00:00.000000")) == 0);
-        t = new DateTrunc(DateLiteral.fromJavaDateType(LocalDateTime.of(1, 1, 
1, 1, 1, 1)),
-                StringLiteral.of("week"));
-        rewritten = executor.rewrite(t, context);
-        Assertions.assertEquals(new DateLiteral("0001-01-01"), rewritten);
         t = new DateTrunc(DateV2Literal.fromJavaDateType(LocalDateTime.of(1, 
1, 1, 1, 1, 1)),
                 StringLiteral.of("week"));
         rewritten = executor.rewrite(t, context);
@@ -1166,7 +1158,7 @@ class FoldConstantTest extends 
ExpressionRewriteTestHelper {
 
         String[] answer = {
                 "1999", "4", "12", "6", "31", "365", "31",
-                "'1999-12-31'", "'1999-12-27'", "'1999-12-31'"
+                "'1999-12-31'", "'1999-12-27'"
         };
         int answerIdx = 0;
 
@@ -1181,7 +1173,6 @@ class FoldConstantTest extends 
ExpressionRewriteTestHelper {
         
Assertions.assertEquals(DateTimeExtractAndTransform.dateFormat(dateLiteral, 
format).toSql(),
                 answer[answerIdx++]);
         
Assertions.assertEquals(DateTimeExtractAndTransform.toMonday(dateLiteral).toSql(),
 answer[answerIdx++]);
-        
Assertions.assertEquals(DateTimeExtractAndTransform.lastDay(dateLiteral).toSql(),
 answer[answerIdx]);
     }
 
     @Test
@@ -1191,7 +1182,7 @@ class FoldConstantTest extends 
ExpressionRewriteTestHelper {
 
         String[] answer = {
                 "1999", "4", "12", "6", "31", "365", "31", "23", "59", "59",
-                "'1999-12-31'", "'1999-12-27'", "'1999-12-31'", 
"'1999-12-31'", "730484", "'1999-12-31'"
+                "'1999-12-31'", "'1999-12-27'", "'1999-12-31'", "730484", 
"'1999-12-31'"
         };
         int answerIdx = 0;
 
@@ -1209,7 +1200,6 @@ class FoldConstantTest extends 
ExpressionRewriteTestHelper {
         
Assertions.assertEquals(DateTimeExtractAndTransform.dateFormat(dateLiteral, 
format).toSql(),
                 answer[answerIdx++]);
         
Assertions.assertEquals(DateTimeExtractAndTransform.toMonday(dateLiteral).toSql(),
 answer[answerIdx++]);
-        
Assertions.assertEquals(DateTimeExtractAndTransform.lastDay(dateLiteral).toSql(),
 answer[answerIdx++]);
         
Assertions.assertEquals(DateTimeExtractAndTransform.toDate(dateLiteral).toSql(),
 answer[answerIdx++]);
         
Assertions.assertEquals(DateTimeExtractAndTransform.toDays(dateLiteral).toSql(),
 answer[answerIdx++]);
         
Assertions.assertEquals(DateTimeExtractAndTransform.date(dateLiteral).toSql(), 
answer[answerIdx]);
@@ -1366,41 +1356,20 @@ class FoldConstantTest extends 
ExpressionRewriteTestHelper {
 
     @Test
     void testDateTrunc() {
-        DateTimeLiteral dateTimeLiteral = new DateTimeLiteral("2001-12-31 
01:01:01");
         DateTimeV2Literal dateTimeV2Literal = new 
DateTimeV2Literal("2001-12-31 01:01:01");
 
         String[] tags = {"year", "month", "day", "hour", "minute", "second"};
 
         String[] answer = {
-                "'2001-01-01 00:00:00'", "'2001-01-01 00:00:00.000000'", 
"'2001-12-01 00:00:00'",
-                "'2001-12-01 00:00:00.000000'", "'2001-12-31 00:00:00'", 
"'2001-12-31 00:00:00.000000'",
-                "'2001-12-31 01:00:00'", "'2001-12-31 01:00:00.000000'", 
"'2001-12-31 01:01:00'",
-                "'2001-12-31 01:01:00.000000'", "'2001-12-31 01:01:01'", 
"'2001-12-31 01:01:01.000000'",
-                "'2001-01-01 00:00:00'", "'2001-01-01 00:00:00'", "'2001-01-01 
00:00:00'",
-                "'2001-04-01 00:00:00'", "'2001-04-01 00:00:00'", "'2001-04-01 
00:00:00'",
-                "'2001-07-01 00:00:00'", "'2001-07-01 00:00:00'", "'2001-07-01 
00:00:00'",
-                "'2001-10-01 00:00:00'", "'2001-10-01 00:00:00'", "'2001-10-01 
00:00:00'",
-                "'2001-01-15 00:00:00'", "'2001-02-12 00:00:00'", "'2001-03-12 
00:00:00'",
+                "'2001-01-01 00:00:00.000000'", "'2001-12-01 
00:00:00.000000'", "'2001-12-31 00:00:00.000000'",
+                "'2001-12-31 01:00:00.000000'", "'2001-12-31 
01:01:00.000000'", "'2001-12-31 01:01:01.000000'"
         };
         int answerIdx = 0;
 
         for (String tag : tags) {
-            
Assertions.assertEquals(DateTimeExtractAndTransform.dateTrunc(dateTimeLiteral, 
new VarcharLiteral(tag)).toSql(),
-                    answer[answerIdx++]);
             
Assertions.assertEquals(DateTimeExtractAndTransform.dateTrunc(dateTimeV2Literal,
 new VarcharLiteral(tag)).toSql(),
                     answer[answerIdx++]);
         }
-
-        VarcharLiteral quarter = new VarcharLiteral("quarter");
-        for (int i = 1; i != 13; ++i) {
-            Assertions.assertEquals(DateTimeExtractAndTransform.dateTrunc(
-                    new DateTimeLiteral(2001, i, 15, 0, 0, 0), 
quarter).toSql(), answer[answerIdx++]);
-        }
-        VarcharLiteral week = new VarcharLiteral("week");
-        for (int i = 1; i != 4; ++i) {
-            Assertions.assertEquals(DateTimeExtractAndTransform.dateTrunc(
-                    new DateTimeLiteral(2001, i, 15, 0, 0, 0), week).toSql(), 
answer[answerIdx++]);
-        }
     }
 
     @Test
diff --git 
a/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out
 
b/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out
index 5e41a443180..8b853fb0494 100644
--- 
a/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out
+++ 
b/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out
@@ -436,7 +436,7 @@ February
 2050
 
 -- !sql --
-\N     \N
+0000-08-01T13:21:03    0
 2019-08-01T13:21:03    2019
 9999-08-01T13:21:03    9999
 
@@ -447,7 +447,7 @@ February
 2049
 
 -- !sql --
-\N     \N
+0000-08-01T13:21:03    0
 2019-08-01T13:21:03    2019
 9999-08-01T13:21:03    9999
 
diff --git 
a/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy
 
b/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy
index 45809955559..50369ce3395 100644
--- 
a/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy
+++ 
b/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy
@@ -489,7 +489,7 @@ suite("test_date_function") {
     qt_sql """ select weekofyear('2008-02-20 00:00:00') """
 
     sql """ truncate table ${tableName} """
-    sql """ insert into ${tableName} values ("2019-08-01 13:21:03"), 
("9999-08-01 13:21:03"),("0-08-01 13:21:03")"""
+    sql """ insert into ${tableName} values ("2019-08-01 13:21:03"), 
("9999-08-01 13:21:03"),("0000-08-01 13:21:03")"""
 
     // YEAR
     qt_sql """ select year('1987-01-01') """


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

Reply via email to