为什么Cassandra不加载CSV文件中的所有值?

时间:2015-03-31 08:25:42

标签: cassandra cassandra-2.0 cqlsh

我刚开始使用Cassandra(单节点设置,2.0.9版本)。我尝试从CSV文件中将数据加载到COLUMNFAMILY,但发现事实上它只加载了239595行中的2行。我不明白为什么。我会感激任何提示。

cqlsh控制台输出:

从CSV

加载数据
cqlsh:keyspace_test1> COPY invoices (date, product_id, customer_id, quantity, sales) FROM '/home/martakarass/Desktop/invoices.csv';
239595 rows imported in 1 minute and 52.766 seconds.

请注意SELECT仅显示2行

cqlsh:keyspace_test1> SELECT * FROM invoices limit 10; 

 date     | customer_id | product_id    | quantity | sales
----------+-------------+---------------+----------+--------
 2/1/2015 |  Client_100 | Product_15702 |        6 | 123.42
 1/9/2015 |  Client_998 | Product_43550 |     3000 | 15.368

(2 rows)

用计数检查并非所有行都已加载

cqlsh:keyspace_test1> SELECT count(*) FROM invoices; 

 count
-------
     2

(1 rows)

cqlsh:keyspace_test1> 

(已更新)表格详情

cqlsh:keyspace_test1> DESCRIBE COLUMNFAMILY keyspace_test1.invoices; 

CREATE TABLE invoices (
  date text,
  customer_id text,
  product_id text,
  quantity int,
  sales float,
  PRIMARY KEY ((date))
) WITH
  bloom_filter_fp_chance=0.010000 AND
  caching='KEYS_ONLY' AND
  comment='' AND
  dclocal_read_repair_chance=0.100000 AND
  gc_grace_seconds=864000 AND
  index_interval=128 AND
  read_repair_chance=0.000000 AND
  replicate_on_write='true' AND
  populate_io_cache_on_flush='false' AND
  default_time_to_live=0 AND
  speculative_retry='99.0PERCENTILE' AND
  memtable_flush_period_in_ms=0 AND
  compaction={'class': 'SizeTieredCompactionStrategy'} AND
  compression={'sstable_compression': 'LZ4Compressor'};

2 个答案:

答案 0 :(得分:4)

我打算猜测日期在invoices.csv文件中并不是唯一的。当我创建一个类似的表时:

CREATE TABLE stackoverflow.invoices (
    date timestamp PRIMARY KEY,
    amount bigint,
    id bigint
)

我使用的CSV文件有4行,如下所示:

date|id|amount
2015-03-30 00:00:00-0500|1|4500
2015-03-31 00:00:00-0500|2|5500
2015-03-31 00:00:00-0500|3|6600
2015-03-31 00:00:00-0500|4|7500

接下来,我使用COPY FROM导入它们:

aploetz@cqlsh:stackoverflow> COPY invoices (date, id, amount) FROM 
    '/home/aploetz/invoices.csv' WITH DELIMITER='|' AND HEADER=true;

4 rows imported in 0.035 seconds.

我应该有4行,对吗?错。

aploetz@cqlsh:stackoverflow> SELECT * FROm invoices;

 date                     | amount | id
--------------------------+--------+----
 2015-03-30 00:00:00-0500 |   4500 |  1
 2015-03-31 00:00:00-0500 |   7500 |  4

(2 rows)

Cassandra PRIMARY KEYs是独一无二的。因此,如果您要从文件中导入239595行,但实际上只有两个唯一日期,那么您将拥有2行。

答案 1 :(得分:0)

这是一个没有解决的错误cqlssh bug

你可以通过这样做来解决你的问题: 拳头进入您的根目录,您将获得 .cassandra 文件夹进入此文件夹即可获得

  

cqlshrc

添加这两行

[csv]
field_size_limit=1000000000

然后关闭你的文件.restart cassandra你的问题将得到解决。