在spark中读取parquet文件时,如果遇到以下问题。
应用程序>线程“main”org.apache.spark.SparkException中的异常:由于阶段失败而中止作业:阶段2.0中的任务0失败4次,最近一次失败:阶段2.0中丢失任务0.3(TID 44,10.23.5.196) ,执行器 2): java.io.EOFException: 已到达流末尾,还剩 193212 字节可供读取 应用程序 > 位于 org.apache.parquet.io.DelegatingSeekableInputStream.readFully(DelegatingSeekableInputStream.java:104) 应用程序 > 在 org.apache.parquet.io.DelegatingSeekableInputStream.readFullyHeapBuffer(DelegatingSeekableInputStream.java:127) 应用程序 > 位于 org.apache.parquet.io.DelegatingSeekableInputStream.readFully(DelegatingSeekableInputStream.java:91) 应用程序 > at org.apache.parquet.hadoop.ParquetFileReader$ConsecutiveChunkList.readAll(ParquetFileReader.java:1174) 应用程序 > at org.apache.parquet.hadoop.ParquetFileReader.readNextRowGroup(ParquetFileReader.java:805) 应用程序 > 在 org.apache.spark.sql.execution.datasources.parquet.VectorizedParquetRecordReader.checkEndOfRowGroup(VectorizedParquetRecordReader.java:301) 应用程序 > at org.apache.spark.sql.execution.datasources.parquet.VectorizedParquetRecordReader.nextBatch(VectorizedParquetRecordReader.java:256) 应用程序 > 在 org.apache.spark.sql.execution.datasources.parquet.VectorizedParquetRecordReader.nextKeyValue(VectorizedParquetRecordReader.java:159) 应用程序 > 在 org.apache.spark.sql.execution.datasources.RecordReaderIterator.hasNext(RecordReaderIterator.scala:39) 应用程序 > 在 org.apache.spark.sql.execution.datasources.FileScanRDD$$anon$1.hasNext(FileScanRDD.scala:124) 应用程序 > 在 org.apache.spark.sql.execution.datasources.FileScanRDD$$anon$1.nextIterator(FileScanRDD.scala:215)
对于以下 Spark 命令:
val df = spark.read.parquet("s3a://.../file.parquet")
df.show(5, false)
我认为你可以绕过这个问题
--conf spark.sql.parquet.enableVectorizedReader=false
对我来说,我在不同的 Spark 应用程序中遇到了以下一组异常:
Caused by: java.io.EOFException: Reached the end of stream with 1008401 bytes left to read
at org.apache.parquet.io.DelegatingSeekableInputStream.readFully(DelegatingSeekableInputStream.java:104)
at org.apache.parquet.io.DelegatingSeekableInputStream.readFullyHeapBuffer(DelegatingSeekableInputStream.java:127)
at org.apache.parquet.io.DelegatingSeekableInputStream.readFully(DelegatingSeekableInputStream.java:91)
和
Caused by: java.io.IOException: could not read page in col [X] optional binary X (UTF8) as the dictionary was missing for encoding PLAIN_DICTIONARY
at org.apache.spark.sql.execution.datasources.parquet.VectorizedColumnReader.initDataReader(VectorizedColumnReader.java:571)
at org.apache.spark.sql.execution.datasources.parquet.VectorizedColumnReader.readPageV1(VectorizedColumnReader.java:616)
设置此 Spark 配置
--conf spark.sql.parquet.enableVectorizedReader=false
解决了这两个问题。