6

I have recently started working with heavy and massive data which also needs to go through regular transaction.

Choosing Cassandra, my data model uses dynamic columns. I understand that with CQL one can alter tables and insert or query columns to get required data.

However, I was using Phantom client with Scala for Cassandra and reading through the documentation I could not find a way to write to or query from dynamic column families.

Given that we use case classes, how can one work with dynamic columns with Cassandra in Scala?

giampaolo
  • 6,906
  • 5
  • 45
  • 73
chbh
  • 336
  • 2
  • 13

1 Answers1

6

I would suggest that you not dynamically alter table schemas as part of your data model. Cassandra is a row oriented database with partitioning and clustering of rows within partitions. So whatever you are trying to represent by adding or removing columns would be better handled by setting values in a fixed set of columns.

Although Cassandra allows table definitions to be altered to add and remove columns, this would normally be done only when adding a new feature to an application, so you would have an operator manually alter the schema, and then use modified application code to make use of the new schema.

I consider it dangerous for a client application to modify the schema by creating or altering tables since you run the risk of having multiple clients make changes at the same time.

Jim Meyer
  • 9,275
  • 1
  • 24
  • 49
  • Moreover there is the tricky question of consitency when altering a table dynamically. – Adrien Piquerez Dec 14 '15 at 15:12
  • @Jim in your opinion, what would be the best way to deal with dynamic data with Cassandra? I come from MongoDB world where things are pretty dynamic. You could add a bunch of stuff in a document regardless of what exactly the data type is. – chbh Dec 15 '15 at 07:40
  • 1
    You might want to look at Cassandra's collection data types: lists, maps, and sets. There are also user defined types, and if all else fails, you can store things as blobs. – Jim Meyer Dec 15 '15 at 12:58
  • @JimMeyer I've tried using Maps. Looks like they fail terribly when you put a lot of data in it. But thanks anyway, I think I'll have to remodel my system to work with Cassandra if it's gonna be the primary database. – chbh Dec 17 '15 at 08:34