用简单的CSV导入到Clickhouse,解析错误
我有一个非常简单的CSV,我试图进口到Clickhouse,但没有成功。创建表语句是:
CREATE TABLE staging.EloLBK
(
`Month` DateTime64(3),
`1958` Int32,
`1959` Int32,
`1960` Int32
)
ENGINE = MergeTree
PRIMARY KEY Month
ORDER BY Month
SETTINGS index_granularity = 8192
CSV数据如下:
"Month", "1958", "1959", "1960"
"JAN", 340, 360, 417
"FEB", 318, 342, 391
"MAR", 362, 406, 419
"APR", 348, 396, 461
"MAY", 363, 420, 472
"JUN", 435, 472, 535
"JUL", 491, 548, 622
"AUG", 505, 559, 606
"SEP", 404, 463, 508
"OCT", 359, 407, 461
"NOV", 310, 362, 390
"DEC", 337, 405, 432
我的导入语句是:
INSERT INTO EloLBK SELECT * FROM file('EloLBK/*.csv', 'CSVWithNames', '"Month" datetime64, "1958" integer, "1959" integer, "1960" integer')
从Clickhouse返回的错误是:
Code: 27. DB::Exception: Cannot parse input: expected '"' before: '417\n"FEB", 318, 342, 391\n"MAR", 362, 406, 419\n"APR", 348, 396, 461\n"MAY", 363, 420, 472\n"JUN", 435, 472, 535\n"JUL", 491, 548, 622\n"AUG", 505,':
Row 1:
Column 0, name: Month, type: DateTime64(3), parsed text: "<DOUBLE QUOTE>JAN<DOUBLE QUOTE>, 340, 360, "ERROR
Code: 27. DB::ParsingException: Cannot parse input: expected '"' before: '417\n"FEB", 318, 342, 391\n"MAR", 362, 406, 419\n"APR", 348, 396, 461\n"MAY", 363, 420, 472\n"JUN", 435, 472, 535\n"JUL", 491, 548, 622\n"AUG", 505,'. (CANNOT_PARSE_INPUT_ASSERTION_FAILED) (version 21.12.1.8928 (official build))
: While executing CSVRowInputFormat: While executing File. (CANNOT_PARSE_INPUT_ASSERTION_FAILED)
我不确定如何解决此问题,因此将不胜感激!
I have an extremely simple CSV I'm trying to import into clickhouse with no success. The create table statement is:
CREATE TABLE staging.EloLBK
(
`Month` DateTime64(3),
`1958` Int32,
`1959` Int32,
`1960` Int32
)
ENGINE = MergeTree
PRIMARY KEY Month
ORDER BY Month
SETTINGS index_granularity = 8192
The CSV data looks like this:
"Month", "1958", "1959", "1960"
"JAN", 340, 360, 417
"FEB", 318, 342, 391
"MAR", 362, 406, 419
"APR", 348, 396, 461
"MAY", 363, 420, 472
"JUN", 435, 472, 535
"JUL", 491, 548, 622
"AUG", 505, 559, 606
"SEP", 404, 463, 508
"OCT", 359, 407, 461
"NOV", 310, 362, 390
"DEC", 337, 405, 432
My import statement is:
INSERT INTO EloLBK SELECT * FROM file('EloLBK/*.csv', 'CSVWithNames', '"Month" datetime64, "1958" integer, "1959" integer, "1960" integer')
The error coming back from clickhouse is:
Code: 27. DB::Exception: Cannot parse input: expected '"' before: '417\n"FEB", 318, 342, 391\n"MAR", 362, 406, 419\n"APR", 348, 396, 461\n"MAY", 363, 420, 472\n"JUN", 435, 472, 535\n"JUL", 491, 548, 622\n"AUG", 505,':
Row 1:
Column 0, name: Month, type: DateTime64(3), parsed text: "<DOUBLE QUOTE>JAN<DOUBLE QUOTE>, 340, 360, "ERROR
Code: 27. DB::ParsingException: Cannot parse input: expected '"' before: '417\n"FEB", 318, 342, 391\n"MAR", 362, 406, 419\n"APR", 348, 396, 461\n"MAY", 363, 420, 472\n"JUN", 435, 472, 535\n"JUL", 491, 548, 622\n"AUG", 505,'. (CANNOT_PARSE_INPUT_ASSERTION_FAILED) (version 21.12.1.8928 (official build))
: While executing CSVRowInputFormat: While executing File. (CANNOT_PARSE_INPUT_ASSERTION_FAILED)
I'm not sure how to resolve this so any advice would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以告诉Clickhouse尽力通过选项
date_time_input_format ='Best_ffort'
,例如:将导致:
You can tell ClickHouse to do a best effort guess by passing the option
date_time_input_format='best_effort'
, for example:Will lead to:
好的,经过更多的混乱,似乎错误消息只是有些误导。实际问题是,Clickhouse(可以理解)无法作为日期时间解析本月。
以下CSV输入效果很好:
Ok, after some more messing around, it appears the error message is just a bit misleading. The actual issue is that clickhouse is (understandably) unable to parse the month as a datetime.
The following CSV input works fine: