mcmmining commented on code in PR #15601: URL: https://github.com/apache/kafka/pull/15601#discussion_r1545728831
########## streams/src/main/java/org/apache/kafka/streams/kstream/internals/KStreamKStreamLeftJoin.java: ########## @@ -0,0 +1,201 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.kafka.streams.kstream.internals; + +import java.util.Optional; +import org.apache.kafka.streams.KeyValue; +import org.apache.kafka.streams.kstream.ValueJoinerWithKey; +import org.apache.kafka.streams.kstream.internals.KStreamImplJoin.TimeTrackerSupplier; +import org.apache.kafka.streams.processor.api.Processor; +import org.apache.kafka.streams.processor.api.Record; +import org.apache.kafka.streams.state.KeyValueIterator; +import org.apache.kafka.streams.state.KeyValueStore; +import org.apache.kafka.streams.state.WindowStoreIterator; +import org.apache.kafka.streams.state.internals.LeftOrRightValue; +import org.apache.kafka.streams.state.internals.TimestampedKeyAndJoinSide; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +class KStreamKStreamLeftJoin<K, V1, V2, VOut> extends KStreamKStreamJoin<K, V1, V2, VOut> { + private static final Logger LOG = LoggerFactory.getLogger(KStreamKStreamJoin.class); + + KStreamKStreamLeftJoin(final String otherWindowName, + final JoinWindowsInternal windows, + final ValueJoinerWithKey<? super K, ? super V1, ? super V2, ? extends VOut> joiner, + final boolean outer, + final Optional<String> outerJoinWindowName, + final TimeTrackerSupplier sharedTimeTrackerSupplier) { + super(otherWindowName, windows, windows.beforeMs, windows.afterMs, joiner, outerJoinWindowName, + sharedTimeTrackerSupplier, outer); + } + + @Override + public Processor<K, V1, K, VOut> get() { + return new KStreamKStreamLeftJoinProcessor(); + } + + private class KStreamKStreamLeftJoinProcessor extends KStreamKStreamJoinProcessor { + @Override + public void process(final Record<K, V1> leftRecord) { + final long inputRecordTimestamp = leftRecord.timestamp(); + final long timeFrom = Math.max(0L, inputRecordTimestamp - joinBeforeMs); + final long timeTo = Math.max(0L, inputRecordTimestamp + joinAfterMs); + sharedTimeTracker.advanceStreamTime(inputRecordTimestamp); + + if (outer && leftRecord.key() == null && leftRecord.value() != null) { + final VOut leftJoinValue = joiner.apply(leftRecord.key(), leftRecord.value(), null); + context().forward(leftRecord.withValue(leftJoinValue)); + return; + } else if (StreamStreamJoinUtil.skipRecord(leftRecord, LOG, droppedRecordsSensor, context())) { + return; + } + + // Emit all non-joined records which window has closed + if (inputRecordTimestamp == sharedTimeTracker.streamTime) { + leftOuterJoinStore.ifPresent(store -> emitNonJoinedOuterRecords(store, leftRecord)); + } + + boolean needOuterJoin = outer; + try (final WindowStoreIterator<V2> iter = otherWindowStore.fetch(leftRecord.key(), timeFrom, timeTo)) { Review Comment: > I also have a couple of questions. When is this store getting filled? I couldn't find anywhere where we call `.put()` for this window store. -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org