将 Spark 数据帧保存到 Hive:表不可读,因为“镶木地板不是 SequenceFile" [英] save Spark dataframe to Hive: table not readable because "parquet not a SequenceFile"
问题描述
我想使用 PySpark 将 Spark (v 1.3.0) 数据帧中的数据保存到 Hive 表中.
I'd like to save data in a Spark (v 1.3.0) dataframe to a Hive table using PySpark.
文档 指出:
spark.sql.hive.convertMetastoreParquet:当设置为 false 时,Spark SQL 将使用 Hive SerDe 来处理拼花表而不是内置支持."
"spark.sql.hive.convertMetastoreParquet: When set to false, Spark SQL will use the Hive SerDe for parquet tables instead of the built in support."
查看 Spark 教程,似乎可以设置此属性:
Looking at the Spark tutorial, is seems that this property can be set:
from pyspark.sql import HiveContext
sqlContext = HiveContext(sc)
sqlContext.sql("SET spark.sql.hive.convertMetastoreParquet=false")
# code to create dataframe
my_dataframe.saveAsTable("my_dataframe")
但是,当我尝试在 Hive 中查询保存的表时,它返回:
However, when I try to query the saved table in Hive it returns:
hive> select * from my_dataframe;
OK
Failed with exception java.io.IOException:java.io.IOException:
hdfs://hadoop01.woolford.io:8020/user/hive/warehouse/my_dataframe/part-r-00001.parquet
not a SequenceFile
如何保存表格以便在 Hive 中立即可读?
How do I save the table so that it's immediately readable in Hive?
推荐答案
我去过那里...
API 在这方面有点误导.DataFrame.saveAsTable
不会创建 Hive 表,而是创建内部 Spark 表源.
它还会将一些内容存储到 Hive Metastore 中,但不是您想要的.
这个 备注 是由 spark-user 邮件列表中关于 Spark 1.3 的.
I've been there...
The API is kinda misleading on this one.
DataFrame.saveAsTable
does not create a Hive table, but an internal Spark table source.
It also stores something into Hive metastore, but not what you intend.
This remark was made by spark-user mailing list regarding Spark 1.3.
如果你想从 Spark 创建一个 Hive 表,你可以使用这种方法:
1. 使用 Create Table ...
通过 SparkSQL for Hive Metastore.
2.对实际数据使用DataFrame.insertInto(tableName, overwriteMode)
(Spark 1.3)
If you wish to create a Hive table from Spark, you can use this approach:
1. Use Create Table ...
via SparkSQL for Hive metastore.
2. Use DataFrame.insertInto(tableName, overwriteMode)
for the actual data (Spark 1.3)
这篇关于将 Spark 数据帧保存到 Hive:表不可读,因为“镶木地板不是 SequenceFile"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!