Confusion with the external tables in hive

前端 未结 1 817
抹茶落季
抹茶落季 2021-01-24 17:39

I have created the hive external table using below command:

 use hive2;

create external table depTable (depId int comment \'This is the unique id for each dep\'         


        
相关标签:
1条回答
  • 2021-01-24 18:32

    The main difference between EXTERNAL and MANAGED tables is in Drop table/partition behavior. When you drop MANAGED table/partition, the location with data files also removed. When you drop EXTERNAL table, the location with data files remains as is.

    UPDATE: TBLPROPERTIES ("external.table.purge"="true") in release 4.0.0+ (HIVE-19981) when set on external table would delete the data as well.

    EXTERNAL table as well as MANAGED is being stored in the location specified in DDL. You can create table on top of existing location with data files already in the location and it will work for both EXTERNAL or MANAGED, does not matter.

    You even can create both EXTERNAL and MANAGED tables on top of the same location, see this answer with more details and tests: https://stackoverflow.com/a/54038932/2700344

    If you specified location, the data will be stored in that location for both types of tables. If you did not specify location, the data will be in default location: /user/hive/warehouse/database_name.db/table_name for both managed and external tables.

    See also official Hive docs on Managed vs External Tables

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