spuru9 commented on code in PR #30262: URL: https://github.com/apache/flink/pull/30262#discussion_r4789858284
########## flink-table/flink-table-runtime/src/test/java/org/apache/flink/table/runtime/operators/join/AsyncLookupJoinRunnerConverterTest.java: ########## @@ -0,0 +1,191 @@ +/* + * 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.flink.table.runtime.operators.join; + +import org.apache.flink.api.common.functions.AbstractRichFunction; +import org.apache.flink.api.common.functions.DefaultOpenContext; +import org.apache.flink.streaming.api.functions.async.AsyncFunction; +import org.apache.flink.streaming.api.functions.async.CollectionSupplier; +import org.apache.flink.streaming.api.functions.async.ResultFuture; +import org.apache.flink.streaming.util.MockStreamingRuntimeContext; +import org.apache.flink.table.api.DataTypes; +import org.apache.flink.table.data.GenericRowData; +import org.apache.flink.table.data.RowData; +import org.apache.flink.table.data.conversion.DataStructureConverter; +import org.apache.flink.table.runtime.generated.GeneratedFunctionWrapper; +import org.apache.flink.table.runtime.generated.GeneratedResultFutureWrapper; +import org.apache.flink.table.runtime.operators.join.lookup.AsyncLookupJoinRunner; +import org.apache.flink.table.runtime.typeutils.InternalSerializers; +import org.apache.flink.table.runtime.typeutils.RowDataSerializer; +import org.apache.flink.types.Row; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import static org.apache.flink.table.data.StringData.fromString; +import static org.apache.flink.table.runtime.util.StreamRecordUtils.row; +import static org.assertj.core.api.Assertions.assertThat; + +/** Checks that no two futures of {@link AsyncLookupJoinRunner} convert with the same converter. */ +class AsyncLookupJoinRunnerConverterTest { Review Comment: **minor:** Could these two tests go into `AsyncLookupJoinRunnerTimeoutTest`? Its `createRunner(fetcher, converter, template, isLeftOuterJoin)` already takes a custom converter, and its `StoringFetcherFunction` could also keep the timed-out futures. That way we don't end up with two `StoringFetcherFunction` classes in one package. ########## flink-table/flink-table-runtime/src/test/java/org/apache/flink/table/runtime/operators/join/AsyncLookupJoinRunnerConverterTest.java: ########## @@ -0,0 +1,191 @@ +/* + * 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.flink.table.runtime.operators.join; + +import org.apache.flink.api.common.functions.AbstractRichFunction; +import org.apache.flink.api.common.functions.DefaultOpenContext; +import org.apache.flink.streaming.api.functions.async.AsyncFunction; +import org.apache.flink.streaming.api.functions.async.CollectionSupplier; +import org.apache.flink.streaming.api.functions.async.ResultFuture; +import org.apache.flink.streaming.util.MockStreamingRuntimeContext; +import org.apache.flink.table.api.DataTypes; +import org.apache.flink.table.data.GenericRowData; +import org.apache.flink.table.data.RowData; +import org.apache.flink.table.data.conversion.DataStructureConverter; +import org.apache.flink.table.runtime.generated.GeneratedFunctionWrapper; +import org.apache.flink.table.runtime.generated.GeneratedResultFutureWrapper; +import org.apache.flink.table.runtime.operators.join.lookup.AsyncLookupJoinRunner; +import org.apache.flink.table.runtime.typeutils.InternalSerializers; +import org.apache.flink.table.runtime.typeutils.RowDataSerializer; +import org.apache.flink.types.Row; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import static org.apache.flink.table.data.StringData.fromString; +import static org.apache.flink.table.runtime.util.StreamRecordUtils.row; +import static org.assertj.core.api.Assertions.assertThat; + +/** Checks that no two futures of {@link AsyncLookupJoinRunner} convert with the same converter. */ +class AsyncLookupJoinRunnerConverterTest { + + private AsyncLookupJoinRunner joinRunner; + + @BeforeEach + void before() throws Exception { + RecordingConverter.USED.clear(); + StoringFetcherFunction.INVOKED.clear(); + StoringFetcherFunction.TIMED_OUT.clear(); + joinRunner = + new AsyncLookupJoinRunner( + new GeneratedFunctionWrapper<>(new StoringFetcherFunction()), + new RecordingConverter(), + new GeneratedResultFutureWrapper<>( + new AsyncLookupJoinHarnessTest.TestingFetcherResultFuture()), + new GeneratedFunctionWrapper<>( + new LookupJoinHarnessTest.TestingPreFilterCondition()), + (RowDataSerializer) + InternalSerializers.<RowData>create( + DataTypes.ROW(DataTypes.INT(), DataTypes.STRING()) + .getLogicalType()), + false, + 10); + joinRunner.setRuntimeContext(new MockStreamingRuntimeContext(1, 0)); + joinRunner.open(DefaultOpenContext.INSTANCE); + } + + @AfterEach + void after() throws Exception { + joinRunner.close(); + } + + @Test + void testInFlightFuturesUseTheirOwnConverter() throws Exception { + final List<CapturingResultFuture> outputs = new ArrayList<>(); + for (int i = 0; i < 3; i++) { + final CapturingResultFuture output = new CapturingResultFuture(); + joinRunner.asyncInvoke(row(i, "a"), output); + outputs.add(output); + } + for (int i = 0; i < 3; i++) { + StoringFetcherFunction.INVOKED.get(i).complete(lookupResult(i)); + } + + assertThat(RecordingConverter.USED).hasSize(3).doesNotHaveDuplicates(); + for (int i = 0; i < 3; i++) { + assertThat(outputs.get(i).result).hasSize(1); + assertThat(outputs.get(i).result.iterator().next().getInt(2)).isEqualTo(i); + } + } + + @Test + void testTimeoutReplacementsUseTheirOwnConverter() throws Exception { + for (int i = 0; i < 2; i++) { + final RowData input = row(i, "a"); + final CapturingResultFuture output = new CapturingResultFuture(); + joinRunner.asyncInvoke(input, output); + joinRunner.timeout(input, output); + } + joinRunner.asyncInvoke(row(2, "a"), new CapturingResultFuture()); + + StoringFetcherFunction.TIMED_OUT.get(0).complete(lookupResult(0)); + StoringFetcherFunction.TIMED_OUT.get(1).complete(lookupResult(1)); + StoringFetcherFunction.INVOKED.get(2).complete(lookupResult(2)); + + assertThat(RecordingConverter.USED).hasSize(3).doesNotHaveDuplicates(); Review Comment: **minor:** This test never reads its outputs, so it doesn't check that each replacement's row reaches the right `ResultFuture`. Could you keep the outputs and assert `getInt(2)` like the first test does? ########## flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/join/lookup/AsyncLookupJoinRunner.java: ########## @@ -140,6 +139,20 @@ public void asyncInvoke(RowData input, ResultFuture<RowData> resultFuture) throw } } + /** + * Converters are not thread-safe and each future converts on the thread that completes it, so + * every future gets its own converter. + */ Review Comment: **nit:** With an identity conversion all futures share one converter, so "every future gets its own converter" isn't quite true. ```suggestion /** * Converters are not thread-safe and each future converts on the thread that completes it, so * every future gets its own copy. An identity converter never converts and can be shared. */ ``` -- 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]
