Create temporary table in Hive?

前端 未结 1 1842
一个人的身影
一个人的身影 2021-02-07 01:07

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

1条回答
  •  长情又很酷
    2021-02-07 01:35

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

    0 讨论(0)
提交回复
热议问题