2017-08-21 12 views
0
var word_count = rdd.flatMap(lines=>lines.split(",").map(words=>(words,1)).reduceByKey(_+_).collect 
word_count:Array[(String,Int)] = Array((Ankita,1),(shelly,1),(A,2),(B,1)) 

//以下のクエリの結果は空の文字列になりますが、(A、2)と(B、1)を抽出します。SCALA:配列から特定の値を抽出する場合の使用例

var filtered = word_count.filter(values=>(values=="A") || (values=="B")).collect 
filtered:Array[(String,Int)] = Array() 

答えて

1

それは次のようになります。

scala> ("A", 1) == "A" 
<console>:24: warning: comparing values of types (String, Int) and String using `==' will always yield false 
     ("A", 1) == "A" 
      ^
res0: Boolean = false 

word_count.filter(x => (x._1 == "A") || (x._1 == "B")) 

または

word_count.filter(x => Seq("A", "B").contains(x._1)) 

あなたのコードはStringTuple2は自明偽の表現を与える比較します

関連する問題