循环执行时数据的同步方式

news2024/9/27 12:09:13

在dataX-web中循环执行时数据的同步方式

解决中文comment中文乱码

在mysql中

# (0)修改库注释
alter table DBS modify column `desc` varchar(256) character set utf8;
alter table DATABASE_PARAMS modify column PARAM_VALUE varchar(256) character set utf8;

# (1)修改表字段注解和表注解
alter table COLUMNS_V2 modify column COMMENT varchar(256) character set utf8;
alter table TABLE_PARAMS modify column PARAM_VALUE varchar(4000) character set utf8;

# (2)修改分区字段注解
alter table PARTITION_PARAMS modify column PARAM_VALUE varchar(4000) character set utf8 ;
alter table PARTITION_KEYS modify column PKEY_COMMENT varchar(4000) character set utf8;

# (3)修改索引注解
alter table INDEX_PARAMS modify column PARAM_VALUE varchar(4000) character set utf8;

前置操作:

启动datax-web

cd /export/server/datax-web-2.1.2
./bin/start-all.sh

登陆主页面

http://hadoop01:9527/index.html
输入用户名 admin 密码 123456 就可以直接访问系统。

在datax-web项目管理中添加项目

在这里插入图片描述

在任务模板中添加任务模板

在这里插入图片描述

添加数据源

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

全量覆盖

不分区,同步时全部覆盖

适用于数据较少,不会发生变更,仅会新增列或行的情况

在这里插入图片描述

例子:全量覆盖----日期维度表
第一步: 在mysql的日期表准备了 700多条数据
第二步: 在hive中建表
第三步: 使用datax 将mysql中的数据 导入到 hive的日期表
第四步: 验证: select count(*) from hive.日期表; -- 700多条
第五步: 通过运行sql脚本 插入2024和2025年的日期数据 -- 365 + 365 = 730 + 730 = 1460 多表
第六步: 使用datax 将mysql中的数据 导入到 hive的日期表
第七步: 验证 select count(*) from hive.日期表; -- 1400多条
建表语句:hive
create table dim.test_dim_base_date_full(
trade_date            string   comment '日期编码',
    year_code             int       comment '年编码',
    month_code            int       comment '月份编码',
    day_code              int       comment '日编码',
    quanter_code          int       comment '季度编码',
    quanter_name          string   comment '季度名称',
    week_trade_date       string  comment '周一时间',
    month_trade_date      string  comment '月一时间',
    week_end_date         string  comment '周末时间',
    month_end_date        string  comment '月末时间',
    last_week_trade_date  string  comment '上周一时间',
    last_month_trade_date string  comment '上月一时间',
    last_week_end_date    string  comment '上周末时间',
    last_month_end_date   string  comment '上月末时间',
    year_week_code        int       comment '一年中第几周',
    week_day_code         int       comment '周几code',
    day_year_num          int       comment '一年第几天',
    month_days            int       comment '本月有多少天',
    is_weekend            int       comment '是否周末(周六和周日)',
    days_after1           string  comment '1天后的日期',
    days_after2           string  comment '2天后的日期',
    days_after3           string  comment '3天后的日期',
    days_after4           string  comment '4天后的日期',
    days_after5           string  comment '5天后的日期',
    days_after6           string  comment '6天后的日期',
    days_after7           string  comment '7天后的日期'
)
row format delimited fields terminated by ','
stored as orc
tblproperties ('orc.compress'='ZLIB');
方式一:datax步骤

构建任务将mysql中dim库的base_data表数据导入到hive中dim库的test_dim_base_date_full中

在这里插入图片描述

在这里插入图片描述

path 路径:
hive中执行
desc formatted dim.test_dim_base_date_full;
hdfs://hadoop01:8020
/user/hive/warehouse/dim.db/test_dim_base_date_full

在这里插入图片描述

构建任务选择模板

在这里插入图片描述

在这里插入图片描述

结果验证

数据库中查看

在这里插入图片描述

在hdfs中也可以查看

在这里插入图片描述

再次执行之后 结果还是跟mysql中一样 说明是全量覆盖

方式二:linux步骤

将 json文件内容拷贝出来 且 修改

