I'm doing batch insert to db, now I'm facing with data types issue when inserting it as a batch into cassandra.
Here I created a table named batch_rows , you can see type of node_id is text :
("""
CREATE TABLE IF NOT EXISTS batch_rows (
local_pid int,
node_id text,
camera_id int,
geolocation int,
filepath int,
PRIMARY KEY (local_pid, node_id)
)
""")
After creating table then I tried to grab 500 of data and do the batch insert to db :
statement = 'BEGIN BATCH '
to_insert = 500
for i in range(to_insert):
location_generator = self.generate_random_coordinate()
local_pid = i
node_id= 'P2'
camera_id= 1
geolocation= 4
filepath = 3
statement += 'INSERT INTO batch_rows (local_pid, node_id, camera_id, geolocation, filepath) VALUES (%s, %s, %s, %s, %s) ' %
(local_pid, node_id, camera_id, geolocation, filepath)
statement += 'APPLY BATCH'
statement = SimpleStatement(statement, consistency_level=ConsistencyLevel.QUORUM)
try:
self.session.execute(statement,timeout=30.0)
except OperationTimedOut:
ex_type, ex, tb = sys.exc_info()
print("Batch wide row insertion timed out, this may require additional investigation")
del tb
And finally it gave me the error :
[Syntax error in CQL query] message="line 1:103 no viable alternative at input ',' (... filepath) VALUES (0, [P2],...)">
so yeah I am kinda stuck atm, all the helps would be appreciated guy.!