mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Unix timestamp format for DateTime fields in CSV. Resolves #366. [#CLICKHOUSE-3168]
This commit is contained in:
parent
dc29ae7e73
commit
ad40104022
@ -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
|
void DataTypeDateTime::deserializeTextCSV(IColumn & column, ReadBuffer & istr, const char delimiter) const
|
||||||
{
|
{
|
||||||
LocalDateTime value;
|
time_t x;
|
||||||
readCSV(value, istr);
|
readCSVSimple(x, istr, readDateTimeText);
|
||||||
static_cast<ColumnUInt32 &>(column).getData().push_back(static_cast<time_t>(value));
|
static_cast<ColumnUInt32 &>(column).getData().push_back(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerDataTypeDateTime(DataTypeFactory & factory)
|
void registerDataTypeDateTime(DataTypeFactory & factory)
|
||||||
|
@ -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.
|
/** 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.
|
* 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.
|
/** Read 10 characters, that could represent unix timestamp.
|
||||||
* Only unix timestamp of 5-10 characters is supported.
|
* 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);
|
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)
|
inline void readDateTimeText(LocalDateTime & datetime, ReadBuffer & buf)
|
||||||
{
|
{
|
||||||
char s[19];
|
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.
|
/// CSV, for numbers, dates, datetimes: quotes are optional, no special escaping rules.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline void readCSVSimple(T & x, ReadBuffer & buf)
|
inline void readCSVSimple(T & x, ReadBuffer & buf, void (*readText_)(T & x, ReadBuffer & buf) = readText)
|
||||||
{
|
{
|
||||||
if (buf.eof())
|
if (buf.eof())
|
||||||
throwReadAfterEOF();
|
throwReadAfterEOF();
|
||||||
@ -777,7 +782,7 @@ inline void readCSVSimple(T & x, ReadBuffer & buf)
|
|||||||
if (maybe_quote == '\'' || maybe_quote == '\"')
|
if (maybe_quote == '\'' || maybe_quote == '\"')
|
||||||
++buf.position();
|
++buf.position();
|
||||||
|
|
||||||
readText(x, buf);
|
readText_(x, buf);
|
||||||
|
|
||||||
if (maybe_quote == '\'' || maybe_quote == '\"')
|
if (maybe_quote == '\'' || maybe_quote == '\"')
|
||||||
assertChar(maybe_quote, buf);
|
assertChar(maybe_quote, buf);
|
||||||
|
@ -2,3 +2,7 @@ Hello, world 123 2016-01-01
|
|||||||
Hello, "world" 456 2016-01-02
|
Hello, "world" 456 2016-01-02
|
||||||
Hello "world" 789 2016-01-03
|
Hello "world" 789 2016-01-03
|
||||||
Hello\n world 100 2016-01-04
|
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
|
||||||
|
@ -11,3 +11,13 @@ Hello "world", 789 ,2016-01-03
|
|||||||
|
|
||||||
clickhouse-client --query="SELECT * FROM test.csv ORDER BY d";
|
clickhouse-client --query="SELECT * FROM test.csv ORDER BY d";
|
||||||
clickhouse-client --query="DROP TABLE test.csv";
|
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";
|
||||||
|
Loading…
Reference in New Issue
Block a user