vim /export/server/datax/job/01_mysql_2_hive_date_full.json
{
  "job": {
    "setting": {
      "speed": {
        "channel": 3,
        "byte": 1048576
      },
      "errorLimit": {
        "record": 0,
        "percentage": 0.02
      }
    },
    "content": [
      {
        "reader": {
          "name": "mysqlreader",
          "parameter": {
            "username": "root",
            "password": "123456",
            "column": [
              "`trade_date`",
              "`year_code`",
              "`month_code`",
              "`day_code`",
              "`quanter_code`",
              "`quanter_name`",
              "`week_trade_date`",
              "`month_trade_date`",
              "`week_end_date`",
              "`month_end_date`",
              "`last_week_trade_date`",
              "`last_month_trade_date`",
              "`last_week_end_date`",
              "`last_month_end_date`",
              "`year_week_code`",
              "`week_day_code`",
              "`day_year_num`",
              "`month_days`",
              "`is_weekend`",
              "`days_after1`",
              "`days_after2`",
              "`days_after3`",
              "`days_after4`",
              "`days_after5`",
              "`days_after6`",
              "`days_after7`"
            ],
            "splitPk": "",
            "connection": [
              {
                "table": [
                  "base_date"
                ],
                "jdbcUrl": [
                  "jdbc:mysql://hadoop01:3306/dim"
                ]
              }
            ]
          }
        },
        "writer": {
          "name": "hdfswriter",
          "parameter": {
            "defaultFS": "hdfs://hadoop01:8020",
            "fileType": "orc",
            "path": "/user/hive/warehouse/dim.db/test_dim_base_date_full",
            "fileName": "base_date",
            "writeMode": "truncate",
            "fieldDelimiter": ",",
            "column": [
              {
                "name": "trade_date",
                "type": "string"
              },
              {
                "name": "year_code",
                "type": "int"
              },
              {
                "name": "month_code",
                "type": "int"
              },
              {
                "name": "day_code",
                "type": "int"
              },
              {
                "name": "quanter_code",
                "type": "int"
              },
              {
                "name": "quanter_name",
                "type": "string"
              },
              {
                "name": "week_trade_date",
                "type": "string"
              },
              {
                "name": "month_trade_date",
                "type": "string"
              },
              {
                "name": "week_end_date",
                "type": "string"
              },
              {
                "name": "month_end_date",
                "type": "string"
              },
              {
                "name": "last_week_trade_date",
                "type": "string"
              },
              {
                "name": "last_month_trade_date",
                "type": "string"
              },
              {
                "name": "last_week_end_date",
                "type": "string"
              },
              {
                "name": "last_month_end_date",
                "type": "string"
              },
              {
                "name": "year_week_code",
                "type": "int"
              },
              {
                "name": "week_day_code",
                "type": "int"
              },
              {
                "name": "day_year_num",
                "type": "int"
              },
              {
                "name": "month_days",
                "type": "int"
              },
              {
                "name": "is_weekend",
                "type": "int"
              },
              {
                "name": "days_after1",
                "type": "string"
              },
              {
                "name": "days_after2",
                "type": "string"
              },
              {
                "name": "days_after3",
                "type": "string"
              },
              {
                "name": "days_after4",
                "type": "string"
              },
              {
                "name": "days_after5",
                "type": "string"
              },
              {
                "name": "days_after6",
                "type": "string"
              },
              {
                "name": "days_after7",
                "type": "string"
              }
            ]
          }
        }
      }
    ]
  }
}

执行

[root@hadoop01 job]# /usr/bin/python /export/server/datax/bin/datax.py /export/server/datax/job/01_mysql_2_hive_date_full.json 
结果验证

在这里插入图片描述

在这里插入图片描述

将执行命令编写到shell脚本中
vim  /export/server/datax/job/g.sh
#!/bin/bash

/usr/bin/python /export/server/datax/bin/datax.py /export/server/datax/job/g_mysql_2_hive_date_full.json
- chmod 777  /export/server/datax/job/g.sh
- /export/server/datax/job/g.sh

全量同步

每天新增一个日期分区,同步存储当天的全量数据

适用于保存周期型快照事实表

在这里插入图片描述

例子:全量同步----门店商品库存天表

将sqlserver中stock库里的dbo中的store_goods_stock_data_day表数据同步到hive中ods库中test_stock_store_goods_stock_data_day_i表中

建表语句:hive 创建分区表
CREATE TABLE IF NOT EXISTS ods.test_stock_store_goods_stock_data_day_i(
    id                  INT    COMMENT '主键',
    store_no            STRING COMMENT '店铺编码',
    goods_no            STRING COMMENT '商品NO',
    is_saleable         BIGINT COMMENT '是否可售:0否,1是',
    stock_qty           DECIMAL(27,3) COMMENT '库存数量',
    stock_price         DECIMAL(27,2) COMMENT '成本价',
    stock_amount        DECIMAL(27,2) COMMENT '库存金额',
    last_update_time    TIMESTAMP COMMENT '更新时间'
)
comment '门店商品库存天表'
partitioned by(dt STRING COMMENT '统计时间')
row format delimited fields terminated by ','
stored as orc
tblproperties ('orc.compress'='SNAPPY');
datax步骤

任务构建

在这里插入图片描述

