Hive-Import/Export(导入导出)

15 篇文章 7 订阅
10 篇文章 6 订阅

1 官方地址

  • Hive 0.8.0 之后引入了EXPORT and IMPORT 命令。

    1. EXPORT命令将表或分区的数据连同元数据一起导出到指定的输出位置(HDFS上)。然后可以将此输出位置移至不同的Hadoop或Hive实例,并使用IMPORT命令进行导入操作。
    2. 导出分区表时,原始数据可能位于不同的HDFS位置。还支持导出/导入分区子集的功能。
    3. 导出的元数据存储在目标目录中,数据文件存储在子目录中。
    4. EXPORT和IMPORT命令独立于所使用的源和目标Metastore DBMS工作;例如,它们可以在Derby和MySQL数据库之间使用。

2 EXPORT

  • 官方语法
EXPORT TABLE tablename [PARTITION (part_column="value"[, ...])]
  TO 'export_target_path' [ FOR replication('eventid') ]
  • 将数据导出到HDFS
 export table join_a to '/home/hadoop/data';
Copying data from file:/tmp/hadoop/b96064b0-888a-4618-a110-fc9d09d7c00b/hive_2018-01-10_08-05-04_501_1397817648848080864-1/-local-10000/_metadata
Copying file: file:/tmp/hadoop/b96064b0-888a-4618-a110-fc9d09d7c00b/hive_2018-01-10_08-05-04_501_1397817648848080864-1/-local-10000/_metadata
Copying data from hdfs://192.168.137.200:9000/user/hive/warehouse/join_a
Copying file: hdfs://192.168.137.200:9000/user/hive/warehouse/join_a/join_a.txt
OK
  • 查看HDFS上的数据
[hadoop@zydatahadoop001 export]$ hdfs dfs -ls /home/hadoop/data
Found 2 items
-rwxr-xr-x   1 hadoop supergroup       1259 2018-01-10 08:05 /home/hadoop/data/_metadata
drwxr-xr-x   - hadoop supergroup          0 2018-01-10 08:05 /home/hadoop/data/data
3 IMPORT
  • 官方语法
IMPORT [[EXTERNAL] TABLE new_or_original_tablename [PARTITION (part_column="value"[, ...])]]
  FROM 'source_path'
  [LOCATION 'import_target_path']
  • 导入数据
hive> import from '/home/hadoop/data';
Copying data from hdfs://192.168.137.200:9000/home/hadoop/data/data
Copying file: hdfs://192.168.137.200:9000/home/hadoop/data/data/join_a.txt
Loading data to table hive1.join_a
OK
Time taken: 7.444 seconds
  • 查询
hive> show tables;
OK
join_a

hive> select * from join_a;
OK
1       zhangsan
2       lisi
3       wangwu1
4 其他例子
  • Rename table on import:(重命名表名)
export table department to 'hdfs_exports_location/department';
import table imported_dept from 'hdfs_exports_location/department';
  • Export partition and import:(导出加上分区)
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:(导入加上分区)
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:(指定地址)
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:
export table department to 'hdfs_exports_location/department';
import external table department from 'hdfs_exports_location/department';
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值