Question

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

Was it helpful?

Solution

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

The syntax is CREATE TEMPORARY TABLE TABLE_NAME_HERE (key string, value string)

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.

The steps would be:

  1. Create Table
  2. Fill Table: INSERT OVERWRITE TABLE temptbl <select_query>
  3. Run query

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...

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top