gyfora commented on code in PR #28837:
URL: https://github.com/apache/flink/pull/28837#discussion_r3776236409


##########
flink-libraries/flink-state-processing-api/src/main/java/org/apache/flink/state/api/StateTableUtils.java:
##########
@@ -0,0 +1,641 @@
+/*
+ * 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.state.api;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.common.state.StateDescriptor;
+import org.apache.flink.api.common.typeutils.TypeSerializerSnapshot;
+import org.apache.flink.runtime.checkpoint.OperatorState;
+import org.apache.flink.runtime.checkpoint.OperatorSubtaskState;
+import org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata;
+import org.apache.flink.runtime.state.IncrementalKeyedStateHandle;
+import org.apache.flink.runtime.state.KeyGroupsSavepointStateHandle;
+import org.apache.flink.runtime.state.KeyGroupsStateHandle;
+import org.apache.flink.runtime.state.KeyedStateHandle;
+import org.apache.flink.runtime.state.StateBackendLoader;
+import org.apache.flink.runtime.state.VoidNamespaceSerializer;
+import org.apache.flink.runtime.state.changelog.ChangelogStateBackendHandle;
+import org.apache.flink.state.api.schema.KeyedStateSchemaInfo;
+import 
org.apache.flink.state.api.schema.SerializerSnapshotToLogicalTypeConverter;
+import org.apache.flink.state.api.schema.StateSchemaExtractor;
+import org.apache.flink.state.api.schema.StateSchemaInfo;
+import org.apache.flink.state.table.SavepointConnectorOptions;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.factories.FactoryUtil;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.logical.ArrayType;
+import org.apache.flink.table.types.logical.BigIntType;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.MapType;
+import org.apache.flink.table.types.logical.VarBinaryType;
+import org.apache.flink.table.types.utils.LogicalTypeDataTypeConverter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nullable;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * High-level utility for inspecting and reading keyed state from a checkpoint 
/ savepoint without
+ * requiring user POJO classes on the classpath.
+ */
+@Internal
+public final class StateTableUtils {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(StateTableUtils.class);
+
+    private StateTableUtils() {}
+
+    /**
+     * Returns the {@link OperatorIdentifier}s of all operators present in the 
given checkpoint
+     * metadata that have at least one non-internal keyed state.
+     *
+     * @param metadata the checkpoint metadata to inspect
+     * @return list of operator identifiers; never null, may be empty
+     */
+    public static List<OperatorIdentifier> 
getOperatorIdentifiers(CheckpointMetadata metadata) {
+        return metadata.getOperatorStates().stream()
+                .filter(StateTableUtils::hasNonInternalKeyedState)
+                .map(
+                        op ->
+                                op.getOperatorUid()
+                                        .map(OperatorIdentifier::forUid)
+                                        .orElseGet(
+                                                () ->
+                                                        
OperatorIdentifier.forUidHash(
+                                                                
op.getOperatorID().toHexString())))
+                .collect(Collectors.toList());
+    }
+
+    private static boolean hasNonInternalKeyedState(OperatorState op) {
+        try {
+            List<StateSchemaInfo> schemas = 
StateSchemaExtractor.extractSchema(op);
+            ClassifiedStates classified = 
classifyStates(op.getOperatorID().toHexString(), schemas);
+            return !classified.voidNamespaceStates.isEmpty()
+                    || !classified.windowNamespaceStates.isEmpty();
+        } catch (Exception e) {

Review Comment:
   It's arguably better to log an error than to effectively disable the whole 
catalog functionality due to a bug. I have changed the logs from warn to error 
to make it more obvious but throwing the error and breaking the catalog is not 
a good idea I think.



-- 
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]

Reply via email to