簡體   English   中英

Apache Spark DataFrame:帶有Java:List屬性的df.where()

[英]Apache Spark DataFrame: df.where() with Java:List attribute

假設您有這樣的df:

a b  
1 1  
1 2  
1 3  
2 1  
2 2  
2 3  

並且您想要實現通用的.where功能; 如何按列表過濾

val l1:List[Int] = List (1,2)  
df.where($"b" === l1:_*) // does not work

甚至還有一個選擇,您可以在其中提出如下要求:

df.where($"a" === l1:_* && $"b" === l1:_*)

如果我說對了,那么您需要IN語義:

df.where($"b" isin (l1: _*)).show()
+---+---+ 
|  a|  b| 
+---+---+ 
|  1|  1| 
|  1|  2| 
|  2|  1| 
|  2|  2| 
+---+---+ 

df.where(($"a" isin (l1: _*)) and ($"b" isin (l1: _*))).show()
+---+---+ 
|  a|  b| 
+---+---+ 
|  1|  1| 
|  1|  2| 
|  2|  1| 
|  2|  2| 
+---+---+ 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM