【问题标题】:Spark partitions: creating RDD partitions but not Hive partitionsSpark 分区:创建 RDD 分区但不创建 Hive 分区
【发布时间】:2016-04-26 19:06:51
【问题描述】:

这是对Save Spark dataframe as dynamic partitioned table in Hive 的跟进。我尝试在答案中使用建议,但无法在 Spark 1.6.1 中使用

我正在尝试从 `DataFrame.以下是相关代码(改编自 Spark 测试):

hc.setConf("hive.metastore.warehouse.dir", "tmp/tests")
//    hc.setConf("hive.exec.dynamic.partition", "true")
//    hc.setConf("hive.exec.dynamic.partition.mode", "nonstrict")
hc.sql("create database if not exists tmp")
hc.sql("drop table if exists tmp.partitiontest1")

Seq(2012 -> "a").toDF("year", "val")
  .write
  .partitionBy("year")
  .mode(SaveMode.Append)
  .saveAsTable("tmp.partitiontest1")
hc.sql("show partitions tmp.partitiontest1").show

完整文件在这里:https://gist.github.com/SashaOv/7c65f03a51c7e8f9c9e018cd42aa4c4a

已在文件系统上正常创建分区文件,但 Hive 抱怨表未分区:

======================
HIVE FAILURE OUTPUT
======================
SET hive.support.sql11.reserved.keywords=false
SET hive.metastore.warehouse.dir=tmp/tests
OK
OK
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Table tmp.partitiontest1 is not a partitioned table
======================

看起来根本原因是org.apache.spark.sql.hive.HiveMetastoreCatalog.newSparkSQLSpecificMetastoreTable 总是创建带有空分区的表。

感谢任何有助于推动这一进程的帮助。

编辑:还创建了SPARK-14927

【问题讨论】:

    标签: apache-spark dataframe hive partitioning


    【解决方案1】:

    我找到了一种解决方法:如果您预先创建表格,那么 saveAsTable() 就不会弄乱它。所以以下工作:

    hc.setConf("hive.metastore.warehouse.dir", "tmp/tests")
    //    hc.setConf("hive.exec.dynamic.partition", "true")
    //    hc.setConf("hive.exec.dynamic.partition.mode", "nonstrict")
    hc.sql("create database if not exists tmp")
    hc.sql("drop table if exists tmp.partitiontest1")
    
    // Added line:
    hc.sql("create table tmp.partitiontest1(val string) partitioned by (year int)")   
    
    
    Seq(2012 -> "a").toDF("year", "val")
      .write
      .partitionBy("year")
      .mode(SaveMode.Append)
      .saveAsTable("tmp.partitiontest1")
    hc.sql("show partitions tmp.partitiontest1").show
    

    此解决方法适用于 1.6.1,但不适用于 1.5.1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-07
      • 2019-07-08
      • 1970-01-01
      • 2023-04-04
      • 2020-09-29
      • 1970-01-01
      • 2022-10-05
      相关资源
      最近更新 更多