lihaosky commented on code in PR #12037:
URL: https://github.com/apache/kafka/pull/12037#discussion_r850100454
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KStreamSlidingWindowAggregate.java:
##########
@@ -50,17 +59,27 @@
private final SlidingWindows windows;
private final Initializer<VAgg> initializer;
private final Aggregator<? super KIn, ? super VIn, VAgg> aggregator;
+ private final EmitStrategy emitStrategy;
private boolean sendOldValues = false;
public KStreamSlidingWindowAggregate(final SlidingWindows windows,
final String storeName,
final Initializer<VAgg> initializer,
final Aggregator<? super KIn, ? super
VIn, VAgg> aggregator) {
+ this(windows, storeName, EmitStrategy.onWindowUpdate(), initializer,
aggregator);
Review Comment:
We can do that if there's no external caller.
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KStreamSlidingWindowAggregate.java:
##########
@@ -81,23 +100,54 @@ private class KStreamSlidingWindowAggregateProcessor
extends ContextualProcessor
private TimestampedWindowStore<KIn, VAgg> windowStore;
private TimestampedTupleForwarder<Windowed<KIn>, VAgg> tupleForwarder;
private Sensor droppedRecordsSensor;
+ private Sensor emittedRecordsSensor;
+ private Sensor emitFinalLatencySensor;
private long observedStreamTime = ConsumerRecord.NO_TIMESTAMP;
+ private long lastEmitCloseTime = ConsumerRecord.NO_TIMESTAMP;
private Boolean reverseIteratorPossible = null;
+ private InternalProcessorContext<Windowed<KIn>, Change<VAgg>>
internalProcessorContext;
+ private final TimeTracker timeTracker = new TimeTracker();
+ private final Time time = Time.SYSTEM;
@Override
public void init(final ProcessorContext<Windowed<KIn>, Change<VAgg>>
context) {
super.init(context);
- final InternalProcessorContext<Windowed<KIn>, Change<VAgg>>
internalProcessorContext =
- (InternalProcessorContext<Windowed<KIn>, Change<VAgg>>)
context;
+ internalProcessorContext =
(InternalProcessorContext<Windowed<KIn>, Change<VAgg>>) context;
Review Comment:
I can take a look how to do it.
##########
streams/src/main/java/org/apache/kafka/streams/kstream/internals/KStreamSlidingWindowAggregate.java:
##########
@@ -467,6 +516,72 @@ private boolean rightWindowIsNotEmpty(final
ValueAndTimestamp<VAgg> rightWinAgg,
return rightWinAgg != null && rightWinAgg.timestamp() >
inputRecordTimestamp;
}
+ private void maybeForwardUpdate(final Record<KIn, VIn> record,
+ final Window window,
+ final VAgg oldAgg,
+ final VAgg newAgg,
+ final long newTimestamp) {
+
+ if (emitStrategy.type() == StrategyType.ON_WINDOW_CLOSE) {
+ return;
+ }
+ tupleForwarder.maybeForward(
+ record.withKey(new Windowed<>(record.key(), window))
+ .withValue(new Change<>(newAgg, sendOldValues ? oldAgg :
null))
+ .withTimestamp(newTimestamp));
+ }
+
+ private void maybeForwardFinalResult(final Record<KIn, VIn> record,
final long closeTime) {
Review Comment:
I'll take a look if it can be unified.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]