简体   繁体   中英

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

I'm using Cassandra, and I want to make a data browser which shows the contents of any column family. I need to get the column names to configure a UI grid. Is it possible to collect the names of columns in all rows?

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.

尝试这个:

select columnfamily_name from system.schema_columnfamilies where keyspace_name=‘mykeyspace';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM