简体   繁体   English

sc.textFile之后的zipWithIndex会给出正确的行号吗?

[英]Would zipWithIndex after sc.textFile give the correct line numbers?

Say If I do, something as shown below. 说如果我这样做,如下所示。

val rdd = sc.textFile("someFile.txt")
val rddWithLines = rdd.zipWithIndex

Would the indices added by zipWithIndex correspond to the line numbers (first line being 0 of course) in the input file? zipWithIndex添加的索引是否与输入文件中的行号(当然第一行为0)相对应? Or is it that the order gets broken in this case? 或者在这种情况下订单是否破裂?

zipWithIndex is a map-only transformation (it doesn't shuffle) so order will be correct. zipWithIndex是一个仅限地图的转换(它不会随机播放),所以订单是正确的。 You can safely use it here. 你可以在这里安全地使用它。

SparkContext.textFile can create multiple partitions for each file. SparkContext.textFile可以为每个文件创建多个分区。 If these partitions are in the correct order you should get the correct result. 如果这些分区的顺序正确,您应该得到正确的结果。 See this answer for more information. 有关更多信息,请参阅此答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM