Apache Flink 上的 zipWithIndex [英] zipWithIndex on Apache Flink
本文介绍了Apache Flink 上的 zipWithIndex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为我输入的每一行分配一个 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.
这篇关于Apache Flink 上的 zipWithIndex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文