【问题标题】:Rolling up events to a minute in Apache Beam在 Apache Beam 中将事件汇总到一分钟
【发布时间】:2018-09-04 07:47:41
【问题描述】:

所以,我有一个具有这种结构的数据流(我很抱歉它在 SQL 中)

CREATE TABLE github_events
(
    event_id bigint,
    event_type text,
    event_public boolean,
    repo_id bigint,
    payload jsonb,
    repo jsonb,
    user_id bigint,
    org jsonb,
    created_at timestamp 
);

在 SQL 中,我会将这些数据汇总到一分钟,如下所示:

1.为此创建一个汇总表:

CREATE TABLE github_events_rollup_minute
(
    created_at timestamp,
    event_count bigint
);

2.并用 INSERT/SELECT 填充:

INSERT INTO github_events_rollup_minute(
    created_at,
    event_count
)
SELECT
    date_trunc('minute', created_at) AS created_at,
    COUNT(*)the  AS event_count
FROM github_events
GROUP BY 1;

在 Apache Beam 中,我试图将事件汇总到一分钟,即根据事件的时间戳字段计算该分钟内收到的事件总数。

Timestamp(in YYYY-MM-DDThh:mm): event_count

因此,稍后在管道中,如果我们收到更多具有相同重叠时间戳的事件(由于事件接收延迟,因为客户可能离线),我们只需要获取汇总计数并增加该计数时间戳。

这将允许我们在应用程序中简单地将YYYY-MM-DDThh:mm 的计数增加event_count

假设,事件可能会延迟,但它们将始终具有 timestamp 字段。

我想在 Apache Beam 中完成同样的事情。我对 Apache Beam 很陌生,我觉得我在 Beam 中遗漏了一些可以让我完成此任务的东西。我已经多次阅读Apache Beam Programming Guide

【问题讨论】:

    标签: apache-beam


    【解决方案1】:

    查看WindowingTriggers 上的部分。您所描述的是具有允许延迟数据的固定时间窗口。管道的一般形状听起来像:

    1. 读取输入github_events数据
    2. 窗口为 1 分钟的固定窗口,允许延迟数据
    3. 统计每个窗口的事件数
    4. 将结果输出到github_events_rollup_minute

    WindowedWordCount 示例项目演示了这种模式。

    【讨论】:

      猜你喜欢
      • 2017-09-10
      • 1970-01-01
      • 2014-04-17
      • 1970-01-01
      • 1970-01-01
      • 2019-10-29
      • 2022-10-26
      • 1970-01-01
      • 2016-08-27
      相关资源
      最近更新 更多