首页 文章

在创建或插入带有Spark分区的Hive表时,不允许操作

提问于
浏览
1

我正在使用Spark 2.2,我正在尝试基于数据框创建一个Hive表 .

我只能使用以下数据创建一个包含数据的新Hive表:

result.write.mode(SaveMode.Overwrite).saveAsTable("db.resultTable")

当我尝试对分区执行相同操作时:

result.write.mode(SaveMode.Overwrite).partitionBy("year", "month", "day").saveAsTable("db.resultTable")

我总是得到错误:

Exception in thread "main" org.apache.spark.sql.AnalysisException: Operation not allowed: ALTER TABLE RECOVER PARTITIONS only works on table with location provided: `db`.`resultTable`;

Note: 尽管错误,它创建了一个包含正确列的表 . 它还创建了分区,表中有一个包含Parquet文件的位置(/user/hive/warehouse/db.db/resultTable/year=2017/month=1/day=1) . 但它包含 no 数据 .

我试着找一些答案,但还没找到 . 根据这个thread,我做的一切都很好 . (我还设置了hive.exec.dynamic.partition和hive.exec.dynamic.partition.mode)

有人知道我错过了什么或做错了吗?

1 回答

  • 0

    不要将其另存为表,而是将其另存为HDFS目录中的文件 .

    result.write.mode(SaveMode.Overwrite).partitionBy("year", "month", "day").parquet("/path/to/table")
    

相关问题