Data exchange – EXPORT and IMPORT
When working with Hive, sometimes we need to migrate data among different environments. Or we may need to back up some data. Since Hive 0.8.0, EXPORT
and
IMPORT
statements are available to support the import and export of data in HDFS for data migration or backup/restore purposes.
The EXPORT
statement will export both data and metadata from a table or partition. Metadata is exported in a file called _metadata
. Data is exported in a subdirectory called data:
jdbc:hive2://> EXPORT TABLE employee TO '/user/dayongd/output3'; No rows affected (0.19 seconds)
After EXPORT
, we can manually copy the exported files to other Hive instances or use Hadoop distcp
commands to copy to other HDFS clusters. Then, we can import the data in the following manner:
Import data to a table with the same name. It throws an error if the table exists:
jdbc:hive2://> IMPORT FROM '/user/dayongd/output3'; Error: Error while compiling statement: FAILED: SemanticException [Error 10119...