Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw exception if timestamp value is not supported by TiFlash (#725) #730

Merged
merged 3 commits into from
May 26, 2020
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
4 changes: 4 additions & 0 deletions dbms/src/Common/MyTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,8 @@ void convertTimeZone(UInt64 from_time, UInt64 & to_time, const DateLUTImpl & tim
MyDateTime from_my_time(from_time);
time_t epoch = time_zone_from.makeDateTime(
from_my_time.year, from_my_time.month, from_my_time.day, from_my_time.hour, from_my_time.minute, from_my_time.second);
if (unlikely(epoch + time_zone_to.getOffsetAtStartEpoch() < 0))
throw Exception("Unsupported timestamp value , TiFlash only support timestamp after 1970-01-01 00:00:00)");
MyDateTime to_my_time(time_zone_to.toYear(epoch), time_zone_to.toMonth(epoch), time_zone_to.toDayOfMonth(epoch),
time_zone_to.toHour(epoch), time_zone_to.toMinute(epoch), time_zone_to.toSecond(epoch), from_my_time.micro_second);
to_time = to_my_time.toPackedUInt();
Expand All @@ -712,6 +714,8 @@ void convertTimeZoneByOffset(UInt64 from_time, UInt64 & to_time, Int64 offset, c
time_t epoch = time_zone.makeDateTime(
from_my_time.year, from_my_time.month, from_my_time.day, from_my_time.hour, from_my_time.minute, from_my_time.second);
epoch += offset;
if (unlikely(epoch < 0))
throw Exception("Unsupported timestamp value , TiFlash only support timestamp after 1970-01-01 00:00:00)");
MyDateTime to_my_time(time_zone.toYear(epoch), time_zone.toMonth(epoch), time_zone.toDayOfMonth(epoch), time_zone.toHour(epoch),
time_zone.toMinute(epoch), time_zone.toSecond(epoch), from_my_time.micro_second);
to_time = to_my_time.toPackedUInt();
Expand Down
9 changes: 9 additions & 0 deletions dbms/src/Functions/FunctionsConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,16 @@ class FunctionFromUnixTime : public IFunction
}

if (timezone_info.timezone_offset != 0)
{
integer_part += timezone_info.timezone_offset;
if (unlikely(integer_part < 0))
throw Exception("Unsupported timestamp value , TiFlash only support timestamp after 1970-01-01 00:00:00)");
}
else
{
if (unlikely(integer_part + datelut->getOffsetAtStartEpoch() < 0))
throw Exception("Unsupported timestamp value , TiFlash only support timestamp after 1970-01-01 00:00:00)");
}
MyDateTime result(datelut->toYear(integer_part), datelut->toMonth(integer_part), datelut->toDayOfMonth(integer_part),
datelut->toHour(integer_part), datelut->toMinute(integer_part), datelut->toSecond(integer_part), fsp_part);
null_res[i] = 0;
Expand Down
3 changes: 3 additions & 0 deletions libs/libcommon/include/common/DateLUTImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ class DateLUTImpl

public:
const std::string & getTimeZone() const { return time_zone; }
time_t getOffsetAtStartEpoch() const {
return offset_at_start_of_epoch;
}

/// All functions below are thread-safe; arguments are not checked.

Expand Down