Skip to content

Use CAPS in a Zeppelin notebook

Max Kießling edited this page Dec 18, 2018 · 16 revisions

This tutorial describes how to set up CAPS within a Zeppelin notebook

CAPS Zeppelin Screenshot

Setup

  1. If you have no working instance of Apache Zeppelin follow the Zeppelin 0.8.0 Quick Start instructions. Note: The graph visualizations require at least version 0.8.0.

  2. Add the spark-cypher dependency to your Zeppelin installation. You can do this inside of your notebook by adding a section with the following code at the top of your notebook:

%spark.dep
z.load("org.opencypher:spark-cypher:0.2.3")
  1. To use the Zeppelin specific methods add the following import statement
import org.opencypher.okapi.api.util.ZeppelinSupport._

Usage

If the Cypher for Apache Spark library is installed it can be used as described in the CAPS documentation and the examples.

Visualization of tabular results

Cypher for Apache Spark offers some tooling to visualize Cypher query results in Zeppelin.

Table

Given a Cypher query that returns a tabular output, e.g.

val tabularResult = capsSession.cypher(
  """|MATCH (n:Person)-[r:KNOWS]-(m:Person)
     |RETURN n.name, r.since, m.person""".stripMargin)

This result can be rendered into a table by calling

tabularResult.records.printTable()

Graph

When the query returns entire nodes and relationships, e.g.

val tabularResult = capsSession.cypher(
  """|MATCH (person:Person)-[r:KNOWS]-(other:Person)
     |RETURN person, r, other""".stripMargin)

This result can also be rendered into a graph by running

tabularResult.records.printGraph()

Visualization of graphs

It is also possible to visualize entire graphs.

val graph = caps.catalog.graph("myGraph")
graph.printGraph()