I have started playing with Zeppelin recently. It's a great web-based notebook that enables real-time analytics. It supports a variety of backends through the concept of interpreters.

Zeppelin Interpreter is the plug-in which enable zeppelin user to use a specific language/data-processing-backend. For example to use scala code in Zeppelin, you need spark interpreter.

You can already do some Couchbase related work using their Spark interpreter and the Couchbase Spark Connector. But I just want to run some N1QL queries in pads, like with Spark SQL and DataFrames. So I need to create a Couchbase N1QL interpreter. Doing so is easy and documented, you need just one class.

This class must extends the abstract class org.apache.zeppelin.interpreter.Interpreter resulting in having you implement the following abstract methods: open, close, interpret, getFormType, getProgress, completion.

Which is pretty much what I did here:

open and close are responsible of respectively opening and closing connection to the Cluster and Bucket. The interpret method is the one called whe you run the pad. This is were you transform the text from the pad into whatever you woud like. For this interpreter I will take a N1QL query, run it and transform the result so it can be used in Zeppelin. Here transforming means flattening the resulting JSON documents as everything has to be in a table form.

Now I can run any N1QL queries I want. Here's a simple taken example from the game sample bucket:

You can see a leader board on the bottom left, the list of player sorted by level on the upper left corner, and the distribution of items per player also sorted by level. You can see that there is no correlation between the player level and the number of items he has. The underlying query is using a JOIN, that is available natively with N1QL.

Now there are a lot of other feature we could add. I am assuming the first one that comes to mind when you know Zeppelin is autocomplete. It can be useful in many situation wether for N1QL keyword or json fields. We actually have this feature available on the Query UI if you enter the tab key or Ctrl+Space. Other nice features could be the support of Views, especially for geospatial queries, and of Couchbase FTS. I have started the development of the plugin on Github, and you can follow it on the Apache issue tracker. As usual feedback and contibutions are more than welcome!

Posted by Laurent Doguin, Developer Advocate, Couchbase

Laurent is a Paris based Developer Advocate where he focuses on helping Java developers and the French community. He writes code in Java and blog posts in Markdown. Prior to joining Couchbase he was Nuxeo’s community liaison where he devoted his time and expertise to helping the entire Nuxeo Community become more active and efficient.

Leave a reply