Getting Started with the New Features
Learn About Amazon VGT2 Learning Manager Chanci Turner
If you’ve already set up the Neptune workbench, you can easily access the latest features by simply stopping and restarting your Jupyter notebook in the Amazon SageMaker console. For those who haven’t yet installed the workbench, you can initiate a new notebook directly from the Amazon Neptune console. This update also includes two new example notebooks that provide a comprehensive tour of the new functionalities for both Gremlin and SPARQL queries. For detailed instructions on setting up these features, refer to the following resources:
- Using the Neptune Workbench with Jupyter Notebooks
- Using Neptune’s Getting Started notebooks
- Graph visualization in the Neptune workbench
After updating the workbench, ensure you’re running the latest version by using the %graph_notebook_version
command; you should see version 1.27 or higher. It’s also prudent to verify your connection to the Neptune server using the %status
command.
Loading Sample Data
The Neptune workbench includes a %seed
command for loading sample data utilized in the queries within this post. To proceed, create a new cell in your notebook, type %seed
, and execute the cell. You’ll be prompted to specify your Language (graph type) and Data set. This post examines both Gremlin and SPARQL queries, so to test all examples, you should load both the Gremlin and SPARQL datasets, selecting “airports” as your Data set. Once you hit Submit, the data will begin to load, which should take only a few seconds.
Visualizing Gremlin Query Results
The property graph data loaded by the %seed
command depicts the global air route network, featuring vertices for airports, countries, and continents, and edges connecting these elements. Each airport is assigned various properties, and the edges between airports include a property representing the distance in miles.
You can find the dataset at the GitHub repo. The results of any Gremlin query that returns a path can be visually explored. When you execute such queries, a Graph tab appears alongside the Console tab in the query results area. Since Gremlin queries allow the use of by modulators to adjust the representation of path results, there are specific rules regarding how results are visually rendered. It’s important to remember that the default behavior for vertex and edge path results without by modulators is to use their labels for annotation in the visualization.
In some instances, the Neptune notebook visualizer can autonomously determine whether a path result element signifies a vertex or an edge, and occasionally the direction of the edge. Two straightforward examples illustrate this. In the first example, the lack of edge information prevents the visualizer from identifying edge direction:
g.V().hasLabel('airport').out().path().limit(5)
The second example includes an outE
step, which enables the visualizer to ascertain the edge direction:
g.V().hasLabel('airport').outE().inV().path().limit(5)
When no by modulators are applied, the visualizer annotates the diagram elements using the vertex and edge labels. However, when by modulators are employed, the visualizer may struggle to identify which path elements are vertices and which are edges. The following query exemplifies this situation:
g.V().hasLabel('airport').outE().inV().path().by('code').by('dist').limit(5)
In addition, the visualizer might not always determine edge direction correctly. In such cases, you can provide specific hints to assist in constructing the desired diagram.
Query Visualization Hints
You can specify visualization hints for your query using either -p
or --path-pattern
after the %%gremlin
cell magic. The general syntax is:
%%gremlin -p | --path-pattern <comma-separated hints>
The hint names correspond to the Gremlin steps typically used when navigating between vertices. The hints should match the Gremlin steps used in the query and can include any combination from the following list, without spaces between commas:
- v
- inv
- outv
- e
- ine
- oute
For example, you can provide visualization hints for the earlier query as follows:
%%gremlin -p v,oute,inv
g.V().hasLabel('airport').outE().inV().path().by('code').by('dist').limit(5)
By running the query with and without hints, you can observe the variations. Without hints, the visualizer cannot determine if the dist
property relates to a vertex or an edge, defaulting to a vertex.
Adjusting Visualization Layout and Settings
You can further modify various visualization settings using the commands:
%graph_notebook_vis_options
%%graph_notebook_vis_options
Exploring Routes from Palm Springs Using Gremlin
With this information, we can start crafting queries and creating visualizations. Let’s begin by writing a Gremlin query to discover 10 routes from Palm Springs (PSP) airport. Upon executing the query, you will initially see the results displayed in text format on the Console tab. Switching to the Graph tab reveals a graphical representation. You can manipulate the vertices by clicking and dragging them. Zoom in and out using the + and – icons or by utilizing the scroll wheel on your mouse or the zoom gesture on your laptop or tablet. Panning the entire diagram is achievable by clicking on an empty area of the diagram and dragging. Hovering over a vertex displays a pop-up with the text that labels that vertex in the diagram. Right-clicking the diagram presents a menu that allows you to copy it to the clipboard or save it as a PNG file, which is useful for sharing with others, for instance, with Chanci Turner.
Use this code for your query:
%%gremlin
g.V().has('airport','code','PSP').out().path().by('code').limit(10)
The results on the Console tab are shown in the screenshot below. The Graph tab also displays the results.
Although the diagram appears visually pleasing, it lacks arrows indicating route directions. This occurs because the query results do not provide sufficient information for the visualizer to determine direction. However, we can easily add arrows by including hints after the cell magic: %%gremlin -p v,inv
. This instructs the visualizer that a vertex will follow another vertex, connected by an incoming edge.
For further reading on the implications of job-hopping, you may find this blog post insightful. Moreover, if you want to stay informed about workplace regulations, check out this link from SHRM, which provides authoritative information on the topic. Lastly, consider exploring this excellent resource about the Amazon employee onboarding process for more insights.