私は、自分のcassandraテーブルとクエリtwitter APIのいずれかでデータを取得して、1人のユーザーのフォロワーと友だちを取得するプログラムを作成しました。私はすべてのIDをセットで安全にして、すべての信者/友人を得るとき、私はそれをカサンドラに書きます。1つのクエリでcassandraに多くのデータを書き込む
この問題は、1M24フォロワーを持っているユーザーの1人です。このコードを実行すると、設定された種類のサイズがcassandraに書き込みエラーを生成します。
def get_data(tweepy_function, author_id, author_username, session):
if tweepy_function == "followers":
followers = set()
for follower_id in tweepy.Cursor(API.followers_ids, id=author_id, count=5000).items():
if len(followers) % 5000 == 0 and len(followers) != 0:
print("Collected followers: ", len(followers))
followers.add(follower_id)
query = "INSERT INTO {0} (node_id, screen_name, centrality, follower_ids) VALUES ({1}, {2}, {3}, {4})"\
.format("network", author_id, author_username, 0.0, followers)
session.execute(query)
if tweepy_function == "friends":
friends = set()
for friend_id in tweepy.Cursor(API.friends_ids, id=author_id, count=5000).items():
if len(friends) % 5000 == 0 and len(friends) != 0:
print("Collected followers: ", len(friends))
friends.add(friend_id)
query = "INSERT INTO {0} (node_id, screen_name, centrality, friend_ids) VALUES ({1}, {2}, {3}, {4})"\
.format("network", author_id, author_username, 0.0, friends)
session.execute(query)
としては、私は私のスキーマを追加尋ねた:
table = """CREATE TABLE IF NOT EXISTS
{0} (
node_id bigint ,
screen_name text,
last_tweets set<text>,
follower_ids set<bigint>,
friend_ids set<bigint>,
centrality float,
PRIMARY KEY (node_id))
""".format(table_name)
は、なぜ私が書き込みエラーが出るのですか?それを防ぐ方法は?それはカッサンドラへの安全なデータへの良い方法ですか?
あなたのスキーマは何ですか? –
@AshrafulIslamそれを追加してください – mel