Skip to content

Commit

Permalink
Throw exception if timestamp value is not supported by TiFlash (#725) (
Browse files Browse the repository at this point in the history
…#730)

* throw error for invalid timestamp value

* fix

* fmt code

Co-authored-by: xufei <[email protected]>
  • Loading branch information
sre-bot and windtalker authored May 26, 2020
1 parent fdac4a3 commit c51c2c5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
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

0 comments on commit c51c2c5

Please sign in to comment.