Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions be/src/vec/functions/function_datetime_floor_ceil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,9 @@ struct TimeRound {
is_null = false;
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) {
Expand Down
1 change: 0 additions & 1 deletion be/src/vec/runtime/vdatetime_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1678,7 +1678,6 @@ bool VecDateTimeValue::date_set_interval(const TimeInterval& interval) {
(unit == MINUTE) || (unit == SECOND),
"date_set_interval function now only support YEAR MONTH DAY HOUR MINUTE SECOND type");
if constexpr ((unit == SECOND) || (unit == MINUTE) || (unit == HOUR)) {
set_zero(type());
// This may change the day information
int64_t seconds = interval.day * 86400L + interval.hour * 3600 + interval.minute * 60 +
interval.second;
Expand Down
3 changes: 3 additions & 0 deletions be/src/vec/runtime/vdatetime_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,9 @@ class VecDateTimeValue { // Now this type is a temp solution with little changes

bool get_date_from_daynr(uint64_t);

// reset 0
void reset_zero_by_type(int type) { set_zero(type); }

private:
// Used to make sure sizeof VecDateTimeValue
friend class UnusedClass;
Expand Down
41 changes: 41 additions & 0 deletions regression-test/data/correctness_p0/test_time_round.out
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,44 @@
-- !select --
2022-01-01T00:00

-- !select --
1970-01-01T01:00:30

-- !select --
1970-01-01T00:00:30

-- !select --
2022-05-25T00:00

-- !select --
2022-05-01T00:00

-- !select --
2022-05-25T00:06

-- !select --
2022-05-25T00:05

-- !select --
2022-05-26T00:00

-- !select --
2022-05-23T00:00

-- !select --
2022-05-29T00:00

-- !select --
2022-05-22T00:00

-- !select --
2022-06-01T00:00

-- !select --
2022-05-01T00:00

-- !select --
2023-01-01T00:00

-- !select --
2022-01-01T00:00
29 changes: 29 additions & 0 deletions regression-test/suites/correctness_p0/test_time_round.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@


suite("test_time_round") {

sql """ set enable_nereids_planner=true , enable_fallback_to_original_planner=false;"""
// fix by issues/9711, expect: '1970-01-01T01:00:30'
qt_select "select hour_ceil('1970-01-01 01:00:10', 1, '1970-01-01 00:00:30')"

Expand All @@ -40,4 +42,31 @@ suite("test_time_round") {
qt_select "select year_ceil('2022-05-25 00:00:00')"
qt_select "select year_floor('2022-05-25 00:00:00')"


sql """ set enable_nereids_planner=false; """

// fix by issues/9711, expect: '1970-01-01T01:00:30'
qt_select "select hour_ceil('1970-01-01 01:00:10', 1, '1970-01-01 00:00:30')"

// fix by issues/9711, expect: '1970-01-01T00:00:30'
qt_select "select hour_floor('1970-01-01 01:00:10', 1, '1970-01-01 00:00:30')"

// fix by issues/9711, expect: '2022-05-25'
qt_select "select day_ceil('2022-05-25')"

// fix by issues/9711, expect: '2022-05-01'
qt_select "select month_ceil('2022-05-01')"

qt_select "select minute_ceil('2022-05-25 00:05:10')"
qt_select "select minute_floor('2022-05-25 00:05:10')"
qt_select "select day_ceil('2022-05-25 02:00:00', 3, '2022-05-20 00:00:00')"
qt_select "select day_floor('2022-05-25 02:00:00', 3, '2022-05-20 00:00:00')"
qt_select "select week_ceil('2022-05-25 00:00:00')"
qt_select "select week_floor('2022-05-25 00:00:00')"
qt_select "select month_ceil('2022-05-25 00:00:00')"
qt_select "select month_floor('2022-05-25 00:00:00')"
qt_select "select year_ceil('2022-05-25 00:00:00')"
qt_select "select year_floor('2022-05-25 00:00:00')"


}