开发者社区> 问答> 正文

可以将spark配置为将空数据集推断为空模式吗

我们有很多parquet数据集,按年/月/日/小时划分。

只有一个_SUCCESS文件,其中一些时间是空的。

我们实现迭代所有分区并执行工作的作业。打开空数据集时遇到问题。org.apache.spark.sql.AnalysisException: Unable to infer schema for Parquet. It must be specified manually.

(使用EMR5.3.0 - 我们正在努力摆脱依赖,以便我们可以升级到更高版本)

Spark-shell示例:

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配置为将空数据集推断为空模式。

展开
收起
小六码奴 2019-04-23 11:18:32 4178 0
2 条回答
写回答
取消 提交回答
  • 添加schema就行了。没那么事多; 如: StructType schema = DataTypes .createStructType(Arrays.asList( DataTypes.createStructField("msisdn", DataTypes.StringType, true), DataTypes.createStructField("eid", DataTypes.IntegerType, true) )); sc.read().schema(schema).parquet("/test");

    2020-06-04 17:10:21
    赞同 展开评论 打赏
  • 理想情况下spark.read.parquet应该采取param ignoreEmptyFiles=true,但这不受支持。

    可以在读取之前过滤空目录

    2019-07-17 23:34:02
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Hybrid Cloud and Apache Spark 立即下载
Scalable Deep Learning on Spark 立即下载
Comparison of Spark SQL with Hive 立即下载