Skip to content

Commit

Permalink
[bug](function) fix milliseconds_diff function return wrong result
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangstar333 committed Mar 27, 2024
1 parent 49995aa commit 70bd1e8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
8 changes: 7 additions & 1 deletion be/src/vec/functions/function_date_or_datetime_computation.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,13 @@ struct TimeDiffImpl {
const auto& ts1 = reinterpret_cast<const DateValueType2&>(t1);
is_null = !ts0.is_valid_date() || !ts1.is_valid_date();
if constexpr (UsingTimev2) {
return ts0.microsecond_diff(ts1);
// refer to https://dev.mysql.com/doc/refman/5.7/en/time.html
// the time type value between '-838:59:59' and '838:59:59', so the return value should limited
int64_t diff_m = ts0.microsecond_diff(ts1);
if (diff_m > (int64_t)3020399 * 1000 * 1000) {
diff_m = (int64_t)3020399 * 1000 * 1000;
}
return (double)diff_m;
} else {
return (1000 * 1000) * ts0.second_diff(ts1);
}
Expand Down
8 changes: 4 additions & 4 deletions be/src/vec/runtime/vdatetime_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -1119,13 +1119,13 @@ class DateV2Value {
return (daynr() - rhs.daynr()) * SECOND_PER_HOUR * HOUR_PER_DAY + time_part_diff(rhs);
}

// used by INT microseconds_diff(DATETIME enddate, DATETIME startdate)
// return it's int type, so shouldn't have any limit.
// when used by TIME TIMEDIFF(DATETIME expr1, DATETIME expr2), it's return time type, should have limited.
template <typename RHS>
double microsecond_diff(const RHS& rhs) const {
int64_t microsecond_diff(const RHS& rhs) const {
int64_t diff_m = (daynr() - rhs.daynr()) * SECOND_PER_HOUR * HOUR_PER_DAY * 1000 * 1000 +
time_part_diff_microsecond(rhs);
if (diff_m > (int64_t)3020399 * 1000 * 1000) {
diff_m = (int64_t)3020399 * 1000 * 1000;
}
return diff_m;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1802,12 +1802,6 @@ public void initFuzzyModeVariables() {
default:
break;
}
randomInt = random.nextInt(2);
if (randomInt % 2 == 0) {
this.enableFoldConstantByBe = false;
} else {
this.enableFoldConstantByBe = true;
}

switch (Config.pull_request_id % 3) {
case 0:
Expand Down Expand Up @@ -1845,8 +1839,10 @@ public void initFuzzyModeVariables() {
if (Config.pull_request_id > 0) {
if (Config.pull_request_id % 2 == 1) {
this.batchSize = 4064;
// this.enableFoldConstantByBe = true;
} else {
this.batchSize = 50;
// this.enableFoldConstantByBe = false;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
63113904000

-- !sql --
3020399000
2176243380000

-- !sql --
3020399000000
2176243380000000

0 comments on commit 70bd1e8

Please sign in to comment.