Showing posts with label NOS. Show all posts
Showing posts with label NOS. Show all posts

12 March 2016

NOSQL : CQLSH Commands

Cqlsh - Start the CQL interactive terminal.
Syntax : cqlsh [options] [host [port]]

Example
/opt/cassandra/dse-4.8.2/bin/cqlsh optrhdbcasra01adev -u cswgadmin -p admin123

CAPTURE - Captures command output and appends it to a file.

To start capturing the output of a query, specify the path of the file relative to the current directory. Enclose the file name in single quotation marks. The shorthand notation in this example is supported for referring to $HOME.
Output is not shown on the console while it is captured. Only query result output is captured. Errors and output from cqlsh-only commands still appear. To stop capturing output and return to normal display of output, use CAPTURE OFF.

Example :  CAPTURE '~/mydir/myfile.txt'

COPY -
Imports and exports CSV (comma-separated values) data to and from Cassandra.

COPY table_name ( column, ...) FROM ( 'file_name' | STDIN ) WITH option = 'value' AND ...

COPY table_name ( column , ... ) TO ( 'file_name' | STDOUT ) WITH option = 'value' AND …

Example :

CREATE KEYSPACE test
  WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'datacenter1' : 1 };

USE test;

CREATE TABLE airplanes (
  name text PRIMARY KEY,
  manufacturer ascii,
  year int,
  mach float
);

INSERT INTO airplanes
  (name, manufacturer, year, mach)
  VALUES ('P38-Lightning', 'Lockheed', 1937, 0.7);

COPY airplanes (name, manufacturer, year, mach) TO 'temp.csv';

TRUNCATE airplanes;

COPY airplanes (name, manufacturer, year, mach) FROM 'temp.csv';

TRUNCATE airplanes;

COPY airplanes (name, manufacturer, year, mach) FROM STDIN;
The output is:

[Use \. on a line by itself to end input]
[copy]
At the [copy] prompt, enter the following data:
'F-14D Super Tomcat', Grumman, 1987, 2.34
'MiG-23 Flogger', Russian-made, 1964, 2.35
'Su-27 Flanker', U.S.S.R., 1981, 2.35
\.


DESCRIBE : Provides information about the connected Cassandra cluster, or about the data objects stored in the cluster.
DESCRIBE FULL ( CLUSTER | SCHEMA )
| KEYSPACES
| ( KEYSPACE keyspace_name )
| TABLES
| ( TABLE table_name )
| TYPES
| ( TYPE user_defined_type )
| INDEX
| ( INDEX index_name )

EXPAND - Formats the output of a query vertically.

This command lists the contents of each row of a table vertically, providing a more convenient way to read long rows of data than the default horizontal format. You scroll down to see more of the row instead of scrolling to the right. Each column name appears on a separate line in column one and the values appear in column two.

EXPAND ON | OFF

PAGING - Enables or disables query paging.

PAGING ON|OFF

SHOW - Shows the Cassandra version, host, or tracing information for the current cqlsh client session.

SHOW VERSION
| HOST
| SESSION tracing_session_id

SOURCE - Executes a file containing CQL statements.


SOURCE '~/mydir/myfile.txt'