diff --git a/be/src/vec/functions/function_date_or_datetime_computation.h b/be/src/vec/functions/function_date_or_datetime_computation.h index 383fb10e34ad1d..bb1b6b9d89c069 100644 --- a/be/src/vec/functions/function_date_or_datetime_computation.h +++ b/be/src/vec/functions/function_date_or_datetime_computation.h @@ -295,7 +295,13 @@ struct TimeDiffImpl { const auto& ts1 = reinterpret_cast(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); } diff --git a/be/src/vec/runtime/vdatetime_value.h b/be/src/vec/runtime/vdatetime_value.h index 7b138b2bc3a1f1..54dc368f620f22 100644 --- a/be/src/vec/runtime/vdatetime_value.h +++ b/be/src/vec/runtime/vdatetime_value.h @@ -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 - 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; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java index 67f3569091418a..d55f27a26ccbe7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java @@ -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: @@ -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; } } } diff --git a/regression-test/data/query_p0/sql_functions/datetime_functions/test_time_diff.out b/regression-test/data/query_p0/sql_functions/datetime_functions/test_time_diff.out index b8944f41df2eff..d9cd4c270a138d 100644 --- a/regression-test/data/query_p0/sql_functions/datetime_functions/test_time_diff.out +++ b/regression-test/data/query_p0/sql_functions/datetime_functions/test_time_diff.out @@ -18,8 +18,8 @@ 63113904000 -- !sql -- -3020399000 +2176243380000 -- !sql -- -3020399000000 +2176243380000000