hive export/import逻辑迁移命令简单梳理

具体语法如下

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

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

例1 简单表的导入导出:

hive
use test1;
export table emp to '/user/hive/warehouse/exp_emp';
exit;
hdfs dfs -ls /user/hive/warehouse/exp_emp
# 将表emp导出到hdfs的/user/hive/warehouse/exp_emp目录中
# 导出的数据包括"_metadata"和"data"两个文件
# 将该目录 hdfs dfs -get 下来
# 将该目录 hdfs dfs -put 到另外一套hadoop集群之上
# 当然实验的话也可以直接放到一个hadoop集群的另外的一个库上
hive
use test4;
show tables;
import from '/user/hive/warehouse/exp_emp';
show tables;
select * from test1.emp;
select * from test4.emp;

例2 简单表的导出改名导入:

hive
use test1;
export table emp to '/user/hive/warehouse/exp_emp';
exit;
hdfs dfs -ls /user/hive/warehouse/exp_emp

hive
use test4;
show tables;
import table rn_emp from '/user/hive/warehouse/exp_emp';
show tables;
select * from test1.emp;
select * from test4.emp;
select * from test4.rn_emp;

例3 分区表导入导出:

hive
use test1;
export table emp_partition 
 partition (deptno="10") 
 to '/user/hive/warehouse/exp_emp_part';
exit;

hive
use test4;
import from '/user/hive/warehouse/exp_emp_part';
select * from test1.emp_partition where deptno=10;
select * from test4.emp_partition;

例4 分区表导出,改名装入某个分区:

hive
use test1;
export table emp_partition
 to '/user/hive/warehouse/exp_emp_part_full';
exit;

hive
use test4;
import table emp_partition_rn partition (deptno="10")
  from '/user/hive/warehouse/exp_emp_part_full';
-- 这个地方做了改名和分区过滤之后的导入
select * from test1.emp_partition;
select * from test4.emp_partition_rn;

例5 分区表导出,改名装入某个分区并指定hdfs目录:

hive
use test1;
export table emp_partition
 to '/user/hive/warehouse/exp_emp_part_full';
exit;

hive
use test4;
import table emp_partition_rn2 partition (deptno="10")
  from '/user/hive/warehouse/exp_emp_part_full'
  location '/user/hive/warehouse/exp_emp_part_full_rn2';
-- 增加了location参数指定hdfs对应的目录

例6 内部表到外部表的导入导出转换:

hive
use test1;
export table emp to '/user/hive/warehouse/exp_emp_ext';
exit;

hive
use test4;
show tables;
import external table rn_emp from '/user/hive/warehouse/exp_emp_ext';

[TOC]

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值