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 all commits
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
66 changes: 33 additions & 33 deletions tests/queries_ported/0_stateless/01340_datetime64_fpe.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
WITH to_datetime64('2019-09-16 19:20:12.3456789102019-09-16 19:20:12.345678910', 0) AS dt64 SELECT dt64; -- { serverError 6 }
WITH to_datetime64('2019-09-16 19:20:12.3456789102019-09-16 19:20:12.345678910', 0) AS dt64 SELECT dt64; -- { serverError 41 }

SELECT to_datetime64('2011-11-11 11:11:11.1234567890123456789', 0);
SELECT to_datetime64('2011-11-11 11:11:11.-12345678901234567890', 0); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.-12345678901234567890', 0); -- { serverError 41 }


SELECT to_datetime64('2011-11-11 11:11:11.1', 0);
Expand All @@ -26,39 +26,39 @@ SELECT to_datetime64('2011-11-11 11:11:11.1111111111111111111', 0);
SELECT to_datetime64('2011-11-11 11:11:11.11111111111111111111', 0);
SELECT to_datetime64('2011-11-11 11:11:11.111111111111111111111', 0);

SELECT to_datetime64('2011-11-11 11:11:11.-1', 0); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.-11', 0); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.-111', 0); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.-1111', 0); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.-11111', 0); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.-111111', 0); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.-1111111', 0); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.-11111111', 0); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.-111111111', 0); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.-1111111111', 0); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.-11111111111', 0); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.-111111111111', 0); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.-1111111111111', 0); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.-11111111111111', 0); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.-111111111111111', 0); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.-1111111111111111', 0); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.-11111111111111111', 0); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.-111111111111111111', 0); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.-1111111111111111111', 0); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.-11111111111111111111', 0); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.-111111111111111111111', 0); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.-1', 0); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.-11', 0); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.-111', 0); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.-1111', 0); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.-11111', 0); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.-111111', 0); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.-1111111', 0); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.-11111111', 0); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.-111111111', 0); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.-1111111111', 0); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.-11111111111', 0); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.-111111111111', 0); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.-1111111111111', 0); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.-11111111111111', 0); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.-111111111111111', 0); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.-1111111111111111', 0); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.-11111111111111111', 0); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.-111111111111111111', 0); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.-1111111111111111111', 0); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.-11111111111111111111', 0); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.-111111111111111111111', 0); -- { serverError 41 }

SELECT to_datetime64('2011-11-11 11:11:11.+1', 0); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.+1', 0); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.++11', 10); -- { serverError 69 }
SELECT to_datetime64('2011-11-11 11:11:11.+111', 3); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.+++1111', 5); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.+11111', 7); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.+++++111111', 2); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.+1111111', 1); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.++++++11111111', 8); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.+111111111', 9); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.+++++++1111111111', 6); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.+11111111111', 4); -- { serverError 6 }
SELECT to_datetime64('2011-11-11 11:11:11.+111', 3); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.+++1111', 5); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.+11111', 7); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.+++++111111', 2); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.+1111111', 1); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.++++++11111111', 8); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.+111111111', 9); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.+++++++1111111111', 6); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.+11111111111', 4); -- { serverError 41 }
SELECT to_datetime64('2011-11-11 11:11:11.++++++++111111111111', 11); -- { serverError 69 }
SELECT to_datetime64('2011-11-11 11:11:11.+1111111111111', 15); -- { serverError 69 }
SELECT to_datetime64('2011-11-11 11:11:11.+++++++++11111111111111', 13); -- { serverError 69 }
Expand Down
17 changes: 0 additions & 17 deletions tests/queries_ported/0_stateless/02991_datetime_timezone.sql

This file was deleted.

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
19 changes: 19 additions & 0 deletions tests/queries_ported/0_stateless/99008_datetime_timezone.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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_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_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;

DROP STREAM IF EXISTS Dates;
Loading