From a775e6c837635cc97ad1ba0f72374e37644c0509 Mon Sep 17 00:00:00 2001 From: Jasmine-ge Date: Fri, 18 Oct 2024 13:50:03 +0800 Subject: [PATCH] Add proton starts/ends syntax --- src/IO/ReadHelpers.cpp | 6 ++++++ src/IO/ReadHelpers.h | 7 ++++++- src/IO/WriteHelpers.h | 5 ++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/IO/ReadHelpers.cpp b/src/IO/ReadHelpers.cpp index dd4c3c964a..12f433bafb 100644 --- a/src/IO/ReadHelpers.cpp +++ b/src/IO/ReadHelpers.cpp @@ -998,12 +998,14 @@ ReturnType readDateTimeTextFallback(time_t & datetime, ReadBuffer & buf, const D static constexpr auto date_broken_down_length = 10; /// hh:mm:ss static constexpr auto time_broken_down_length = 8; + /// proton: starts /// +zz:zz static constexpr auto zone_broken_down_length = 6; /// YYYY-MM-DD hh:mm:ss+zz:zz static constexpr auto date_time_with_zone_broken_down_length = date_broken_down_length + 1 + time_broken_down_length + zone_broken_down_length; char s[date_time_with_zone_broken_down_length]; + /// proton: ends char * s_pos = s; /** Read characters, that could represent unix timestamp. @@ -1045,10 +1047,12 @@ ReturnType readDateTimeTextFallback(time_t & datetime, ReadBuffer & buf, const D { const auto already_read_length = s_pos - s; const size_t remaining_date_size = date_broken_down_length - already_read_length; + /// proton: starts /// If have time zone symbol bool has_time_zone_offset = false; Int8 time_zone_offset_hour = 0; Int8 time_zone_offset_minute = 0; + /// proton: ends size_t size = buf.read(s_pos, remaining_date_size); if (size != remaining_date_size) @@ -1088,6 +1092,7 @@ ReturnType readDateTimeTextFallback(time_t & datetime, ReadBuffer & buf, const D minute = (s[3] - '0') * 10 + (s[4] - '0'); second = (s[6] - '0') * 10 + (s[7] - '0'); } + /// proton: starts if (!buf.eof() && (*buf.position() == '+' || *buf.position() == '-')) { @@ -1138,6 +1143,7 @@ ReturnType readDateTimeTextFallback(time_t & datetime, ReadBuffer & buf, const D { datetime = date_lut.makeDateTime(year, month, day, hour, minute, second); } + /// proton: ends } else { diff --git a/src/IO/ReadHelpers.h b/src/IO/ReadHelpers.h index dddc3925fe..8d076cb3b2 100644 --- a/src/IO/ReadHelpers.h +++ b/src/IO/ReadHelpers.h @@ -936,10 +936,13 @@ inline ReturnType readDateTimeTextImpl(time_t & datetime, ReadBuffer & buf, cons static constexpr auto date_time_with_time_zone_broken_down_length = 25; /// YYYY-MM-DD hh:mm:ss static constexpr auto date_time_broken_down_length = 19; + + /// proton: starts /// YYYY-MM-DD static constexpr auto date_broken_down_length = 10; bool optimistic_path_for_date_time_with_zone_input = s + date_time_with_time_zone_broken_down_length <= buf.buffer().end(); + /// proton: ends if (optimistic_path_for_date_time_with_zone_input) { @@ -967,6 +970,7 @@ inline ReturnType readDateTimeTextImpl(time_t & datetime, ReadBuffer & buf, cons else buf.position() += date_broken_down_length; + /// proton: starts /// processing time zone bool has_time_zone_offset = false; Int8 time_zone_offset_hour = 0; @@ -1000,7 +1004,7 @@ inline ReturnType readDateTimeTextImpl(time_t & datetime, ReadBuffer & buf, cons has_time_zone_offset = true; ++buf.position(); } - + if (unlikely(year == 0)) { datetime = 0; @@ -1018,6 +1022,7 @@ inline ReturnType readDateTimeTextImpl(time_t & datetime, ReadBuffer & buf, cons { datetime = date_lut.makeDateTime(year, month, day, hour, minute, second); } + /// proton: ends return ReturnType(true); } diff --git a/src/IO/WriteHelpers.h b/src/IO/WriteHelpers.h index 85fb0b9475..445cf33516 100644 --- a/src/IO/WriteHelpers.h +++ b/src/IO/WriteHelpers.h @@ -760,6 +760,7 @@ inline void writeDateTimeText(time_t datetime, WriteBuffer & buf, const DateLUTI writeDateTimeText(LocalDateTime(datetime, time_zone), buf); } +/// proton: starts /// In the format YYYY-MM-DD HH:MM:SS+time zone, according to the specified time zone. template inline void writeDateTimeTextWithTimeZone(time_t datetime, WriteBuffer & buf, const DateLUTImpl & time_zone = DateLUT::instance()) @@ -781,6 +782,7 @@ inline void writeDateTimeTextWithTimeZone(time_t datetime, WriteBuffer & buf, co buf.write(':'); buf.write(&digits100[minutes * 2], 2); } +/// proton: ends /// In the format YYYY-MM-DD HH:MM:SS.NNNNNNNNN, according to the specified time zone. template @@ -816,7 +818,7 @@ inline void writeDateTimeText(DateTime64 datetime64, UInt32 scale, WriteBuffer & } } - +/// proton: starts /// In the format YYYY-MM-DD HH:MM:SS.NNNNNNNNN+time zone, according to the specified time zone. template inline void writeDateTimeTextWithTimeZone(DateTime64 datetime64, UInt32 scale, WriteBuffer & buf, const DateLUTImpl & time_zone = DateLUT::instance()) @@ -843,6 +845,7 @@ inline void writeDateTimeTextWithTimeZone(DateTime64 datetime64, UInt32 scale, W buf.write(':'); buf.write(&digits100[minutes * 2], 2); } +/// proton: ends /// In the RFC 1123 format: "Tue, 03 Dec 2019 00:11:50 GMT". You must provide GMT DateLUT. /// This is needed for HTTP requests.