查看路径
desc formatted ods.test_stock_store_goods_stock_data_day_i;
hdfs://hadoop01:8020
/user/hive/warehouse/ods.db/test_stock_store_goods_stock_data_day_i

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

编辑任务

在这里插入图片描述

结果验证

在这里插入图片描述

但是在hive中查不到数据是因为创建的外部看不到分区

解决方案

set hive.exec.dynamic.partition.mode=nonstrict; -- 先设置一下动态分区模式
MSCK REPAIR TABLE ods.test_stock_store_goods_stock_data_day_i --修复分区

然后就可以查到数据咯

在这里插入图片描述

在这里插入图片描述

也可以通过postsql将下列语句加到任务中

"postSql":[
    "MSCK REPAIR TABLE ods.ods_stock_store_goods_stock_data_day_i"
],

在这里插入图片描述

仅增量同步

每天新增一个日期分区,同步并存储当天的新增数据

适用于事务型事实表,只会新增不会更新的数据,如退货订单表

在这里插入图片描述

例子:仅增量同步----门店销售支付表
首次执行,同步全量数据并且导入到多个对应分区

先将mysql中sale库里的store_sale_pay表数据导入到临时表中(hive里ods库的test_sale_store_sale_pay_i_temp表中)

然后通过insert overwrite插入到正式表中(test_sale_store_sale_pay_i)

建表语句:
hive创建分区表
CREATE TABLE IF NOT EXISTS ods.test_sale_store_sale_pay_i(
    id              BIGINT COMMENT '主键',
    order_no        STRING COMMENT '单据唯一编号',
    order_id        BIGINT COMMENT '单据唯一编号',
    store_no        STRING COMMENT '门店编码',
    store_name      STRING COMMENT '门店名称',
    trade_date      TIMESTAMP COMMENT '交易日期',
    pay_date        TIMESTAMP COMMENT '支付日期',
    deal_date       TIMESTAMP COMMENT '库存处理时间',
    pos_no          STRING COMMENT 'POS机编号',
    ser_id          BIGINT COMMENT '交易序号',
    trade_id        BIGINT COMMENT '销售类型:1-销售,2-退货,3-拒收,4-取消',
    parent_order_sn STRING COMMENT '母单号,如果单据是子单有值',
    source_order_sn STRING COMMENT '原始单据,退款的单据,则代表是原始销售单据',
    source_type     BIGINT COMMENT '销售渠道:1-门店POS,2-商城小程序,3-团购销售',
    create_time     STRING COMMENT '记录创建时间',
    business_code   STRING COMMENT '业务类型//预售、及时达、B2C',
    pay_type_id     STRING COMMENT '支付类别ID',
    third_party_id  STRING COMMENT '第三方支付类别ID',
    third_party_name STRING COMMENT '第三方类别',
    pay_amount      DECIMAL(27, 2) COMMENT '支付金额',
    third_trade_no  STRING COMMENT '三方交易单号',
    trade_no        STRING COMMENT '交易单号',
    source_trade_no STRING COMMENT '原始交易单号',
    item            BIGINT COMMENT '序号,同一种支付方式可能多个条记录',
    ratio           DECIMAL(27, 4) COMMENT '支付费率',
    memo            STRING COMMENT '备注'
) 
comment '门店销售支付表'
partitioned by (dt STRING COMMENT '销售日期')
row format delimited fields terminated by ','
stored as orc
tblproperties ('orc.compress'='ZLIB');
hive临时表
CREATE TABLE IF NOT EXISTS ods.test_sale_store_sale_pay_i_temp(
    id              BIGINT COMMENT '主键',
    order_no        STRING COMMENT '单据唯一编号',
    order_id        BIGINT COMMENT '单据唯一编号',
    store_no        STRING COMMENT '门店编码',
    store_name      STRING COMMENT '门店名称',
    trade_date      TIMESTAMP COMMENT '交易日期',
    pay_date        TIMESTAMP COMMENT '支付日期',
    deal_date       TIMESTAMP COMMENT '库存处理时间',
    pos_no          STRING COMMENT 'POS机编号',
    ser_id          BIGINT COMMENT '交易序号',
    trade_id        BIGINT COMMENT '销售类型:1-销售,2-退货,3-拒收,4-取消',
    parent_order_sn STRING COMMENT '母单号,如果单据是子单有值',
    source_order_sn STRING COMMENT '原始单据,退款的单据,则代表是原始销售单据',
    source_type     BIGINT COMMENT '销售渠道:1-门店POS,2-商城小程序,3-团购销售',
    create_time     STRING COMMENT '记录创建时间',
    business_code   STRING COMMENT '业务类型//预售、及时达、B2C',
    pay_type_id     STRING COMMENT '支付类别ID',
    third_party_id  STRING COMMENT '第三方支付类别ID',
    third_party_name STRING COMMENT '第三方类别',
    pay_amount      DECIMAL(27, 2) COMMENT '支付金额',
    third_trade_no  STRING COMMENT '三方交易单号',
    trade_no        STRING COMMENT '交易单号',
    source_trade_no STRING COMMENT '原始交易单号',
    item            BIGINT COMMENT '序号,同一种支付方式可能多个条记录',
    ratio           DECIMAL(27, 4) COMMENT '支付费率',
    memo            STRING COMMENT '备注'
) 
comment '门店销售支付临时表'
row format delimited fields terminated by ','
stored as orc
tblproperties ('orc.compress'='ZLIB');

