Failed with exception java.io.IOException:org.apache.parquet.io.ParquetDecodingException

1 篇文章 0 订阅
1 篇文章 0 订阅

Failed with exception java.io.IOException:org.apache.parquet.io.ParquetDecodingException: Can not read value at 0 in block -1 in file hdfs://hadoop102:8020/warehouse/gmall/ads_user_action4/dt=2020-06-14/part-00000-52558b00-e39f-453c-8d9a-a924776a0aa7.c000.snappy.parquet

记录一次spark on hive,写数据到hive表后,使用hive查询报错的问题。

网上查了好多都没有查到具体原因,最后在spark官网找到了问题所在,有一个参数:spark.sql.parquet.writeLegacyFormat,默认为false。
先看官网解释:
If true, data will be written in a way of Spark 1.4 and earlier. For example, decimal values will be written in Apache Parquet’s fixed-length byte array format, which other systems such as Apache Hive and Apache Impala use. If false, the newer format in Parquet will be used. For example, decimals will be written in int-based format. If Parquet output is intended for use with systems that do not support this newer format, set to true.
大概意思就是:
参数如果为true,数据将以Spark 1.4及更早版本的方式写入。例如,十进制值将以Apache Parquet的固定长度字节数组格式写入,Apache Hive和Apache Impala等其他系统也使用这种格式。如果为false,将使用Parquet中的较新格式。例如,小数将基于int的格式写入。如果Parquet输出用于不支持这种新格式的系统,请设置为true。
设置参数如下:

    val spark: SparkSession = SparkSession
      .builder()
      .appName("SparkSqlFromHdfs")
      .master("local[*]")
      .config("spark.sql.parquet.writeLegacyFormat", value = true)
      .enableHiveSupport()
      .getOrCreate()

设置参数后,问题得到解决。
注:如果写入的数据没有小数,不添加这项配置也不会有问题。

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值