在配置单元查询中使用scala集合

bnl4lu3b  于 2021-06-24  发布在  Hive
关注(0)|答案(1)|浏览(215)

我有一个scala数组集合。我需要从配置单元查询访问此集合中的值。这可以使用hivecontext实现。

qxgroojn

qxgroojn1#

定义 collection 作为 string 如果在配置单元查询中使用: Example: ```
val df=Seq((1,"a"),(2,"b"),(3,"c")).toDF("id","name")
spark.sql("select * from tmp").show()
df.createOrReplaceTempView("tmp")
spark.sql("select * from tmp").show()
val st=""""a","b""""
spark.sql(s"select * from tmp where name in ($st)").show()
//Output:
//+---+----+
//| id|name|
//+---+----+
//| 1| a|
//| 2| b|
//+---+----+

如果正在使用,请定义集合
dataframe api: `Example:` ```
val st_list=List("a","b")
df.filter('name.isin(st_list:_*)).show()
//output:
//+---+----+
//| id|name|
//+---+----+
//|  1|   a|
//|  2|   b|
//+---+----+

相关问题