Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache spark Spark没有从二进制文件读取所有记录_Apache Spark_Deserialization_Avro_Binaryfiles_Spark Avro - Fatal编程技术网

Apache spark Spark没有从二进制文件读取所有记录

Apache spark Spark没有从二进制文件读取所有记录,apache-spark,deserialization,avro,binaryfiles,spark-avro,Apache Spark,Deserialization,Avro,Binaryfiles,Spark Avro,我正在尝试从S3读取Avro文件,如图所示,我能够很好地读取它。我的文件如下,这些文件由5000条记录组成 s3a://bucket/part-0.avro s3a://bucket/part-1.avro s3a://bucket/part-2.avro val byteRDD: RDD[Array[Byte]] = sc.binaryFiles(s"$s3URL/*.avro").map{ case(file, pds) => { val dis = pds.open() v

我正在尝试从S3读取Avro文件,如图所示,我能够很好地读取它。我的文件如下,这些文件由5000条记录组成

s3a://bucket/part-0.avro
s3a://bucket/part-1.avro
s3a://bucket/part-2.avro

val byteRDD: RDD[Array[Byte]] = sc.binaryFiles(s"$s3URL/*.avro").map{ case(file, pds) => {
  val dis = pds.open()
  val len = dis.available()
  val buf = Array.ofDim[Byte](len)
  pds.open().readFully(buf)
  buf
}}

import org.apache.avro.io.DecoderFactory
val deserialisedAvroRDD = byteRDD.map(record => {

  import org.apache.avro.Schema
  val schema = new Schema.Parser().parse(schemaJson)
  val datumReader = new GenericDatumReader[GenericRecord](schema)

  val decoder = DecoderFactory.get.binaryDecoder(record, null)
  var datum: GenericRecord = null
  while (!decoder.isEnd()) {
    datum = datumReader.read(datum, decoder)
  }
  datum
}
)

deserialisedAvroRDD.count() ---> 3
我正在反序列化binaryAvro消息以生成GenericRecords,我希望反序列化后的RDD有15k条记录,因为每个.avro文件有5k条记录,但是反序列化后我只得到3条记录。有人能帮我找出代码的问题吗?如何一次序列化一条记录

这应该行得通

val recRDD: RDD[GenericRecord] = sc.binaryFiles(s"$s3URL/*.avro").flatMap {
  case (file, pds) => {
    val schema =  new Schema.Parser().parse(schemaJson)
    val datumReader = new GenericDatumReader[GenericRecord](schema)

    val decoder = DecoderFactory.get.binaryDecoder(pds.toArray(), null)
    var datum: GenericRecord = null
    val out = ArrayBuffer[GenericRecord]()
    while (!decoder.isEnd()) {
      out += datumReader.read(datum, decoder)
    }
    out
  }
}

这回答了你的问题吗?这些是二进制Avros,即数组[字节]。问题可能出在
byteRDD
读取中。它不知道记录何时开始和停止。是否有理由将ops分为两个不同的步骤?为什么不使用
二进制解码器
读取
pds
?为什么不使用二进制解码器读取pds?->你能举个例子吗?