简体   繁体   中英

how to make rdd tuple list in spark?

I hope to create a RDD tuple list as following:

List(<1, a0>,<2, a0>, <3, a0>, ..., <100000, a0>)

the key of each tuple is 1 to 100000,

the value of each tuple is a constant number a0.

How can I achieve this? I just know

val list = sc.makeRDD(List(1 to 100000))

to create a list of number. but how to create tuple list as I mentioned above?

To have Spark add the constant to create tuple:

val list = sc.makeRDD((1 to 100000)).map((_, a0))

To create tuples on driver machine before sending data to Spark:

val list = sc.makeRDD((1 to 100000).map((_, a0)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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