如何将 DataFrame 直接保存到 Hive? [英] How to save DataFrame directly to Hive?

查看:50
本文介绍了如何将 DataFrame 直接保存到 Hive?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