1. 数据时序
- 通过CK接管MySQL业务库数据。
- 使用XXL-JOB作为调度工具,通过SHELL脚本做ETL操作,在CK中建立数仓模型,最终结果表反写到MySQL报表库中。
- 报表平台通过Dataway创建接口,给前端提供数据。
2. 使用教程
2.1. CK入门
官方文档非常详细:https://clickhouse.com/docs/zh
2.1.1. 接管业务库
- 使用MySQL引擎创建xuanfb_user_sales库
CREATE DATABASE IF NOT EXISTS xuanfb_user_sales
ENGINE = MySQL('127.0.0.1:3306', 'xuanfb_user_sales', 'test_rw', '123456');
2.验证结果
select * from xuanfb_user_sales.ztc_clue;
2.1.2.建库建表
1.创建testdb库
CREATE DATABASE IF NOT EXISTS testdb
2.创建dwd_customer表
CREATE TABLE testdb.dwd_customer
(
`clue_id` String,
`NicheUUID` String,
`project_id` String,
`name` String,
`mobile` Nullable(String),
`referrer_account_id` Nullable(String),
`referrer_name` Nullable(String),
`counselor_user_id` Nullable(String),
`counselor_name` Nullable(String),
`create_time` DateTime
)
ENGINE = ReplacingMergeTree(create_time)
ORDER BY (clue_id,NicheUUID)
SETTINGS index_granularity = 8192;
2.1.3.手工ETL
1.初始化数据
insert into testdb.dwd_customer (clue_id,NicheUUID,project_id,name,mobile,referrer_account_id,referrer_name,counselor_user_id,counselor_name,create_time)
select zc.clue_id,NicheUUID,zc.project_id,zc.name,mobile,zc.referrer_account_id,zc.referrer_name,zc.counselor_user_id,zc.counselor_name,zc.create_time
from xuanfb_user_sales.ztc_clue zc left join xuanfb_user_sales.m_niche mn on zc.clue_id = mn.LeadUUID ;
2.1.4.调度工具
统一使用xxl-job进行调度。官方参考文档:https://www.xuxueli.com/xxl-job/
-
新建调度任务
2.编辑调度脚本
2.2. Dataway入门
官方参考文档:https://www.hasor.net/
2.2.1. 后台管理
地址:http://localhost:8080/report-center/interface-ui/#/
2.2.2.编写UDF函数
/**
* @description: 数据权限-测试
* @author: Dreamson.Ma
* @create: 2022-08-22 21:30
**/
@Slf4j
@Component
@DimUdf("dpUdf")
public class DpUdf implements Udf {
@Resource
private UserTokenService userTokenService;
@Override
public Object call(Hints hints, Object... objects) {
log.info("当前用户信息:{}", userTokenService.getUser());
return "2";
}
}
2.2.3.编写DataSQL
hint FRAGMENT_SQL_QUERY_BY_PAGE = true
hint FRAGMENT_SQL_QUERY_BY_PAGE_NUMBER_OFFSET = 1
var dataFun = @@sql(ownerType) <%
select
owner_name as ownerName,
card_id as cardId,
(case gender
when 0 then '一手业主'
when 1 then '二手业主'
when 2 then '一手/二手业主'
end) as gender
from owner_profile where owner_type = #{ownerType}
and card_id is not null
%>
var queryPage = dataFun(dpUdf());
run queryPage.setPageInfo({
"pageSize" : 5, // 页大小
"currentPage" : 1 // 第3页
});
return {
"pageInfo": queryPage.pageInfo(),
"pageData": queryPage.data()
}