转换一个斯卡拉可迭代[元组]到RDD [英] Converting a Scala Iterable[tuple] to RDD

查看:248
本文介绍了转换一个斯卡拉可迭代[元组]到RDD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个元组列表,(字符串,字符串,INT,双人间),我要转换为星火RDD。

I have a list of tuples, (String, String, Int, Double) that I want to convert to Spark RDD.

在一般情况下,我怎么转换斯卡拉可迭代[(A1,A2,A3,...,AN)]成火花RDD?

In general, how do I convert a Scala Iterable[(a1, a2, a3, ..., an)] into a Spark RDD?

推荐答案

有几个方法可以做到这一点,但最海峡前进的方式就是使用星火上下文:

There are a few ways to do this, but the most strait forward way is just to use Spark Context:

import org.apache.spark._
import org.apache.spark.rdd._
import org.apache.spark.SparkContext._

sc.parallelize(YourIterable.toList)

我觉得sc.Parallelize需要一个转换名单,但它会preserve你的结构,因此,你仍然会得到一个RDD [字符串,字符串,整数,双]

I think sc.Parallelize needs a conversion to List, but it will preserve your structure, thus you will still get a RDD[String,String,Int,Double]

这篇关于转换一个斯卡拉可迭代[元组]到RDD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