二百七十二、Kettle——ClickHouse中增量导入数据重复性统计表数据(1天1次)

一、目的

在数据质量模块,需要对原始数据的重复性进行统计

Hive中原有SQL语句和ClickHouse现有SQL语句很大不同

二、Hive中原有代码

2.1 表结构

复制代码
--41、八大类基础数据重复性统计表  事件+事件资源不需要重复
create  table  if not exists  hurys_db.dwd_data_duplicate(
    data_type      int        comment '1:转向比,2:统计,3:评价,4:区域,5:过车,6:静态排队,7:动态排队,8:轨迹,9:事件数据,10:事件资源',
    device_no      string     comment '设备编号',
    data_duplicate float      comment '数据重复率'
)
comment '数据重复性统计表'
partitioned by (day string)
stored as orc
;

2.2 SQL代码

复制代码
insert  overwrite  table  hurys_db.dwd_data_duplicate partition(day)
select
       '6' data_type,
       device_no,
       round(sum(num)/count_num,2)  data_duplicate,
       day
from (select
       device_no,
       create_time,
       lane_no,
       count(1) num,
       count_num,
       day
from (select device_no,
             create_time,
             lane_no,
             count(device_no) over (partition by device_no,day) count_num,
             day
      from hurys_db.ods_queue
      where day = '2024-09-04'
    ) as t1
group by device_no, create_time, lane_no, count_num, day
having count(1) > 1
) as t3
group by device_no, count_num, day;

三、ClickHouse中现有代码

3.1 表结构

复制代码
--41、八大类基础数据重复性统计表(长期存储)
create  table  if not exists  hurys_jw.dwd_data_duplicate(
    data_type      Int32            comment '1:转向比,2:统计,3:评价,4:区域,5:过车,6:静态排队,7:动态排队,8:轨迹,9:事件数据,10:事件资源',
    device_no      String           comment '设备编号',
    data_duplicate Decimal(10, 2)   comment '数据重复率',
    day            Date             comment '日期'
)
ENGINE = MergeTree
PARTITION BY day
PRIMARY KEY day
ORDER BY day
SETTINGS index_granularity = 8192;

3.2 SQL代码

复制代码
select
       '6' data_type,
       device_no,
       round(sum(num)/count_num,2)  data_duplicate,
       day
from (select
       device_no,
       create_time,
       lane_no,
       count(1) num,
       count_num,
       day
from (select device_no,
             create_time,
             lane_no,
             count(device_no) over (partition by device_no,DATE(create_time)) AS count_num,
             DATE(create_time) day
      from hurys_jw.ods_queue
      where day = '2024-10-22' -- where day > ?
    ) as t1
group by device_no, create_time, lane_no, count_num, day
having count(1) > 1
) as t3
group by device_no, count_num, day;

3.3 Kettle任务

3.3.1 newtime

3.3.2 替换NULL值

3.3.3 clickhouse输入1

select

'6' data_type,

device_no,

round(sum(num)/count_num,2) data_duplicate,
cast(day as String) day

from (select

device_no,

create_time,

lane_no,

count(1) num,

count_num,

day

from (select device_no,

create_time,

lane_no,

count(device_no) over (partition by device_no,DATE(create_time)) AS count_num,

DATE(create_time) day

from hurys_jw.ods_queue
where day > ?

) as t1

group by device_no, create_time, lane_no, count_num, day

having count(1) > 1

) as t3

group by device_no, count_num, day

;

其他clickhouse输入控件代码类似

3.3.4 字段选择

3.3.5 clickhouse输出

3.3.6 执行任务

3.3.7 海豚调度(1天1次)

ClickHosue的SQL语句与Hive真的好多地方不一样,尤其是函数!

相关推荐
从未完美过9 小时前
ClickHouse集成Mysql表引擎跨服务器读表说明
服务器·mysql·clickhouse
华为云开发者联盟2 天前
华为云开源时序数据库openGemini:使用列存引擎解决时序高基数问题
clickhouse·时序数据库·高基数·opengemini
偏振万花筒3 天前
【BUG分析】clickhouse表final成功,但存在数据未合并
clickhouse·bug
爱折腾的小码农3 天前
宝塔使用clickhouse踩坑
clickhouse
激流丶3 天前
【Clikhouse 探秘】ClickHouse 物化视图:加速大数据分析的新利器
java·clickhouse·数据挖掘·数据分析·物化视图
程序员阿明3 天前
clickhouse配置用户角色与权限
java·数据库·clickhouse
isNotNullX4 天前
一文详解开源ETL工具Kettle!
大数据·数据仓库·etl·kettle
sunny052965 天前
Docker方式部署ClickHouse
java·clickhouse·docker
天地风雷水火山泽5 天前
二百七十五、Kettle——ClickHouse增量导入数据补全以及数据修复记录表数据(实时)
clickhouse·kettle