Custom Search

Sunday, March 15, 2015

Tutorial Cassandra Query Language (CQL) commands using cqlsh utility

The Cassandra installation includes the cqlsh utility, a python-based command line client for executing Cassandra Query Language (CQL) commands. The cqlsh command is used on the Linux or Windows command line to start the cqlsh utility.

You can use cqlsh to execute CQL commands interactively. cqlsh supports tab completion. http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/cqlsh.html



#cqlsh

cqlsh> help

cqlsh> help DESCRIBE

cqlsh> DESCRIBE KEYSPACES;

cqlsh> DESCRIBE KEYSPACE [mykeyspce];

cqlsh> DESCRIBE TABLES <== Show all the tables in all keyspaces

cqlsh> help USE

cqlsh> USE [name]; <== Goto keyspace/database

cqlsh:> DESCRIBE TABLES <== Show all the tables in selected keyspace

cqlsh:> DESCRIBE TABLE  [tablename]; <== Describe the table in the selected keyspace.

cqlsh:> help SELECT


1)
Delete  Keyspace
cqlsh> DROP KEYSPACE config_db_uuid;

2)
a)
cqlsh> DESCRIBE TABLES
Keyspace "DISCOVERY_SERVER"
---------------------------
discovery

b)
cqlsh> DESCRIBE table DISCOVERY_SERVER.discovery

CREATE TABLE discovery (
  key blob,
  column1 ascii,
  column2 text,
  column3 text,
  value ascii,
  PRIMARY KEY (key, column1, column2, column3)
) WITH COMPACT STORAGE AND
  bloom_filter_fp_chance=0.010000 AND
  caching='KEYS_ONLY' AND
  comment='' AND
  dclocal_read_repair_chance=0.000000 AND
  gc_grace_seconds=0 AND
  read_repair_chance=0.100000 AND
  replicate_on_write='true' AND
  populate_io_cache_on_flush='false' AND
  compaction={'class': 'SizeTieredCompactionStrategy'} AND
  compression={'sstable_compression': 'SnappyCompressor'};

cqlsh>

c)
cqlsh> use "DISCOVERY_SERVER";
cqlsh:DISCOVERY_SERVER>

* Imp, use double quotes

d)
cqlsh:DISCOVERY_SERVER> select * from discovery limit 1;

 key                | column1 | column2                | column3        | value
--------------------+---------+------------------------+----------------+--------------------------------------------------------------------------------
 0x4f70536572766572 |  client | vpc-cfg1:ContrailWebUI | $client-entry$ | {"instances": 20, "client_type": "ContrailWebUI", "remote": "192.168.100.185"}

e)
Get all services/publisher
cqlsh:DISCOVERY_SERVER> select * from discovery where column1 = 'service' ALLOW FILTERING;

f)
Get all clients
cqlsh:DISCOVERY_SERVER> select * from discovery where column1 = 'client' ALLOW FILTERING;

g)
Get all subscribers
cqlsh:DISCOVERY_SERVER> select * from discovery where column1 = 'subscriber' ALLOW FILTERING;








No comments:

Post a Comment