问题描述
限时送ChatGPT账号..是否可以将 spark 中的 DataFrame
直接保存到 Hive?
Is it possible to save DataFrame
in spark directly to Hive?
我尝试将 DataFrame
转换为 Rdd
,然后保存为文本文件,然后加载到 hive 中.但是我想知道是否可以直接将 dataframe
保存到 hive
I have tried with converting DataFrame
to Rdd
and then saving as a text file and then loading in hive. But I am wondering if I can directly save dataframe
to hive
推荐答案
您可以使用 sqlContext 创建一个内存中的临时表并将它们存储在 hive 表中.
You can create an in-memory temporary table and store them in hive table using sqlContext.
假设您的数据框是 myDf.您可以使用,
Lets say your data frame is myDf. You can create one temporary table using,
myDf.createOrReplaceTempView("mytempTable")
然后您可以使用简单的 hive 语句来创建表并从临时表中转储数据.
Then you can use a simple hive statement to create table and dump the data from your temp table.
sqlContext.sql("create table mytable as select * from mytempTable");
这篇关于如何将 DataFrame 直接保存到 Hive?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论