How to import column value in Cassandra like one having such values “13/01/09 23:13”?

╄→尐↘猪︶ㄣ 提交于 2019-12-25 05:06:05

问题


Query:

CREATE TABLE IF NOT EXISTS "TEMP_tmp".temp (
"Date_Time" timestamp,
PRIMARY KEY ("Date_Time")
);

CSV Contains "13/01/09 23:13" values.

Error : Failed to import 1 rows: ParseError - Failed to parse 13/01/09 23:13 : invalid literal for long() with base 10: '13/01/09 23:13',  given up without retries.

What Data Type should I Use ?


回答1:


Default Cqlsh timestamp format is : year-month-day hour:min:sec+timezone
Example :

2017-02-01 05:28:36+0000

You either change your date format to above or you can change the format from cqlshrc file
Check this answer custom cassandra / cqlsh time_format




回答2:


cassandra will store timestamp as 2017-02-01 08:28:21+0000. For example, if I store a timestamp in your described table "TEMP_tmp".temp:

cassandra@cqlsh> INSERT INTO  TEMP_tmp.temp ("Date_Time") VALUES ( toTimestamp(now()));
cassandra@cqlsh> SELECT * FROM TEMP_tmp.temp;

Date_Time
--------------------------
2017-02-01 09:14:29+0000

If we copy all the data to csv:

cassandra@cqlsh> COPY Temp_tmp.temp TO 'temp.csv';

temp.csv will contain:

2017-02-01 09:14:29+0000

If we truncate the table:

cassandra@cqlsh> TRUNCATE TABLE TEMP_tmp.temp;
cassandra@cqlsh> SELECT * FROM TEMP_tmp.temp;

Date_Time
--------------------------

Then if we import temp.csv:

cassandra@cqlsh> COPY Temp_tmp.temp FROM 'temp.csv';
Using 1 child processes

Starting copy of Temp_tmp.temp with columns [Date_Time].
Processed: 1 rows; Rate:       1 rows/s; Avg. rate:       1 rows/s
1 rows imported from 1 files in 0.746 seconds (0 skipped).

If you want custom date/time format, then follow Ashraful Islam's answer from your question.



来源:https://stackoverflow.com/questions/41972052/how-to-import-column-value-in-cassandra-like-one-having-such-values-13-01-09-23

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!