Reputation: 1261
I want to store python dict
objects (same structure) in Cassandra. I only want to store them in one column. I can create a Cassandra column:
MAP
TEXT
. I can then serialize dict into json string and store it.But not all the items in my python dict
map to the same type, for example
dict = {"key_1": "abc", "key_2": 10, "key_3": True}
In this case, I think only Option 2 is valid? In my actual project, I have many columns to create. Some map to the same type and some don't. For convience, I want to just serialize all of them and store as TEXT
. But this feels a bit unorthodox to me. What's the best practice?
Upvotes: 1
Views: 447
Reputation: 16293
If you don't care about mapping each dict
key to a CQL column then storing the whole dict
into a CQL text
column is generally what I recommend.
If the data type of the values are the same (they're either all texts or integers), you can store the key-value pairs in a CQL map
collection so it's easier to retrieve the values based on the key although you already stated the values are of different data types. Cheers!
Upvotes: 2