【发布时间】:2016-05-09 07:49:45
【问题描述】:
我正在寻找更好的方法将 Dataframe 转换为 RDD。现在我正在将数据帧转换为集合并循环集合以准备 RDD。但我们知道循环不是好习惯。
val randomProduct = scala.collection.mutable.MutableList[Product]()
val results = hiveContext.sql("select id,value from details");
val collection = results.collect();
var i = 0;
results.collect.foreach(t => {
val product = new Product(collection(i)(0).asInstanceOf[Long], collection(i)(1).asInstanceOf[String]);
i = i+ 1;
randomProduct += product
})
randomProduct
//returns RDD[Product]
请建议我将其设为适用于大量数据的标准且稳定的格式。
【问题讨论】:
-
一是海量数据和收集的不是很好的朋友,二是Loop,为什么?你想做什么:“转换+???”?
-
谢谢以利亚。我需要 RDD[Product],我将使用它来应用一些规则。
标签: scala hadoop apache-spark apache-spark-sql