Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cassandra: get column names of a columnfamily?

I'm wondering if there is a query in CQL3 that allows you to get column names of a specific columnfamily that has a static schema?
Thanks in advance :)

like image 837
user2090879 Avatar asked Apr 17 '13 09:04

user2090879


People also ask

How do I get column names in Cassandra?

To Select the data from Cassandra , Select statement is used. If you need to select all columns , you can use "*" or provide list of column names.

How do I get unique column values in Cassandra?

Use the DISTINCT keyword to return only distinct (different) values of partition keys. The FROM clause specifies the table to query. You may want to precede the table name with the name of the keyspace followed by a period (.). If you do not specify a keyspace, Cassandra queries the current keyspace.

How do I select a keyspace?

Using Keyspace To select a keyspace in Cassandra and perform actions on it, use the keyword USE . The CQL shell switches to the name of the keyspace you specified. To change the current keyspace, use the same command with another name.


2 Answers

If you want to get column names of a specific table with CQL3 then i guess try this

select * from system.schema_columns WHERE keyspace_name='#KS' AND columnfamily_name='#CF' allow filtering;

Note: keyspace_name in the where clause is optional. Its mainly used for better filtration purpose (say, table with the same name in multiple keyspace)

like image 92
abhi Avatar answered Sep 21 '22 13:09

abhi


You could use the system keyspace to do this:

SELECT column_name FROM system.schema_columnfamilies 
  WHERE keyspace_name = 'testks' AND columnfamily_name = 'testcf';

Output in cqlsh (using cql3):

 column_name
-------------
    password

You can work out the key for the column by using:

SELECT key_aliases FROM system.schema_columnfamilies WHERE keyspace_name='testks' 
AND columnfamily_name='testcf';

Output:

 key_aliases
--------------
 ["username"]
like image 44
Lyuben Todorov Avatar answered Sep 22 '22 13:09

Lyuben Todorov