hive与Oracle数据库的相互同步

1、Oracle数据同步到hive

1.1 不是分区表,覆盖数据

sqoop import --connect jdbc:oracle:thin:@ip:1521/服务名--username 用户名--password 密码 --table LTE_CELL_HIGHTRAFFIC_PRE --num-mappers 1  --fields-terminated-by "|" --hive-import --hive-table wxwy.lte_cell_hightraffic_pre --hive-overwrite  --hive-drop-import-delims

1.2 分区表同步

    sqoop import --connect jdbc:oracle:thin:@ip:1521/服务名--username 用户名--password 密码--table LTE_CELL_HIGHTRAFFIC_PRE --num-mappers 1  --fields-terminated-by "|" --hive-import --hive-table wxwy.lte_cell_hightraffic_pre --target-dir /user/hive/warehouse/wxwy.db/lte_cell_hightraffic_pre/partitionday=20220213

同步完后会发现无法查询出数据,此时需要标记表的分区信息

alter table LTE_CELL_HIGHTRAFFIC_PRE add partition(partitionday='20220213') location '/user/hive/warehouse/wxwy.db/lte_cell_hightraffic_pre/partitionday=20220213'

数据验证
在这里插入图片描述2、Oracle同步到hive

 sqoop export \
 --connect jdbc:oracle:thin:@ip:1521/服务名--username 用户名 --password 密码\
 --table F_L_C_EUTRANCELLTDD_H \
 --columns \
 START_TIME,COLUMN1,COLUMN2,COLUMN3,EUTRANCELLTDD_UK ,COLUMN4,\
 COLUMN5,....COLUMNN \
 --fields-terminated-by "|" --update-key START_TIME,EUTRANCELLTDD_UK \
 --update-mode allowinsert --export-dir \
 /user/hive/warehouse/wxwy.db/f_l_c_eutrancelltdd_h/partitionday="20220213"/partitionhour="2022021310" \
 --num-mappers 8 --batch --input-null-string '\\N'  --input-null-non-string '\\N'\
 
为实现定时同步数据,定时脚本的配置信息
partitionday="$CustFunc:getTime(yyyyMMdd,-H2,partitionday)$"
partitionhour="$CustFunc:getTime(yyyyMMddHH,-H2,start_time)$"

注意:
–table F_L_C_EUTRANCELLTDD_H \ 表名大写
–fields-terminated-by “|” --update-key START_TIME,EUTRANCELLTDD_UK \ START_TIME,EUTRANCELLTDD_UK 为Oracle表中约束字段

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值