Doris bitmap人群圈选案例

  1. 构建标签表
 CREATE TABLE `user_label` (
  `label_name` varchar(20) NULL COMMENT '标签名称',
  `label_version` datetime NULL COMMENT '标签版本号',
  `label_type` varchar(10) NULL COMMENT '标签类型data-double-int-string',
  `label_value` varchar(100) NULL COMMENT 'label_string标签值',
  `bitmap_uid` bitmap BITMAP_UNION NULL COMMENT '实体id集合'
) ENGINE=OLAP
AGGREGATE KEY(`label_name`, `label_version`, `label_type`, `label_value`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`label_name`) BUCKETS 20
PROPERTIES (
"bloom_filter_columns" = "label_value",
"replication_allocation" = "tag.location.default: 1"
);      
  1. 构建事实表(明细表)

CREATE TABLE dwd_event
(
event_id VARCHAR(100),
event_time DateTime,
event_type VARCHAR(100),
tag_name VARCHAR(100), 
uid BIGINT,  
ver VARCHAR(20) COMMENT 'app版本号', 
brand VARCHAR(80) COMMENT '设备所属品牌',
app_id VARCHAR(20)
)DUPLICATE KEY(`event_id`,`event_time`)
PARTITION BY RANGE(`event_time`) ()
DISTRIBUTED BY HASH(`event_id`) BUCKETS 12
PROPERTIES (
 "dynamic_partition.enable" = "true",
 "dynamic_partition.time_unit" = "DAY",
  "dynamic_partition.start" = "-30",
  "dynamic_partition.end" = "3",
  "dynamic_partition.prefix" = "p",
  "dynamic_partition.buckets" = "12",
  "dynamic_partition.create_history_partition"="true",
  "bloom_filter_columns"="uid,tag_name",
  "replication_allocation" = "tag.location.default: 1"
);
  1. 人群圈选
    标签过滤的和行为明细数据求交集
select '2023-03-11' as group_version
, 123  as group_id
, bitmap_uid as bitmap_uid
from (
SELECT bitmap_union(bitmap_uid) as bitmap_uid, 1 as joinKey
FROM (            
    SELECT bitmap_uid as bitmap_uid, 1 joinKey
    FROM user_label
    WHERE label_version = '2023-03-11'
    and label_name = 'charge_amt'
    AND label_value < 1000.0    
    UNION ALL               
    SELECT to_bitmap(entity_id) as bitmap_uid, 1 as joinKey
    FROM (
        SELECT uid as entity_id
        FROM dwd_event
        WHERE brand = 'xiaomi' AND event_time BETWEEN '2022-11-04 00:00:00'
         AND '2023-02-02 23:59:59' and tag_name IN ('tag_a') GROUP BY uid HAVING COUNT(1) >= 1
    ) t2    
) t3
) user_group_temp
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Flink CDC(Change Data Capture)是一种数据同步技术,可以从源数据库中捕获变更数据并将其同步到目标数据库中。DorisDB是一款分布式数据仓库,支持海量数据的存储和查询分析。下面以将数据从DorisDB同步到DorisDB为例,介绍如何使用Flink CDC实现数据同步。 1. 准备工作 在开始之前,需要安装好以下工具和环境: - DorisDB - Flink - Flink CDC 2. 创建数据源 首先需要创建一个数据源,用于从DorisDB中读取数据。可以使用Flink的JDBCInputFormat来读取DorisDB中的数据。在Flink中,可以使用以下代码创建一个JDBCInputFormat: ``` JDBCInputFormat jdbcInputFormat = JDBCInputFormat.buildJDBCInputFormat() .setDrivername(driverName) .setDBUrl(dbUrl) .setUsername(username) .setPassword(password) .setQuery("SELECT * FROM table") .finish(); ``` 其中,driverName、dbUrl、username和password是DorisDB的连接信息,"SELECT * FROM table"是要读取的表的SQL语句。 3. 创建数据同步任务 接下来需要创建一个Flink的数据流任务,用于将从DorisDB中读取的数据同步到另一个DorisDB中。可以使用Flink的DataStream API来实现数据同步。以下是一个示例代码: ``` StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); DataStream<Row> sourceStream = env.createInput(jdbcInputFormat); DataStream<Row> sinkStream = sourceStream.map(new MapFunction<Row, Row>() { @Override public Row map(Row value) throws Exception { // 对数据进行转换 return value; } }); DorisDBOutputFormat dorisDBOutputFormat = new DorisDBOutputFormat(); dorisDBOutputFormat.setDrivername(driverName); dorisDBOutputFormat.setDBUrl(dbUrl); dorisDBOutputFormat.setUsername(username); dorisDBOutputFormat.setPassword(password); dorisDBOutputFormat.setTable(table); dorisDBOutputFormat.setBatchSize(batchSize); sinkStream.writeUsingOutputFormat(dorisDBOutputFormat); env.execute(); ``` 其中,sourceStream是从DorisDB中读取的数据流,sinkStream是经过转换后要写入到DorisDB的数据流。可以使用map函数对数据进行转换。DorisDBOutputFormat是一个自定义的输出格式,用于将数据写入到DorisDB中。在这个示例代码中,DorisDBOutputFormat的batchSize属性设置为1000,表示每1000条数据进行一次批量写入。 4. 运行数据同步任务 将上述代码保存为一个Java程序,并使用Flink命令行工具提交任务即可开始数据同步。在执行过程中,Flink CDC会自动监控DorisDB中的数据变更,将新增、修改、删除等操作同步到目标数据库中。 总的来说,使用Flink CDC实现DorisDB数据同步是一种高效、可靠的方式。它不仅可以帮助用户快速实现数据同步,还可以提高数据的实时性和准确性,为企业的数据分析和决策提供有力支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值