Create a table in Cassandra 1.2 with CQL3 where column names will be created at runtime

淺唱寂寞╮ 提交于 2019-12-08 06:27:49

问题


I want to store snapshots of an object in Apache Cassandra 1.2

Row key is the Object#ID and there will be a column for each snapshot.

--------    latest  --------   v2   -------- v1
id-122      100     --------   50   -------- 66
--------

So column names are created dynamically at runtime.

How to create the previous table in Cassandra 1.2 using CQL3?


回答1:


You would use the compound primary key feature of CQL3:

CREATE TABLE foo (
  object_id int,
  version int,
  value int,
  PRIMARY KEY (object_id, version));



回答2:


In CQL3, Table schema is fixed. So you can't really get dynamic column names. For that you have to switch to CQL2.



来源:https://stackoverflow.com/questions/14720472/create-a-table-in-cassandra-1-2-with-cql3-where-column-names-will-be-created-at

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