Managing Keyspaces and Column Families¶
You can perform keyspace and column family operations, such as adding and getting information about keyspaces and column families, using these HTTP methods:
Keyspace Management Methods¶
- GET /{cluster_id}/keyspaces¶
Retrieve all configured keyspaces in the cluster.
Path arguments: cluster_id – A Cluster Config ID.
Opt. params: - ksfields – Comma delimited list of explicit keyspace properties to return.
- cffields – Comma delimited list of explicit column family 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 column families depends on the version of DataStax Enterprise/Cassandra that you’re running.
Example:
curl http://127.0.0.1:8888/Test_Cluster/keyspaces
Output:
{ "Keyspace1": { "column_families": { "ColFam1": { "column_type": "Standard", "min_compaction_threshold": 4, ... }, ... }, "replica_placement_strategy": "org.apache.cassandra.locator.SimpleStrategy", "strategy_options": { "replication_factor": "1" }, ... }, ... }
- GET /{cluster_id}/keyspaces/{ks_name}¶
Retrieve information about a specific keyspace in the cluster.
Path arguments: - cluster_id – A Cluster Config ID.
- ks_name – The value of a ‘keyspace’ property in the output of
GET /{cluster_id}/keyspaces
.
Opt. params: - ksfields – Comma delimited list of explicit keyspace properties to return.
- cffields – Comma delimited list of explicit column family properties to return.
Returns the dictionary containing all keyspace properties. The properties returned depend on the version of DataStax Enterprise/Cassandra.
Example
curl http://127.0.0.1:8888/Test_Cluster/keyspaces/Keyspace1
Output:
{ "column_families": { "ColFam1": { "column_type": "Standard", "min_compaction_threshold": 4, ... }, ... }, "replica_placement_strategy": "org.apache.cassandra.locator.SimpleStrategy", "strategy_options": { "replication_factor": "1" }, ... }
- GET /{cluster_id}/keyspaces/{ks_name}/{attribute}¶
Retrieve a single property of a keyspace.
Path arguments: - cluster_id – A Cluster Config ID.
- ks_name – The value of a keyspace property in the output of
GET /{cluster_id}/keyspaces
. - attribute – One of the keys returned by
GET /{cluster_id}/keyspaces/{ks_name}
.
Example
curl http://127.0.0.1:8888/Test_Cluster/keyspaces/Keyspace1/replica_placement_strategy
Output:
"org.apache.cassandra.locator.SimpleStrategy"
- POST /{cluster_id}/keyspaces/{ks_name}¶
Add a keyspace to the cluster.
Path arguments: - cluster_id – A Cluster Config ID.
- ks_name – The name of the keyspace to add to the cluster.
Body: A JSON dictionary describing the attributes of the keyspace you are adding.
Responses: 201 – Keyspace created successfully
The CQL keyspace storage parameters have keys corresponding to Cassandra keys in the keyspace dictionary and are valid attributes for strategy_class and strategy_options parameters:
Keyspace Storage Parameter Keyspace Dictionary Key strategy_class replica_placement_strategy strategy_options strategy_options durable_writes durable_writes Example
curl -X POST http://127.0.0.1:8888/Test_Cluster/keyspaces/Keyspace2 -d '{ "strategy_class": "org.apache.cassandra.locator.SimpleStrategy", "strategy_options": {"replication_factor": "1"}, "durable_writes": true }'
- PUT /{cluster_id}/keyspaces/{ks_name}¶
Update a keyspace.
Path arguments: - cluster_id – A Cluster Config ID.
- 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 – A Cluster Config ID.
- ks_name – The name of the keyspace to delete.
Responses: 204 – Keyspace deleted successfully
Example
curl -X DELETE http://127.0.0.1:8888/Test_Cluster/keyspaces/test_ks
Column Family Management Methods¶
- GET /{cluster_id}/keyspaces/{ks_name}/cf/{cf_name}¶
Get the description of a column family.
Path arguments: - cluster_id – A Cluster Config ID.
- ks_name – The name of the keyspace that contains the column family.
- cf_name – The name of the column family.
Returns a dictionary describing the requested column family. Properties returned depend on the DataStax Enterprise/Cassandra version.
Example
curl http://127.0.0.1:8888/Test_Cluster/keyspaces/test_ks/cf/users
Output:
{ "column_metadata": { "state": { "validation_class": "AsciiType", "index_type": null, "index_name": null, "index_options": null } }, "column_type": "Standard", "min_compaction_threshold": 4, ... }
- POST /{cluster_id}/keyspaces/{ks_name}/cf/{cf_name}¶
Add a column family to a keyspace.
Path arguments: - cluster_id – A Cluster Config ID.
- ks_name – The name of an existing keyspace.
- cf_name – The name of the column family to add.
Body: A JSON dictionary describing the attributes of the column family. Keys in the dictionary are valid column family attributes, such as column_type and comparator_type, in Cassandra.
Responses: 201 – Column family created successfully
Example
curl -X POST http://127.0.0.1:8888/Test_Cluster/keyspaces/Keyspace1/cf/MyColFam -d '{ "column_type": "Standard", "comment": "", "comparator_type": "org.apache.cassandra.db.marshal.UTF8Type", "default_validation_class": "org.apache.cassandra.db.marshal.BytesType", "read_repair_chance": 1.0, "bloom_filter_fp_chance": 0.01, "subcomparator_type": null }'
- PUT /{cluster_id}/keyspaces/{ks_name}/cf/{cf_name}¶
Update or modify select attributes of a column family.
Path arguments: - cluster_id – A Cluster Config ID.
- ks_name – The name of an existing keyspace.
- cf_name – The name of an existing column family.
Body: A JSON dictionary describing the attributes of the column family to update. Keys in the dictionary are valid column family attributes, such as read_repair_chance and bloom_filter_fp_chance, in Cassandra. Note that Cassandra does not allow some attributes, such as the column type and the comparator type, to be altered once set.
Example
curl -X PUT http://127.0.0.1:8888/Test_Cluster/keyspaces/Keyspace1/cf/MyColFam -d '{ "read_repair_chance": 0.1, "bloom_filter_fp_chance": 0.03, }'
- GET /{cluster_id}/keyspaces/{ks_name}/cf/{cf_name}/create_query¶
Get the CQL3 CREATE query for a column family.
Path arguments: - cluster_id – A Cluster Config ID.
- ks_name – The name of an existing keyspace.
- cf_name – The name of an existing column family.
Returns an array of CQL3 CREATE queries. Only column families that were created with CQL3 have CREATE queries. Any indexes that were created on the column family will also be returned.
Example
curl http://127.0.0.1:8888/Test_Cluster/keyspaces/test_ks/cf/users/create_query
Output:
[ "CREATE TABLE test_ks.users ( foo int PRIMARY KEY, bar int, baz int ) WITH bloom_filter_fp_chance=0.010000 AND caching='KEYS_ONLY' AND comment='' AND dclocal_read_repair_chance=0.000000 AND gc_grace_seconds=864000 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'}", "CREATE INDEX users_bar_idx ON test_ks.users (bar)" ]
- PUT /{cluster_id}/keyspaces/{ks_name}/cf/{cf_name}/column/{colname}¶
Set the validation class (data type) for a column.
Path arguments: - cluster_id – A Cluster Config ID.
- ks_name – The name of an existing keyspace.
- cf_name – The name of an existing column family.
- colname – The name of the column to set a validation class for.
Body: A JSON string of the new validation class, such as “UT8Type”.
Responses: 200 – Column validator was set successfully.
Returns null.
Example
curl -X PUT http://127.0.0.1:8888/Test_Cluster/keyspaces/Keyspace1/cf/Users/column/state -d '"AsciiType"'
- DELETE /{cluster_id}/keyspaces/{ks_name}/cf/{cf_name}/column/{colname}¶
Clear the validation class (data type) for a column.
Path arguments: - cluster_id – A Cluster Config ID.
- ks_name – The name of an existing keyspace.
- cf_name – The name of an existing column family.
- colname – The name of the column that has the validation class to be cleared.
Responses: 200 – Column validator was cleared successfully.
Returns null.
Example
curl -X DELETE http://127.0.0.1:8888/Test_Cluster/keyspaces/Keyspace1/cf/Users/column/state
- POST /{cluster_id}/keyspaces/{ks_name}/cf/{cf_name}/index/{colname}¶
Add a secondary index to a column family.
Path arguments: - cluster_id – A Cluster Config ID.
- ks_name – The name of an existing keyspace.
- cf_name – The name of an existing column family.
- colname – The name of the column to be indexed.
Body: A JSON dictionary describing the attributes of the index. Valid keys include validation_class, index_type, index_name, and index_options.
Responses: 201 – Index was added successfully
Returns null.
Example
curl -X POST http://127.0.0.1:8888/Test_Cluster/keyspaces/Keyspace1/cf/Users/index/state -d '{ "validation_class": "AsciiType", "index_type": "KEYS", "index_name": "state_index", "index_options": null }'
- DELETE /{cluster_id}/keyspaces/{ks_name}/cf/{cf_name}/index/{colname}¶
Drop a secondary index from a column family.
Path arguments: - cluster_id – A Cluster Config ID.
- ks_name – The name of an existing keyspace.
- cf_name – The name of an existing column family.
- colname – The name of the indexed column.
Responses: 204 – Index was dropped successfully
Returns null.
Example
curl -X DELETE http://127.0.0.1:8888/Test_Cluster/keyspaces/Keyspace1/cf/Users/index/state
- DELETE /{cluster_id}/data/{ks_name}/{cf_name}¶
Truncate a column family. Deletes all data from the column family but does not delete the column family itself.
Path arguments: - cluster_id – A Cluster Config ID.
- ks_name – The name of the keyspace containing the column family.
- cf_name – The name of the column family to truncate.
Responses: 204 – Column family 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 column family.
Path arguments: - cluster_id – A Cluster Config ID.
- ks_name – The name of the keyspace containing the column family.
- cf_name – The name of the column family to delete.
Responses: 204 – Column family dropped successfully
Example
curl -X DELETE http://127.0.0.1:8888/Test_Cluster/keyspaces/test_ks/cf/users