Managing Keyspaces and Tables

You can perform keyspace and table operations, such as adding and getting information about keyspaces and tables, using these HTTP methods:

Keyspace Management Methods URL

Retrieve information about all keyspaces

Retrieve information about a keyspace

Update an existing keyspace

Drop a keyspace in a cluster

Truncate a table

Drop a table itself

Keyspace Management Methods

GET /{cluster_id}/keyspaces

Retrieve all configured keyspaces in the cluster.

Path arguments: * cluster_id: The ID of a cluster returned from GET /cluster-configs.

Optional parameters:

  • ksfields: Comma-delimited list of explicit keyspace properties to return.

  • cffields: Comma-delimited list of explicit table properties to return.

Returns a dictionary where the key is the keyspace name, and the value is a dictionary of its properties. The list of properties for keyspaces and tables depends on the version of DataStax Enterprise that you’re running.

Example:

 curl http://127.0.0.1:8888/Test_Cluster/keyspaces

Output:

        {
          "Keyspace1": {
            "strategy_options": {
              "replication_factor": 1
            },
            "column_families": {
              "SuperCounter1": {
                "is_in_memory": false,
                "create_query": "CREATE TABLE \"Keyspace1\".\"SuperCounter1\" (\
                                 key blob, ...)",
                "solr_core": false
              },
              ...
            }
            "durable_writes": true,
            "replica_placement_strategy": "org.apache.cassandra.locator.SimpleStrategy",
            "is_system": false
          },
          ...
        }

GET /{cluster_id}/keyspaces/{ks_name}

Retrieve information about a specific keyspace in the cluster.

Path arguments:

  • cluster_id: The ID of a cluster returned from GET /cluster-configs.

  • ks_name: The value of a 'keyspace' property in the output of GET /{cluster_id}/keyspaces.

  • ksfields: Comma-delimited list of explicit keyspace properties to return.

  • cffields: Comma-delimited list of explicit table properties to return.

Returns the dictionary containing all keyspace properties. The properties returned depend on the version of DataStax Enterprise.

Example:

 curl http://127.0.0.1:8888/Test_Cluster/keyspaces/Keyspace1

Output:

        {
          "strategy_options": {
            "replication_factor": 1
          },
          "column_families": {
            "SuperCounter1": {
              "is_in_memory": false,
              "create_query": "CREATE TABLE \"Keyspace1\".\"SuperCounter1\" (\
                               key blob, ...)",
              "solr_core": false
            },
            ...
          }
          "durable_writes": true,
          "replica_placement_strategy": "org.apache.cassandra.locator.SimpleStrategy",
          "is_system": false
        }

PUT /{cluster_id}/keyspaces/{ks_name}

Update a keyspace.

Path arguments:

  • cluster_id: The ID of a cluster returned from GET /cluster-configs.

  • ks_name: The name of the 'keyspace' to update.

Body: A JSON dictionary of all keyspace attributes, not just those you wish to change.

The JSON body should be similar to the one used when creating a keyspace.

Example:

 curl -X PUT
   http://127.0.0.1:8888/Test_Cluster/keyspaces/Keyspace1
   -d '{
     "strategy_class": "org.apache.cassandra.locator.SimpleStrategy",
     "strategy_options": {"replication_factor": "2"},
     "durable_writes": true
   }'

DELETE /{cluster_id}/keyspaces/{ks_name}

Drop a keyspace from the cluster.

Path arguments:

  • cluster_id: The ID of a cluster returned from GET /cluster-configs.

  • ks_name: The name of the keyspace to delete.

Response 204: Keyspace deleted successfully

Example:

 curl -X DELETE http://127.0.0.1:8888/Test_Cluster/keyspaces/test_ks

Table Management Methods

DELETE /{cluster_id}/data/{ks_name}/{cf_name}

Truncate a table. Deletes all data from the table but does not delete the table itself.

  • cluster_id: The ID of a cluster returned from GET /cluster-configs.

  • ks_name: The name of the keyspace containing the table.

  • cf_name: The name of the table to truncate.

Response 204: Table truncated successfully

Returns null.

Example:

 curl -X DELETE http://127.0.0.1:8888/Test_Cluster/data/test_ks/users

DELETE /{cluster_id}/keyspaces/{ks_name}/cf/{cf_name}

Drop a table.

  • cluster_id: The ID of a cluster returned from GET /cluster-configs.

  • ks_name: The name of the keyspace containing the table.

  • cf_name: The name of the table to delete.

Response 204: Table deleted successfully

Example:

 curl -X DELETE http://127.0.0.1:8888/Test_Cluster/keyspaces/test_ks/cf/users

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com