Apache - Zeppelin using paragraph variables

I am trying to execute the following usage scenario on Apache Zeppelin: for example, when I write sql query

 %sql SELECT * FROM table1 WHERE column1 = ${column1=1,1|2|3|4} 

I get a combo box with these values (1,2,3,4) as parameters. What I want to do is populate this list with all the different values ​​available for this column (or virtually any other set of values ​​that I might want to take from another paragraph in the form of a variable). So I'm currently stuck on how to use some variables defined in one paragraph inside an sql statement in another paragraph?

Diving into the code, I saw that inside the Zeppelin interpreter, a file named Input.java checks the template ${someColumn=someValues} , fills in the parameters of the combo box, and then creates a simple request, and therefore I rejected the Idea to fill it by running the request in the same paragraph.

+8
sql data-analysis paragraph apache-zeppelin
source share
2 answers

You can use ZeppelinContext to do this, as it allows you to use put () and get () to set and retrieve objects between paragraphs.

To quote an example from the linked page, note that the z object is the default ZeppelinContext instance:

 // Put object from scala %spark val myObject = ... z.put("objName", myObject) # Get object from python %spark.pyspark myObject = z.get("objName") 
+1
source share

I am using the Scala variable from one paragraph in Shell Script in another paragraph. Here is the answer.

Scala cage

 %spark2 val myVal = "test-value-across-paragraphs" z.put("objName", myVal) 

In the shell

 %sh echo {objName} 

To do this, enable interpolation of the object, which can be done by setting the zeppelin.shell.interpolation property to true . Check out Apache Zeppelin for more help.

May 19, 2019 Patch

The above procedure may not work in Zeppelin 2.2 but obviously works in Zeppelin 2.3 . Also in 2.3 , the interpolation value can be changed from the sh.config cell.

 %sh.conf zeppelin.shell.interpolation true 
+1
source share

All Articles