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'; |

相关推荐
一张假钞5 小时前
Spark SQL读写Hive Table部署
hive·sql·spark
想做富婆6 小时前
Hive:窗口函数[ntile, first_value,row_number() ,rank(),dens_rank()]和自定义函数
数据仓库·hive·hadoop
好记性+烂笔头13 小时前
4 Hadoop 面试真题
大数据·hadoop·面试
B站计算机毕业设计超人1 天前
计算机毕业设计Python+CNN卷积神经网络考研院校推荐系统 考研分数线预测 考研推荐系统 考研爬虫 考研大数据 Hadoop 大数据毕设 机器学习
hadoop·python·机器学习·spark·网络爬虫·课程设计·数据可视化
字节全栈_rJF2 天前
Hive 整合 Spark 全教程 (Hive on Spark)
hive·hadoop·spark
好记性+烂笔头2 天前
2 MapReduce
大数据·hadoop·mapreduce
字节全栈_ZKt2 天前
Hadoop集群中Hbase的介绍、安装、使用_root@master001 hadoop]# start-hbase
大数据·hadoop·hbase
一张假钞2 天前
Sqoop源码修改:增加落地HDFS文件数与MapTask数量一致性检查
java·hadoop·hdfs·sqoop
weixin_307779132 天前
设计转换Apache Hive的HQL语句为Snowflake SQL语句的Python程序方法
数据仓库·hive·python·sql
想做富婆2 天前
Hive:窗口函数(1)
数据仓库·hive·hadoop