0

I have a data model as below using CQL3

CREATE TABLE test(
   userid text,
   entry_date timestamp,
   attributes map<text, text>,
   primary key (userid,entry_date)
 );

Map contains lot of data. I need to have a search based on map key as well along with queries to support search based on userId and date range. Can you help me with data model along with an example in java using datastax drive api. If I could convert in to a wide row can you let me know how data will be organized and fetched using java.

Peanut
  • 3,753
  • 3
  • 31
  • 45

1 Answers1

1

First, when you say lots of data is contained in your map, what does that mean? There is a 64K item limit in collections, so be mindful of that.

Second, C* tables should be designed to support your queries. If you have multiple queries, that will typically result in multiple tables. The table you have provided will support your query of userid and date range. For the query based on your attributes, you can try storing them not in a map:

CREATE TABLE test(
userid text,
entry_date timestamp,
attribute_key text, 
attribute_value text,
PRIMARY KEY ((userid, entry_date), attribute_key)
);

This data model breaks your map out by it's key and value. By adding attribute_key as a clustering column you'll have your wide rows. Keep in mind with the compound partition key though that you will need the userid and entry_date fields for the query.

PhilB
  • 66
  • 2