Here is my table's definition.
Код: Выделить всё
CREATE TABLE chat_data.twitch_chat_by_broadcaster_and_timestamp ( broadcaster_id int, year_month int, timestamp bigint, message_id uuid, message text, PRIMARY KEY ((broadcaster_id, year_month), timestamp, message_id) ) WITH CLUSTERING ORDER BY (timestamp ASC, message_id ASC)
Код: Выделить всё
import logging import auth.secrets as secrets from cassandra.auth import PlainTextAuthProvider from cassandra.cluster import Cluster from cassandra.policies import DCAwareRoundRobinPolicy, TokenAwarePolicy from cassandra.query import BatchStatement, BatchType, tuple_factory from datetime_helpers import get_month, get_next_month class DatabaseConnection: def __init__(self, keyspace): auth_provider = PlainTextAuthProvider( secrets.get_astra_client_id(), secrets.get_astra_secret() ) load_balancing_policy = TokenAwarePolicy(DCAwareRoundRobinPolicy()) cluster = Cluster( cloud=secrets.get_astra_cloud_config(), auth_provider=auth_provider, load_balancing_policy=load_balancing_policy, ) self.session = cluster.connect(keyspace) def insert_chats(self, messages): logging.info(f"Inserting {len(messages)} message") batch = BatchStatement( consistency_level="QUORUM", batch_type=BatchType.UNLOGGED ) statement = self.session.prepare( """ INSERT INTO twitch_chat_by_broadcaster_and_timestamp (broadcaster_id, year_month, timestamp, message_id, message) VALUES (?, ?, ?, ?, ?) """ ) for m in messages: broadcaster_id, timestamp, message_id, message = m month = get_month(timestamp) batch.add( statement, (broadcaster_id, month, timestamp, message_id, message) ) try: self.session.execute(batch) logging.info("Messages inserted successfully") return True except Exception as e: logging.error(f"Exception: {e}") return False
Код: Выделить всё
execute
Код: Выделить всё
Exception: ('Unable to complete the operation against any hosts', {
Источник: [url]https://stackoverflow.com/questions/78131589/cassandra-throws-errorrequired-argument-is-not-an-integer-when-i-set-the-con[/url]