Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

Import/Export

Table of Contents
Info
titleVersion

The EXPORT and IMPORT commands were added in Hive 0.8.0 (see HIVE-1918).

Overview

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.

When exporting a partitioned table, the original data may be located in different HDFS locations. The ability to export/import a subset of the partition is also supported.

Exported metadata is stored in the target directory, and data files are stored in subdirectories.

The EXPORT and IMPORT commands work independently of the source and target metastore DBMS used; for example, they can be used between Derby and MySQL databases.

Export Syntax

Code Block
EXPORT TABLE tablename [PARTITION (part_column="value"[, ...])] 
  TO 'export_target_path'

Import Syntax

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

Examples

Simple export and import:

No Format
export table department to 'hdfs_exports_location/department';
import from 'hdfs_exports_location/department';

Rename table on import:

No Format
export table department to 'hdfs_exports_location/department';
import table imported_dept from 'hdfs_exports_location/department';

Export partition and import:

No Format
export table employee partition (emp_country="in", emp_state="ka") to 'hdfs_exports_location/employee';
import from 'hdfs_exports_location/employee';

Export table and import partition:

No Format
export table employee to 'hdfs_exports_location/employee';
import table employee partition (emp_country="us", emp_state="tn") from 'hdfs_exports_location/employee';

Specify the import location:

No Format
export table department to 'hdfs_exports_location/department';
import table department from 'hdfs_exports_location/department' 
       location 'import_target_location/department';

Import as an external table:

No Format
export table department to 'hdfs_exports_location/department';
import external table department from 'hdfs_exports_location/department';