将具有多值(集合)属性的CSV导入Cassandra
假设我想将csv文件导入下表:将具有多值(集合)属性的CSV导入Cassandra,csv,collections,cassandra,Csv,Collections,Cassandra,假设我想将csv文件导入下表: CREATE TABLE example_table ( id int PRIMARY KEY, comma_delimited_str_list list<ascii>, space_delimited_str_list list<ascii> ); 我想把“hello,world”和“stack overflow”看作两个多值属性 我能知道如何将这样的CSV文件导入Cassandra中相应的表中吗?最好使用CQL COPY
CREATE TABLE example_table (
id int PRIMARY KEY,
comma_delimited_str_list list<ascii>,
space_delimited_str_list list<ascii>
);
我想把“hello,world”
和“stack overflow”
看作两个多值属性
我能知道如何将这样的CSV文件导入Cassandra中相应的表中吗?最好使用CQL COPY?CQL 1.2能够将带有多值字段的CSV文件直接移植到表中。但是,这些多值字段的格式必须与CQL格式匹配 例如,列表的格式必须为
['abc'、'def'、'ghi']
,集合的格式必须为{'123'、'456'、'789'}
下面是将CSV格式的数据从STDIN导入OP中提到的example_表
的示例:
cqlsh:demo> copy example_table from STDIN;
[Use \. on a line by itself to end input]
[copy] 12345,"['hello','world']","['stack','overflow']"
[copy] 56780,"['this','is','a','test','list']","['here','is','another','one']"
[copy] \.
2 rows imported in 11.304 seconds.
cqlsh:demo> select * from example_table;
id | comma_delimited_str_list | space_delimited_str_list
-------+---------------------------+--------------------------
12345 | [hello, world] | [stack, overflow]
56780 | [this, is, a, test, list] | [here, is, another, one]
从CSV文件导入格式不正确的列表或设置值将引发错误:
cqlsh:demo> copy example_table from STDIN;
[Use \. on a line by itself to end input]
[copy] 9999,"hello","world"
Bad Request: line 1:108 no viable alternative at input ','
Aborting import at record #0 (line 1). Previously-inserted values still present.
上述输入应替换为9999、“['hello']”、“['world']”
:
CQL 1.2能够将带有多值字段的CSV文件直接移植到表中。但是,这些多值字段的格式必须与CQL格式匹配 例如,列表的格式必须为
['abc'、'def'、'ghi']
,集合的格式必须为{'123'、'456'、'789'}
下面是将CSV格式的数据从STDIN导入OP中提到的example_表
的示例:
cqlsh:demo> copy example_table from STDIN;
[Use \. on a line by itself to end input]
[copy] 12345,"['hello','world']","['stack','overflow']"
[copy] 56780,"['this','is','a','test','list']","['here','is','another','one']"
[copy] \.
2 rows imported in 11.304 seconds.
cqlsh:demo> select * from example_table;
id | comma_delimited_str_list | space_delimited_str_list
-------+---------------------------+--------------------------
12345 | [hello, world] | [stack, overflow]
56780 | [this, is, a, test, list] | [here, is, another, one]
从CSV文件导入格式不正确的列表或设置值将引发错误:
cqlsh:demo> copy example_table from STDIN;
[Use \. on a line by itself to end input]
[copy] 9999,"hello","world"
Bad Request: line 1:108 no viable alternative at input ','
Aborting import at record #0 (line 1). Previously-inserted values still present.
上述输入应替换为9999、“['hello']”、“['world']”
:
在CQL 3.1.1中不适用于我:
从STDIN复制mylist
'test'、“['foo'、'bar'、'baz']”
记录0(第1行)的字段数错误(4而不是2)
代码>'test'、[\'foo\'、\'bar\'、\'baz\']
\.
在CQL 3.1.1中对我不起作用:从STDIN复制mylist
'test'、“['foo'、'bar'、'baz']”
记录0(第1行)的字段数错误(4而不是2)
代码>'test'、[\'foo\'、\'bar\'、\'baz\']
\.