-
Notifications
You must be signed in to change notification settings - Fork 62
Use CAPS in a Zeppelin notebook
This tutorial describes how to set up CAPS within a Zeppelin notebook
-
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.
-
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")
- To use the Zeppelin specific methods add the following import statement
import org.opencypher.okapi.api.util.ZeppelinSupport._
If the Cypher for Apache Spark library is installed it can be used as described in the CAPS documentation and the examples.
Cypher for Apache Spark offers some tooling to visualize Cypher query results in Zeppelin.
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()
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()
It is also possible to visualize entire graphs.
val graph = caps.catalog.graph("myGraph")
graph.printGraph()