diff --git a/dbms/src/DataTypes/DataTypeDateTime.cpp b/dbms/src/DataTypes/DataTypeDateTime.cpp index a74918f08b6..fe6ccf81439 100644 --- a/dbms/src/DataTypes/DataTypeDateTime.cpp +++ b/dbms/src/DataTypes/DataTypeDateTime.cpp @@ -72,9 +72,9 @@ void DataTypeDateTime::serializeTextCSV(const IColumn & column, size_t row_num, void DataTypeDateTime::deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const { - LocalDateTime value; - readCSV(value, istr); - static_cast(column).getData().push_back(static_cast(value)); + time_t x; + readCSVSimple(x, istr, readDateTimeText); + static_cast(column).getData().push_back(x); } void registerDataTypeDateTime(DataTypeFactory & factory) diff --git a/dbms/src/IO/ReadHelpers.h b/dbms/src/IO/ReadHelpers.h index 544f4e25c7b..1c4e93bbd06 100644 --- a/dbms/src/IO/ReadHelpers.h +++ b/dbms/src/IO/ReadHelpers.h @@ -629,7 +629,7 @@ void readDateTimeTextFallback(time_t & datetime, ReadBuffer & buf, const DateLUT /** In YYYY-MM-DD hh:mm:ss format, according to specified time zone. * As an exception, also supported parsing of unix timestamp in form of decimal number. */ -inline void readDateTimeText(time_t & datetime, ReadBuffer & buf, const DateLUTImpl & date_lut = DateLUT::instance()) +inline void readDateTimeText(time_t & datetime, ReadBuffer & buf, const DateLUTImpl & date_lut) { /** Read 10 characters, that could represent unix timestamp. * Only unix timestamp of 5-10 characters is supported. @@ -666,6 +666,11 @@ inline void readDateTimeText(time_t & datetime, ReadBuffer & buf, const DateLUTI readDateTimeTextFallback(datetime, buf, date_lut); } +inline void readDateTimeText(time_t & datetime, ReadBuffer & buf) +{ + readDateTimeText(datetime, buf, DateLUT::instance()); +} + inline void readDateTimeText(LocalDateTime & datetime, ReadBuffer & buf) { char s[19]; @@ -767,7 +772,7 @@ inline void readDoubleQuoted(LocalDateTime & x, ReadBuffer & buf) /// CSV, for numbers, dates, datetimes: quotes are optional, no special escaping rules. template -inline void readCSVSimple(T & x, ReadBuffer & buf) +inline void readCSVSimple(T & x, ReadBuffer & buf, void (*readText_)(T & x, ReadBuffer & buf) = readText) { if (buf.eof()) throwReadAfterEOF(); @@ -777,7 +782,7 @@ inline void readCSVSimple(T & x, ReadBuffer & buf) if (maybe_quote == '\'' || maybe_quote == '\"') ++buf.position(); - readText(x, buf); + readText_(x, buf); if (maybe_quote == '\'' || maybe_quote == '\"') assertChar(maybe_quote, buf); diff --git a/dbms/tests/queries/0_stateless/00301_csv.reference b/dbms/tests/queries/0_stateless/00301_csv.reference index d038fc8ac38..435eb0c87da 100644 --- a/dbms/tests/queries/0_stateless/00301_csv.reference +++ b/dbms/tests/queries/0_stateless/00301_csv.reference @@ -2,3 +2,7 @@ Hello, world 123 2016-01-01 Hello, "world" 456 2016-01-02 Hello "world" 789 2016-01-03 Hello\n world 100 2016-01-04 +2016-01-01 01:02:03 1 +2016-01-02 01:02:03 2 +2017-08-15 13:15:01 3 +1970-01-02 06:46:39 4 diff --git a/dbms/tests/queries/0_stateless/00301_csv.sh b/dbms/tests/queries/0_stateless/00301_csv.sh index 37f59eba277..8d1fe7055a2 100755 --- a/dbms/tests/queries/0_stateless/00301_csv.sh +++ b/dbms/tests/queries/0_stateless/00301_csv.sh @@ -11,3 +11,13 @@ Hello "world", 789 ,2016-01-03 clickhouse-client --query="SELECT * FROM test.csv ORDER BY d"; clickhouse-client --query="DROP TABLE test.csv"; + +clickhouse-client --query="CREATE TABLE test.csv (t DateTime, s String) ENGINE = Memory"; + +echo '"2016-01-01 01:02:03","1" +2016-01-02 01:02:03, "2" +1502792101,"3" +99999,"4"' | clickhouse-client --query="INSERT INTO test.csv FORMAT CSV"; + +clickhouse-client --query="SELECT * FROM test.csv ORDER BY s"; +clickhouse-client --query="DROP TABLE test.csv"; diff --git a/docs/en/getting_started/example_datasets/star_schema.rst b/docs/en/getting_started/example_datasets/star_schema.rst index b3b5a199c25..0e041fb343b 100644 --- a/docs/en/getting_started/example_datasets/star_schema.rst +++ b/docs/en/getting_started/example_datasets/star_schema.rst @@ -42,11 +42,11 @@ Create tables in ClickHouse: LO_TAX UInt8, LO_COMMITDATE Date, LO_SHIPMODE String - )Engine=MergeTree(LO_ORDERDATE,(LO_ORDERKEY,LO_LINENUMBER,LO_ORDERDATE),8192); + ) Engine = MergeTree(LO_ORDERDATE,(LO_ORDERKEY,LO_LINENUMBER,LO_ORDERDATE),8192); CREATE TABLE customer ( C_CUSTKEY UInt32, - C_NAME String, + C_NAME String, C_ADDRESS String, C_CITY String, C_NATION String, @@ -54,7 +54,7 @@ Create tables in ClickHouse: C_PHONE String, C_MKTSEGMENT String, C_FAKEDATE Date - )Engine=MergeTree(C_FAKEDATE,(C_CUSTKEY,C_FAKEDATE),8192); + ) Engine = MergeTree(C_FAKEDATE,(C_CUSTKEY,C_FAKEDATE),8192); CREATE TABLE part ( P_PARTKEY UInt32, @@ -67,7 +67,7 @@ Create tables in ClickHouse: P_SIZE UInt8, P_CONTAINER String, P_FAKEDATE Date - )Engine=MergeTree(P_FAKEDATE,(P_PARTKEY,P_FAKEDATE),8192); + ) Engine = MergeTree(P_FAKEDATE,(P_PARTKEY,P_FAKEDATE),8192); CREATE TABLE lineorderd AS lineorder ENGINE = Distributed(perftest_3shards_1replicas, default, lineorder, rand()); CREATE TABLE customerd AS customer ENGINE = Distributed(perftest_3shards_1replicas, default, customer, rand());