Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix to_datetime64 parsing problem #845

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/IO/ReadHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,52 @@ inline ReturnType readDateTimeTextImpl(DateTime64 & datetime64, UInt32 scale, Re
components.whole = components.whole / common::exp10_i32(scale);
}

/// proton: starts
/// processing time zone
bool has_time_zone_offset = false;
Int8 time_zone_offset_hour = 0;
Int8 time_zone_offset_minute = 0;
UInt8 timezone_length = 6;

if (*buf.position() == '+' || *buf.position() == '-')
{
has_time_zone_offset = true;
char timezone_sign = *buf.position();
++buf.position();

char tz[timezone_length];
auto size = buf.read(tz, timezone_length - 1);
tz[size] = 0;

if (size != timezone_length - 1 || tz[2] != ':')
throw ParsingException(std::string("Cannot parse Timezone ") + tz, ErrorCodes::CANNOT_PARSE_DATETIME);

time_zone_offset_hour = (tz[0] - '0') * 10 + (tz[1] - '0');
time_zone_offset_minute = (tz[3] - '0') * 10 + (tz[4] - '0');

if (timezone_sign == '-')
{
time_zone_offset_hour = -time_zone_offset_hour;
time_zone_offset_minute = -time_zone_offset_minute;
}
}
else if (*buf.position() == 'Z')
{
has_time_zone_offset = true;
++buf.position();
}

if (has_time_zone_offset)
{
components.whole -= date_lut.timezoneOffset(components.whole);
if (time_zone_offset_hour)
components.whole -= time_zone_offset_hour * 3600;

if (time_zone_offset_minute)
components.whole -= time_zone_offset_minute * 60;
}
/// proton: ends

bool is_ok = true;
if constexpr (std::is_same_v<ReturnType, void>)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
2022-12-30 05:44:17.000Z 2022-12-30 05:44:17Z
2024-06-09 13:28:00+01:00 2024-06-09 12:28:00 2024-06-09 22:28:00+10:00
2024-06-09 13:28:00.000+01:00 2024-06-09 05:28:00.000-07:00 2024-06-09 12:28:00.000
6 changes: 4 additions & 2 deletions tests/queries_ported/0_stateless/02991_datetime_timezone.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
DROP STREAM IF EXISTS Dates;

SELECT to_datetime64('2022-12-30 13:44:17.000+08:00', 3, 'Europe/London'), to_datetime('2022-12-30 13:44:17+08:00', 'Europe/London');

CREATE stream Dates(t1 datetime('Europe/London'), t2 datetime, t3 datetime('Australia/Sydney')) ENGINE = Memory();

INSERT INTO Dates VALUES (to_time('6/9/2024 13:28','Europe/London'), to_time('6/9/2024 13:28','Europe/London'), to_time('6/9/2024 13:28','Europe/London'));
INSERT INTO Dates VALUES (to_datetime('2024-06-09 13:28:00','Europe/London'), to_time('6/9/2024 13:28','Europe/London'), to_time('6/9/2024 13:28','Europe/London'));

SELECT t1, t2, t3 FROM Dates;

DROP STREAM IF EXISTS Dates;

CREATE stream Dates(t1 datetime64(3, 'Europe/London'), t2 datetime64(3, 'America/Vancouver'), t3 datetime64(3)) ENGINE = Memory();

INSERT INTO Dates VALUES (to_time('6/9/2024 13:28','Europe/London'), to_time('6/9/2024 13:28','Europe/London'), to_time('6/9/2024 13:28','Europe/London'));
INSERT INTO Dates VALUES (to_datetime64('2024-06-09 13:28:00.000',3 ,'Europe/London'), to_time('6/9/2024 13:28','Europe/London'), to_time('6/9/2024 13:28','Europe/London'));

SELECT t1, t2, t3 FROM Dates;
yl-lisen marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
Loading