Hive 批量数据迁移

测试环境
HDP 2.6.2 到 HDP 2.5.0
hdfs 2.7.3 到 hdfs 2.7.1
两个集群都没有启用kerberos以及ranger权限
1. 通过hive export/import 迁移数据
1.1 导出hive表数据
beeline -u "jdbc:hive2://dc2.xx.com:2181,dc3.xx.com:2181,dc4.xx.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2" -n "hive"
export table customer to '/tmp/export/customer' ;
1.2 采用distcp把文件夹导出到目标系统
hadoop distcp hdfs://dc1.xx.com:8020/tmp/export/ hdfs://dc2.xx.com:8020/tmp/export
1.3 在目标系统中把表导入
beeline -u "jdbc:hive2://dc2.xx.com:2181,amb03.v120.ubuntu:2181,amb02.v120.ubuntu:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2" -n "hive"
import from '/tmp/export/customer';
import table ds_customer from '/tmp/export/customer';
1.4 特殊表导入导出
1.4.1 导出整个分区表
源端 hive beeline 
export table saleslineitem_orc to '/tmp/export/saleslineitem_orc' ;
export table saleslineitem_parquet to '/tmp/export/saleslineitem_parquet' ;
同步数据
hadoop distcp hdfs://dc1.xx.com:8020/tmp/export/ hdfs://dc2.xx.com:8020/tmp/export
目标端
import from '/tmp/export/saleslineitem_orc';
import from '/tmp/export/saleslineitem_parquet';
检查
show tables;
show partitions saleslineitem_orc ;
1.4.2 导出一个分区并导入到指定分区
目标端执行
export table saleslineitem_orc partition(dt='20171216') to '/tmp/export/saleslineitem_orc_dt_20171216' ;
同步数据
hadoop distcp hdfs://dc1.xx.com:8020/tmp/export/ hdfs://dc2.xx.com:8020/tmp/export
目标端执行
alter table saleslineitem_orc drop partition(dt='20171216');
import from '/tmp/export/saleslineitem_orc_dt_20171216'


注意事项: 
1. 目标分区必须不存在
2. 不能把导出得分区导入到其他分区,例如导出得是 dt='20171216' 分区数据,不能使用 import table saleslineitem_orc partition(dt='20171215') from '/tmp/export/saleslineitem_orc_dt_20171216' 导入到201715分区中


2. 通过distcp 命令导出到目标集群,然后建立表
此出省略
3. 总结
可以使用hive export/import 进行hive数据的批量迁移,本实验测试了text,orc,parquet,分区表,并测试了不同版本的导入导出。理论上hive导入导出的数据迁移不受版本,数据格式以及表的限制,可以得出结论可以适应hive export/import进行任何hive数据的迁移


4. 使用脚本
create table if not exists proc.saleslineitem (
saleslineitemid int,
productid int,
customerid int,
quantity int,
extendedamount float ,
transactiondate timestamp
)
comment 'saleslineitem information'
row format delimited
fields terminated by '|'
lines terminated by '\n'
stored as textfile;


load data inpath '/tmp/saleslineitem.txt' overwrite into table proc.saleslineitem;


create table if not exists proc.saleslineitem_orc (
saleslineitemid int,
productid int,
customerid int,
quantity int,
extendedamount float ,
transactiondate timestamp
) partitioned by (dt string)
stored as orc;


create table if not exists proc.saleslineitem_parquet (
saleslineitemid int,
productid int,
customerid int,
quantity int,
extendedamount float ,
transactiondate timestamp
) partitioned by (dt string)
stored as parquet;


insert overwrite table proc.saleslineitem_orc partition(dt='20171216') select * from saleslineitem;
insert overwrite table proc.saleslineitem_orc partition(dt='20171217') select * from saleslineitem;
insert overwrite table proc.saleslineitem_orc partition(dt='20171218') select * from saleslineitem;


show partitions saleslineitem_orc
set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nostrick;


insert overwrite table proc.saleslineitem_parquet partition(dt) select * from proc.saleslineitem_orc;

