Creating a graph
Creating a graph.
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.
Procedure
- Start DataStax Graph. If using Studio, continue to the next step. If using Gremlin console, skip to this step.
- Install and start Studio.
- In DataStax Studio, create a connection to a DSG node in the cluster.
-
In DataStax Studio, create a
notebook. Select the connection created in the last step.
A blank notebook will open with a single cell. A graph will not yet be created or associated with the notebook.
-
Create a graph. Note that after a graph is created in Studio, the configuration
cannot be changed.
Studio can create a graph from a number of different places. You can create the graph as the last step during notebook creation, or open a notebook and add a graph. Either way, several choices must be configured. The graph must be given a name, graph type designated, and replication factor settings selected.
- Graph type: Core is the default graph engine for DataStax Graph 6.8. If a notebook will use graph data created using DataStax Graph 6.7 or earlier, choose Classic as the graph engine. The schema for Core and Classic graphs is different.
- Replication factor: The default is set to 1. Production clusters and multi-datacenter clusters need a higher replication factor.
- Replication strategy: The default is NetworkTopologyStrategy. In general, this default is the good option.
Once a graph exists, a graph traversal g is configured that will allow graph traversals to be executed. Graph traversals are used to query the graph data and return results. A graph traversal is bound to a specific traversal source which is the standard OLTP traversal engine.
- Start the Gremlin console.
-
Create a simple graph with default settings, if the graph does not already
exist:
system.graph('food_simple').ifNotExists().create()
==>OK
The replication factor is set to a default of 1 and the replication strategy is set to
NetworkTopologyStrategy
. Graphs created in multi-datacenter clusters must useNetworkTopologyStrategy
and a replication factor greater than one, as shown in the next step. -
Create a graph with specified settings:
system.graph('food'). ifNotExists(). withReplication("{'class': 'NetworkTopologyStrategy', '<DC_NAME>': 1}"). andDurableWrites(true). create()
==>OK
As in DataStax Studio, this step configures replication strategy and replication factor. The variable
<DC_NAME>
must be changed to a valid cluster name. Durable writes are set to TRUE by default. DataStax recommends using the default value. -
On the remote Gremlin Server, set the alias for the graph traversal
g
to the graph traversal specified infood
. To run traversals, the graph traversal must be aliased to a graph.// Set the specified graph as the active graph :remote config alias g food.g
As with all queries in DSG, if you are using Gremlin console, alias the graph traversal to a graph before running any commands.==>g=food.g