带有序列文件的 Spark RDD take()

Spark RDD take() with Sequence File

看起来 RDD.take() 在 SequenceFile 的支持下只是重复读取的最后一个元素。
例如:

val rdd = sc.sequenceFile("records.seq", classOf[LongWritable], classOf[RecordWritable])
val records: Array[(LongWritable, RecordWritable)] = rdd.take(5)
System.out.println(records.map(_._2.toString).mkString("\n"))

输出:

Record(3.1, 2.5)
Record(3.1, 2.5)
Record(3.1, 2.5)
Record(3.1, 2.5)
Record(3.1, 2.5)

尽管我知道这些行是唯一的。

此问题也存在于 sc.binaryRecords()

我知道这可能与 Hadoop 可写缓存问题有关,但是否有解决此问题的计划?有任何变通办法吗?

我尝试复制您的问题,是的,我在直接对 sc.sequenceFile()[= 的结果调用 take 时也看到了类似的行为20=]。但能够找到解决方法:

注意:我正在解释使用 LongWritable 和 Text 而不是 RecordWritable。我不确定 RecordWritable 所需的导入
我的序列文件有:(0,0) (1,1) (2,2) ...

val rdd = sc.sequenceFile("sequencefile.seq", classOf[LongWritable], classOf[Text])
val map = rdd.map(case (k,v) => (k.get(),v.toString()))
map.take(1);
res5: Array[(Long, String)] = Array((0,0))
map.take(5);
res4: Array[(Long, String)] = Array((0,0), (1,1), (2,2), (3,3), (4,4))