如何将 DataFrame 直接保存到 Hive?

编程入门 行业动态 更新时间:2024-10-26 19:24:57
本文介绍了如何将 DataFrame 直接保存到 Hive?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-19 01:28:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/951986.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   DataFrame   Hive

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!