我需要创建包含1000多个列,1000万个以上行,具有1000个分区的大型Spark数据框架,并带有随机数据进行测试。我知道我需要创建一个较大的rdd并使用spark.sqlContext.createDataFrame(rdd, schema)
在其上应用架构。到目前为止,我已经使用val schema = StructType((0 to 1000).map(n => StructField(s"column_$n", IntegerType)))
创建了架构,但我仍然坚持生成带有随机内容的大型RDD。我该怎么做?
最佳答案
使用mllib包中的RandomRDD使其正常工作
import org.apache.spark.mllib.random.RandomRDDs._
val rdd = normalRDD(sc, 1000000L, 10).map(m => Row(schema.map(_ => Array.fill(1000)(m).mkString).toList: _*))
val schema = StructType((0 to 2000).map(n => StructField(s"column_$n", IntegerType)))
spark.sqlContext.createDataFrame(rows, schema)
关于scala - 如何使用Scala创建具有随机内容的大型Spark数据框架?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54989082/