Spark 写Hive出现HiveFileFormat. It doesn't match the specified format 错误

背景:

在 python spark 任务中,调用

lua 复制代码
df.repartition("a","b","c").write.format("parquet").mode(saveMode).partitionBy("date").saveAsTable("table_name")

出现报错,提示:

swift 复制代码
org.apache.spark.sql.AnalysisException: The format of the existing table xxx is `HiveFileFormat`. It doesn't match the specified format `ParquetFileFormat`.

提示我们写入 hive 的 fileformat 不对。

这个报错在 spark 1.x 版本不会报错,在 spark 2.x 版本开始出现。

解决方案

  1. 如果我们的 hive 表不是分区表。将format("parquet")改成 format("hive")即可。

将format设置为Hive以后,无论hive建表的时候,使用的fileformat使用的是哪一种,都没有关系。

  1. 如果我们的 hive 表是分区表,可以先将数据存到一个临时表,再调用 spark.sql 插入数据。
python 复制代码
        df = spark.createDataFrame(data, ["a", "b", "c", "ctime"])
        df.createOrReplaceTempView("temp_view")
        spark.sql("""
        INSERT INTO $hive_table_name PARTITION (date = '{}')
        select * from temp_view
        """.format(date))
相关推荐
小白学大数据7 小时前
Scrapling:极简高效的 Python 智能爬虫框架
开发语言·爬虫·python·数据分析
辣椒思密达7 小时前
Python爬虫中如何正确配置住宅IP代理?新手避坑指南
c语言·python
ZhiqianXia7 小时前
流畅的Python笔记
笔记·python
财经资讯数据_灵砚智能7 小时前
基于全球经济类多源新闻的NLP情感分析与数据可视化(夜间-次晨)2026年5月20日
人工智能·python·信息可视化·自然语言处理·ai编程·灵砚智能
布吉岛的石头7 小时前
Java 程序员第 18 阶段:实战Agent工作流:Java搭建自动化业务智能体
java·python·自动化
Jurio.7 小时前
使用.py脚本下载并加载开源大模型LLMs
python·ai·llama
张哈大7 小时前
解密Function Calling:AI Agent工具调用的标准化核心
人工智能·python·ai
子榆.8 小时前
CANN ATC编译器:模型从Python到达芬奇指令走了多远
开发语言·python·neo4j
lookaroundd8 小时前
llm-compressor 普通量化调用链分析
python·算法
Loo国昌8 小时前
从 Agent 编排到 Skill Runtime:企业 AI 工程化的下一层抽象
大数据·人工智能·后端·python·自然语言处理