Since, cassandra supports map type. I want to insert a python dict into cassandra. I tried this:
cql = "Insert into table_name (my_key, name, my_dict) values (%s, %s, %s)" % (my_key, name, my_dict)
session.execute(cql)
This obviously didn't work.
I already have a map type column in my column family. How do I go about it?
Error: TypeError: not all arguments converted during string formatting
A map is a name and a pair of typed values. Using the map type, you can store timestamp-related information in user profiles. Each element of the map is internally stored as one Cassandra column that you can modify, replace, delete, and query.
Python module for working with Cassandra database is called Cassandra Driver. It is also developed by Apache foundation. This module contains an ORM API, as well as a core API similar in nature to DB-API for relational databases. Installation of Cassandra driver is easily done using pip utility.
Use parameter passing form instead of string interpolation:
cql = "Insert into table_name (my_key, name, my_dict) values (%s, %s, %s)"
session.execute(cql, (my_key, name, my_dict))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With