构建任务

在这里插入图片描述

在这里插入图片描述

json文件记得修改为truncate

执行任务

数据从临时表导入到分区表

执行hivesql将全量数据从临时表导入到分区表。

set hive.exec.dynamic.partition.mode=nonstrict;
 
insert overwrite table ods.test_sale_store_sale_pay_i partition(dt)
select *,date_format(pay_date,'yyyy-MM-dd') as dt from ods.test_sale_store_sale_pay_i_temp t
;

查看数据

在这里插入图片描述

删除临时表 hive中

drop table ods.test_sale_store_sale_pay_i_temp

每天执行,同步前一天数据,放到前一天的分区

在mysql中插入数据

-- 模拟store_sale_pay 增量数据(上一天的数据)
insert into sale.store_sale_pay
select * from (
    select null as id, order_no, order_id, store_no, store_name, trade_date,
       concat(date_sub(current_date, interval 1 day), substr(pay_date, 11)) as pay_date, deal_date, pos_no, ser_id, trade_id, parent_order_sn,
       source_order_sn, source_type, create_time, business_code, pay_type_id,
       third_party_id, third_party_name, pay_amount, third_trade_no, trade_no, source_trade_no, item, ratio, memo
    from sale.store_sale_pay
    where id<3
) as t1
;

select * from sale.store_sale_pay
where date(pay_date)=date_sub(current_date, interval 1 day)

任务构建 在where中要加上条件

pay_date >= date_sub(curdate(),interval 1 day) and pay_date < curdate()

在这里插入图片描述

在这里插入图片描述

编辑任务

在这里插入图片描述

查看结果 前一天数据成功导入

在这里插入图片描述

在这里插入图片描述

新增及更新同步

每天新增一个日期分区,同步并存储当天的新增和更新数据

适用于既有新增又有更新的数据,最常见的就是累计型快照快照事实表,比如订单表

也适用于关心数据变化的维表,比如后续需要维护一个拉链表时,需要知道每天新增和更新的数据

在这里插入图片描述

例子:商城订单表

将mysql里sale库里的shop_order表数据导入到hive里ods库中的临时表中

创建表

