Hi I'm trying to upload a large blod to Cassandra with Python and I'm stuck. I need to allow uploads of around 1MB to be loaded into a blob column but I keep getting a Cassandra error, 'cssandra.cluster.NoHostAvailable: ("Unable to complete the operation against any hosts', {})
I'm getting stuck using the following code, I presume its cause by the max query params (Query parameters in a query: 65535 (216-1)-- https://docs.datastax.com/en/cql/3.3/cql/cql_reference/refLimits.html).
Does anyone know if there's a way around the limit?
import ssl
import os
from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider
from cassandra.query import SimpleStatement
from cassandra.encoder import Encoder
def e_var(name):
try:
return os.environ[name]
except KeyError:
print ("Please set the environment variable " + name)
sys.exit(1)
ssl_options = {
'ssl_version': ssl.PROTOCOL_TLSv1}
user = e_var('CAS_USER')
pwd = e_var('CAS_PWD')
ip = e_var('CAS_IPS').split(',')
keyspace = e_var('CAS_KEYSPACE')
ap = PlainTextAuthProvider(username=user, password=pwd)
cluster = Cluster(ip, auth_provider=ap, ssl_options=ssl_options)
session = cluster.connect(keyspace)
session.execute('CREATE TABLE IF NOT EXISTS sample (key text,data blob, PRIMARY KEY (key))')
print('***table done')
def insert(bytes_length, message ):
e = Encoder()
data = ('a' * bytes_length).encode()
d = { 'key' : 'bucket_1', 'data' :bytearray(data) }
session.execute("""INSERT INTO sample (key,data) VALUES (%(key)s, %(data)s)""",d)
print('***' + message)
insert(3000, 'done first insert')
insert(32727, 'done second insert')
insert(32728, 'done third insert')