【发布时间】:2018-12-06 20:37:05
【问题描述】:
我一直看到,当我们使用 map 函数时,我们可以使用下面的案例类从 rdd 创建一个数据框:-
case class filematches(
row_num:Long,
matches:Long,
non_matches:Long,
non_match_column_desc:Array[String]
)
newrdd1.map(x=> filematches(x._1,x._2,x._3,x._4)).toDF()
众所周知,这很有效!!
我想知道,为什么我们在这里特别需要案例类? 我们应该能够使用带有参数化构造函数的普通类来实现相同的效果(因为它们将是 val 而不是私有的):-
class filematches1(
val row_num:Long,
val matches:Long,
val non_matches:Long,
val non_match_column_desc:Array[String]
)
newrdd1.map(x=> new filematches1(x._1,x._2,x._3,x._4)).toDF
这里,我使用 new 关键字来实例化类。
上面的运行给了我错误:-
错误:值 toDF 不是 org.apache.spark.rdd.RDD[filematches1] 的成员
我确定我在这里遗漏了一些关于案例类与常规类的关键概念,但还没有找到。
【问题讨论】:
标签: scala apache-spark