GroupByKey 创建的 Iterable 是否有序
Is the Iterable created by GroupByKey ordered
即,如果我的 window 是
Window.into(new GlobalWindows())
.triggering(Repeatedly.forever(AfterPane.elementCountAtLeast(0)))
.accumulatingFiredPanes();
在我按键分组后,每当新元素进入该键的 window 时,管道中的下一步都会收到一个 Iterable,我可以可靠地说 Iterable 的最后一个或第一个元素是进入 window?
的元素
我们有一连串的论坛评论进来,可能是乱序的,我们希望输出一个主题的评论数量列表,每次发表评论。如果我们有迟到的评论,我们需要重新发布我们之前发布的跟在该评论之后的所有主题状态,因为它们的数量现在相差一个。
即输入:
topic_id, event_time
1, 1
1, 2
1, 3
1, 4
1, 0 // out of order
1, 5
输出:
topic_id, state_time, num_comments
1, 1, 1 // in order, issue states accumulating as they came in
1, 2, 2
1, 3, 3
1, 4, 4
1, 0, 1 // got out of order event, need to reissue everything after it
1, 1, 2 // reissue
1, 2, 3 // reissue
1, 3, 4 // reissue
1, 4, 5 // reissue
1, 5, 5 // back to normal processing
该示例是人为设计的,实际上 "num_comments" 表示的输出是相当复杂的逻辑,需要查看某个主题当时存在的所有数据。
显然,一种选择是为每个事件重新发布所有状态。但这会稍微增加数据量。
不,GroupByKey
返回的 PCollection<KV<K, Iterable<V>>>
中的 Iterable<V>
没有顺序保证。
您能否在问题中详细说明您要实现的目标以及为什么需要排序?我们发现,在几乎所有情况下,当人们需要在 GBK 中进行排序时,都有一种替代方法可以实现他们的目标。
即,如果我的 window 是
Window.into(new GlobalWindows())
.triggering(Repeatedly.forever(AfterPane.elementCountAtLeast(0)))
.accumulatingFiredPanes();
在我按键分组后,每当新元素进入该键的 window 时,管道中的下一步都会收到一个 Iterable,我可以可靠地说 Iterable 的最后一个或第一个元素是进入 window?
的元素我们有一连串的论坛评论进来,可能是乱序的,我们希望输出一个主题的评论数量列表,每次发表评论。如果我们有迟到的评论,我们需要重新发布我们之前发布的跟在该评论之后的所有主题状态,因为它们的数量现在相差一个。
即输入:
topic_id, event_time
1, 1
1, 2
1, 3
1, 4
1, 0 // out of order
1, 5
输出:
topic_id, state_time, num_comments
1, 1, 1 // in order, issue states accumulating as they came in
1, 2, 2
1, 3, 3
1, 4, 4
1, 0, 1 // got out of order event, need to reissue everything after it
1, 1, 2 // reissue
1, 2, 3 // reissue
1, 3, 4 // reissue
1, 4, 5 // reissue
1, 5, 5 // back to normal processing
该示例是人为设计的,实际上 "num_comments" 表示的输出是相当复杂的逻辑,需要查看某个主题当时存在的所有数据。
显然,一种选择是为每个事件重新发布所有状态。但这会稍微增加数据量。
不,GroupByKey
返回的 PCollection<KV<K, Iterable<V>>>
中的 Iterable<V>
没有顺序保证。
您能否在问题中详细说明您要实现的目标以及为什么需要排序?我们发现,在几乎所有情况下,当人们需要在 GBK 中进行排序时,都有一种替代方法可以实现他们的目标。