diff options
author | dgolear <dgolear@yandex-team.com> | 2024-03-19 23:08:17 +0300 |
---|---|---|
committer | dgolear <dgolear@yandex-team.com> | 2024-03-19 23:16:14 +0300 |
commit | 51abdcf4bfdd1b9ca77966c06289d099f59c1af1 (patch) | |
tree | 1b360bb5b6b8a7d01edac2a5414b770eed6a4728 /yt | |
parent | d314d6ddf6131c2ee96e97067fb3e5f560395dfb (diff) | |
download | ydb-51abdcf4bfdd1b9ca77966c06289d099f59c1af1.tar.gz |
YTORM-275: Support nanosecond values
565b14f6ccd0cbee0a50d2e1208a98dbbd102531
Diffstat (limited to 'yt')
-rw-r--r-- | yt/yt/core/ytree/serialize-inl.h | 1 | ||||
-rw-r--r-- | yt/yt/core/ytree/serialize.cpp | 10 |
2 files changed, 8 insertions, 3 deletions
diff --git a/yt/yt/core/ytree/serialize-inl.h b/yt/yt/core/ytree/serialize-inl.h index e6e1a4d897..59d18ee68d 100644 --- a/yt/yt/core/ytree/serialize-inl.h +++ b/yt/yt/core/ytree/serialize-inl.h @@ -17,7 +17,6 @@ #include <library/cpp/yt/misc/cast.h> #include <optional> -#include <numeric> namespace NYT::NYTree { diff --git a/yt/yt/core/ytree/serialize.cpp b/yt/yt/core/ytree/serialize.cpp index 885aef17de..f6a1b23ca6 100644 --- a/yt/yt/core/ytree/serialize.cpp +++ b/yt/yt/core/ytree/serialize.cpp @@ -25,10 +25,14 @@ using namespace google::protobuf::io; // log2(timeEpoch("2100-01-01") * 10**3) < 42. // log2(timeEpoch("1970-03-01") * 10**6) > 42. // log2(timeEpoch("2100-01-01") * 10**6) < 52. +// log2(timeEpoch("1970-03-01") * 10**9) > 52. +// log2(timeEpoch("2100-01-01") * 10**9) < 62. static constexpr ui64 MicrosecondLowerWidthBoundary = 42; static constexpr ui64 MicrosecondUpperWidthBoundary = 52; +static constexpr ui64 NanosecondUpperWidthBoundary = 62; static constexpr ui64 UnixTimeMicrosecondLowerBoundary = 1ull << MicrosecondLowerWidthBoundary; static constexpr ui64 UnixTimeMicrosecondUpperBoundary = 1ull << MicrosecondUpperWidthBoundary; +static constexpr ui64 UnixTimeNanosecondUpperBoundary = 1ull << NanosecondUpperWidthBoundary; TInstant ConvertRawValueToUnixTime(ui64 value) { @@ -36,6 +40,8 @@ TInstant ConvertRawValueToUnixTime(ui64 value) return TInstant::MilliSeconds(value); } else if (value < UnixTimeMicrosecondUpperBoundary) { return TInstant::MicroSeconds(value); + } else if (value < UnixTimeNanosecondUpperBoundary) { + return TInstant::MicroSeconds(value / 1'000); } else { THROW_ERROR_EXCEPTION("Value %Qv does not represent valid UNIX time", value); @@ -281,7 +287,7 @@ void Deserialize(TDuration& value, INodePtr node) if (ms < 0) { THROW_ERROR_EXCEPTION("Duration cannot be negative"); } - value = TDuration::MicroSeconds(static_cast<ui64>(ms * 1000.0)); + value = TDuration::MicroSeconds(static_cast<ui64>(ms * 1'000.0)); break; } @@ -316,7 +322,7 @@ void Deserialize(TInstant& value, INodePtr node) if (ms < 0) { THROW_ERROR_EXCEPTION("Instant cannot be negative"); } - value = TInstant::MicroSeconds(static_cast<ui64>(ms * 1000.0)); + value = ConvertRawValueToUnixTime(ms); break; } |