Skip to Main Content
Spark高级数据分析(第2版)
book

Spark高级数据分析(第2版)

by Sandy Ryza, Uri Laserson, Sean Owen, Josh Wills
June 2018
Beginner to intermediate content levelBeginner to intermediate
246 pages
6h 57m
Chinese
Posts & Telecom Press
Content preview from Spark高级数据分析(第2版)
44
3
case _: NumberFormatException => None
}
}
}.toDF("id", "name")
这里返回一个
DataFrame
,艺术家
ID
和名字分别对应列“
id
”和“
name
”。
artist_alias.txt
将拼写错误的艺术家
ID
或非标准的艺术家
ID
映射为艺术家的正规名字。其
中每行有两个
ID
,用制表符分隔。这个文件相对较小,有
200 000
个记录。有必要把它转
Map
集合的形式,将“不良的”艺术家
ID
映射到“良好的”
ID
,而不是简单地把它作
为包含艺术家
ID
二元组的数据集。这里又有一点小问题:由于某种原因有些行没有艺术
家的第一个
ID
。这些行将被过滤掉:
val rawArtistAlias = spark.read.textFile("hdfs:///user/ds/artist_alias.txt")
val artistAlias = rawArtistAlias.flatMap { line =>
val Array(artist, alias) = line.split('\t')
if (artist.isEmpty) {
None
} else {
Some((artist.toInt, alias.toInt))
}
}.collect().toMap
artistAlias.head
...
(1208690,1003926)
比如,第一条将
ID 1208690
映射为
1003926
。接下来我们可以从包含艺术家名字的数据集 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

大数据项目管理:从规划到实现

大数据项目管理:从规划到实现

Ted Malaska, Jonathan Seidman
管理Kubernetes

管理Kubernetes

Brendan Burns, Craig Tracey

Publisher Resources

ISBN: 9787115482525