CREATE TABLE IF NOT EXISTS ods.test_sale_shop_order_i(
    id                        BIGINT COMMENT '编号',
    parent_order_no           STRING COMMENT '父单订单号',
    order_id                  STRING COMMENT '订单编号',
    is_split                  BIGINT COMMENT '是否拆单:0-不需要拆单;1-待拆单;2-已拆单',
    platform_id               BIGINT COMMENT '平台id:1-有赞,2-京东到家,3-美团外卖,4-饿了么',
    tid                       STRING COMMENT '平台订单号',
    source_type               BIGINT COMMENT '订单来源:10,20,30,40,41,50,60,70',
    source_name               STRING COMMENT '订单来源名称:10-有赞,20-京东到家,30-美团外卖,40-饿了么,41-百度外卖,50-传智鲜精选,60-黑马优选,70-抖店',
    store_no                  STRING COMMENT '门店编码',
    city_id                   BIGINT COMMENT '城市编号',
    city_name                 STRING COMMENT '城市名称',
    region_code               STRING COMMENT '区域编码',
    order_status              BIGINT,
    order_status_desc         STRING COMMENT '主订单状态描述:0-新建; 1-待出票;2-待备货;3-待揽件;4-待自提; 5-配送中;6-已完成;7-已取消',
    pay_type                  BIGINT COMMENT '支付类型:1-线下支付;2-线上支付',
    trade_type                STRING COMMENT '交易类型。取值范围:fixed(一口价) gift(送礼)bulk_purchase(来自分销商的采购)present (赠品领取)group (拼团订单) pifa (批发订单) cod (货到付款) peer (代付) qrcode(扫码商家二维码直接支付的交易)qrcode_3rd(线下收银台二维码交易)',
    is_deleted                BIGINT COMMENT '是否有效,1:已删除,0:正常',
    order_create_time         TIMESTAMP COMMENT '平台订单创建时间',
    order_pay_time            TIMESTAMP COMMENT '订单支付时间',
    create_time               TIMESTAMP COMMENT '创建时间',
    print_status              BIGINT COMMENT '打印状态:0-未打票;1-已打票',
    print_time                TIMESTAMP COMMENT '出票时间',
    stock_up_status           BIGINT COMMENT '门店处理状态:0-待备货/1-已备货',
    stock_up_time             TIMESTAMP COMMENT '备货完成时间',
    order_type                BIGINT COMMENT '配送类型(真正的订单类型由业务类型来决定):1-及时送;2-隔日送;3-自提单',
    express_type              BIGINT COMMENT '配送方式:0-三方平台配送;1-自配送;2-快递;3-自提',
    receive_time              TIMESTAMP COMMENT '要求送达/自提时间',
    express_code              STRING COMMENT '配送单号',
    delivery_status           BIGINT COMMENT '配送状态:0-待配送;1-配送中;2-已送达',
    delivery_time             TIMESTAMP COMMENT '配送时间',
    pick_up_status            BIGINT COMMENT '自提状态:0-待自提;1-已自提',
    qr_code                   STRING COMMENT 'qr提货码',
    pick_up_time              TIMESTAMP COMMENT '自提时间',
    complete_time             TIMESTAMP COMMENT '订单完结时间',
    is_cancel                 BIGINT COMMENT '是否取消',
    cancel_time               TIMESTAMP COMMENT '取消时间',
    cancel_reason             STRING COMMENT '取消原因',
    refund_status             BIGINT COMMENT '退款状态:0未退款,1部分退款,2已全额退款',
    refund_time               TIMESTAMP COMMENT '已退款时间',
    last_update_time          TIMESTAMP COMMENT '最新更新时间',
    order_total_amount        DECIMAL(27, 2) COMMENT '订单总金额',
    product_total_amount      DECIMAL(27, 2) COMMENT '商品总金额(原价)',
    pack_amount               DECIMAL(27, 2) COMMENT '餐盒费/打包费',
    delivery_amount           DECIMAL(27, 2) COMMENT '配送费',
    discount_amount           DECIMAL(27, 2) COMMENT '订单优惠金额=商家承担优惠金额+平台补贴金额',
    seller_discount_amount    DECIMAL(27, 2) COMMENT '商家承担优惠金额',
    platform_allowance_amount DECIMAL(27, 2) COMMENT '平台补贴金额',
    real_paid_amount          DECIMAL(27, 2) COMMENT '实付金额',
    product_discount          DECIMAL(27, 2) COMMENT '商品优惠金额',
    real_product_amount       DECIMAL(27, 2) COMMENT '商品实际金额',
    buyer_id                  BIGINT COMMENT '买家id',
    buyer_phone               STRING COMMENT '买家电话',
    buyer_remark              STRING COMMENT '买家备注',
    r_name                    STRING COMMENT '收货人姓名',
    r_tel                     STRING COMMENT '收货人电话',
    r_province                STRING COMMENT '收货人省份',
    r_city                    STRING COMMENT '收货人城市',
    r_district                STRING COMMENT '收货人区域',
    r_address                 STRING COMMENT '收货人地址',
    r_zipcode                 STRING COMMENT '收货人邮编',
    is_tuan_head              BIGINT COMMENT '是否为团长订单',
    store_leader_id           BIGINT COMMENT '团长id',
    order_group_no            STRING COMMENT '团单号',
    commision_amount          DECIMAL(27, 2) COMMENT '抽佣金额',
    settle_amount             DECIMAL(27, 2) COMMENT '结算金额',
    points_amount             DECIMAL(27, 2) COMMENT '积分抵扣金额',
    pay_point                 BIGINT COMMENT '消费积分数',
    balance_amount            DECIMAL(27, 2) COMMENT '余额扣除金额',
    pay_channel_amount        DECIMAL(27, 2) COMMENT '通过支付渠道支付的金额',
    point_amount              DECIMAL(27, 2) COMMENT '消费赠送积分',
    sync_erp_status           BIGINT COMMENT '同步erp状态',
    sync_erp_msg              STRING COMMENT '同步erp失败消息'
)
COMMENT '商城订单表(更新表)'
partitioned by (dt STRING COMMENT '更新日期')
row format delimited fields terminated by ','
stored as orc
tblproperties ('orc.compress'='ZLIB');
CREATE TABLE IF NOT EXISTS ods.test_sale_shop_order_i_temp(
    id                      BIGINT COMMENT '编号',
    parent_order_no         STRING COMMENT '父单订单号',
    order_id                STRING COMMENT '订单编号',
    is_split                BIGINT COMMENT '是否拆单:0-不需要拆单;1-待拆单;2-已拆单',
    platform_id             BIGINT COMMENT '平台id:1-有赞,2-京东到家,3-美团外卖,4-饿了么',
    tid                     STRING COMMENT '平台订单号',
    source_type             BIGINT COMMENT '订单来源:10,20,30,40,41,50,60,70',
    source_name             STRING COMMENT '订单来源名称:10-有赞,20-京东到家,30-美团外卖,40-饿了么,41-百度外卖,50-传智鲜精选,60-黑马优选,70-抖店',
    store_no                STRING COMMENT '门店编码',
    city_id                 BIGINT COMMENT '城市编号',
    city_name               STRING COMMENT '城市名称',
    region_code             STRING COMMENT '区域编码',
    
    order_status            BIGINT,
    order_status_desc       STRING COMMENT '主订单状态描述:0-新建; 1-待出票;2-待备货;3-待揽件;4-待自提; 5-配送中;6-已完成;7-已取消',
    pay_type                BIGINT COMMENT '支付类型:1-线下支付;2-线上支付',
    trade_type              STRING COMMENT '交易类型。取值范围:fixed(一口价) gift(送礼)bulk_purchase(来自分销商的采购)present (赠品领取)group (拼团订单) pifa (批发订单) cod (货到付款) peer (代付) qrcode(扫码商家二维码直接支付的交易)qrcode_3rd(线下收银台二维码交易)',
    is_deleted              BIGINT COMMENT '是否有效,1:已删除,0:正常',
    order_create_time       TIMESTAMP COMMENT '平台订单创建时间',
    order_pay_time          TIMESTAMP COMMENT '订单支付时间',
    create_time             TIMESTAMP COMMENT '创建时间',
    print_status            BIGINT COMMENT '打印状态:0-未打票;1-已打票',
    print_time              TIMESTAMP COMMENT '出票时间',
    stock_up_status         BIGINT COMMENT '门店处理状态:0-待备货/1-已备货',
    stock_up_time           TIMESTAMP COMMENT '备货完成时间',
    
    order_type              BIGINT COMMENT '配送类型(真正的订单类型由业务类型来决定):1-及时送;2-隔日送;3-自提单',
    express_type            BIGINT COMMENT '配送方式:0-三方平台配送;1-自配送;2-快递;3-自提',
    receive_time            TIMESTAMP COMMENT '要求送达/自提时间',
    express_code            STRING COMMENT '配送单号',
    delivery_status         BIGINT COMMENT '配送状态:0-待配送;1-配送中;2-已送达',
    delivery_time           TIMESTAMP COMMENT '配送时间',
    pick_up_status          BIGINT COMMENT '自提状态:0-待自提;1-已自提',
    qr_code                 STRING COMMENT 'qr提货码',
    pick_up_time            TIMESTAMP COMMENT '自提时间',
    
    complete_time           TIMESTAMP COMMENT '订单完结时间',
    is_cancel               BIGINT COMMENT '是否取消',
    cancel_time             TIMESTAMP COMMENT '取消时间',
    cancel_reason           STRING COMMENT '取消原因',
    refund_status           BIGINT COMMENT '退款状态:0未退款,1部分退款,2已全额退款',
    refund_time             TIMESTAMP COMMENT '已退款时间',
    last_update_time        TIMESTAMP COMMENT '最新更新时间',
    
    order_total_amount      DECIMAL(27, 2) COMMENT '订单总金额',
    product_total_amount    DECIMAL(27, 2) COMMENT '商品总金额(原价)',
    pack_amount             DECIMAL(27, 2) COMMENT '餐盒费/打包费',
    delivery_amount         DECIMAL(27, 2) COMMENT '配送费',
    discount_amount         DECIMAL(27, 2) COMMENT '订单优惠金额=商家承担优惠金额+平台补贴金额',
    seller_discount_amount  DECIMAL(27, 2) COMMENT '商家承担优惠金额',
    platform_allowance_amount DECIMAL(27, 2) COMMENT '平台补贴金额',
    real_paid_amount        DECIMAL(27, 2) COMMENT '实付金额',
    product_discount        DECIMAL(27, 2) COMMENT '商品优惠金额',
    real_product_amount     DECIMAL(27, 2) COMMENT '商品实际金额',
    buyer_id                BIGINT COMMENT '买家id',
    buyer_phone             STRING COMMENT '买家电话',
    buyer_remark            STRING COMMENT '买家备注',
    r_name                  STRING COMMENT '收货人姓名',
    r_tel                   STRING COMMENT '收货人电话',
    r_province              STRING COMMENT '收货人省份',
    r_city                  STRING COMMENT '收货人城市',
    r_district              STRING COMMENT '收货人区域',
    r_address               STRING COMMENT '收货人地址',
    r_zipcode               STRING COMMENT '收货人邮编',
    
    is_tuan_head            BIGINT COMMENT '是否为团长订单',
    store_leader_id         BIGINT COMMENT '团长id',
    order_group_no          STRING COMMENT '团单号',
    commision_amount        DECIMAL(27, 2) COMMENT '抽佣金额',
    settle_amount           DECIMAL(27, 2) COMMENT '结算金额',
    
    points_amount           DECIMAL(27, 2) COMMENT '积分抵扣金额',
    pay_point               BIGINT COMMENT '消费积分数',
    balance_amount          DECIMAL(27, 2) COMMENT '余额扣除金额',
    pay_channel_amount      DECIMAL(27, 2) COMMENT '通过支付渠道支付的金额',
    point_amount            DECIMAL(27, 2) COMMENT '消费赠送积分',
    
    sync_erp_status         BIGINT COMMENT '同步erp状态',
    sync_erp_msg            STRING COMMENT '同步erp失败消息'
)
comment '商城订单临时表'
row format delimited fields terminated by ','
stored as orc
tblproperties ('orc.compress'='ZLIB');

