本文介绍了在Hive中创建临时表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hive是否支持临时表?我在apache文档中找不到它.

Does Hive support temporary tables? I can't find it in the apache docs.

推荐答案

自Hive 0.14.0起从Hive 0.14.0开始,支持临时表 https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-TemporaryTables
链接到JIRA: https://issues.apache.org/jira/browse/HIVE- 7090

As of Hive 0.14.0 Thanks to @hwrdprkns for commenting. As of Hive 0.14.0 there is support for temporary tables https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-TemporaryTables
Link to the JIRA: https://issues.apache.org/jira/browse/HIVE-7090

语法为CREATE TEMPORARY TABLE TABLE_NAME_HERE (key string, value string)

Pre Hive 0.14.0
我不认为Hive具有与SQL Server类似的临时表.不过,您可以使用Hive进行临时表之类的操作.

Pre Hive 0.14.0
I don't think Hive has temporary tables the same as something like SQL Server does. You can do something like temporary tables with Hive though.

如果使用临时表所需的架构创建表,然后在运行需要数据的查询之前进行查询以填充该表,它将像临时表一样工作.

If you create a table with the schema your temporary table needs, then do a query populating the table before you run the query needing the data, it will act like a temporary table.

步骤将是:

  1. 创建表
  2. 填充表:INSERT OVERWRITE TABLE temptbl <select_query>
  3. 运行查询

运行查询时,可以像使用其他任何表一样使用temptbl. INSERT OVERWRITE将覆盖表中的所有数据,因此仅填充该运行中的数据.数据仍然存在,因此,如果您在不重新填充表的情况下重复使用该表,那么您将使用上一次运行的数据.

When you run your query you can use temptbl like any other table. The INSERT OVERWRITE will overwrite all data in the table so it will only be populated with data for that run. The data persists, so if you re-use the table without re-populating it, you will be using the data from whatever the last run was.

如果同时需要相同的表但对于不同的数据,肯定会遇到问题...

This can definitely run into issues if the same table will be needed at the same time but for different data...

根据我的发现,这是目前Hive中临时"表的唯一解决方案.

From what I've been able to find, this is the only solution to a 'temporary' table in Hive right now.

这篇关于在Hive中创建临时表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 15:47