zclllyybb commented on code in PR #47755:
URL: https://github.com/apache/doris/pull/47755#discussion_r1950353546


##########
be/src/vec/functions/function_datetime_floor_ceil.cpp:
##########
@@ -237,189 +211,54 @@ class FunctionDateTimeFloorCeil : public IFunction {
         } else {
             return Status::RuntimeError("Illegal column {} of first argument 
of function {}",
                                         
block.get_by_position(arguments[0]).column->get_name(),
-                                        Impl::name);
+                                        Flag::name);
         }
         return Status::OK();
     }
-};
 
-template <typename Impl>
-struct FloorCeilImpl {
-    static constexpr auto name = Impl::name;
-
-    template <typename NativeType>
+private:
     static void vector(const PaddedPODArray<NativeType>& dates, 
PaddedPODArray<NativeType>& res,
                        NullMap& null_map) {
         // time_round(datetime)
         for (int i = 0; i < dates.size(); ++i) {
-            if constexpr (std::is_same_v<NativeType, UInt32>) {
-                SET_NULLMAP_IF_FALSE(
-                        (Impl::template time_round<UInt32, 
DateV2Value<DateV2ValueType>>(dates[i],
-                                                                               
          res[i])));
-
-            } else if constexpr (std::is_same_v<NativeType, UInt64>) {
-                SET_NULLMAP_IF_FALSE(
-                        (Impl::template time_round<UInt64, 
DateV2Value<DateTimeV2ValueType>>(
-                                dates[i], res[i])));
-            } else {
-                SET_NULLMAP_IF_FALSE(
-                        (Impl::template time_round<Int64, 
VecDateTimeValue>(dates[i], res[i])));
-            }
+            SET_NULLMAP_IF_FALSE((time_round_reinterpret_one_arg(dates[i], 
res[i])));
         }
     }
 
-    template <typename NativeType>
-    static void vector_constant(const PaddedPODArray<NativeType>& dates, 
NativeType origin_date,
-                                PaddedPODArray<NativeType>& res, NullMap& 
null_map) {
+    static void vector_const_anchor(const PaddedPODArray<NativeType>& dates, 
NativeType origin_date,
+                                    PaddedPODArray<NativeType>& res, NullMap& 
null_map) {
         // time_round(datetime, const(origin))
         for (int i = 0; i < dates.size(); ++i) {
-            if constexpr (std::is_same_v<NativeType, UInt32>) {
-                SET_NULLMAP_IF_FALSE((Impl::template 
time_round_with_constant_optimization<
-                                      UInt32, DateV2Value<DateV2ValueType>, 1>(
-                        dates[i], origin_date, res[i])));
-            } else if constexpr (std::is_same_v<NativeType, UInt64>) {
-                SET_NULLMAP_IF_FALSE((Impl::template 
time_round_with_constant_optimization<
-                                      UInt64, 
DateV2Value<DateTimeV2ValueType>, 1>(
-                        dates[i], origin_date, res[i])));
-            } else {
-                SET_NULLMAP_IF_FALSE((Impl::template 
time_round_with_constant_optimization<
-                                      Int64, VecDateTimeValue, 1>(dates[i], 
origin_date, res[i])));
-            }
+            SET_NULLMAP_IF_FALSE(
+                    (time_round_reinterpret_three_args(dates[i], 1, 
origin_date, res[i])));
         }
     }
 
-    template <typename NativeType>
-    static void vector_constant_delta(const PaddedPODArray<NativeType>& dates, 
Int32 period,
-                                      PaddedPODArray<NativeType>& res, 
NullMap& null_map) {
+    static void vector_const_period(const PaddedPODArray<NativeType>& dates, 
Int32 period,
+                                    PaddedPODArray<NativeType>& res, NullMap& 
null_map) {
         // time_round(datetime,const(period))
-        if (period < 1) {
+        if (period < 1) [[unlikely]] {
             memset(null_map.data(), 1, sizeof(UInt8) * dates.size());
             return;
         }
         for (int i = 0; i < dates.size(); ++i) {
-            if constexpr (std::is_same_v<NativeType, UInt32>) {
-                SET_NULLMAP_IF_FALSE(
-                        (Impl::template time_round<UInt32, 
DateV2Value<DateV2ValueType>>(
-                                dates[i], period, res[i])));
-            } else if constexpr (std::is_same_v<NativeType, UInt64>) {
-                SET_NULLMAP_IF_FALSE(
-                        (Impl::template time_round<UInt64, 
DateV2Value<DateTimeV2ValueType>>(
-                                dates[i], period, res[i])));
-            } else {
-                SET_NULLMAP_IF_FALSE((Impl::template time_round<Int64, 
VecDateTimeValue>(
-                        dates[i], period, res[i])));
-            }
+            SET_NULLMAP_IF_FALSE((time_round_reinterpret_two_args(dates[i], 
period, res[i])));
         }
     }
 
-    template <typename NativeType, UInt32 period>
-    static void vector_const_const_with_constant_optimization(
-            const PaddedPODArray<NativeType>& dates, NativeType origin_date,
-            PaddedPODArray<NativeType>& res, NullMap& null_map) {
-        for (int i = 0; i < dates.size(); ++i) {
-            if constexpr (std::is_same_v<NativeType, UInt32>) {
-                SET_NULLMAP_IF_FALSE((Impl::template 
time_round_with_constant_optimization<
-                                      UInt32, DateV2Value<DateV2ValueType>, 
period>(
-                        dates[i], origin_date, res[i])));
-            } else if constexpr (std::is_same_v<NativeType, UInt64>) {
-                SET_NULLMAP_IF_FALSE((Impl::template 
time_round_with_constant_optimization<
-                                      UInt64, 
DateV2Value<DateTimeV2ValueType>, period>(
-                        dates[i], origin_date, res[i])));
-            } else {
-                SET_NULLMAP_IF_FALSE(
-                        (Impl::template time_round_with_constant_optimization<
-                                Int64, VecDateTimeValue, period>(dates[i], 
origin_date, res[i])));
-            }
-        }
-    }
-    template <typename NativeType>
     static void vector_const_const(const PaddedPODArray<NativeType>& dates, 
const Int32 period,
                                    NativeType origin_date, 
PaddedPODArray<NativeType>& res,
                                    NullMap& null_map) {
         if (period < 1) {
             memset(null_map.data(), 1, sizeof(UInt8) * dates.size());
             return;
         }
-        switch (period) {
-        case 1: {
-            vector_const_const_with_constant_optimization<NativeType, 
1>(dates, origin_date, res,
-                                                                         
null_map);
-            break;
-        }
-        case 2: {
-            vector_const_const_with_constant_optimization<NativeType, 
2>(dates, origin_date, res,
-                                                                         
null_map);
-            break;
-        }
-        case 3: {
-            vector_const_const_with_constant_optimization<NativeType, 
3>(dates, origin_date, res,
-                                                                         
null_map);
-            break;
-        }
-        case 4: {
-            vector_const_const_with_constant_optimization<NativeType, 
4>(dates, origin_date, res,
-                                                                         
null_map);
-            break;
-        }
-        case 5: {
-            vector_const_const_with_constant_optimization<NativeType, 
5>(dates, origin_date, res,
-                                                                         
null_map);
-            break;
-        }
-        case 6: {
-            vector_const_const_with_constant_optimization<NativeType, 
6>(dates, origin_date, res,
-                                                                         
null_map);
-            break;
-        }
-        case 7: {
-            vector_const_const_with_constant_optimization<NativeType, 
7>(dates, origin_date, res,
-                                                                         
null_map);
-            break;
-        }
-        case 8: {
-            vector_const_const_with_constant_optimization<NativeType, 
8>(dates, origin_date, res,
-                                                                         
null_map);
-            break;
-        }
-        case 9: {
-            vector_const_const_with_constant_optimization<NativeType, 
9>(dates, origin_date, res,
-                                                                         
null_map);
-            break;
-        }
-        case 10: {
-            vector_const_const_with_constant_optimization<NativeType, 
10>(dates, origin_date, res,
-                                                                          
null_map);
-            break;
-        }
-        case 11: {
-            vector_const_const_with_constant_optimization<NativeType, 
11>(dates, origin_date, res,
-                                                                          
null_map);
-            break;
-        }
-        case 12: {
-            vector_const_const_with_constant_optimization<NativeType, 
12>(dates, origin_date, res,
-                                                                          
null_map);
-            break;
-        }
-        default:
-            for (int i = 0; i < dates.size(); ++i) {
-                if constexpr (std::is_same_v<NativeType, UInt32>) {
-                    SET_NULLMAP_IF_FALSE(
-                            (Impl::template time_round<UInt32, 
DateV2Value<DateV2ValueType>>(
-                                    dates[i], period, origin_date, res[i])));
-                } else if constexpr (std::is_same_v<NativeType, UInt64>) {
-                    SET_NULLMAP_IF_FALSE(
-                            (Impl::template time_round<UInt64, 
DateV2Value<DateTimeV2ValueType>>(
-                                    dates[i], period, origin_date, res[i])));
-                } else {
-                    SET_NULLMAP_IF_FALSE((Impl::template time_round<Int64, 
VecDateTimeValue>(
-                            dates[i], period, origin_date, res[i])));
-                }
-            }
+        for (int i = 0; i < dates.size(); ++i) {
+            SET_NULLMAP_IF_FALSE(
+                    (time_round_reinterpret_three_args(dates[i], period, 
origin_date, res[i])));

Review Comment:
   expand for specific periods



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to