2017-12-04 9 views
-1

私はapache sparkを学習しており、scala端末上で小さなプログラムを実行しようとしています。エラーを解決する方法:値reduceByKeyはorg.apache.spark.rdd.RDD [(Int、Int)]のメンバーではありませんか?

私は、次のコマンドを使用して、DFS、糸や履歴サーバを開始しました:

start-dfs.sh 
start-yarn.sh 
mr-jobhistory-deamon.sh start historyserver 

、その後、Scalaのターミナルで、私は次のコマンドを書かれている:

var file = sc.textFile("/Users/****/Documents/backups/h/*****/input/ncdc/micro-tab/sample.txt"); 
val records = lines.map(_.split("\t")); 
val filters = records.filter(rec => (rec(1) != "9999" && rec(2).matches("[01459]"))); 
val tuples = filters.map(rec => (rec(0).toInt, rec(1).toInt)); 
val maxTemps = tuples.reduceByKey((a,b) => Math.max(a,b)); 

すべてのコマンドがあります最後のものを除いて正常に実行され、次のエラーがスローされます。

error: value reduceByKey is not a member of org.apache.spark.rdd.RDD[(Int, Int)] 

私は以下のようないくつかのソリューションを見つけました:

This comes from using a pair rdd function generically. The reduceByKey method is actually a method of the PairRDDFunctions class, which has an implicit conversion from RDD.So it requires several implicit typeclasses. Normally when working with simple concrete types, those are already in scope. But you should be able to amend your method to also require those same implicit.

しかし、これを達成する方法がわかりません。

この問題を解決するにはどうすればよいですか?

+1

[reduceByKeyの値は、org.apache.spark.rdd.RDDのメンバーではありません](https://stackoverflow.com/questions/45620797/value-reducebykey-is-not-a-member-of) -org-apache-spark-rdd-rdd) –

+1

エラーを再現できません。あなたはあなたが使用しているsparkのバージョンと一緒にMVCEを追加してもよろしいですか? – eliasah

答えて

1

インポートが不足しているようです。

import org.apache.spark.SparkContext._ 

そして、上記のコマンドを実行してください。このインポートによって暗黙の変換が行われ、reduceByKeyメソッドを使用できます。

関連する問題