ZeppelinノートブックでSparkを使用していますが、groupByKey()が動作していないようです。 スパークエラー:データセットに格納されているタイプのエンコーダが見つかりません
このコード:(私が働いているデータセットがかなり大きい一方で、それは時間がない中で現れているので、おそらくコンパイルエラー)df.groupByKey(row => row.getLong(0))
.mapGroups((key, iterable) => println(key))
は私に、このエラーを与える:
error: Unable to find encoder for type stored in a Dataset. Primitive types (Int, String, etc) and Product types (case classes) are supported by importing spark.implicits._ Support for serializing other types will be added in future releases.
私はケースクラスを追加して、それにすべての行をマップしようとしましたが、同じエラーが発生しました。
import spark.implicits._
case class DFRow(profileId: Long, jobId: String, state: String)
def getDFRow(row: Row):DFRow = {
return DFRow(row.getLong(row.fieldIndex("item0")),
row.getString(row.fieldIndex("item1")),
row.getString(row.fieldIndex("item2")))
}
df.map(DFRow(_))
.groupByKey(row => row.getLong(0))
.mapGroups((key, iterable) => println(key))
私のデータフレームのスキーマは次のとおりです。
root
|-- item0: long (nullable = true)
|-- item1: string (nullable = true)
|-- item2: string (nullable = true)
を参照してくださいzero323 @、あなたの完全な答えをいただき、ありがとうございます。私は現在Sparkを拾っています。あなたのEncoderの紹介は、質問がダムであっても大きな助けになりました。しかし、簡単な質問がありますが、計算を実行し、そのためのエンコーダが存在しないので、 'List'のような基本データ型を得るにはどうすればよいですか? – Wahbivic
まずはhttps://spark.apache.org/docs/latest/sql-programming-guide.html#data-typesをご覧ください。何かがテーブルの中にあれば、あなたは修正されています。大文字小文字のクラスは、フィールドがSQL型に対応している限り、そのままの状態で処理されます。残りの部分:http://stackoverflow.com/q/36648128/1560062 – zero323