Creating a graph
Creating a graph is the first task required to work with DataStax Graph (DSG). A graph corresponds to an Apache Cassandra keyspace. A graph is created in either DataStax Studio or Gremlin console. The replication settings for DataStax Graph are the same as for Apache Cassandra.
|
Graph creation in DSG 6.8 is different than in previous versions of DSE Graph. Earlier graph creation of Classic graph is included in DSG 6.8 for migration purposes and is deprecated. |
DSG can also create a graph using the CQL command CREATE KEYSPACE, or convert a CQL keyspace into a graph using ALTER KEYSPACE.
See the CQL commands to create a keyspace as a graph or convert a keyspace into a graph.
Prerequisites
-
Start a node in Graph mode, also known as a DSG node.
Create a graph in DataStax Studio
-
In DataStax Studio, create a connection to a DSG node in the cluster.
-
In DataStax Studio, create a notebook that uses the connection created in the previous step.
-
Create a graph during notebook creation, or add a graph to your new notebook.
The graph configuration is immutable after you create the graph in DataStax Studio.
The following parameters are required:
-
Graph name: The name of the graph.
-
Graph type: The engine used for the graph, either Core or Classic.
Core is the default and intended graph engine for DataStax Graph 6.8.
Use the Classic engine only for notebooks that work with graph data created using DSE Graph 6.7 or earlier.
Core and Classic graphs have different schemas.
-
Replication factor: The number of replicas for the graph data. The default is 1. Production and multi-datacenter clusters require a higher replication factor.
-
Replication strategy: The strategy for replicating graph data across the cluster. The default is NetworkTopologyStrategy. This is a good choice for most use cases.
-
Once a graph exists, a graph traversal g is configured that allows graph traversals to be executed. Graph traversals query the graph data and return results. A graph traversal is bound to a specific traversal source, which is the standard OLTP traversal engine.
Create a graph in the Gremlin console
-
Create a graph:
Use the default settings for a non-production single-node cluster:
+
system.graph('food_simple').ifNotExists().create()+
==>OK+ By default, the replication factor is 1 and the replication strategy is NetworkTopologyStrategy.
+ Graphs in production and multi-datacenter clusters must use NetworkTopologyStrategy and a replication factor greater than 1, as shown in the following example. Replace
<DC_NAME>with the datacenter name in your cluster configuration.+
system.graph('food'). ifNotExists(). withReplication("{'class': 'NetworkTopologyStrategy', '<DC_NAME>': 1}"). andDurableWrites(true). create()+
==>OK+ Durable writes are set to
TRUEby default. DataStax recommends using the default value. Disabling durable writes can cause data loss when a node goes down unexpectedly. -
On the remote Gremlin Server, set the alias for the graph traversal
gto the graph traversal specified infood.To run traversals, the graph traversal must be aliased to a graph. For all DSG queries using the Gremlin console, you must alias the graph traversal to a graph before running any commands.
// Set the specified graph as the active graph :remote config alias g food.g==>g=food.g