Просмотр исходного кода

YTORM-275: Support nanosecond values
565b14f6ccd0cbee0a50d2e1208a98dbbd102531

dgolear 11 месяцев назад
Родитель
Сommit
51abdcf4bf
2 измененных файлов с 8 добавлено и 3 удалено
  1. 0 1
      yt/yt/core/ytree/serialize-inl.h
  2. 8 2
      yt/yt/core/ytree/serialize.cpp

+ 0 - 1
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 {
 

+ 8 - 2
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;
         }