SQL中的Zeppelin动态表单下拉值 [英] Zeppelin Dynamic Form Drop Down value in SQL
问题描述
我的Zeppelin笔记本中有一个下拉菜单元素
I have a dropdown element in my Zeppelin notebook
val instrument = z.select("Select Item", Seq(("A", "1"),("B", "2"),("C", "3")))
val instrument = z.select("Select Item", Seq(("A", "1"),("B", "2"),("C", "3")))
我想在我的sql中使用此变量instrument
的值.例如,我在笔记本中的下一段包含
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>>'
%sql select * from table_name where item='<<instrument selected above>>'
这可能吗?如果是,语法会是什么样?
Is this possible? If yes, what would the syntax look like?
推荐答案
这是完全可能的,这是%spark
和%sql
解释器的示例:
This is completely possible and here is an example with both %spark
and %sql
interpreters :
单元格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")))
单元格2:
z.show(df.filter($"item"===instrument))
使用%sql
的替代解决方案:
alternative solution using %sql
:
%sql select * from table_name where item="${item=A,A|B|C}"
PS:instrument
设置在B,2上
PS: instrument
is set on B,2
这篇关于SQL中的Zeppelin动态表单下拉值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!