基于这个例子(https://github.com/confluentinc/kafka-streams-examples/blob/5.5.0-post/src/test/java/io/confluent/examples/streams/window/DailyTimeWindows.java),我想创建一个每月的时间窗口。问题是尺寸法,我不知道它的大小,因为每个月都有不同的大小。
对于更多的上下文,我希望计算每个在一个月内基于userId进行事务的唯一用户。
windowsFor方法的实际实现:
public Map<Long, TimeWindow> windowsFor(final long timestamp) {
final Instant instant = Instant.ofEpochMilli(timestamp);
final ZonedDateTime zonedDateTime = instant.atZone(this.zoneId);
final ZonedDateTime startTime = zonedDateTime.truncatedTo(ChronoUnit.DAYS).withDayOfMonth(1);
final ZonedDateTime endTime = startTime.plusMonths(1);
final Map<Long, TimeWindow> windows = new LinkedHashMap<>();
windows.put(toEpochMilli(startTime), new TimeWindow(toEpochMilli(startTime), toEpochMilli(endTime)));
return windows;
}有人有主意吗?
https://stackoverflow.com/questions/65202905
复制相似问题