簡體   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