二百七十五、Kettle——ClickHouse增量导入数据补全以及数据修复记录表数据(实时)

一、目的

在完成数据修复后,需要生成修复记录

二、Hive中原有代码

2.1 表结构

复制代码
--52、数据补全以及数据修复记录表 dwd_data_correction_record
create  table  if not exists  hurys_db.dwd_data_correction_record(
    data_type      int        comment '数据类型 1:转向比,2:统计,3:评价,4:区域,6:静态排队,7:动态排队',
    device_no      string     comment '设备编号',
    id             string     comment '唯一ID',
    create_time    timestamp  comment '创建时间',
    record_type    int        comment '记录类型 0:补全,1:修复'
)
comment '数据补全以及数据修复记录表'
partitioned by (day string)
stored as orc
;

2.2 SQL代码

复制代码
--6 静态排队数据修复记录
insert into table  hurys_db.dwd_data_correction_record partition(day)
select
       '6' data_type,
       t1.device_no,
       t1.id,
       t1.create_time,
       '1' record_type,
       t1.day
from hurys_db.dwd_queue_error as t1
right join hurys_db.dwd_queue as t2
on t1.id=t2.id and t1.device_no=t2.device_no
where t1.id is not null and t1.day='2024-09-04'
;

三、ClickHouse中现有代码

3.1 表结构

复制代码
--52、数据补全以及数据修复记录表 dwd_data_correction_record
create  table  if not exists  hurys_jw.dwd_data_correction_record(
    data_type      Int32      comment '数据类型 1:转向比,2:统计,3:评价,4:区域,6:静态排队,7:动态排队',
    device_no      String     comment '设备编号',
    id             String     comment '唯一ID',
    create_time    DateTime   comment '创建时间',
    record_type    Int32      comment '记录类型 0:补全,1:修复',
    day            Date       comment '日期'
)
ENGINE = MergeTree
PARTITION BY day
PRIMARY KEY (day,id)
ORDER BY (day,id)
SETTINGS index_granularity = 8192;

3.2 SQL代码

复制代码
--6 静态排队数据修复记录
select
       '6' data_type,
       t1.device_no,
       t1.id,
       t1.create_time,
       '1' record_type,
       cast(t1.day as String) day
from hurys_jw.dwd_queue_error as t1
inner join  hurys_jw.dwd_queue as t2
on t1.id=t2.id and t1.device_no=t2.device_no
where t1.id is not null --and t1.create_time > ?
group by t1.device_no,  t1.id, t1.create_time,  t1.day
;

四、Kettle任务

由于修复记录必须是数据完成修复后执行,但是又不能每天执行一次,因为数据修复任务最后会删除错误数据表当天分区数据

4.1 newtime 2

4.2 替换NULL值 2

4.3 clickhouse输入 2

select

'6' data_type,

t1.device_no,

t1.id,

t1.create_time,

'1' record_type,

cast(t1.day as String) day

from hurys_jw.dwd_queue_error as t1

inner join hurys_jw.dwd_queue as t2

on t1.id=t2.id and t1.device_no=t2.device_no

where t1.id is not null and t1.create_time > ?

group by t1.device_no, t1.id, t1.create_time, t1.day

;

4.4 字段选择 2

4.5 clickhouse输出 2

4.6 执行任务

修复记录和数据修复任务放在一个kettle任务里

相关推荐
zhangjin12225 小时前
kettle插件-excel插件,kettle读取excel动态表头,kettle根据列名读取excel
excel·kettle·kettle excel插件·kettle 动态excel
顾随1 天前
(二)kettle--输入与输出
javascript·数据库·kettle
4t4run7 天前
1、clickhouse 安装
数据库·clickhouse
JackSparrow4148 天前
使用Elasticsearch代替数据库like以加快查询的各种技术方案+实现细节
大数据·clickhouse·elk·elasticsearch·搜索引擎·postgresql·全文检索
梦想与想象-广州大智汇15 天前
MySQL 同步数据到 ClickHouse 方案对比分析
数据库·mysql·clickhouse
Smile_25422041816 天前
clickhouse日志疯涨问题
linux·运维·服务器·clickhouse
计算机魔术师16 天前
【技术硬核 | 存储】ClickHouse 原理与 Langfuse 存储实践:当 LLM Trace 爆炸时,PG 还扛得住吗?
人工智能·clickhouse·工程实践·sbti·职场焦虑
fire-flyer19 天前
ClickHouse系列(九):慢查询、内存 OOM 与稳定性治理
android·clickhouse
fire-flyer19 天前
ClickHouse系列(十):生产架构与最佳实践总结
clickhouse·架构
fire-flyer20 天前
ClickHouse系列(八):ClickHouse 的 UPDATE / DELETE 正确姿势
大数据·数据库·clickhouse