This is an automated email from the ASF dual-hosted git repository. xtsong pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/flink.git
commit 798a20a2c948db976ff7ef9e24f92191834bd921 Author: Wencong Liu <liuwencle...@163.com> AuthorDate: Fri Sep 8 11:04:27 2023 +0800 [FLINK-32978][flink-core] Deprecate RichFunction#open(Configuration parameters) --- .../api/common/functions/DefaultOpenContext.java | 28 +++++++++++ .../flink/api/common/functions/OpenContext.java | 29 ++++++++++++ .../flink/api/common/functions/RichFunction.java | 55 ++++++++++++++++++++++ 3 files changed, 112 insertions(+) diff --git a/flink-core/src/main/java/org/apache/flink/api/common/functions/DefaultOpenContext.java b/flink-core/src/main/java/org/apache/flink/api/common/functions/DefaultOpenContext.java new file mode 100644 index 00000000000..21fca4e4c31 --- /dev/null +++ b/flink-core/src/main/java/org/apache/flink/api/common/functions/DefaultOpenContext.java @@ -0,0 +1,28 @@ +/* + * 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.api.common.functions; + +import org.apache.flink.annotation.PublicEvolving; + +/** The default implementation of {@link OpenContext}. */ +@PublicEvolving +public class DefaultOpenContext implements OpenContext { + + public static final OpenContext INSTANCE = new DefaultOpenContext(); +} diff --git a/flink-core/src/main/java/org/apache/flink/api/common/functions/OpenContext.java b/flink-core/src/main/java/org/apache/flink/api/common/functions/OpenContext.java new file mode 100644 index 00000000000..4ff5484b3b0 --- /dev/null +++ b/flink-core/src/main/java/org/apache/flink/api/common/functions/OpenContext.java @@ -0,0 +1,29 @@ +/* + * 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.api.common.functions; + +import org.apache.flink.annotation.PublicEvolving; + +/** + * The {@link OpenContext} interface provides necessary information required by the {@link + * RichFunction} when it is opened. The {@link OpenContext} is currently empty because it can be + * used to add more methods without affecting the signature of {@code RichFunction#open}. + */ +@PublicEvolving +public interface OpenContext {} diff --git a/flink-core/src/main/java/org/apache/flink/api/common/functions/RichFunction.java b/flink-core/src/main/java/org/apache/flink/api/common/functions/RichFunction.java index 240b228557f..ae83fb30f2b 100644 --- a/flink-core/src/main/java/org/apache/flink/api/common/functions/RichFunction.java +++ b/flink-core/src/main/java/org/apache/flink/api/common/functions/RichFunction.java @@ -19,6 +19,7 @@ package org.apache.flink.api.common.functions; import org.apache.flink.annotation.Public; +import org.apache.flink.annotation.PublicEvolving; import org.apache.flink.configuration.Configuration; /** @@ -61,9 +62,63 @@ public interface RichFunction extends Function { * When the runtime catches an exception, it aborts the task and lets the fail-over logic * decide whether to retry the task execution. * @see org.apache.flink.configuration.Configuration + * @deprecated This method is deprecated since Flink 1.19. The users are recommended to + * implement {@code open(OpenContext openContext)} and implement {@code open(Configuration + * parameters)} with an empty body instead. 1. If you implement {@code open(OpenContext + * openContext)}, the {@code open(OpenContext openContext)} will be invoked and the {@code + * open(Configuration parameters)} won't be invoked. 2. If you don't implement {@code + * open(OpenContext openContext)}, the {@code open(Configuration parameters)} will be + * invoked in the default implementation of the {@code open(OpenContext openContext)}. + * @see <a href="https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=263425231"> + * FLIP-344: Remove parameter in RichFunction#open </a> */ + @Deprecated void open(Configuration parameters) throws Exception; + /** + * Initialization method for the function. It is called before the actual working methods (like + * <i>map</i> or <i>join</i>) and thus suitable for one time setup work. For functions that are + * part of an iteration, this method will be invoked at the beginning of each iteration + * superstep. + * + * <p>The openContext object passed to the function can be used for configuration and + * initialization. The openContext contains some necessary information that were configured on + * the function in the program composition. + * + * <pre>{@code + * public class MyFilter extends RichFilterFunction<String> { + * + * private String searchString; + * + * public void open(OpenContext openContext) { + * // initialize the value of searchString + * } + * + * public boolean filter(String value) { + * return value.equals(searchString); + * } + * } + * }</pre> + * + * <p>By default, this method does nothing. + * + * <p>1. If you implement {@code open(OpenContext openContext)}, the {@code open(OpenContext + * openContext)} will be invoked and the {@code open(Configuration parameters)} won't be + * invoked. 2. If you don't implement {@code open(OpenContext openContext)}, the {@code + * open(Configuration parameters)} will be invoked in the default implementation of the {@code + * open(OpenContext openContext)}. + * + * @param openContext The context containing information about the context in which the function + * is opened. + * @throws Exception Implementations may forward exceptions, which are caught by the runtime. + * When the runtime catches an exception, it aborts the task and lets the fail-over logic + * decide whether to retry the task execution. + */ + @PublicEvolving + default void open(OpenContext openContext) throws Exception { + open(new Configuration()); + } + /** * Tear-down method for the user code. It is called after the last call to the main working * methods (e.g. <i>map</i> or <i>join</i>). For functions that are part of an iteration, this