斯卡拉火花阵列映射 [英] scala-spark Array mapping

查看:214
本文介绍了斯卡拉火花阵列映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于中阶绘图阵列的问题。我有以下阵列:

I have a question about mapping Array in scala. I have the following Array:

Array[(scala.collection.immutable.Set[String], com.trends.City, com.trends.State)]

基本上,我要地图的阵列,使得设置每个String将有com.trends.City和国家重视它。结果应该是这样的:

Basically, I want to map the Array such that each String in the Set will have com.trends.City and State attached to it. The result should look something like:

Array[(String, com.trends.City, com.trends.State)] 

这好比flatMap,但我想com.trends将在那里。

Which is like flatMap, but I want the com.trends to be in there.

我也可以转换成数组一个RDD如果需要的话,用flatMapValues​​,但我担心的效率,可能有人告诉我什么是最好的方式去?

I could also convert the Array into a RDD if needed and use flatMapValues, but I am concerned for the efficiency, could someone tell me what is the best way to go?

推荐答案

您可以斯卡拉阵列像这样上使用flatMap:

You can use flatMap on scala array like this:

class City
class State
val array: Array[(scala.collection.immutable.Set[String], City, State)] = Array()
array.flatMap(p => p._1.map(q => (q, p._2, p._3)))

这篇关于斯卡拉火花阵列映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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