matriv commented on a change in pull request #18479: URL: https://github.com/apache/flink/pull/18479#discussion_r797470332
########## File path: flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/ExecNodeContext.java ########## @@ -0,0 +1,145 @@ +/* + * 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.planner.plan.nodes.exec; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.annotation.VisibleForTesting; +import org.apache.flink.table.planner.plan.utils.ExecNodeMetadataUtil; + +import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator; +import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonValue; +import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DatabindContext; + +import static org.apache.flink.util.Preconditions.checkNotNull; + +/** + * Helper class that holds the necessary identifier fields that are used for JSON plan serialization + * and deserialization. It is instantiated using {@link ExecNodeContext#newContext(Class)} when + * creating a new instance of an {@link ExecNode}, so that is contains the info from the {@link + * ExecNodeMetadata} annotation of the class with the latest {@link ExecNodeMetadata#version()}. It + * can also be instantiated with {@link ExecNodeContext#ExecNodeContext(String)} automatically when + * the {@link ExecNode} is deserialized from a JSON Plan, and in this case the {@link + * ExecNodeContext} contains the version that is read from the JSON Plan and not the latest one. + */ +@Internal +public final class ExecNodeContext { + + /** This is used to assign a unique ID to every ExecNode. */ + private static Integer idCounter = 0; + + /** Generate an unique ID for ExecNode. */ + public static int newNodeId() { + idCounter++; + return idCounter; + } + + /** Reset the id counter to 0. */ + @VisibleForTesting + public static void resetIdCounter() { + idCounter = 0; + } + + private Integer id; Review comment: I'm not marking here as `@Nullable` but int the relevant ctor and added the javadoc there. -- 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]
