2
votes

As stated and discussed by Mr. Ellis in dynamic-columns/wide-rows, dynamic table is possible through Map Collection. However, I can see that this is only applicable for data with the same types. Example from the link:

CREATE TABLE users (
  user_id text PRIMARY KEY,
  name text,
  birth_year int,
  phone_numbers map
);

INSERT INTO users (user_id, name, birth_year, phone_numbers)
VALUES ('jbellis', 'Jonathan Ellis', 1976, {'home': 1112223333, 'work': 2223334444});

Both home and work phone_numbers are type integer. But we need a collection with various datatypes. Say,

Create table storage ( mobile_id int PRIMARY KEY, date timestamp, data map );

Then data contains these:

{'state': String, 'protocol': Integer, 'weight': Double, 'frame': Blob ... }

So my question is that, do we have an alternative for this? Is this possible with CQL?

2
Check user defined types datastax.com/dev/blog/cql-in-2-1 - phact

2 Answers

1
votes

At this time, I believe that it is not possible. You would be better off using a String with some sort of type information embedded in it

ie {'home': 'int:1112223333', 'work': 'str:222-333-4444'}

or alternatively use a blob and save a language-specific map into Cassandra using the blob type and language-specific serialization to save your variable map.

0
votes

Maps are typed. Still you can create one map field per type? map_int, map_text, map_etc

This has the added benefit it'll be a bit faster, as collections are loaded as a whole when read, so splitting up by type will load less data one each query. You should be able to find out the type of what you're looking for up front I hope.