Open In App

Schema descriptions in Cassandra

Last Updated : 04 May, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will discuss where we can use describe commands, how it will help to describe schema, also discuss how describe command is useful. Let’s discuss one by one.

    Describe command is very helpful in CQL just because it gives the description of the newly created database, newly created table, description of function if any, description of any user-defined function if any. You can see the following points listed for describe commands.

  • It gives information about Cluster.
  • It provides information about Index type created on any table.
  • It gives the information of newly created database.
  • It also gives the information about function.
  • It gives the information of user-defined type if any.

Now, you can use the help command to see all the use cases of describe command. let’s have a look.

cassandra@cqlsh> help describe

Output:

  • DESCRIBE [cqlsh only]
    (DESC may be used as a shorthand.)
    Outputs information about the connected Cassandra cluster, or about the data objects stored in the cluster. Use in one of the following ways:

  • DESCRIBE KEYSPACES
    Output the names of all keyspaces.
  • DESCRIBE KEYSPACE []
    Output CQL commands that could be used to recreate the given keyspace, and the objects in it (such as tables, types, functions, etc.).
    In some cases, as the CQL interface matures, there will be some metadata about a keyspace that is not representable with CQL. That metadata will not be shown.
    The ” argument may be omitted, in which case the current keyspace will be described.

  • DESCRIBE TABLES
    Output the names of all tables in the current keyspace, or in all keyspaces if there is no current keyspace.

    DESCRIBE TABLE [.]
    

    Output CQL commands that could be used to recreate the given table. In some cases, as above, there may be table metadata which is not representable and which will not be shown.

  • DESCRIBE INDEX
    Output the CQL command that could be used to recreate the given index. In some cases, there may be index metadata which is not representable and which will not be shown.

  • DESCRIBE MATERIALIZED VIEW
    Output the CQL command that could be used to recreate the given materialized view. In some cases, there may be materialized view metadata which is not representable and which will not be shown.

  • DESCRIBE CLUSTER
    Output information about the connected Cassandra cluster, such as the cluster name, and the partitioner and snitch in use. When you are connected to a non-system keyspace, it also shows endpoint-range ownership information for the Cassandra ring.

  • DESCRIBE [FULL] SCHEMA
    Output CQL commands that could be used to recreate the entire (non-system) schema. Works as though “DESCRIBE KEYSPACE k” was invoked for each non-system keyspace k. Use DESCRIBE FULL SCHEMA to include the system keyspaces.

  • DESCRIBE TYPES
    Output the names of all user-defined-types in the current keyspace, or in all keyspaces if there is no current keyspace.

  • DESCRIBE TYPE [.]
    Output the CQL command that could be used to recreate the given user-defined-type.

  • DESCRIBE FUNCTIONS
    Output the names of all user-defined-functions in the current keyspace, or in all keyspaces if there is no current keyspace.

  • DESCRIBE FUNCTION [.]
    Output the CQL command that could be used to recreate the given user-defined-function.

  • DESCRIBE AGGREGATES
    Output the names of all user-defined-aggregates in the current keyspace, or in all keyspaces if there is no current keyspace.

  • DESCRIBE AGGREGATE [.]
    Output the CQL command that could be used to recreate the given user-defined-aggregate.

  • DESCRIBE
    Output CQL commands that could be used to recreate the entire object schema, where an object can be either a keyspace or a table or an index or a materialized view (in this order).

for example:
Example: list all Existing keyspaces

cassandra@cqlsh> describe keyspaces;

Output

system_schema  system    backup_copy         system_traces  university
system_auth    app_data  system_distributed  operation

Example: app_data keyspace schema

cassandra@cqlsh> describe app_data;

Output

CREATE KEYSPACE app_data WITH replication = 
{
'class': 'NetworkTopologyStrategy', 
         'datacenter1': '3', 'datacenter2': '2'
}  
AND durable_writes = true;

CREATE TABLE app_data.t (
    k text,
    i int,
    s text static,
    PRIMARY KEY (k, i)
) WITH CLUSTERING ORDER BY (i ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {
'class': 'org.apache.cassandra
          .db.compaction
          .SizeTieredCompactionStrategy', 
'max_threshold': '32', 'min_threshold': '4'
}
    AND compression = {
'chunk_length_in_kb': '64',
 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'
}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';

CREATE TABLE app_data.user_data (
    user_id uuid PRIMARY KEY,
    address text,
    name text
) WITH bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {
'class': 'org.apache.cassandra.db
               .compaction.SizeTieredCompactionStrategy', 
'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {
'chunk_length_in_kb': '64', 
'class': 'org.apache.cassandra.io
               .compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';

Example: user_data table schema

cassandra@cqlsh> describe app_data.user_data;

Output

CREATE TABLE app_data.user_data (
    user_id uuid PRIMARY KEY,
    address text,
    name text
) WITH bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = 
{
'class': 'org.apache.cassandra
             .db.compaction.SizeTieredCompactionStrategy',
 'max_threshold': '32', 'min_threshold': '4'
}
    AND compression = {
'chunk_length_in_kb': '64', 
'class': 'org.apache.cassandra.io.compress.LZ4Compressor'
}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads