将结果增量导出MySQL-将每天的订单总个数和订单总金额合并,写入结果表t3,并增量导出到MySQL

  • 04.export.sh

    #!/bin/bash
    
    #step1:先获取要采集的数据时间,规则:如果没有给参数,就默认处理昨天的日期,如果给了参数,就参数对应的日期
    if [ $# -ne 0 ]
    then
    	#参数个数不为0
    	if [ $# -ne 1 ]
    	then
    		echo "参数至多只能有一个,为处理的日期,请重新运行!"
    		exit 100
    	else
    		#参数个数只有1个,就用第一个参数作为处理的日期
    		yesterday=$1
    	fi
    else
    	#参数个数为0,默认处理昨天的日期
    	yesterday=`date -d '-1 day' +%Y-%m-%d`
    fi
    echo "step1:要处理的日期是:${yesterday}"
    
    echo "step2:开始运行分析"
    #step2:运行分析程序
    HIVE_HOME=/export/server/hive-1.1.0-cdh5.14.0
    $HIVE_HOME/bin/hive --hiveconf yest=${yesterday}  -f  hdfs://node1:8020/user/oozie/shell/04.export.sql
    
    echo "step2:分析的程序运行结束"
    
    echo "step3:开始运行导出的程序"
    #step2:运行增量采集
    SQOOP_HOME=/export/server/sqoop-1.4.6-cdh5.14.0
    $SQOOP_HOME/bin/sqoop export \
    --connect jdbc:mysql://node3:3306/db_order \
    --username root \
    --password-file hdfs://node1:8020/user/oozie/shell/sqoop.passwd \
    --table tb_order_rs \
    --hcatalog-database default \
    --hcatalog-table tb_order_rs \
    --input-fields-terminated-by '\t' \
    --update-key daystr \
    --update-mode allowinsert \
    -m 1
    
    echo "step3:导出的程序运行结束"
    
    
  • 04.export.sql

    create table if not exists default.tb_order_rs(
      daystr string,
      order_number int,
      order_price double
    )
    row format delimited fields terminated by '\t';
    
    insert into table default.tb_order_rs
    select
      a.daystr,
      a.order_number,
      b.order_price
    from default.tb_order_num_rs a join default.tb_order_price_rs b on a.daystr = b.daystr
    where a.daystr='${hiveconf:yest}';
    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

章鱼哥TuNan&Z

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值