Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

map<text, object> Cassandra, is it possible

I want to create a table with a map accepting string as key and any object as value (boolean, string, int, timestamp).

Is it possible ?

Thanks

like image 356
Fundhor Avatar asked May 20 '16 09:05

Fundhor


People also ask

How do I add a map value in Cassandra?

Use the UPDATE command to insert values into the map. Append an element to the map by enclosing the key-value pair in curly brackets and using the addition (+) operator. cqlsh> UPDATE cycling.

What is map in Cassandra?

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.

What is tuple in Cassandra?

The tuple data type holds fixed-length sets of typed positional fields. Use a tuple as an alternative to a user-defined type. A tuple can accommodate many fields (32768), more than can be prudently used. Typically, create a tuple with a few fields.


2 Answers

Currently, no, keys and values in a map must be of a known CQL type. There is a request for "dynamic types", but nobody has worked on it so far.

like image 57
adutra Avatar answered Oct 27 '22 18:10

adutra


Any object isn't possible. You can create user defined types but this type isn't dynamic: https://docs.datastax.com/en/cql/3.1/cql/cql_reference/cqlRefcreateType.html

You can parse your object as json and this json as string. You can insert this string in a text column.

like image 36
Citrullin Avatar answered Oct 27 '22 17:10

Citrullin