简体   繁体   English

如何使用scala创建具有随机内容的大型火花数据框?

[英]How to create large spark data frame with random content using scala?

I need to create large spark data frame with 1000+ columns, 10M+ rows, 1000 partitions with random data for testing. 我需要创建具有1000+列,10M +行,1000个分区以及随机数据的大型火花数据帧进行测试。 I know I need to create a large rdd and apply schema on it using spark.sqlContext.createDataFrame(rdd, schema) So far I have created schema using val schema = StructType((0 to 1000).map(n => StructField(s"column_$n", IntegerType))) I'm stuck with generating large RDD with random content. 我知道我需要使用spark.sqlContext.createDataFrame(rdd, schema)创建一个大的rdd并在其上应用模式到目前为止,我已经使用val schema = StructType((0 to 1000).map(n => StructField(s"column_$n", IntegerType)))我坚持用随机内容生成大型RDD。 How do I do it? 我该怎么做?

Got it working using RandomRDD from mllib package 使用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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM