在hive-0.8.0后引入了import/export命令。工具
Export命令能够导出一张表或分区的数据和元数据信息到一个输出位置,而且导出数据能够被移动到另外一个hadoop集群或hive实例,而且能够经过import命令导入数据。oop
当导出一个分区表,原始数据可能在hdfs的不一样位置,export/import命令也支持导出分区表的不一样子分区。对象
导出的元数据存储在目标目录,而且数据文件是存储在不一样的子目录下。hadoop
Export/import命令能够独立工做在使用存储元数据的rdbms中。get
1、语法it
Export语法:io
EXPORT TABLE tablename [PARTITION (part_column="value"[, ...])]event TO 'export_target_path' [ FOR replication('eventid') ]table |
Import语法:ast
IMPORT [[EXTERNAL] TABLE new_or_original_tablename [PARTITION (part_column="value"[, ...])]] FROM 'source_path' [LOCATION 'import_target_path'] |
2、使用复制:
Export/import命令当在复制环境中使用时略有不一样,而且肯定使用该工具在两个数据仓库之间使用复制。在大多数状况下,用户不须要使用这个附加功能,除非手动引导仓库之间的复制,这样它能够做为一个增量复制工具。
他们使用一个特殊的表属性“repl.last.id”在一个表或分区对象中,确保export/import工具每次复制的数据时最近更新的数据。在导出完成后,会对export的dump文件使用一个id打一个复制标签,表示在源仓库集成商单调递增的。此外,为复制导出打印的标记不会致使错误若是试图导出一个对象可是标记列当前不存在。
在import方面,没有语法变化,可是import有一个通常性的标签对于复制的dump文件,他讲检查要复制的对象是否存在,若是对象已经存在,它检查对象的repl.last.id属性,肯定是否导入当前对象的最新数据对于目标仓库,若是更新是最新的,那么它将复制最新的信息,若是更新已是很旧的了对于已经存在的对象,那么更新将被忽略,而且不会产生错误。
对于那些使用export进行首次手动引导用例,用户推荐使用“引导”标签,
3、示例
一、简单导入和导出
export table department to 'hdfs_exports_location/department'; import from 'hdfs_exports_location/department'; |
二、在import时重命名表
export table department to 'hdfs_exports_location/department'; import table imported_dept from 'hdfs_exports_location/department'; |
三、导出分区而且导入
export table employee partition (emp_country="in", emp_state="ka") to 'hdfs_exports_location/employee'; import from 'hdfs_exports_location/employee'; |
四、导出表而且导入到分区表分区
export table employee to 'hdfs_exports_location/employee'; import table employee partition (emp_country="us", emp_state="tn") from 'hdfs_exports_location/employee'; |
五、指定导入位置
export table department to 'hdfs_exports_location/department'; import table department from 'hdfs_exports_location/department' location 'import_target_location/department'; |
六、导入做为一个外部表
export table department to 'hdfs_exports_location/department'; import external table department from 'hdfs_exports_location/department'; |