### 回答1: datax是一个开源的数据传输工具,用于将数据从不同的数据源传输到目标数据仓库,其中包括将数据迁移Hive中。 在数据迁移过程中,datax提供了多种方式来覆盖更新数据Hive。其中最常用的是使用增量更新策略。增量更新是指仅将源数据中发生变化的部分传输到目标数据仓库中,以减少数据传输的时间和成本。 在使用datax进行增量更新时,需要设置一个增量字段,用于判断数据是否发生变化。常用的增量字段可以是时间戳或者是递增的ID。datax会周期性地检查源数据的增量字段,然后将发生变化的数据传输到Hive中。 除了增量更新,datax还支持全量更新和覆盖更新两种方式。全量更新是指将整个源数据重新传输到目标数据仓库中,适用于源数据量不大的情况。而覆盖更新是指每次传输数据时先清空目标数据仓库中的数据,然后再传输新的数据,适用于整个数据集都需要更新的情况。 总的来说,datax提供了多种方式来覆盖更新迁移数据Hive,可以根据具体的需求和数据量选择合适的更新策略。无论是增量更新、全量更新还是覆盖更新,都可以通过datax来实现数据的高效传输和迁移。 ### 回答2: DataX是一种开源的数据迁移工具,它可以用于将数据从不同的数据迁移Hive中。Hive是一种大数据处理框架,它提供了类似于SQL的查询语言,用于查询和分析存储在Hadoop集群上的大规模数据。 当我们使用DataX进行数据迁移时,首先需要配置数据源和目标源的连接信息。例如,我们可以配置数据源为关系型数据库(如MySQL、Oracle等)或其他数据存储系统,而目标源可以是Hive。 配置完成后,我们还需要指定数据源和目标源的表结构信息,以及数据的映射关系。这包括指定源表和目标表的名称、列名、数据类型等信息,以确保数据能够正确地迁移Hive中。 在数据迁移过程中,DataX会读取源表的数据,并将其转换成Hive表的格式。这包括将数据分割成小批量的文件,并按照Hive的分区规则进行存储。同时,DataX还支持数据转换和过滤操作,以允许我们在迁移过程中对数据进行清洗和加工。 一旦数据迁移完成,我们就可以使用Hive来进行数据的查询和分析了。Hive提供了类似于SQL的查询语言,这使得数据分析师和开发人员可以轻松地使用已迁移数据进行各种复杂的数据操作。 总而言之,DataX是一个强大的数据迁移工具,它可以帮助我们将数据从不同数据迁移Hive中。通过使用DataX,我们可以轻松地实现数据的覆盖更新,以及在Hive上进行数据分析和查询的需求。 ### 回答3: datax是一个开源的数据迁移工具,可以方便地将数据从不同的数据迁移Hive中。它支持各种数据源和目标格式,如关系型数据库、文件系统、NoSQL数据库等。通过使用datax,可以实现数据的覆盖更新和迁移。 首先,我们需要编写一个datax作业配置文件,指定数据源和目标表的信息。在配置文件中,我们可以指定源数据和目标表的连接信息,以及数据的映射关系、字段转换和过滤条件等。通过这些配置,datax能够准确地将数据从源数据迁移Hive中。 对于数据的覆盖更新,我们可以在配置文件中指定覆盖模式。这样,当我们运行datax作业时,它会根据覆盖模式来更新数据。例如,我们可以选择全表覆盖模式,即删除目标表中的数据,然后将源数据插入到目标表中;或者选择增量覆盖模式,即根据主键或唯一键来判断是否更新数据。 在数据迁移过程中,datax会按照配置文件中的设置,将数据从源数据源读取出来,并按照映射关系进行转换和过滤。然后,datax会将转换后的数据写入到Hive表中。在写入过程中,datax会根据配置文件中的覆盖模式进行相应的操作,确保数据的准确性和完整性。 总之,通过使用datax,我们可以方便地将数据从各种数据迁移Hive中,并实现数据的覆盖更新。无论是全表覆盖还是增量覆盖,datax都能够提供灵活而高效的数据迁移解决方案。同时,datax还支持分布式部署和任务调度等功能,可以满足大规模数据迁移和更新的需求。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值