运行此代码时我收到相同的错误消息:
import org.apache.spark.ml.feature.{CountVectorizer, CountVectorizerModel}
import org.apache.spark.ml.clustering.LDA
import org.apache.spark.sql.functions.udf
import scala.collection.mutable.WrappedArray
val txt = Array("A B B C", "A B D D", "A C D")
val txtDf = spark.sparkContext.parallelize(txt).toDF("txt")
val txtDfSplit = txtDf.withColumn("txt", split(col("txt"), " "))
// val txtDfSplit = df.withColumn("txt", split(col("txt"), " "))
// create sparse vector with the number
// of occurrences of each word using CountVectorizer
val cvModel = new CountVectorizer().setInputCol("txt").setOutputCol("features").setVocabSize(4).setMinDF(2).fit(txtDfSplit)
val txtDfTrain = cvModel.transform(txtDfSplit)
txtDfTrain.show(false)
产生这个错误:
org.apache.spark.SparkException:作业因阶段失败而中止:
阶段 1.0 中的任务 9 失败 4 次,最近一次失败:丢失任务 9.3
在 1.0 阶段(TID 25,somehostname.domain,执行程序 1):
java.lang.ClassCastException:无法分配实例
scala.collection.immutable.List$SerializationProxy 到字段
org.apache.spark.rdd.RDD.org$apache$spark$rdd$RDD$$dependencies_ of
在实例中键入 scala.collection.Seq
org.apache.spark.rdd.MapPartitionsRDD
我一直在浏览描述此错误的各个页面,这似乎是某种版本冲突。该代码适用于 IntelliJ(独立)。将应用提交到 Spark 时出现错误。