Mapper (cassandra-driver-mapping) and writes to multiple tables

568 views
Skip to first unread message

Kevin Ford

unread,
Sep 6, 2016, 2:48:48 PM9/6/16
to DataStax Java Driver for Apache Cassandra User Mailing List
I'm evaluating Cassandra as a POC for a potential move from another database.  I read that when using CQL it's recommended to optimize tables as one-per-query, which means that when I insert/update/delete one of those records, I'll have to do so in every table in which I've written it.

Is there some support for this in the mapper?  My initial usage of it does not indicate that there is any support, or can I just add multiple annotations to a class to tell it there are many tables, and each has a key that looks like x/y/z/etc.?

Thanks

Sebastian Estevez

unread,
Sep 14, 2016, 7:57:04 PM9/14/16
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi Kevin, 

I read that when using CQL it's recommended to optimize tables as one-per-query, which means that when I insert/update/delete one of those records, I'll have to do so in every table in which I've written it.

This is largely accurate. In order to support different access patterns and maintain cql latencices (microseconds / single digit millies) folks often duplicate their data accross multiple tables. Cassandra materialized views allow you to maintain multiple layouts of the same table effortlessly. You define the MV on the table once and then on each write, c* will perform the fan out for you. Then you can read from the right view based on your access pattern. Keep in mind that when designing your MV's you still want to make sure you are following data modeling best practices (for example, keep your partition sizes to a reasonable size). Check out this detailed blog post on MV's from Jake.


Is there some support for this in the mapper?  My initial usage of it does not indicate that there is any support, or can I just add multiple annotations to a class to tell it there are many tables, and each has a key that looks like x/y/z/etc.?

The exact functionality you are describing does not exist today in the Mapper, though it sounds like this is what you want https://datastax-oss.atlassian.net/browse/JAVA-549 feel free to vote for that jira or submit a PR. Alternatively, Achilles (an object mapper that wraps the java driver) has support for MV's which might be what you need depending on the use case. 

I tend to see that most solutions require a combination of MV's, secondary indexes, and search indexes (see DSE Search) to handle full fledged applications.
Reply all
Reply to author
Forward
0 new messages