14

Let's say I use CQL to define this table.

CREATE TABLE songs (
    id uuid PRIMARY KEY, 
    title text,
    album text, 
    artist text, 
    tags set<text>, 
    data blob);

How can other developers (or myself after a few weeks) (re)discover the layout of this table?

I'm thinking of an equivalent to the MySQL DESCRIBE {tablename} command.

[EDIT]

I see there is a DESCRIBE method in Cassandra's command line interface (CLI), but upon using it, it states that it doesn't include information on CQL tables in its results.

giampaolo
  • 6,906
  • 5
  • 45
  • 73
Vinnie
  • 12,400
  • 15
  • 59
  • 80

2 Answers2

26

You should try the cqlsh tool which will show you exactly what you want:

lyubent@vm: ~$ ./cqlsh 
cqlsh> use system;
cqlsh> describe columnfamily local;

CREATE TABLE local (
  key text PRIMARY KEY,
  bootstrapped text,
  cluster_name text,
  cql_version text,
  data_center text,
  gossip_generation int,
  host_id uuid,
  partitioner text,
  rack text,
  release_version text,
  schema_version uuid,
  thrift_version text,
  tokens set<text>,
  truncated_at map<uuid, blob>
) WITH
  bloom_filter_fp_chance=0.010000 AND
  caching='KEYS_ONLY' AND
  comment='information about the local node' AND
  dclocal_read_repair_chance=0.000000 AND
  gc_grace_seconds=0 AND
  read_repair_chance=0.000000 AND
  replicate_on_write='true' AND
  populate_io_cache_on_flush='false' AND
  compaction={'class': 'SizeTieredCompactionStrategy'} AND
  compression={'sstable_compression': 'SnappyCompressor'};

EDIT
Although great at the time the blog i linked is ood. To run cqlsh in windows:

  • first install python 2.7.x (not python 3!) download
  • Add python to your path (as a new environment variable)
  • Run the setup by navigating to C:\dir\to\cassandra\pylib in a cmd prompt and executing the below line:

    python setup.py install
    

GZ. Now you have cqlsh on windows.

Lyuben Todorov
  • 13,987
  • 5
  • 50
  • 69
  • What is the Windows equivalent of this program? I only see a UNIX shell script that I can't run from Windows. – Vinnie Aug 07 '13 at 15:00
  • You need to install python 2.7.x and start cqlsh via python, there is no windows alternative, cqlsh is the application that you want. Check [**this blog out**](http://devasive.blogspot.co.uk/2012/10/cql-terminal-for-cassandra-on-windows.html), it explains it in details. – Lyuben Todorov Aug 07 '13 at 15:02
  • As a note, you dont need to download python thrift, it comes with cassandra under the `C:\apache-cassandra-1.2.4\pylib` folder. Just navigate to the `pylib` folder and execute `python setup.py install` – Lyuben Todorov Aug 07 '13 at 15:07
  • Thanks, I guess this still uses the 'columnfamily' usage instead of the 'table'. – Raylite3 Jan 12 '14 at 17:30
  • @Raylite3 Mix and match as you please, cf == table :) – Lyuben Todorov Jan 13 '14 at 02:05
  • Is there any other way for old Cassandra version? I got this: "WARN: DESCRIBE|DESC was moved to server side in Cassandra 4.0. As a consequence DESRIBE|DESC will not work in cqlsh '6.0.0' connected to Cassandra '3.11.6', the version that you are connected to. DESCRIBE does not exist server side prior Cassandra 4.0." – ZhengguanLi May 09 '22 at 23:36
10

It can also be done with DevCenter and OpsCenter.

DevCenter: Find the table in Schema -> right click -> clone table. You can find CQL Preview at the button of the window.

OpsCenter: Cluster -> Data -> Table

treehouse
  • 2,521
  • 1
  • 21
  • 39