我有以下代码:
file = spark.textFile("hdfs://...")
counts = file.flatMap(lambda line: line.split(" ")) \
.map(lambda word: (word, 1)) \
.reduceByKey(lambda a, b: a + b)
counts.saveAsTextFile("hdfs://...")
http://spark.apache.org/examples.html 我从这里复制了例子。
我不理解这段代码,特别是以下关键字:
- flatmap,
- map 和
- reduceby
请有人能以通俗易懂的语言解释一下这些关键字吗?
spark.textFile("hdfs://...").flatMap(_.split(" ")).map((_, 1)).reduceByKey(_ + _).saveAsTextFile("hdfs://...")
- samthebest