这是对将火花数据作为动态分区表保存在蜂巢中的跟进。我试着在答案中使用建议,但无法在Spark1.6.1中工作。
我正在尝试以编程方式从“`DataFrame”创建分区。以下是相关代码(改编自火花测试):
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总是创建带有空分区的表。
任何帮助,以推动这一点是值得感谢的。
编辑:还创建了火花-14927
发布于 2016-04-27 00:29:35
我找到了一个解决办法:如果预先创建表,那么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中无效。
https://stackoverflow.com/questions/36873678
复制相似问题