Move Hive Table from One Cluster to Another

 This tutorial uses examples to describe how to move Hive table from one cluster to another.  The basic idea is to use the EXPORT and IMPORT commands. 

The EXPORT command exports the data of a table or partition, along with the metadata, into a specified output location. This output location can then be moved over to a different Hadoop or Hive instance and imported from there with the IMPORT command.

Export Syntax

EXPORT TABLE tablename [PARTITION (part_column="value"[, ...])]
  TO 'export_target_path' [ FOR replication('eventid') ]

Import Syntax

IMPORT [[EXTERNAL] TABLE new_or_original_tablename [PARTITION (part_column="value"[, ...])]]
  FROM 'source_path'
  [LOCATION 'import_target_path']

Examples to Move Hive Table from one cluster (grid) to another

Suppose you have two clusters : cluster A and cluster B. 

  1. On Cluster A, use EXPORT command to exports the data of a table or a partition, along with the metadata to a specified output location named hdfs_path_a;
  2. Use discp to copy the data in cluster A to cluster B.  e.g., discp hdfs_path_a hdfs_path_b
  3. On cluster B, use IMPORT command to import the data in hdfs_path_b to a new_table. 

The following code shows the process:

 

On Cluster A:

Copy the file to cluster B using discp:

On Cluster B:

Or rename the table:

Rename table on import:

Export partition and import:

Export table and import partition:

Specify the import location:

Import as an external table: