How to list all column names in a column family in Cassandra?

大城市里の小女人 提交于 2019-12-04 10:02:46

The best way, if you are using Cassandra 1.1:

SELECT column_name FROM system.schema_columnfamilies WHERE keyspace_name = X AND columnfamily_name = Y

See also http://www.datastax.com/dev/blog/schema-in-cassandra-1-1

There are several parts to this answer.

First, to answer your specific question, you should use a sliceQuery to get all of the columns in a row. Pass an empty ByteBuffer as the start and end values to effectively request all columns:

ByteBuffer empty = ByteBufferUtil.EMPTY_BYTE_BUFFER;       
sliceQuery.setRange(empty,empty,false,100);

Second, you need to make a assumption about the data model being stored in the column family.

If the data model is static (one row per object, one column per attribute) then the column names you get back should be the column names you want to display. If, however, the data is being stored in a dynamic way (one object per column, all objects with the same primary key stored in the same row) - as in a time series, for example - then you need to understand how the columns names (possibly composite) need to be interpreted. Another very common use of the dynamic approach is the way column families are persisted when defined via CQL.

I should add that there is no way to tell how a column family is being used to store objects. There is the schema that you can query, but that only tells you how the data is to be formatted when it's persisted, and not how the data (and the attribute names) are serialized and deserialized.

try this:

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