Question

i am new at cassandra cli, i want to know is it is a good practice to define a columns name as LongType instead of Utf8type and also please tell me is there anything wrong in my code or coding style?
i am doing it in the scala in playframework with hector.

val mutator = HFactory.createMutator(Group, le);
mutator.addInsertion(groupId,"groupRefrence",HFactory.createColumn(userId,userId,le,le))
mutator.execute()

def getMembersRefrence(groupId: Long) = {
val sliceQuery = HFactory.createSliceQuery(Group, le, le, le)
sliceQuery.setColumnFamily("groupRefrence")
sliceQuery.setKey(groupId)
sliceQuery.setRange(Long.MIN_VALUE,Long.MAX_VALUE, false, Integer.MAX_VALUE)
val result = sliceQuery.execute()
val res = result.get()
val columns = res.getColumns()
val response = columns.toList
response
}
Was it helpful?

Solution

good practice to define a columns name as LongType instead of Utf8type

You should define your column name datatype to whatever makes sense for your data model. As far as best practices go, eBay posted a tech blog on this a couple of years ago, and it is definitely a good read. Part 2 covers column names:

Storing values in column names is perfectly OK

Leaving column values empty (“valueless” columns) is also OK.

It’s a common practice with Cassandra to store a value (actual data) in the column name (a.k.a. column key), and even to leave the column value field empty if there is nothing else to store. One motivation for this practice is that column names are stored physically sorted, but column values are not.

Notes:

  • The maximum column key (and row key) size is 64KB. However, don’t store something like ‘item description’ as the column key!

  • Don’t use timestamp alone as a column key. You might get colliding timestamps from two or more app servers writing to Cassandra. Prefer timeuuid (type-1 uuid) instead.

  • The maximum column value size is 2 GB. But becuase there is no streaming and the whole value is fetched in heap memory when requested, limit the size to only a few MBs. (Large objects are not likely to be supported in the near future – Cassandra-265. However, the Astyanax client library supports large objects by chunking them.)

I also feel compelled to mention that newer versions of Cassandra are moving away from the original column family and cli interaction. I'm not sure if the newer CQL3 drivers support storing values in column names or not (I've also had to do it in via Thrift with Hector, but not CQL3). In any case, here is a good article (A thrift to CQL3 upgrade guide) that describes these differences, and it is something you should read through for future endeavors.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top