Notebook code editor in Gremlin code cells

The Notebook code editor supports the Groovy programming language in Gremlin code cells.

The Notebook code editor supports the Apache Groovy™ programming language in Gremlin code cells. Syntax validation supported for a subset of Groovy.

A notebook connects to a DSE cluster based on the connection information. Each notebook has only one connection. One piece of information that a connection specifies is its Graph Name.

The code editor provides pre-defined alias variables:

graph
The variable that refers to the graph.
g
The traversal source associated with the graph for OLTP graph traversals.
a
The traversal source associated with the graph for OLAP graph traversals.

A drop-down list shows for content-assist on a blank line in the editor.

The code editor supports inline code validation. If some code is invalid or uses Groovy syntax that the editor does not support, the invalid code is displayed with a red underlining. Use the slider () to Disable editor validations to turn off.

Cancel execution

When code is running in a Gremlin cell, you can cancel the execution to kill the gremlin session. This cancel execution is helpful when you want to make a change to the code and do not want to wait until a long running query finishes.
  • Click Kill Session.
    The confirmation dialog appears:
    Gremlin cell executions will be stopped by killing the notebook session. Proceed?
  • Click Yes to proceed, no to cancel.

  • After you cancel execution, this message is shown:
    The Gremlin Session associated with the notebook was killed.
  • You can make code changes to the cell and run the execution again.

Content assistance

The code editor provides content assistance (Ctrl+Space).

Content-assistance proposes content based on context:
  • Methods
  • Variables
Press Return to select the highlighted choice from the assistance list.

You can filter proposals by typing enough characters to select a line in the pull-down menu.

Use Shift-Tab to return to the beginning of a line.

Code validation

The notebook editor supports these validations:
  • Groovy syntax—The code in a Gremlin cell is executed within DSE Graph as Groovy. The notebook editor adds enough Groovy syntax support to help you craft Gremlin statements.

  • Type-checking—The code in a cell is also checked for type. If you try to call a method on an object of the wrong type or pass a parameter of an invalid type, a validation error is displayed.

  • Domain-specific—Common errors in code are pointed out when possible.

The notebook editor performs validation as code is entered into the cell. You can turn off validation on a per-cell basis.

The code editor cells in a notebook have no Gremlin session scope context and rely on an implicit scope based on their order. Validation occurs from the top cell down in the order in the notebook. If you execute code out of order, validation errors can occur even if the code executes successfully.

Groovy language support

Supported:

  • variable declarations in Groovy style:
    • def foo
    • def SomeType foo
    • SomeType foo
    • Shell-style variables
  • method invocations
  • optional semicolons to complete statements
  • generics
  • strings in both forms:
    • '123'
    • "123"
  • for loops: basic and for in syntax
  • while loops
  • try-catch-finally: a type is required for catching the exception
  • if-else statements
  • switch statements
  • casting in both styles: (SomeType) foo and foo as SomeType
  • list literals

Unsupported Groovy language

  • closures
  • multi-variable assignment and other advanced variable assignments like object deconstruction
  • import statements explicitly disabled
  • map literals or other complex type literals that are not supported by Java
  • try-catch-finally: multi-catch is not supported

Notebook information

Selecting Information displays:
  • Connection being used for the notebook.
  • Last update to the notebook.
  • Version of Studio JAR file being run.

Notebook schema

Selecting Information displays the current graph schema for the notebook.

In addition to visual schema representation, the code-assist feature also provides schema-assist proposals.

That’s a lot of proposals. Let’s break them down:
  • The editor is intelligent enough to know that this is a Vertex-based traversal because of type inference. The editor presents only the schema proposals that are relevant for vertex properties and keys.
  • Because there are multiple has methods, Studio proposes possibilities for all of these variations.
  • The editor concretely makes a proposal for each possible property key.