我们有很多按年/月/日/小时划分的镶木地板数据集。
只有几个_SUCCESS
文件,其中有几个小时是空的。
我们实现了遍历所有分区并执行工作的作业。打开空数据集时遇到问题。使用org.apache.spark.sql.AnalysisException: Unable to infer schema for Parquet. It must be specified manually.
(使用EMR5.3.0-我们正在努力摆脱依赖关系,以便我们可以升级到更高版本)
火花壳示例:
Welcome to
____ __
/ __/__ ___ _____/ /__
_\ \/ _ \/ _ `/ __/ '_/
/___/ .__/\_,_/_/ /_/\_\ version 2.1.0
/_/
Using Scala version 2.11.8 (OpenJDK 64-Bit Server VM, Java 1.8.0_121)
Type in expressions to have them evaluated.
Type :help for more information.
scala> val df = spark.read.parquet("s3://some-bucket/empty-dataset/")
org.apache.spark.sql.AnalysisException: Unable to infer schema for Parquet. It must be specified manually.;
at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$8.apply(DataSource.scala:189)
at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$8.apply(DataSource.scala:189)
正如spark所言,我可以指定一个架构,但这对我来说是不切实际的,因为该架构很大并且每个分区都不同(不要问)。
我的首选解决方案是将spark配置为将空数据集推断为空模式。
答案 0 :(得分:1)
理想情况下,spark.read.parquet
应该使用参数ignoreEmptyFiles=true
,但不幸的是不支持此参数。
最好的办法是在读取过滤器空目录之前