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

I am using Cassandra, and I want to make a data browser that displays the contents of any column family. I need to get the column names for customizing the user interface grid. Is it possible to collect column names in all rows?

+4
java cassandra hector
source share
3 answers

Best way if you use 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

+8
source share

There are several parts to the answer.

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

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

Secondly, you need to make the assumption that the data model is stored in a column family.

If the data model is static (one row per object, one column per attribute), then the column names that you return must be the names of the columns that you want to display. However, if the data is stored dynamically (one object per column, all objects with the same primary key stored in one row) - for example, as in a time series, then you need to understand how the column names (possibly compound) should be interpreted. Another very common application of the dynamic approach is how column families are preserved when defined through CQL.

I must add that there is no way to tell how a family of columns is used to store objects. There is a schema that you can request, but this only talks about how the data should be formatted when it is stored, not how the data (and attribute names) are serialized and deserialized.

+1
source share

try the following:

 select columnfamily_name from system.schema_columnfamilies where keyspace_name='mykeyspace'; 
0
source share

All Articles