I want to import a csv file in cassandra using python script. I already know how to import csv in cassandra using the COPY command in the cqlsh.
My csv file with dtypes: timestamp, timestamp, decimal, decimal, decimal, decimal, decimal, decimal
I already have a code, and I am only lacking on how I would import the csv file inside cassandra
KEYSPACE = "test_cassandra"
cluster = Cluster(['127.0.0.1'])
session = cluster.connect()
log.info("creating keyspace . . .")
session.execute("""
CREATE KEYSPACE IF NOT EXISTS %s
WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}
""" % KEYSPACE)
log.info("setting keyspace . . .")
session.set_keyspace(KEYSPACE)
log.info("creating table . . .")
session.execute("""
CREATE TABLE IF NOT EXISTS test_NYC_taxi (
pickup timestamp,
dropoff timestamp,
distance decimal,
fare decimal,
p_long decimal,
p_lat decimal,
d_long decimal,
d_lat decimal,
PRIMARY KEY(pickup, dropoff, distance));
""")
prepared = session.prepare("""
INSERT INTO test_nyc_taxi (pickup, dropoff, distance, fare, p_long, p_lat, d_long, d_lat)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
""")
Any help would be very much appreciated. :)