任务构建

在这里插入图片描述

将临时表中的数据加载到正式表中 在hive中

set hive.exec.dynamic.partition.mode=nonstrict;

insert overwrite table  ods.test_sale_shop_order_i partition(dt)
select *,date_format(t.create_time,'yyyy-MM-dd') as dt from ods.test_sale_shop_order_i_temp t

查看分区表

在这里插入图片描述

删除临时表

drop table ods.test_sale_shop_order_i_temp;

循环执行 任务构建

每次只同步前一天数据新增和变化的数据,所以构建reader时,where后加上条件

(create_time >= date_sub(curdate(),interval 1 day) and create_time < curdate())
or (last_update_time >= date_sub(curdate(),interval 1 day) and last_update_time < curdate())

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

查看结果 前一天数据已导入

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1992602.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

用python创建极坐标平面

极坐标的介绍 http://t.csdnimg.cn/ucau3http://t.csdnimg.cn/ucau3这个文章里可以知道极坐标的基本知识&#xff0c;接下来实现极坐标的绘制 PolarPlane 是 Manim&#xff08;一个用于数学动画的Python库&#xff09;中的一个类&#xff0c;用于创建极坐标平面。与笛卡尔…

汇昌联信数字做拼多多运营怎么做?

在当今电商竞争激烈的环境下&#xff0c;如何有效地在拼多多这样的平台上进行运营&#xff0c;是许多商家和品牌都在思考的问题。汇昌联信数字作为一家致力于提供数字化解决方案的公司&#xff0c;其在拼多多上的运营策略值得深入探讨。本文将详细分析汇昌联信数字在拼多多上的…

