Skip to content

Commit

Permalink
Add proton starts/ends syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasmine-ge committed Oct 18, 2024
1 parent 5be3e67 commit b3b218c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/IO/ReadHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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() == '-'))
{

Expand Down Expand Up @@ -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
{
Expand Down
7 changes: 6 additions & 1 deletion src/IO/ReadHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion src/IO/WriteHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@ inline void writeDateTimeText(time_t datetime, WriteBuffer & buf, const DateLUTI
writeDateTimeText<date_delimeter, time_delimeter, between_date_time_delimiter>(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 <char date_delimeter = '-', char time_delimeter = ':', char between_date_time_delimiter = ' '>
inline void writeDateTimeTextWithTimeZone(time_t datetime, WriteBuffer & buf, const DateLUTImpl & time_zone = DateLUT::instance())
Expand All @@ -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 <char date_delimeter = '-', char time_delimeter = ':', char between_date_time_delimiter = ' ', char fractional_time_delimiter = '.'>
Expand Down Expand Up @@ -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 <char date_delimeter = '-', char time_delimeter = ':', char between_date_time_delimiter = ' '>
inline void writeDateTimeTextWithTimeZone(DateTime64 datetime64, UInt32 scale, WriteBuffer & buf, const DateLUTImpl & time_zone = DateLUT::instance())
Expand All @@ -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.
Expand Down

0 comments on commit b3b218c

Please sign in to comment.