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.

Synopsis

system.graph('graph_name').
replication("{'class' : 'NetworkTopologyStrategy', 'data_center_name' : replication_factor, 'data_center_name' : replication_factor }").
systemReplication("{'class' : 'NetworkTopologyStrategy', 'data_center_name' : replication_factor, 'data_center_name' : replication_factor }").
[options(arg)].
[ifNotExists().] create() | [ifExists().]truncate() | [ifExists().]drop() | exists()
replication, systemReplication
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 number of nodes will determine the default replication factor:
number of nodes per datacenter graph_name replication factor (replication) graph_name_system replication factor (systemReplication)
1-3 number of nodes per datacenter number of nodes per datacenter
greater than 3 3 5
Important: Because the graph's schema is stored in graph_name_system, it is extremely important that the replication factor is set consistent with the table values above. If the graph's schema is lost, it renders the entire graph inoperable. Once set, the replication factor for these keyspaces cannot be altered.
The system replication settings can be verified using the cqlsh tool, running the CQL command DESCRIBE keyspace food_system command:
DESCRIBE KEYSPACE food_system;
with a result:
CREATE KEYSPACE food_system WITH replication = {'class': 'NetworkTopologyStrategy', 'dc1: '3', 'dc2' : 2 }  AND durable_writes = true;
options (arg)
Options that can be set when creating a graph; see option for details on available options.
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 before attempting the operations.
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 without checking for the existence of a graph with the specified name:
system.graph('fridge_item').create()
The resulting list:
==>fridge_item
Create a new graph if it doesn't currently exist by modifying with ifNotExists().
system.graph('fridge_item').ifNotExists().create()
The resulting list:
==>fridge_item
Creating a graph should include setting the replication factor for the graph and system replicaton factor for the graph_system. It can also include other options to set schema settings. For example, create a new graph, setting replication factors and options:
system.graph('food2').
  replication("{'class' : 'NetworkTopologyStrategy', 'dc1' : 3, 'dc2' : 2 }").  
  systemReplication("{'class' : 'NetworkTopologyStrategy', 'dc1' : 3, 'dc2' : 2 }").
  option("graph.schema_mode").set("Development").
  option("graph.allow_scan").set("false").
  option("graph.default_property_key_cardinality").set("multiple").
  option("graph.tx_groups.*.write_consistency").set("ALL").
  ifNotExists().create()
A wildcard * sets the write consistency for all transaction groups.
Restriction: The replication factor and system replication factor cannot be altered once set for the graph_name and graph_name_system keyspaces.
Truncate a graph
Truncate a graph.
system.graph('fridge_item').truncate()
The resulting list:
==>null
Truncate an existing graph if it exists.
system.graph('pedometer').ifExists().truncate()
The resulting list:
==>null
Drop a graph
Drop a graph.
system.graph('fridge_item').drop()
The resulting list:
==>OK
Drop an existing graph if it exists.
system.graph('fridge_sensors').ifExists().drop()
The resulting list:
==>null
Check graph existence
Discover if a particular graph exists. The return value is a boolean value.
system.graph('fridge_item').exists()
The resulting list:
==>true
Setting system graph options
Options can be set when a graph is created with the System API. However, to check the schema settings, use the schema config option to describe:
schema.config().describe()
the results:
graph.schema_mode: Development
graph.allow_scan: False
graph.tx_groups.*.write_consistency: ALL
graph.default_property_key_cardinality: Multiple
gremlin> schema.config().option("graph.allow_scan").set("true")