Export and Import a Hive Table/Partition

EXPORT

We use EXPORT command to export data of a table or partition into a specified output location. The EXPORT command exports the metadata along-with the data at the output location.

EXPORT a table :-

EXPORT table employee to '/home/hadoop/employee';

EXPORT a partition :-

EXPORT table employee partition(department='BIGDATA') to '/home/hadoop/employee_bigdata';

IMPORT

The IMPORT command can then be used to import the table/partition, along-with data, from the exported directory into another Hive database/instance.

IMPORT a table:-

#Maintain the exported table name 
IMPORT from '/home/hadoop/employee';

#Change the table name on Import
IMPORT table employee_new from '/home/hadoop/employee';

#Import as external table
IMPORT external table employee_new_ext from '/home/hadoop/employee';

IMPORT a partition:-

#Maintain the exported table name
IMPORT from '/home/hadoop/employee_bigdata';

#Change the table name on import, we can not change the partition name
IMPORT table employee_par from '/home/hadoop/employee_bigdata';
OR
IMPORT table employee_par partition(department='BIGDATA') from '/home/hadoop/employee_bigdata';

#Import as external table
IMPORT external table employee_par_ext from '/home/hadoop/employee_bigdata';
OR
IMPORT external table employee_par_ext partition(department='BIGDATA') from '/home/hadoop/employee_bigdata';

 

Leave a Reply

Your email address will not be published. Required fields are marked *