github-actions[bot] commented on code in PR #25026: URL: https://github.com/apache/doris/pull/25026#discussion_r1341628679
########## be/src/vec/functions/function_datetime_floor_ceil.cpp: ########## @@ -682,97 +755,69 @@ ts1.template date_add_interval<Impl::Unit, false>(interval); } - template <typename NativeType, typename DateValueType, Int32 period> + template <typename DateValueType, Int32 period> static void time_round_with_constant_optimization(const DateValueType& ts2, DateValueType& ts1) { - time_round<NativeType, DateValueType>(ts2, period, ts1); + time_round<DateValueType>(ts2, period, ts1); } - static constexpr uint64_t MASK_DAY_FLOOR = - 0b1111111111111111111111111110000000000000000000000000000000000000; - static constexpr uint64_t MASK_HOUR_FLOOR = - 0b1111111111111111111111111111111100000000000000000000000000000000; - static constexpr uint64_t MASK_MINUTE_FLOOR = - 0b1111111111111111111111111111111111111100000000000000000000000000; - static constexpr uint64_t MASK_SECOND_FLOOR = - 0b1111111111111111111111111111111111111111111100000000000000000000; - - static constexpr bool USE_OPTIMIZE_FLOOR = - Impl::Unit == DAY || Impl::Unit == HOUR || Impl::Unit == MINUTE || Impl::Unit == SECOND; - template <typename NativeType, typename DateValueType> - static void datetimev2_floor(const DateValueType& ts2, DateValueType& ts1) { - // Optimize the performance of the datetimev2 type on the floor operation. - // Now supports days, hours, minutes, and seconds. - if constexpr (Impl::Unit == DAY) { - ts1.set_int_val(ts2.to_date_int_val() & MASK_DAY_FLOOR); - } - if constexpr (Impl::Unit == HOUR) { - ts1.set_int_val(ts2.to_date_int_val() & MASK_HOUR_FLOOR); - } - if constexpr (Impl::Unit == MINUTE) { - ts1.set_int_val(ts2.to_date_int_val() & MASK_MINUTE_FLOOR); - } - if constexpr (Impl::Unit == SECOND) { - ts1.set_int_val(ts2.to_date_int_val() & MASK_SECOND_FLOOR); - } - } - template <typename NativeType, typename DateValueType> + template <typename DateValueType> static void time_round(const DateValueType& ts2, DateValueType& ts1) { static_assert(Impl::Unit != WEEK); - if constexpr (std::is_same_v<DateValueType, DateV2Value<DateTimeV2ValueType>> && - Impl::Type == FLOOR && USE_OPTIMIZE_FLOOR) { - datetimev2_floor<NativeType, DateValueType>(ts2, ts1); - return; - }; - if constexpr (std::is_same_v<DateValueType, VecDateTimeValue>) { - ts1.reset_zero_by_type(ts2.type()); - } - int64_t diff; - int64_t part; - if constexpr (Impl::Unit == YEAR) { - diff = ts2.year(); - part = (ts2.month() - 1) + (ts2.day() - 1) + ts2.hour() + ts2.minute() + ts2.second(); - } - if constexpr (Impl::Unit == MONTH) { - diff = ts2.year() * 12 + ts2.month() - 1; - part = (ts2.day() - 1) + ts2.hour() + ts2.minute() + ts2.second(); - } - if constexpr (Impl::Unit == DAY) { - diff = ts2.daynr(); - part = ts2.hour() + ts2.minute() + ts2.second(); - } - if constexpr (Impl::Unit == HOUR) { - diff = ts2.daynr() * 24 + ts2.hour(); - part = ts2.minute() + ts2.second(); - } - if constexpr (Impl::Unit == MINUTE) { - diff = ts2.daynr() * 24L * 60 + ts2.hour() * 60 + ts2.minute(); - part = ts2.second(); - } - if constexpr (Impl::Unit == SECOND) { - diff = ts2.daynr() * 24L * 60 * 60 + ts2.hour() * 60L * 60 + ts2.minute() * 60L + - ts2.second(); - part = 0; - if constexpr (std::is_same_v<DateValueType, DateV2Value<DateTimeV2ValueType>>) { - part = ts2.microsecond(); + if constexpr (TimeRoundOpt<Impl, DateValueType>::can_use_optimize(1)) { + TimeRoundOpt<Impl, DateValueType>::floor_opt_one_period(ts2, ts1); + } else { + if constexpr (std::is_same_v<DateValueType, VecDateTimeValue>) { + ts1.reset_zero_by_type(ts2.type()); + } + int64_t diff; + int64_t part; Review Comment: warning: variable 'part' is not initialized [cppcoreguidelines-init-variables] ```suggestion int64_t part = 0; ``` ########## be/src/vec/functions/function_datetime_floor_ceil.cpp: ########## @@ -682,97 +755,69 @@ struct TimeRound { ts1.template date_add_interval<Impl::Unit, false>(interval); } - template <typename NativeType, typename DateValueType, Int32 period> + template <typename DateValueType, Int32 period> static void time_round_with_constant_optimization(const DateValueType& ts2, DateValueType& ts1) { - time_round<NativeType, DateValueType>(ts2, period, ts1); + time_round<DateValueType>(ts2, period, ts1); } - static constexpr uint64_t MASK_DAY_FLOOR = - 0b1111111111111111111111111110000000000000000000000000000000000000; - static constexpr uint64_t MASK_HOUR_FLOOR = - 0b1111111111111111111111111111111100000000000000000000000000000000; - static constexpr uint64_t MASK_MINUTE_FLOOR = - 0b1111111111111111111111111111111111111100000000000000000000000000; - static constexpr uint64_t MASK_SECOND_FLOOR = - 0b1111111111111111111111111111111111111111111100000000000000000000; - - static constexpr bool USE_OPTIMIZE_FLOOR = - Impl::Unit == DAY || Impl::Unit == HOUR || Impl::Unit == MINUTE || Impl::Unit == SECOND; - template <typename NativeType, typename DateValueType> - static void datetimev2_floor(const DateValueType& ts2, DateValueType& ts1) { - // Optimize the performance of the datetimev2 type on the floor operation. - // Now supports days, hours, minutes, and seconds. - if constexpr (Impl::Unit == DAY) { - ts1.set_int_val(ts2.to_date_int_val() & MASK_DAY_FLOOR); - } - if constexpr (Impl::Unit == HOUR) { - ts1.set_int_val(ts2.to_date_int_val() & MASK_HOUR_FLOOR); - } - if constexpr (Impl::Unit == MINUTE) { - ts1.set_int_val(ts2.to_date_int_val() & MASK_MINUTE_FLOOR); - } - if constexpr (Impl::Unit == SECOND) { - ts1.set_int_val(ts2.to_date_int_val() & MASK_SECOND_FLOOR); - } - } - template <typename NativeType, typename DateValueType> + template <typename DateValueType> static void time_round(const DateValueType& ts2, DateValueType& ts1) { static_assert(Impl::Unit != WEEK); - if constexpr (std::is_same_v<DateValueType, DateV2Value<DateTimeV2ValueType>> && - Impl::Type == FLOOR && USE_OPTIMIZE_FLOOR) { - datetimev2_floor<NativeType, DateValueType>(ts2, ts1); - return; - }; - if constexpr (std::is_same_v<DateValueType, VecDateTimeValue>) { - ts1.reset_zero_by_type(ts2.type()); - } - int64_t diff; - int64_t part; - if constexpr (Impl::Unit == YEAR) { - diff = ts2.year(); - part = (ts2.month() - 1) + (ts2.day() - 1) + ts2.hour() + ts2.minute() + ts2.second(); - } - if constexpr (Impl::Unit == MONTH) { - diff = ts2.year() * 12 + ts2.month() - 1; - part = (ts2.day() - 1) + ts2.hour() + ts2.minute() + ts2.second(); - } - if constexpr (Impl::Unit == DAY) { - diff = ts2.daynr(); - part = ts2.hour() + ts2.minute() + ts2.second(); - } - if constexpr (Impl::Unit == HOUR) { - diff = ts2.daynr() * 24 + ts2.hour(); - part = ts2.minute() + ts2.second(); - } - if constexpr (Impl::Unit == MINUTE) { - diff = ts2.daynr() * 24L * 60 + ts2.hour() * 60 + ts2.minute(); - part = ts2.second(); - } - if constexpr (Impl::Unit == SECOND) { - diff = ts2.daynr() * 24L * 60 * 60 + ts2.hour() * 60L * 60 + ts2.minute() * 60L + - ts2.second(); - part = 0; - if constexpr (std::is_same_v<DateValueType, DateV2Value<DateTimeV2ValueType>>) { - part = ts2.microsecond(); + if constexpr (TimeRoundOpt<Impl, DateValueType>::can_use_optimize(1)) { + TimeRoundOpt<Impl, DateValueType>::floor_opt_one_period(ts2, ts1); + } else { + if constexpr (std::is_same_v<DateValueType, VecDateTimeValue>) { + ts1.reset_zero_by_type(ts2.type()); + } + int64_t diff; Review Comment: warning: variable 'diff' is not initialized [cppcoreguidelines-init-variables] ```suggestion int64_t diff = 0; ``` -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org