Skip to content

Commit

Permalink
[exec](vec) opt the datetime/date function is_invalid func performance
Browse files Browse the repository at this point in the history
  • Loading branch information
HappenLee committed Jan 5, 2025
1 parent 2a815f9 commit 2c86ef9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 28 deletions.
4 changes: 0 additions & 4 deletions be/src/util/time_lut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ uint32_t calc_days_in_year(uint32_t year) {
return is_leap(year) ? 366 : 365;
}

bool is_leap(uint32_t year) {
return ((year % 4) == 0) && ((year % 100 != 0) || ((year % 400) == 0 && year));
}

uint8_t calc_weekday(uint64_t day_nr, bool is_sunday_first_day) {
return (day_nr + 5L + (is_sunday_first_day ? 1L : 0L)) % 7;
}
Expand Down
4 changes: 3 additions & 1 deletion be/src/util/time_lut.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ uint32_t calc_daynr(uint16_t year, uint8_t month, uint8_t day);

uint8_t calc_weekday(uint64_t day_nr, bool is_sunday_first_day);

bool is_leap(uint32_t year);
inline bool is_leap(uint32_t year) {
return ((year % 4) == 0) && ((year % 100 != 0) || ((year % 400) == 0 && year));
}

uint32_t calc_days_in_year(uint32_t year);

Expand Down
3 changes: 3 additions & 0 deletions be/src/vec/functions/date_time_transforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@ struct Transformer {
auto res = Transform::execute(vec_from[i]);
using RESULT_TYPE = std::decay_t<decltype(res)>;
vec_to[i] = cast_set<ToType, RESULT_TYPE, false>(res);
}

for (size_t i = 0; i < size; ++i) {
null_map[i] = !((typename DateTraits<typename Transform::OpArgType>::T&)(vec_from[i]))
.is_valid_date();
}
Expand Down
22 changes: 0 additions & 22 deletions be/src/vec/runtime/vdatetime_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1936,28 +1936,6 @@ std::size_t hash_value(VecDateTimeValue const& value) {
return HashUtil::hash(&value, sizeof(VecDateTimeValue), 0);
}

template <typename T>
bool DateV2Value<T>::is_invalid(uint32_t year, uint32_t month, uint32_t day, uint8_t hour,
uint8_t minute, uint8_t second, uint32_t microsecond,
bool only_time_part) {
if (hour >= 24 || minute >= 60 || second >= 60 || microsecond > 999999) {
return true;
}
if (only_time_part) {
return false;
}
if (year > MAX_YEAR) {
return true;
}
if (month == 2 && day == 29 && doris::is_leap(year)) {
return false;
}
if (month == 0 || month > 12 || day > S_DAYS_IN_MONTH[month] || day == 0) {
return true;
}
return false;
}

template <typename T>
void DateV2Value<T>::format_datetime(uint32_t* date_val, bool* carry_bits) const {
// ms
Expand Down
14 changes: 13 additions & 1 deletion be/src/vec/runtime/vdatetime_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,19 @@ class DateV2Value {
// Return true if range or date is invalid
static bool is_invalid(uint32_t year, uint32_t month, uint32_t day, uint8_t hour,
uint8_t minute, uint8_t second, uint32_t microsecond,
bool only_time_part = false);
bool only_time_part = false) {
if constexpr (is_datetime) {
if (hour >= 24 || minute >= 60 || second >= 60 || microsecond > 999999) {
return true;
}
if (only_time_part) {
return false;
}
}
return year > MAX_YEAR || !day || !month || month > 12 ||
(day > 28 && ((month != 2 && day > S_DAYS_IN_MONTH[month]) ||
(month == 2 && day > 28 + doris::is_leap(year))));
}

[[nodiscard]] bool check_range_and_set_time(uint16_t year, uint8_t month, uint8_t day,
uint8_t hour, uint8_t minute, uint8_t second,
Expand Down

0 comments on commit 2c86ef9

Please sign in to comment.