【发布时间】:2020-02-18 16:42:10
【问题描述】:
我正在尝试创建在给定时间内发生的事件计数的时间序列。
事件被编码为
PCollection<KV<String, Long>> events;
其中String是事件源的id,long是事件的时间戳。
我想要的是具有以下形式的时间序列的PCollection<Timeseries>
class Timeseries {
String id;
List<TimeseriesWindow> windows;
}
class TimeseriesWindow {
long timestamp;
long count;
}
具有10秒的固定窗口大小(这是正确的术语吗?)的玩具示例,总时间序列持续时间60秒:
输入:
[("one", 1), ("one", 13), ("one", 2), ("one", 43), ("two", 3)]
输出:
[
{
id: "one"
windows: [
{
timestamp: 0,
count: 2
},
{
timestamp: 10,
count: 1
},
{
timestamp: 20,
count: 0
},
{
timestamp: 30,
count: 0
},
{
timestamp: 40,
count: 1
},
{
timestamp: 50,
count: 0
}
]
},
{
id: "two"
windows: [
{
timestamp: 0,
count: 1
},
{
timestamp: 10,
count: 0
},
{
timestamp: 20,
count: 0
},
{
timestamp: 30,
count: 0
},
{
timestamp: 40,
count: 0
},
{
timestamp: 50,
count: 0
}
]
}
]
我希望这是有道理的:)
【问题讨论】:
标签: java apache-beam windowing