1.13 Using the Graph Zeppelin Interpreter Client

Oracle Graph provides an interpreter client implementation for Apache Zeppelin. This tutorial topic explains how to perform simple operations using the graph Zepplin interpreter client.

See Installing the Graph Zeppelin Interpreter Client for more details to install the graph interpreter into your local Zeppelin installation.

Using the Interpreter

If you named the graph interpreter pgx, you can send paragraphs to the graph server by starting the paragraphs with the %pgx directive, just as with any other interpreter.

The interpreter acts like a client that talks to a remote graph server. You cannot run a graph server instance embedded inside the Zeppelin interpreter. You must provide the graph server base URL and connection information as illustrated in the following example:

%pgx
import oracle.pgx.api.*
import groovy.json.*
 
baseUrl = '<base-url>'
username = '<username>'
password = '<password>'
 
conn = new URL("$baseUrl/auth/token").openConnection()
conn.setRequestProperty('Content-Type', 'application/json')
token = conn.with {
  doOutput = true
  requestMethod = 'POST'
  outputStream.withWriter { writer ->
    writer << JsonOutput.toJson([username: username, password: password])
  }
  return new JsonSlurper().parseText(content.text).access_token
}
 
instance = Pgx.getInstance(baseUrl, token)
session = instance.createSession("my-session")

The in-memory analyst Zeppelin interpreter evaluates paragraphs in the same way that the in-memory analyst shell does, and returns the output. Therefore, any valid in-memory analyst shell script will run in the in-memory analyst interpreter, as in the following example:

%pgx
g_brands = session.readGraphWithProperties("/opt/data/exommerce/brand_cat.json")
g_brands.getNumVertices()
rank = analyst.pagerank(g_brands, 0.001, 0.85, 100)
rank.getTopKValues(10)

The following figure shows the results of that query after you click the icon to execute it.

As you can see in the preceding figure, the Zeppelin interpreter automatically renders the values returned by rank.getTopKValues(10) as a Zeppelin table, to make it more convenient for you to browse results.

Besides the property values (getTopKValues(), getBottomKValues(), and getValues()), the following return types are automatically rendered as table also if they are returned from a paragraph:

  • PgqlResultSet - the object returned by the queryPgql("...") method of the PgxGraph class.
  • MapIterable - the object returned by the entries() method of the PgxMap class

All other return types and errors are returned as normal strings, just as the in-memory analyst shell does.

For more information about Zeppelin, see the official Zeppelin documentation.