【HBZ分享】Spring启动时核心refresh方法流程

refresh核心代码所在位置 在AbstractApplicationContext类中的refresh方法中 refresh的业务流程编排 调用obtainFreshBeanFactory()去创建一个全新的BeanFactory工厂&#xff0c;类型为DefaultListableBeanFctory&#xff0c;其功能为【解析xml】将里面bean标签内容解析成【…

信息学奥林匹克竞赛详解-CSP、NOIP、NOI、IOI是什么

近年来&#xff0c;随着计算机在教育领域的影响力越来越大&#xff0c;信息学奥林匹克竞赛也越来越受关注。 山东省在2017年秋季正式出版了《小学信息技术》&#xff0c;大幅度引入了Scratch、Python等编程语言。 浙江省在2018年的高考选考科目中新增了信息技术&#xff0c;包…

【Qt】图形化和纯代码实现Hello world的比较

本篇文章使用俩种方式实现Qt上的Hello world&#xff1a; 通过图形化的方式&#xff0c;在界面上创建出一个控件&#xff0c;显式Hello world通过纯代码的方式&#xff0c;通过编写代码&#xff0c;在界面上创建控件&#xff0c;显示Hello world 图形化方式 双击Forms文件中的…

CTFHUB-web-RCE-读取源代码

开启题目 网页发现了源代码&#xff0c;还是和前几题一样是 php:// &#xff0c;提示说 flag 在代码中&#xff0c;并且在 /flag 文件夹中&#xff0c;题目名字也叫读取源代码。 php://filter 是一种元封装器&#xff0c;专门用于数据流的过滤和筛选。与传统的文件操作函数相比…

selenium的UI自动化框架入门

环境准备 python、pycharme、chromedriver google下载的官网地址 https://google.cn/chrome/ chromedriver chromedriver的下载 https://chromedriver.storage.googleapis.com/index.html chromedriver配置环境变量 C:\Users\Administrator\.cache\selenium\chromedrive…

Python的安装环境以及应用

1.环境python2&#xff0c;Python 最新安装3.12可以使用源码安装 查看安装包 [rootpython001 ~]# yum list installed | grep epel 3[rootpython001 ~]# yum list installed | grep python [rootpython001 ~]# yum -y install python3 安装python3 查看版本 [root…

