zipWithIndex在Apache Flink上 [英] zipWithIndex on Apache Flink
本文介绍了zipWithIndex在Apache Flink上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为输入的每一行分配一个id
-应该是从0
到N - 1
的数字,其中N
是输入中的行数.
I'd like to assign each row of my input an id
- which should be a number from 0
to N - 1
, where N
is the number of rows in the input.
大致上,我希望能够执行以下操作:
Roughly, I'd like to be able to do something like the following :
val data = sc.textFile(textFilePath, numPartitions)
val rdd = data.map(line => process(line))
val rddMatrixLike = rdd.zipWithIndex.map { case (v, idx) => someStuffWithIndex(idx, v) }
但是在Apache Flink中.是否有可能?
But in Apache Flink. Is it possible?
推荐答案
这是Apache Flink 0.10-SNAPSHOT发行版的一部分. zipWithIndex(in)
和zipWithUniqueId(in)
的示例在官方 Flink文档.
This is now a part of the 0.10-SNAPSHOT release of Apache Flink. Examples for zipWithIndex(in)
and zipWithUniqueId(in)
are available in the official Flink documentation.
这篇关于zipWithIndex在Apache Flink上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文