leonardBang commented on a change in pull request #14207:
URL: https://github.com/apache/flink/pull/14207#discussion_r537301231
##########
File path:
flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/operators/join/lookup/AsyncLookupJoinRunner.java
##########
@@ -153,11 +154,20 @@ public void close() throws Exception {
if (fetcher != null) {
FunctionUtils.closeFunction(fetcher);
}
- for (JoinedRowResultFuture rf : allResultFutures) {
- rf.close();
+ if (allResultFutures != null) {
+ for (JoinedRowResultFuture rf : allResultFutures) {
+ if (rf != null) {
Review comment:
`rf` should always not null ?
##########
File path:
flink-table/flink-table-runtime-blink/src/test/java/org/apache/flink/table/runtime/operators/join/AsyncLookupJoinRunnerTest.java
##########
@@ -0,0 +1,156 @@
+/*
+ * 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.configuration.Configuration;
+import org.apache.flink.streaming.api.functions.async.AsyncFunction;
+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.runtime.collector.TableFunctionCollector;
+import org.apache.flink.table.runtime.collector.TableFunctionResultFuture;
+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.InternalTypeInfo;
+
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.function.Supplier;
+
+import static org.apache.flink.table.data.StringData.fromString;
+import static org.apache.flink.table.runtime.util.StreamRecordUtils.row;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+/**
+ * Tests for {@link AsyncLookupJoinRunner}.
+ */
+public class AsyncLookupJoinRunnerTest {
+
+ @Test
+ public void testCloseAsyncLookupJoinRunner() throws Exception {
+ final InternalTypeInfo<RowData> rightRowTypeInfo =
InternalTypeInfo.ofFields(
+ DataTypes.INT().getLogicalType(),
+ DataTypes.STRING().getLogicalType());
+ final AsyncLookupJoinRunner joinRunner = new
AsyncLookupJoinRunner(
+ new GeneratedFunctionWrapper(new
TestingFetcherFunction()),
+ new GeneratedResultFutureWrapper<>(new
TestingFetcherResultFuture()),
+ rightRowTypeInfo,
+ rightRowTypeInfo,
+ true,
+ 100);
+ assertNull(joinRunner.getAllResultFutures());
+ closeAsyncLookupJoinRunner(joinRunner);
+
+ joinRunner.setRuntimeContext(new
MockStreamingRuntimeContext(false, 1, 0));
+ joinRunner.open(new Configuration());
+ assertNotNull(joinRunner.getAllResultFutures());
+ closeAsyncLookupJoinRunner(joinRunner);
+
+ joinRunner.open(new Configuration());
+ joinRunner.asyncInvoke(row(1, "a"), new
TestingFetcherResultFuture());
+ assertNotNull(joinRunner.getAllResultFutures());
+ closeAsyncLookupJoinRunner(joinRunner);
+ }
+
+ private void closeAsyncLookupJoinRunner(AsyncLookupJoinRunner
joinRunner) throws Exception {
+ try {
+ joinRunner.close();
+ } catch (NullPointerException e) {
+ fail("Expected close to fail with null pointer
exception.");
+ }
+ }
+
+ //
---------------------------------------------------------------------------------
+
+ /**
+ * The {@link TestingFetcherFunction} only accepts a single integer
lookup key and
+ * returns zero or one or more RowData.
+ */
+ public static final class TestingFetcherFunction
+ extends AbstractRichFunction
+ implements AsyncFunction<RowData, RowData> {
+
+ private static final long serialVersionUID =
4018474964018227081L;
Review comment:
looks like `TestingFetcherFunction` and `TestingFetcherResultFuture`
are redundant, we defined same inner class in three tests with same versionId,
I think it's an existed issue. Could we only define once and reuse them?
##########
File path:
flink-table/flink-table-runtime-blink/src/test/java/org/apache/flink/table/runtime/operators/join/AsyncLookupJoinRunnerTest.java
##########
@@ -0,0 +1,156 @@
+/*
+ * 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.configuration.Configuration;
+import org.apache.flink.streaming.api.functions.async.AsyncFunction;
+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.runtime.collector.TableFunctionCollector;
+import org.apache.flink.table.runtime.collector.TableFunctionResultFuture;
+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.InternalTypeInfo;
+
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.function.Supplier;
+
+import static org.apache.flink.table.data.StringData.fromString;
+import static org.apache.flink.table.runtime.util.StreamRecordUtils.row;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+/**
+ * Tests for {@link AsyncLookupJoinRunner}.
+ */
+public class AsyncLookupJoinRunnerTest {
+
+ @Test
+ public void testCloseAsyncLookupJoinRunner() throws Exception {
+ final InternalTypeInfo<RowData> rightRowTypeInfo =
InternalTypeInfo.ofFields(
+ DataTypes.INT().getLogicalType(),
+ DataTypes.STRING().getLogicalType());
+ final AsyncLookupJoinRunner joinRunner = new
AsyncLookupJoinRunner(
+ new GeneratedFunctionWrapper(new
TestingFetcherFunction()),
+ new GeneratedResultFutureWrapper<>(new
TestingFetcherResultFuture()),
+ rightRowTypeInfo,
+ rightRowTypeInfo,
+ true,
+ 100);
+ assertNull(joinRunner.getAllResultFutures());
+ closeAsyncLookupJoinRunner(joinRunner);
+
+ joinRunner.setRuntimeContext(new
MockStreamingRuntimeContext(false, 1, 0));
+ joinRunner.open(new Configuration());
+ assertNotNull(joinRunner.getAllResultFutures());
+ closeAsyncLookupJoinRunner(joinRunner);
+
+ joinRunner.open(new Configuration());
+ joinRunner.asyncInvoke(row(1, "a"), new
TestingFetcherResultFuture());
+ assertNotNull(joinRunner.getAllResultFutures());
+ closeAsyncLookupJoinRunner(joinRunner);
+ }
+
+ private void closeAsyncLookupJoinRunner(AsyncLookupJoinRunner
joinRunner) throws Exception {
+ try {
+ joinRunner.close();
+ } catch (NullPointerException e) {
+ fail("Expected close to fail with null pointer
exception.");
Review comment:
```suggestion
fail("Unexpected close that failed with " + e.getMessage());
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]