creating partition in external table in hive

后端 未结 4 1276

I have successfully created and added Dynamic partitions in an Internal table in hive. i.e. by using following steps:

1-created a sourc

4条回答
  •  南方客
    南方客 (楼主)
    2021-02-03 11:40

    Follow the below steps:

    1. Create a temporary table/Source table

      create table source_table(name string,age int,height int) row format delimited by ',';
      

      Use your delimiter as in the file instead of ',';

    2. Load data into the source table

      load data local inpath 'path/to/dataFile/in/HDFS';
      
    3. Create external table with partition

      create external table external_dynamic_partitions(name string,height int) 
      partitioned by (age int) 
      location 'path/to/dataFile/in/HDFS';
      
    4. Enable dynamic partition mode to nonstrict

      set hive.exec.dynamic.partition.mode=nonstrict
      
    5. Load data to external table with partitions from source file

      insert into table external_dynamic partition(age) 
      select * from source_table;
      

    That's it. You can check the partitions information using

    show partitions external_dynamic;
    

    You can even check if it is an external table or not using

    describe formatted external_dynamic;
    

    External table is a type of table in Hive where the data is not moved to the hive warehouse. That means even if U delete the table, the data still persists and you will always get the latest data, which is not the case with Managed table.

提交回复
热议问题