【LLM大模型】中国人工智能系列白皮书--大模型技术

近期&#xff0c;中国人工智能学会发布了 《2023 中国人工智能系列白皮书–大模型技术&#xff08;2023版&#xff09;》&#xff0c;涵盖了大模型发展历程、技术概述、风险与挑战以及未来发展展望等。 &#x1f449;CSDN大礼包&#x1f381;&#xff1a;全网最全《LLM大模型入…

控制某些请求不记录日志

说明&#xff1a;由于统一拦截日志请求&#xff0c;导致所有匹配的请求都会打印日志&#xff0c;这里需要控制有些请求执行不打印日志&#xff0c;比如定时每隔几秒执行某些请求。 具体实现如下&#xff1a; 一、自定义注解&#xff0c;如下&#xff1a; /** * Description: …

代码随想录算法(哈希表一)

目录 242有效的字母异位词 349两个数组的交集​编辑 set解决 数组解决 1两数之和 242有效的字母异位词 如果使用暴力解法的话直接可以使用两层for循环 我们平时用到的哈希表的数据结构就是数组 set和map 用到哈希表的话 就可以想这三个数据结构 这个题的话只有小写的英文…

Advanced IP Scanner - 网络管理工具介绍

Advanced IP Scanner 是一款免费、快速且用户友好的网络扫描工具。它能够帮助用户扫描局域网&#xff08;LAN&#xff09;中的所有设备&#xff0c;提供详细的设备信息&#xff0c;包括IP地址、MAC地址、设备名称和厂商信息。该工具对IT管理员和普通用户都非常有用&#xff0c;…

Java0 Java基础知识

预备知识 我们各种各样的信息是怎么存储到计算中的&#xff1f; 二进制 二进制是什么 由德国的莱布尼茨于 1679 年发明。 二进制数据是用0 和 1 两个数码来表示的数。它的基数为 2 &#xff0c;进位规则是"逢二进一" &#xff0c;数字计算机只能识别和处理由0和1符…

联想电脑重装系统时无法发现硬盘

&#x1f3c6;本文收录于《CSDN问答解惑-专业版》专栏&#xff0c;主要记录项目实战过程中的Bug之前因后果及提供真实有效的解决方案&#xff0c;希望能够助你一臂之力&#xff0c;帮你早日登顶实现财富自由&#x1f680;&#xff1b;同时&#xff0c;欢迎大家关注&&收…

C语言—水手分椰子问题

自己敲得&#xff1a; #include<stdio.h> #include<math.h> int main() {int i, j;float n;for (i 0;; i){n 5 * i 1;for (j 0; j < 4; j)//要求这四次每次的n都是整数才行{n n * 5 / 4 1;if (fmod(n, 1) ! 0) break;//或者 if(n!(int)n) break;}if (j …

TypeScript位运算

参考文献&#xff1a; https://blog.csdn.net/xuaner8786/article/details/138858747 https://www.runoob.com/typescript/ts-operators.html 位运算符 TypeScript 中的位运算符用于在二进制位级别上操作数字。这些运算符在处理整数和底层系统编程时特别有用。以下是一些使用…

C:冒泡排序

1、冒泡排序介绍&#xff1a; 冒泡排序的核心思想就是&#xff1a;两两相邻的元素进行比较。 先用一个例子来帮助大家理解一下冒泡排序的算法是怎们进行的 有一排高矮不同的人站成一列&#xff0c;要按照从矮到高的顺序重新排队。 冒泡排序的方法就是&#xff0c;从第一个人…

【栈和队列】常见面试题

文章目录 1.[有效的括号](https://leetcode.cn/problems/valid-parentheses/description/)1.1 题目要求1.2 利用栈解决 2. [用队列实现栈](https://leetcode.cn/problems/implement-stack-using-queues/description/)2.1 题目要求2.2 用队列实现栈 3.[用栈实现队列](https://le…

cesium gltf模型

cesium 支持的三维模型格式包括GLTF和GLB&#xff08;二进制glTF文件&#xff09;。 本文通过使用Entity图元的modelGraphics对象来加载gltf模型&#xff0c;简单对gltf模型的加载进行了封装。通过设置模型的欧拉角&#xff0c;可以计算模型的朝向。 1 3D数学中模型旋转的方式…

数据定义和操作

一、数据定义语言和操作语言 1. 分析需求设计数据库表 根据“优乐网”系统需求&#xff1a; 此系统满足以下需求&#xff1a; 系统支持生成商品的入库和出库。入库之后的商品可以在平台显示 所有用户都可以浏览系统的商品信息&#xff0c;只有注册用户才能订购团购商品和服…