Temporary Tables
Temporary tables are supported in Hive 0.14 and later. A temporary table is a convenient
way for an application to automatically manage intermediate data generated during a complex
query. Rather than manually deleting tables needed only as temporary data in a complex
query, Hive automatically deletes all temporary tables at the end of the Hive session in
which they are created. The data in these tables is stored in the user's scratch directory
rather than in the Hive warehouse directory. The scratch directory effectively acts as the
data sandbox for a user, located by default in
/tmp/hive-<username>
.
Tip | |
---|---|
See Apache Hive AdminManual Configuration for information about configuration to use a non-default scratch directory. |
Hive users create temporary tables using the TEMPORARY
keyword:
CREATE TEMPORARY TABLE tmp1 (c1 string); CREATE TEMPORARY TABLE tmp2 AS ... CREATE TEMPORARY TABLE tmp3 LIKE ...
Multiple Hive users can create multiple Hive temporary tables with the same name because each table resides in a separate session.
Temporary tables support most table options, but not all. The following features are not supported:
Partitioned columns
Indexes
Note | |
---|---|
A temporary table with the same name as a permanent table causes all references to that table name to resolve to the temporary table. The user cannot access the permanent table during that session without dropping or renaming the temporary table. |