Composite Column Values in Cassandra?

落花浮王杯 提交于 2019-12-12 01:14:48

问题


Can we have a composite values in each columns in Cassandra Column Family?

user-id   column1-name
123      (Column1-Value  Column1-SchemaName  Column1-LastModifiedDate)

userId is the rowKey here. And same thing will be for other columns as well.

Each column value will contain below three things always-

ByteType for Column-Value

UTF8Type for Column-SchemaName

DateType for LastModifiedDate

If yes, can anyone help me in designing the column family for this? I will be using Astyanax client to insert into above column family.


回答1:


I don't think, it is at all possible in Cassandra. Either you have to de-normalized your Column Family or look after Cassandra Collection support. If you can restrict your data models data type for Value, SchemaName, LastModifiedDate to a single type, then probably Map will be helpful in your case.




回答2:


There are two ways to go:

  1. Use CompositeType for your columns. In this case there will be 4 component composite column name and empty column value.
  2. Use astyanax custom serializer. In this case column name will remain the same. Custom serializer will convert from bytebuffer to your custom object and back.



回答3:


You seem to be trying create a so called "super column", which has been highly "unrecommended" in Cassandra lately (Why are super columns in Cassandra no longer favoured?). So, I would say you should try to rethink your design, and if you really need to have all those values in one column you could do a marshaling/unmarshaling yourself from the application, alternatively you can also think about using "composite keys", if that helps you.



来源:https://stackoverflow.com/questions/18921964/composite-column-values-in-cassandra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!