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
SELECT column_name FROM system.schema_columns WHERE keyspace_name = ? AND columnfamily_name = ?
–
Folketing 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';
© 2022 - 2024 — McMap. All rights reserved.