Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zeppelin Dynamic Form Drop Down value in SQL

I have a dropdown element in my Zeppelin notebook

val instrument = z.select("Select Item", Seq(("A", "1"),("B", "2"),("C", "3")))

I want to use the value of this variable instrument in my sql. For e.g., my next paragraph in the notebook contains

%sql select * from table_name where item='<<instrument selected above>>'

Is this possible? If yes, what would the syntax look like?

like image 792
van_d39 Avatar asked Aug 05 '16 02:08

van_d39


2 Answers

This is completely possible and here is an example with both %spark and %sql interpreters :

cell 1:

val df = Seq((1,2,"A"),(3,4,"B"),(3,2,"B")).toDF("x","y","item")
df.registerTempTable("table_name")
val instrument = z.select("Select Item", Seq(("A", "1"),("B", "2"),("C", "3")))

cell 2:

z.show(df.filter($"item"===instrument))

dynamic_spark

alternative solution using %sql :

%sql select * from table_name where item="${item=A,A|B|C}" 

dynamic_sql

PS: instrument is set on B,2

like image 179
eliasah Avatar answered Nov 17 '22 05:11

eliasah


The other answers haven't really addressed the issue, the syntax you are looking for is:

where item = "${Select Item=,1(A)|2(B)|3(C)}"

Cheers.

like image 36
user1119575 Avatar answered Nov 17 '22 05:11

user1119575