-
Notifications
You must be signed in to change notification settings - Fork 64
hive_data_transfer_udtf
这是Hive的一个UDTF,可以实现将hive上的数据导入到MaxCompute的表中。
odps.conf配置:
access_id#xxxxxxxxxxxxxx
access_key#xxxxxxxxxxxxxxxxxx
project_name#xxxxxxxxxxxxxxx
odps_endpoint#xxxxxxxxxxxxxxx
tunnel_endpoint#xxxxxxxxxxxxx
(1)添加资源和创建函数
add jar ./odps_data_dumper-2.0.2-jar-with-dependencies.jar;
add file ./odps.conf;
create temporary function odps_data_dump as 'odps.data.dump.MaxComputeDataTransferUDTF';
(2)odps_data_dump参数说明:
-
固定参数: 第一个: 表名 第二个:分区,形式为a=1,b=2,非分区表置空 第三个:列名,支持列裁剪,指定多个列名 , 如导入a,b,c三列,就将三个列的列名写上,逗号分隔
-
不定参数: 从第四个开始的参数是不定参数,但是要和第三个参数指定的列名相匹配,即第三个参数指定了多少个列,后面就给这几个列的参数。
(3)用法示例:
select odps_data_dump('test_part', 'pta=1,ptb=1', 'a,c', a, c ) from hive_test_part where pta=1 and ptb = 1;
就是将hive表hive_test_part的pta=1,ptb=1分区的数据a,c两列导入到odps的表test_part对应的分区中。
(1)添加资源和创建函数 add jar ./odps_data_dumper-xxx.xxx.jar; add file ./odps.conf; create temporary function odps_data_dump as 'odps.data.dump.MaxComputeDataTransferUDTFMultiPart';
(2)odps_data_dump参数说明:
-
固定参数: 第一个:表名 第二个: 列名list,支持列裁剪,指定多个列名 , 如导入a,b,c三列,就将三个列的列名写上,逗号分隔 第三个:分区名list,逗号分隔
-
不定参数: 从第四个开始的参数是不定参数,但是要和第二,三个参数指定的列名相匹配,即第二,三个参数指定了多少个列,后面就给这几个列的参数。
(3)用法示例: select odps_data_dump('test_part', 'a,c', 'pta,ptb', a, c, pta, ptb) from hive_test_part; 就是将hive表hive_test_part的所有分区的数据a,c两列导入到odps的表test_part对应的分区中。
使用导入函数前,要先将odps这边对应的分区建立好。
(1)为表test_part增加一个分区: alter table test_part add partition (pta='1', ptb='1');
(2)删除表test_part的分区和数据: ALTER TABLE test_part DROP PARTITION(pta='1', ptb='1') PURGE;