File size: 1,130 Bytes
e8c001c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
-- flinksql_019: 全局分组 + 过滤统计
-- 生成 3000 行/秒的交易事件流,使用反引号包裹保留字

-- 1. 交易事件流 datagen 源表(无事件时间/Watermark)
CREATE TABLE trade_source (
    trade_id BIGINT,
    `type` INT,
    `status` INT,
    amount DOUBLE
) WITH (
    'connector' = 'datagen',
    'rows-per-second' = '3000',
    'fields.trade_id.kind' = 'random',
    'fields.trade_id.min' = '1',
    'fields.trade_id.max' = '1000000000',
    'fields.type.kind' = 'random',
    'fields.type.min' = '1',
    'fields.type.max' = '5',
    'fields.status.kind' = 'random',
    'fields.status.min' = '0',
    'fields.status.max' = '2',
    'fields.amount.kind' = 'random',
    'fields.amount.min' = '0',
    'fields.amount.max' = '5000'
);

-- 2. Console 输出表
CREATE TABLE console_output (
    `type` INT,
    trade_cnt BIGINT,
    total_amount DOUBLE
) WITH (
    'connector' = 'print'
);

-- 3. 过滤 status=1 + 按 type 分组统计
INSERT INTO console_output
SELECT
    `type`,
    COUNT(*) AS trade_cnt,
    SUM(amount) AS total_amount
FROM trade_source
WHERE `status` = 1
GROUP BY `type`;