繁体   English   中英

使用python将大列表插入Cassandra

[英]Insert big list into Cassandra using python

我在使用python将大列表插入Cassandra时遇到问题。 我有一个要保存在Cassandra中的3200字符串列表:

CREATE TABLE IF NOT EXISTS my_test (
                id bigint PRIMARY KEY,
                list_strings list<text>
            );

当我减少清单时,我没有问题。 有用。

prepared_statement = session.prepare("INSERT INTO my_test (id, list_strings) VALUES (?, ?)")
        session.execute(prepared_statement, [id, strings[:5]])

但是,如果我保留列表的总数,则会出错:

Error from server: code=1500 [Replica(s) failed to execute write] message="Operation failed - received 0 responses and 1 failures" info={'required_responses': 1, 'consistency': 'LOCAL_ONE', 'received_responses': 0, 'failures': 1}

如何将大列表插入Cassandra?

不建议使用DB数组类型来保存该数量的数据。 使用表的不同行存储每个字符串会更好:

    id     |    time    | strings
-----------+------------+---------
  bigint   | timestamp  | string
 partition | clustering |

使用id作为群集密钥将是一个不好的解决方案,因为当从用户id请求所有tweet时,它将需要在多个节点中进行读取,而当用作分区密钥时,它仅需要在每个用户中读取一个节点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM