Hive之import和export使用详解

在hive-0.8.0后引入了import/export命令。

Export命令可以导出一张表或分区的数据和元数据信息到一个输出位置,并且导出数据可以被移动到另一个hadoop集群或hive实例,并且可以通过import命令导入数据。

当导出一个分区表,原始数据可能在hdfs的不同位置,export/import命令也支持导出分区表的不同子分区。

导出的元数据存储在目标目录,并且数据文件是存储在不同的子目录下。

Export/import命令可以独立工作在使用存储元数据的rdbms中。

一、语法

Export语法:

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

Import语法:

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

二、使用复制:

Export/import命令当在复制环境中使用时略有不同,并且确定使用该工具在两个数据仓库之间使用复制。在大多数情况下,用户不需要使用这个附加功能,除非手动引导仓库之间的复制,这样它可以作为一个增量复制工具。

他们使用一个特殊的表属性"repl.last.id"在一个表或分区对象中,确保export/import工具每次复制的数据时最近更新的数据。在导出完成后,会对export的dump文件使用一个id打一个复制标签,表示在源仓库集成商单调递增的。此外,为复制导出打印的标记不会导致错误如果试图导出一个对象但是标记列当前不存在。

在import方面,没有语法变化,但是import有一个一般性的标签对于复制的dump文件,他讲检查要复制的对象是否存在,如果对象已经存在,它检查对象的repl.last.id属性,确定是否导入当前对象的最新数据对于目标仓库,如果更新是最新的,那么它将复制最新的信息,如果更新已经是很旧的了对于已经存在的对象,那么更新将被忽略,并且不会产生错误。

对于那些使用export进行首次手动引导用例,用户推荐使用"引导"标签,

三、示例

1、简单导入和导出

|----------------------------------------------------------------------------------------------------------------|
| export table department to 'hdfs_exports_location/department'; import from 'hdfs_exports_location/department'; |

tablename?

2、在import时重命名表

|------------------------------------------------------------------------------------------------------------------------------------|
| export table department to 'hdfs_exports_location/department'; import table imported_dept from 'hdfs_exports_location/department'; |

3、导出分区并且导入

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

tablename?

4、导出表并且导入到分区表分区

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

5、指定导入位置

|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| export table department to 'hdfs_exports_location/department'; import table department from 'hdfs_exports_location/department' location 'import_target_location/department'; |

6、导入作为一个外部表

|------------------------------------------------------------------------------------------------------------------------------------------|
| export table department to 'hdfs_exports_location/department'; import external table department from 'hdfs_exports_location/department'; |

相关推荐
随心............1 天前
在开发过程中遇到问题如何解决,以及两个经典问题
hive·hadoop·spark
yumgpkpm1 天前
CMP (类ClouderaCDP7.3(404次编译) )华为鲲鹏Aarch64(ARM)信创环境 查询2100w行 hive 查询策略
数据库·数据仓库·hive·hadoop·flink·mapreduce·big data
CoookeCola2 天前
MovieNet(A holistic dataset for movie understanding) :面向电影理解的多模态综合数据集与工具链
数据仓库·人工智能·目标检测·计算机视觉·数据挖掘
K_i1342 天前
Hadoop 集群自动化运维实战
运维·hadoop·自动化
Q26433650232 天前
【有源码】基于Python与Spark的火锅店数据可视化分析系统-基于机器学习的火锅店综合竞争力评估与可视化分析-基于用户画像聚类的火锅店市场细分与可视化研究
大数据·hadoop·python·机器学习·数据分析·spark·毕业设计
想ai抽3 天前
深入starrocks-多列联合统计一致性探查与策略(YY一下)
java·数据库·数据仓库
starfalling10243 天前
【hive】一种高效增量表的实现
hive
顧棟3 天前
【Yarn实战】Yarn 2.9.1滚动升级到3.4.1调研与实践验证
hadoop·yarn
D明明就是我3 天前
Hive 拉链表
数据仓库·hive·hadoop
嘉禾望岗5033 天前
hive join优化和数据倾斜处理
数据仓库·hive·hadoop