You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by dw...@apache.org on 2020/07/30 14:13:11 UTC
[flink] 01/04: [hotfix] Remove dead code in TypeExtractor
This is an automated email from the ASF dual-hosted git repository.
dwysakowicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit 250a6c1ca911535efb5a03433e3f95daf8be3ff7
Author: Dawid Wysakowicz <dw...@apache.org>
AuthorDate: Wed Jul 29 13:53:54 2020 +0200
[hotfix] Remove dead code in TypeExtractor
---
.../flink/api/common/typeinfo/TypeInfoFactory.java | 4 +-
.../flink/api/java/typeutils/TypeExtractor.java | 72 ++++------------------
2 files changed, 13 insertions(+), 63 deletions(-)
diff --git a/flink-core/src/main/java/org/apache/flink/api/common/typeinfo/TypeInfoFactory.java b/flink-core/src/main/java/org/apache/flink/api/common/typeinfo/TypeInfoFactory.java
index 898b05e..54f9335 100644
--- a/flink-core/src/main/java/org/apache/flink/api/common/typeinfo/TypeInfoFactory.java
+++ b/flink-core/src/main/java/org/apache/flink/api/common/typeinfo/TypeInfoFactory.java
@@ -19,7 +19,6 @@
package org.apache.flink.api.common.typeinfo;
import org.apache.flink.annotation.Public;
-import org.apache.flink.api.java.typeutils.TypeExtractor;
import java.lang.reflect.Type;
import java.util.Map;
@@ -29,8 +28,7 @@ import java.util.Map;
* plugging-in user-defined {@link TypeInformation} into the Flink type system. The factory is
* called during the type extraction phase if the corresponding type has been annotated with
* {@link TypeInfo}. In a hierarchy of types the closest factory will be chosen while traversing
- * upwards, however, a globally registered factory has highest precedence
- * (see {@link TypeExtractor#registerFactory(Type, Class)}).
+ * upwards.
*
* @param <T> type for which {@link TypeInformation} is created
*/
diff --git a/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java b/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java
index adcfdbb..b94dd5f 100644
--- a/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java
+++ b/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java
@@ -18,7 +18,6 @@
package org.apache.flink.api.java.typeutils;
-import org.apache.commons.lang3.ClassUtils;
import org.apache.flink.annotation.Internal;
import org.apache.flink.annotation.Public;
import org.apache.flink.annotation.PublicEvolving;
@@ -53,6 +52,8 @@ import org.apache.flink.types.Row;
import org.apache.flink.types.Value;
import org.apache.flink.util.InstantiationUtil;
import org.apache.flink.util.Preconditions;
+
+import org.apache.commons.lang3.ClassUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -72,14 +73,14 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import static org.apache.flink.api.java.typeutils.TypeExtractionUtils.getTypeHierarchy;
-import static org.apache.flink.api.java.typeutils.TypeExtractionUtils.hasSuperclass;
-import static org.apache.flink.util.Preconditions.checkNotNull;
import static org.apache.flink.api.java.typeutils.TypeExtractionUtils.checkAndExtractLambda;
import static org.apache.flink.api.java.typeutils.TypeExtractionUtils.getAllDeclaredMethods;
+import static org.apache.flink.api.java.typeutils.TypeExtractionUtils.getTypeHierarchy;
+import static org.apache.flink.api.java.typeutils.TypeExtractionUtils.hasSuperclass;
import static org.apache.flink.api.java.typeutils.TypeExtractionUtils.isClassType;
import static org.apache.flink.api.java.typeutils.TypeExtractionUtils.sameTypeVars;
import static org.apache.flink.api.java.typeutils.TypeExtractionUtils.typeToClass;
+import static org.apache.flink.util.Preconditions.checkNotNull;
/**
* A utility for reflection analysis on classes, to determine the return type of implementations of transformation
@@ -132,34 +133,6 @@ public class TypeExtractor {
}
// --------------------------------------------------------------------------------------------
- // TypeInfoFactory registry
- // --------------------------------------------------------------------------------------------
-
- private static Map<Type, Class<? extends TypeInfoFactory>> registeredTypeInfoFactories = new HashMap<>();
-
- /**
- * Registers a type information factory globally for a certain type. Every following type extraction
- * operation will use the provided factory for this type. The factory will have highest precedence
- * for this type. In a hierarchy of types the registered factory has higher precedence than annotations
- * at the same level but lower precedence than factories defined down the hierarchy.
- *
- * @param t type for which a new factory is registered
- * @param factory type information factory that will produce {@link TypeInformation}
- */
- private static void registerFactory(Type t, Class<? extends TypeInfoFactory> factory) {
- Preconditions.checkNotNull(t, "Type parameter must not be null.");
- Preconditions.checkNotNull(factory, "Factory parameter must not be null.");
-
- if (!TypeInfoFactory.class.isAssignableFrom(factory)) {
- throw new IllegalArgumentException("Class is not a TypeInfoFactory.");
- }
- if (registeredTypeInfoFactories.containsKey(t)) {
- throw new InvalidTypesException("A TypeInfoFactory for type '" + t + "' is already registered.");
- }
- registeredTypeInfoFactories.put(t, factory);
- }
-
- // --------------------------------------------------------------------------------------------
// Function specific methods
// --------------------------------------------------------------------------------------------
@@ -1498,22 +1471,6 @@ public class TypeExtractor {
}
}
- private static void validateInputContainsExecutable(LambdaExecutable exec, TypeInformation<?> typeInfo) {
- List<Method> methods = getAllDeclaredMethods(typeInfo.getTypeClass());
- for (Method method : methods) {
- if (exec.executablesEquals(method)) {
- return;
- }
- }
- Constructor<?>[] constructors = typeInfo.getTypeClass().getDeclaredConstructors();
- for (Constructor<?> constructor : constructors) {
- if (exec.executablesEquals(constructor)) {
- return;
- }
- }
- throw new InvalidTypesException("Type contains no executable '" + exec.getName() + "'.");
- }
-
// --------------------------------------------------------------------------------------------
// Utility methods
// --------------------------------------------------------------------------------------------
@@ -1524,19 +1481,14 @@ public class TypeExtractor {
@Internal
public static <OUT> TypeInfoFactory<OUT> getTypeInfoFactory(Type t) {
final Class<?> factoryClass;
- if (registeredTypeInfoFactories.containsKey(t)) {
- factoryClass = registeredTypeInfoFactories.get(t);
+ if (!isClassType(t) || !typeToClass(t).isAnnotationPresent(TypeInfo.class)) {
+ return null;
}
- else {
- if (!isClassType(t) || !typeToClass(t).isAnnotationPresent(TypeInfo.class)) {
- return null;
- }
- final TypeInfo typeInfoAnnotation = typeToClass(t).getAnnotation(TypeInfo.class);
- factoryClass = typeInfoAnnotation.value();
- // check for valid factory class
- if (!TypeInfoFactory.class.isAssignableFrom(factoryClass)) {
- throw new InvalidTypesException("TypeInfo annotation does not specify a valid TypeInfoFactory.");
- }
+ final TypeInfo typeInfoAnnotation = typeToClass(t).getAnnotation(TypeInfo.class);
+ factoryClass = typeInfoAnnotation.value();
+ // check for valid factory class
+ if (!TypeInfoFactory.class.isAssignableFrom(factoryClass)) {
+ throw new InvalidTypesException("TypeInfo annotation does not specify a valid TypeInfoFactory.");
}
// instantiate