【发布时间】:2017-04-25 22:20:39
【问题描述】:
我正在为使用“PointFeature”对象的 spark 使用第三方包。我正在尝试获取一个 csv 文件并将每一行的元素放入这些 PointFeature 对象的数组中。
我的实现的 PointFeature 构造函数如下所示:
Feature(Point( _c1, _c2), _c3)
其中 _c1、_c2 和 _c3 是我的 csv 的列,代表双精度。
这是我目前的尝试:
val points: Array[PointFeature[Double]] = for{
line <- sc.textFile("file.csv")
point <- Feature(Point(line._c1,line._c2),line._c3)
} yield point
引用列时出现我的错误
<console>:36: error: value _c1 is not a member of String
point <- Feature(Point(line._c1,line._c2),line._c3.toDouble)
^
<console>:36: error: value _c2 is not a member of String
point <- Feature(Point(line._c1,line._c2),line._c3.toDouble)
^
<console>:36: error: value _c3 is not a member of String
point <- Feature(Point(line._c1,line._c2),line._c3.toDouble)
^
这显然是因为我引用了一个字符串,就好像它是 DataFrame 的一个元素一样。我想知道是否有一种方法可以以这种循环格式使用 DataFrame,或者有一种方法可以将每一行拆分为一个双精度列表。也许我需要一个 RDD?
另外,我不确定这会产生一个数组。实际上,我怀疑它会返回一个 RDD...
我在 Amazon EMR 上使用 Spark 2.1.0
以下是我从中得出的一些其他问题:
How to read csv file into an Array of arrays in scala
【问题讨论】:
标签: arrays scala csv object apache-spark