Creating a schema in DataStax Studio

Create a schema to give your graph a structure.

Prerequisites

To create a schema, execute Gremlin code in a Gremlin cell in your notebook. The schema used in this example represents users and products and their relationships to one another.

Procedure

  1. Add a code cell to your notebook.
  2. Write code to create a schema:
    1. Drop the schema if it exists.
      schema.clear()
      When creating a notebook, some variables are created by default (if none exist) for you to access in code cells. For example, a graph (graph), a graph traversal (g), and a schema (schema). The graph variable is set to an empty graph with the name that you previously provided in the notebook's connection.
    1. Create the property keys for the schema.
      schema.propertyKey('id').Int().create()
      schema.propertyKey('name').Text().create()
      schema.propertyKey('role').Text().create()
      
      The id and name property keys are used by both the user and the product vertices. The role property key is only used by the user vertex.
    2. Create the vertex labels for user and product.
      schema.vertexLabel('user').create()
      schema.vertexLabel('product').create()
      
    3. Create the edge label for use between the user and product vertices.
      schema.edgeLabel('bought').create()
  3. Execute the code by selecting Run Cell.

    You have created the schema for the example.

  4. View the resulting schema by selecting Schema in the upper-right-hand corner of the notebook.

Results

The schema you created in this task is based on the following data model: