graph

How to create, truncate, or drop a graph.

This command is used to create a new graph, truncate an existing graph, or drop an existing graph. A graph can also be convert from an existing non-graph Cassandra keyspace.

Synopsis

system.graph('graph_name').
[ifNotExists(). | ifExists().] 
[withReplication("{'class': 'NetworkTopologyStrategy', 'data_center_name': replication_factor}").]
[andDurableWrites( true | false ).]
[fromExistingKeyspace().]
create() | truncate() | drop() | exists()
ifNotExists, ifExists
Creating a graph can check for lack of current existence with ifNotExists() before creating a graph. Truncating and dropping a graph can check for existence with ifExists() before attempting the operations.
withReplication
Set replication class and replication factor for each datacenter using the same guidelines as for CQL keyspaces.
Important: The replication factor cannot be altered once set for the graph, just as the replication factor for a keyspace cannot be changed.

DSE database settings for replication factor are used, either SimpleStrategy for single datacenters or NetworkTopologyStrategy for multiple datacenters. The default replication strategy for a multi-datacenter graph is NetworkTopologyStrategy, whereas for a single datacenter, the replication strategy will default to SimpleStrategy.

The system replication settings can be verified using the cqlsh tool, running the CQL command DESCRIBE keyspace food command:
DESCRIBE KEYSPACE food;
with a result:
CREATE KEYSPACE food_system WITH replication = {'class': 'NetworkTopologyStrategy', 'dc1: '3', 'dc2' : 2 }  AND durable_writes = true;
andDurableWrites (true | false)
Set to true by default. While the setting can be changed, it is NOT recommended to set andDurableWrites to false.
fromExistingKeyspace
Convert an existing non-graph keyspace to a Core Engine Graph.
create

Create a new graph. The graph_name specified is used to create two DSE database keyspaces, graph_name and graph_name_system, and can only contain alphanumeric and underscore characters.

truncate

Truncate an existing graph using this command. All data will be removed from the graph.

drop

Drop an existing graph using this command. All data and schema will be lost. For better performance, truncate a graph before dropping it.

exists

Check existence of a graph using this command.

Examples

Create a graph
Create a new graph, checking for the existence of a graph with the specified name:
system.graph('food_simple').ifNotExists().create()
The resulting list:
==> OK
and is created with NetworkTopologyStrategy.
Create a graph and set the replication factor for the graph. It can also include andDurableWrites if desired:
system.graph('food').
  ifNotExists().
  withReplication("{'class': 'NetworkTopologyStrategy', '<DC_NAME>': 1}").
  andDurableWrites(true).
  create()
Restriction: The replication factor and system replication factor cannot be altered once set for the graph_name keyspace.
Create a graph from existing Cassandra data
Create a graph from an existing non-graph Cassandra keyspace:
system.graph('food_cql_conversion').
   fromExistingKeyspace().
   create()
Truncate a graph
Truncate a graph if it exists:
system.graph('food').
  ifExists().
  truncate()
The resulting list:
==> OK
Drop a graph
Drop an existing graph if it exists:
system.graph('food').
  ifExists().
  drop()
The resulting list:
==> OK
Check graph existence
Discover if a particular graph exists. The return value is a boolean value.
system.graph('food').exists()
The resulting list:
==> true