我有一个 Spark 数据框,我想将它保存为带有分区的 Hive 表。我尝试了以下两个语句,但它们不起作用。我在 HDFS 目录中没有看到任何 ORC 文件,它是空的。我可以看到 baseTable 在 Hive 控制台中,但显然它是空的,因为 HDFS 中没有文件。
以下两行saveAsTable()
和 insertInto()
不工作。 registerDataFrameAsTable() 方法有效,但它在内存表中创建并在我的用例中导致 OOM,因为我有数千个 Hive 分区要处理。我是 Spark 的新手。
dataFrame.write().mode(SaveMode.Append).partitionBy("entity","date").format("orc").saveAsTable("baseTable");
dataFrame.write().mode(SaveMode.Append).format("orc").partitionBy("entity","date").insertInto("baseTable");
//the following works but creates in memory table and seems to be reason for OOM in my case
hiveContext.registerDataFrameAsTable(dataFrame, "baseTable");
最佳答案
希望你已经得到你的答案,但发布这个答案供其他人引用,partitionBy 仅支持 Parquet 直到 Spark 1.4,在 1.5+ 版本中添加了对 ORC、JSON、text 和 avro 的支持,请参阅下面的文档
https://spark.apache.org/docs/1.6.1/api/java/org/apache/spark/sql/DataFrameWriter.html
关于apache-spark - Spark DataFrame saveAsTable with partitionBy 在 HDFS 中不创建 ORC 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32362206/