mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-30 11:32:03 +00:00
Merge pull request #35840 from zzsmdfj/issue/#34966_fix_dateTime_deserialize
to #34966_fix_dateTime_deserialize
This commit is contained in:
commit
c73115ffb4
@ -851,6 +851,8 @@ inline ReturnType readDateTimeTextImpl(time_t & datetime, ReadBuffer & buf, cons
|
|||||||
|
|
||||||
/// YYYY-MM-DD hh:mm:ss
|
/// YYYY-MM-DD hh:mm:ss
|
||||||
static constexpr auto DateTimeStringInputSize = 19;
|
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();
|
bool optimistic_path_for_date_time_input = s + DateTimeStringInputSize <= buf.buffer().end();
|
||||||
|
|
||||||
if (optimistic_path_for_date_time_input)
|
if (optimistic_path_for_date_time_input)
|
||||||
@ -861,16 +863,27 @@ inline ReturnType readDateTimeTextImpl(time_t & datetime, ReadBuffer & buf, cons
|
|||||||
UInt8 month = (s[5] - '0') * 10 + (s[6] - '0');
|
UInt8 month = (s[5] - '0') * 10 + (s[6] - '0');
|
||||||
UInt8 day = (s[8] - '0') * 10 + (s[9] - '0');
|
UInt8 day = (s[8] - '0') * 10 + (s[9] - '0');
|
||||||
|
|
||||||
UInt8 hour = (s[11] - '0') * 10 + (s[12] - '0');
|
UInt8 hour = 0;
|
||||||
UInt8 minute = (s[14] - '0') * 10 + (s[15] - '0');
|
UInt8 minute = 0;
|
||||||
UInt8 second = (s[17] - '0') * 10 + (s[18] - '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
|
||||||
|
bool dt_long = (s[10] == ' ' || s[10] == 'T');
|
||||||
|
if (dt_long)
|
||||||
|
{
|
||||||
|
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))
|
if (unlikely(year == 0))
|
||||||
datetime = 0;
|
datetime = 0;
|
||||||
else
|
else
|
||||||
datetime = date_lut.makeDateTime(year, month, day, hour, minute, second);
|
datetime = date_lut.makeDateTime(year, month, day, hour, minute, second);
|
||||||
|
|
||||||
buf.position() += DateTimeStringInputSize;
|
if (dt_long)
|
||||||
|
buf.position() += DateTimeStringInputSize;
|
||||||
|
else
|
||||||
|
buf.position() += DateStringInputSize;
|
||||||
return ReturnType(true);
|
return ReturnType(true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
2022-03-31T00:00:00Z 1
|
||||||
|
2022-04-01T09:10:24Z 2
|
||||||
|
2022-03-31T10:18:56Z 3
|
||||||
|
2022-03-31T10:18:56Z 4
|
||||||
|
2022-04-01T09:10:24Z 5
|
10
tests/queries/0_stateless/02249_parse_date_time_basic.sql
Normal file
10
tests/queries/0_stateless/02249_parse_date_time_basic.sql
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
SET date_time_output_format='iso';
|
||||||
|
drop table if exists t;
|
||||||
|
CREATE TABLE t (a DateTime('UTC'), 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);
|
||||||
|
INSERT INTO t(a, b, c, d ,e) VALUES ('2022-03-31T10:18:56','','','',4);
|
||||||
|
INSERT INTO t(a, b, c, d ,e) VALUES ('1648804224','','','',5);
|
||||||
|
select a, e from t order by e;
|
||||||
|
drop table if exists t;
|
Loading…
Reference in New Issue
Block a user