to #34966_fix_dateTime_deserialize

This commit is contained in:
zzsmdfj 2022-04-01 20:13:34 +08:00
parent a711fc0402
commit ececee3817
3 changed files with 24 additions and 3 deletions

View File

@ -851,6 +851,8 @@ inline ReturnType readDateTimeTextImpl(time_t & datetime, ReadBuffer & buf, cons
/// YYYY-MM-DD hh:mm:ss
static constexpr auto DateTimeStringInputSize = 19;
///YYYY-MM-DD
static constexpr auto DateStringInputSize = 10;
bool optimistic_path_for_date_time_input = s + DateTimeStringInputSize <= buf.buffer().end();
if (optimistic_path_for_date_time_input)
@ -861,16 +863,26 @@ inline ReturnType readDateTimeTextImpl(time_t & datetime, ReadBuffer & buf, cons
UInt8 month = (s[5] - '0') * 10 + (s[6] - '0');
UInt8 day = (s[8] - '0') * 10 + (s[9] - '0');
UInt8 hour = (s[11] - '0') * 10 + (s[12] - '0');
UInt8 minute = (s[14] - '0') * 10 + (s[15] - '0');
UInt8 second = (s[17] - '0') * 10 + (s[18] - '0');
UInt8 hour = 0;
UInt8 minute = 0;
UInt8 second = 0;
///simply determine whether it is YYYY-MM-DD hh:mm:ss or YYYY-MM-DD by the content of the tenth character in an optimistic scenario
if (s[10] == ' ')
{
hour = (s[11] - '0') * 10 + (s[12] - '0');
minute = (s[14] - '0') * 10 + (s[15] - '0');
second = (s[17] - '0') * 10 + (s[18] - '0');
}
if (unlikely(year == 0))
datetime = 0;
else
datetime = date_lut.makeDateTime(year, month, day, hour, minute, second);
if (s[10] == ' ')
buf.position() += DateTimeStringInputSize;
else
buf.position() += DateStringInputSize;
return ReturnType(true);
}
else

View File

@ -0,0 +1,3 @@
2022-03-31 00:00:00 1
2022-04-01 17:10:24 2
2022-03-31 10:18:56 3

View File

@ -0,0 +1,6 @@
drop table if exists t;
CREATE TABLE t (a DateTime, b String, c String, d String, e Int32) ENGINE = Memory;
INSERT INTO t(a, b, c, d ,e) VALUES ('2022-03-31','','','',1);
INSERT INTO t(a, b, c, d ,e) VALUES (1648804224,'','','',2);
INSERT INTO t(a, b, c, d ,e) VALUES ('2022-03-31 10:18:56','','','',3);
select a, e from t;