Java Apache Beam从事件流创建时间序列
我试图创建一个时间序列,记录在给定时间内发生的事件的数量 事件被编码为Java Apache Beam从事件流创建时间序列,java,apache-beam,windowing,Java,Apache Beam,Windowing,我试图创建一个时间序列,记录在给定时间内发生的事件的数量 事件被编码为 PCollection<KV<String, Long>> events; 输出: [ { id: "one" windows: [ { timestamp: 0, count: 2 }, { timestamp: 10, count: 1 }, {
PCollection<KV<String, Long>> events;
输出:
[
{
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
}
]
}
]
我希望这是有意义的:)您可以做一些工作,将您的输入转换为
[
("one", [1, 13, 2, 43]),
("two", [3]),
]
此时,您可以应用DoFn将整数列表转换为Timeseries对象(例如,通过在适当的时间创建TimeseriesWindow列表,然后迭代增加计数的值)
你也可以调查一下,看看这是否能满足你的需要
[
{
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
}
]
}
]
[
("one", [1, 13, 2, 43]),
("two", [3]),
]