From e715c28bf6d8a12ce1a38ef3a084b2658386a839 Mon Sep 17 00:00:00 2001 From: yanghua Date: Wed, 9 May 2018 17:13:06 +0800 Subject: [PATCH 1/4] [FLINK-9292] [core] Remove TypeInfoParser (part 2) --- .../kafka/KafkaProducerTestBase.java | 4 +- .../api/java/typeutils/TypeInfoParser.java | 417 ------------------ .../common/typeinfo/TypeInformationTest.java | 2 +- .../api/java/typeutils/TypeExtractorTest.java | 105 +++-- .../api/java/sca/UdfAnalyzerExamplesTest.java | 80 ++-- .../flink/api/java/sca/UdfAnalyzerTest.java | 237 +++++----- .../asm/dataset/ChecksumHashCodeTest.java | 5 +- .../flink/graph/asm/dataset/CollectTest.java | 5 +- .../flink/graph/asm/dataset/CountTest.java | 5 +- 9 files changed, 222 insertions(+), 638 deletions(-) delete mode 100644 flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeInfoParser.java diff --git a/flink-connectors/flink-connector-kafka-base/src/test/java/org/apache/flink/streaming/connectors/kafka/KafkaProducerTestBase.java b/flink-connectors/flink-connector-kafka-base/src/test/java/org/apache/flink/streaming/connectors/kafka/KafkaProducerTestBase.java index 5023a7eae719b..629497e99925a 100644 --- a/flink-connectors/flink-connector-kafka-base/src/test/java/org/apache/flink/streaming/connectors/kafka/KafkaProducerTestBase.java +++ b/flink-connectors/flink-connector-kafka-base/src/test/java/org/apache/flink/streaming/connectors/kafka/KafkaProducerTestBase.java @@ -24,9 +24,9 @@ import org.apache.flink.api.common.serialization.SerializationSchema; import org.apache.flink.api.common.serialization.TypeInformationSerializationSchema; import org.apache.flink.api.common.typeinfo.BasicTypeInfo; +import org.apache.flink.api.common.typeinfo.TypeHint; import org.apache.flink.api.common.typeinfo.TypeInformation; import org.apache.flink.api.java.tuple.Tuple2; -import org.apache.flink.api.java.typeutils.TypeInfoParser; import org.apache.flink.configuration.Configuration; import org.apache.flink.runtime.client.JobExecutionException; import org.apache.flink.runtime.state.CheckpointListener; @@ -116,7 +116,7 @@ public void testCustomPartitioning() { expectedTopicsToNumPartitions.put(defaultTopic, defaultTopicPartitions); expectedTopicsToNumPartitions.put(dynamicTopic, dynamicTopicPartitions); - TypeInformation> longStringInfo = TypeInfoParser.parse("Tuple2"); + TypeInformation> longStringInfo = TypeInformation.of(new TypeHint>(){}); StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); env.setRestartStrategy(RestartStrategies.noRestart()); diff --git a/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeInfoParser.java b/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeInfoParser.java deleted file mode 100644 index bb74e708946df..0000000000000 --- a/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeInfoParser.java +++ /dev/null @@ -1,417 +0,0 @@ - /* - * 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.java.typeutils; - - import org.apache.flink.annotation.Public; - import org.apache.flink.api.common.typeinfo.BasicArrayTypeInfo; - import org.apache.flink.api.common.typeinfo.BasicTypeInfo; - import org.apache.flink.api.common.typeinfo.PrimitiveArrayTypeInfo; - import org.apache.flink.api.common.typeinfo.TypeInformation; - import org.apache.flink.types.Value; - - import java.lang.reflect.Field; - import java.util.ArrayList; - import java.util.regex.Matcher; - import java.util.regex.Pattern; - -/** - * @deprecated Use {@link org.apache.flink.api.common.typeinfo.Types} instead. - */ -@Deprecated -@Public -public class TypeInfoParser { - private static final String TUPLE_PACKAGE = "org.apache.flink.api.java.tuple"; - private static final String VALUE_PACKAGE = "org.apache.flink.types"; - private static final String WRITABLE_PACKAGE = "org.apache.hadoop.io"; - - private static final Pattern tuplePattern = Pattern.compile("^(" + TUPLE_PACKAGE.replaceAll("\\.", "\\\\.") + "\\.)?((Tuple[1-9][0-9]?)<|(Tuple0))"); - private static final Pattern writablePattern = Pattern.compile("^((" + WRITABLE_PACKAGE.replaceAll("\\.", "\\\\.") + "\\.)?Writable)<([^\\s,>]*)(,|>|$|\\[)"); - private static final Pattern enumPattern = Pattern.compile("^((java\\.lang\\.)?Enum)<([^\\s,>]*)(,|>|$|\\[)"); - private static final Pattern basicTypePattern = Pattern - .compile("^((java\\.lang\\.)?(String|Integer|Byte|Short|Character|Double|Float|Long|Boolean|Void))(,|>|$|\\[)"); - private static final Pattern basicTypeDatePattern = Pattern.compile("^((java\\.util\\.)?Date)(,|>|$|\\[)"); - private static final Pattern basicTypeBigIntPattern = Pattern.compile("^((java\\.math\\.)?BigInteger)(,|>|$|\\[)"); - private static final Pattern basicTypeBigDecPattern = Pattern.compile("^((java\\.math\\.)?BigDecimal)(,|>|$|\\[)"); - private static final Pattern primitiveTypePattern = Pattern.compile("^(int|byte|short|char|double|float|long|boolean|void)(,|>|$|\\[)"); - private static final Pattern valueTypePattern = Pattern.compile("^((" + VALUE_PACKAGE.replaceAll("\\.", "\\\\.") - + "\\.)?(String|Int|Byte|Short|Char|Double|Float|Long|Boolean|List|Map|Null))Value(,|>|$|\\[)"); - private static final Pattern pojoGenericObjectPattern = Pattern.compile("^([^\\s,<>\\[]+)(<)?"); - private static final Pattern fieldPattern = Pattern.compile("^([^\\s,<>\\[]+)="); - - /** - * Generates an instance of TypeInformation by parsing a type - * information string. A type information string can contain the following - * types: - * - *
    - *
  • Basic types such as Integer, String, etc. - *
  • Basic type arrays such as Integer[], - * String[], etc. - *
  • Tuple types such as Tuple1<TYPE0>, - * Tuple2<TYPE0, TYPE1>, etc.
  • - *
  • Pojo types such as org.my.MyPojo<myFieldName=TYPE0,myFieldName2=TYPE1>, etc.
  • - *
  • Generic types such as java.lang.Class, etc. - *
  • Custom type arrays such as org.my.CustomClass[], - * org.my.CustomClass$StaticInnerClass[], etc. - *
  • Value types such as DoubleValue, - * StringValue, IntegerValue, etc.
  • - *
  • Tuple array types such as Tuple2<TYPE0,TYPE1>[], etc.
  • - *
  • Writable types such as Writable<org.my.CustomWritable>
  • - *
  • Enum types such as Enum<org.my.CustomEnum>
  • - *
- * - * Example: - * "Tuple2<String,Tuple2<Integer,org.my.MyJob$Pojo<word=String>>>" - * - * @param infoString - * type information string to be parsed - * @return TypeInformation representation of the string - */ - @SuppressWarnings("unchecked") - public static TypeInformation parse(String infoString) { - try { - if (infoString == null) { - throw new IllegalArgumentException("String is null."); - } - String clearedString = infoString.replaceAll("\\s", ""); - if (clearedString.length() == 0) { - throw new IllegalArgumentException("String must not be empty."); - } - StringBuilder sb = new StringBuilder(clearedString); - TypeInformation ti = (TypeInformation) parse(sb); - if (sb.length() > 0) { - throw new IllegalArgumentException("String could not be parsed completely."); - } - return ti; - } catch (Exception e) { - throw new IllegalArgumentException("String could not be parsed: " + e.getMessage(), e); - } - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - private static TypeInformation parse(StringBuilder sb) throws ClassNotFoundException { - String infoString = sb.toString(); - final Matcher tupleMatcher = tuplePattern.matcher(infoString); - - final Matcher writableMatcher = writablePattern.matcher(infoString); - final Matcher enumMatcher = enumPattern.matcher(infoString); - - final Matcher basicTypeMatcher = basicTypePattern.matcher(infoString); - final Matcher basicTypeDateMatcher = basicTypeDatePattern.matcher(infoString); - final Matcher basicTypeBigIntMatcher = basicTypeBigIntPattern.matcher(infoString); - final Matcher basicTypeBigDecMatcher = basicTypeBigDecPattern.matcher(infoString); - - final Matcher primitiveTypeMatcher = primitiveTypePattern.matcher(infoString); - - final Matcher valueTypeMatcher = valueTypePattern.matcher(infoString); - - final Matcher pojoGenericMatcher = pojoGenericObjectPattern.matcher(infoString); - - if (infoString.length() == 0) { - return null; - } - - TypeInformation returnType = null; - boolean isPrimitiveType = false; - - // tuples - if (tupleMatcher.find()) { - boolean isGenericTuple = true; - String className = tupleMatcher.group(3); - if(className == null) { // matched Tuple0 - isGenericTuple = false; - className = tupleMatcher.group(2); - sb.delete(0, className.length()); - } else { - sb.delete(0, className.length() + 1); // +1 for "<" - } - - if (infoString.startsWith(TUPLE_PACKAGE)) { - sb.delete(0, TUPLE_PACKAGE.length() + 1); // +1 for trailing "." - } - - int arity = Integer.parseInt(className.replaceAll("\\D", "")); - Class clazz = loadClass(TUPLE_PACKAGE + "." + className); - - TypeInformation[] types = new TypeInformation[arity]; - for (int i = 0; i < arity; i++) { - types[i] = parse(sb); - if (types[i] == null) { - throw new IllegalArgumentException("Tuple arity does not match given parameters."); - } - } - if (isGenericTuple) { - if(sb.charAt(0) != '>') { - throw new IllegalArgumentException("Tuple arity does not match given parameters."); - } - // remove '>' - sb.deleteCharAt(0); - } - returnType = new TupleTypeInfo(clazz, types); - } - // writable types - else if (writableMatcher.find()) { - String className = writableMatcher.group(1); - String fullyQualifiedName = writableMatcher.group(3); - sb.delete(0, className.length() + 1 + fullyQualifiedName.length() + 1); - Class clazz = loadClass(fullyQualifiedName); - returnType = TypeExtractor.createHadoopWritableTypeInfo(clazz); - } - // enum types - else if (enumMatcher.find()) { - String className = enumMatcher.group(1); - String fullyQualifiedName = enumMatcher.group(3); - sb.delete(0, className.length() + 1 + fullyQualifiedName.length() + 1); - Class clazz = loadClass(fullyQualifiedName); - returnType = new EnumTypeInfo(clazz); - } - // basic types - else if (basicTypeMatcher.find()) { - String className = basicTypeMatcher.group(1); - sb.delete(0, className.length()); - Class clazz; - // check if fully qualified - if (className.startsWith("java.lang")) { - clazz = loadClass(className); - } else { - clazz = loadClass("java.lang." + className); - } - returnType = BasicTypeInfo.getInfoFor(clazz); - } - // special basic type "Date" - else if (basicTypeDateMatcher.find()) { - String className = basicTypeDateMatcher.group(1); - sb.delete(0, className.length()); - Class clazz; - // check if fully qualified - if (className.startsWith("java.util")) { - clazz = loadClass(className); - } else { - clazz = loadClass("java.util." + className); - } - returnType = BasicTypeInfo.getInfoFor(clazz); - } - // special basic type "BigInteger" - else if (basicTypeBigIntMatcher.find()) { - String className = basicTypeBigIntMatcher.group(1); - sb.delete(0, className.length()); - Class clazz; - // check if fully qualified - if (className.startsWith("java.math")) { - clazz = loadClass(className); - } else { - clazz = loadClass("java.math." + className); - } - returnType = BasicTypeInfo.getInfoFor(clazz); - } - // special basic type "BigDecimal" - else if (basicTypeBigDecMatcher.find()) { - String className = basicTypeBigDecMatcher.group(1); - sb.delete(0, className.length()); - Class clazz; - // check if fully qualified - if (className.startsWith("java.math")) { - clazz = loadClass(className); - } else { - clazz = loadClass("java.math." + className); - } - returnType = BasicTypeInfo.getInfoFor(clazz); - } - // primitive types - else if (primitiveTypeMatcher.find()) { - String keyword = primitiveTypeMatcher.group(1); - sb.delete(0, keyword.length()); - - Class clazz = null; - if (keyword.equals("int")) { - clazz = int.class; - } else if (keyword.equals("byte")) { - clazz = byte.class; - } else if (keyword.equals("short")) { - clazz = short.class; - } else if (keyword.equals("char")) { - clazz = char.class; - } else if (keyword.equals("double")) { - clazz = double.class; - } else if (keyword.equals("float")) { - clazz = float.class; - } else if (keyword.equals("long")) { - clazz = long.class; - } else if (keyword.equals("boolean")) { - clazz = boolean.class; - } else if (keyword.equals("void")) { - clazz = void.class; - } - returnType = BasicTypeInfo.getInfoFor(clazz); - isPrimitiveType = true; - } - // values - else if (valueTypeMatcher.find()) { - String className = valueTypeMatcher.group(1); - sb.delete(0, className.length() + 5); - - Class clazz; - // check if fully qualified - if (className.startsWith(VALUE_PACKAGE)) { - clazz = loadClass(className + "Value"); - } else { - clazz = loadClass(VALUE_PACKAGE + "." + className + "Value"); - } - returnType = ValueTypeInfo.getValueTypeInfo((Class) clazz); - } - // pojo objects or generic types - else if (pojoGenericMatcher.find()) { - String fullyQualifiedName = pojoGenericMatcher.group(1); - sb.delete(0, fullyQualifiedName.length()); - - boolean isPojo = pojoGenericMatcher.group(2) != null; - - // pojo - if (isPojo) { - sb.deleteCharAt(0); - Class clazz = loadClass(fullyQualifiedName); - - ArrayList fields = new ArrayList(); - while (sb.charAt(0) != '>') { - final Matcher fieldMatcher = fieldPattern.matcher(sb); - if (!fieldMatcher.find()) { - throw new IllegalArgumentException("Field name missing."); - } - String fieldName = fieldMatcher.group(1); - sb.delete(0, fieldName.length() + 1); - - Field field = TypeExtractor.getDeclaredField(clazz, fieldName); - if (field == null) { - throw new IllegalArgumentException("Field '" + fieldName + "'could not be accessed."); - } - fields.add(new PojoField(field, parse(sb))); - } - sb.deleteCharAt(0); // remove '>' - returnType = new PojoTypeInfo(clazz, fields); - } - // generic type - else { - returnType = new GenericTypeInfo(loadClass(fullyQualifiedName)); - } - } - - if (returnType == null) { - throw new IllegalArgumentException("Error at '" + infoString + "'"); - } - - // arrays - int arrayDimensionCount = 0; - while (sb.length() > 1 && sb.charAt(0) == '[' && sb.charAt(1) == ']') { - arrayDimensionCount++; - sb.delete(0, 2); - } - - if (sb.length() > 0 && sb.charAt(0) == '[') { - throw new IllegalArgumentException("Closing square bracket missing."); - } - - // construct multidimension array - if (arrayDimensionCount > 0) { - TypeInformation arrayInfo = null; - - // first dimension - // primitive array - if (isPrimitiveType) { - if (returnType == BasicTypeInfo.INT_TYPE_INFO) { - arrayInfo = PrimitiveArrayTypeInfo.INT_PRIMITIVE_ARRAY_TYPE_INFO; - } else if (returnType == BasicTypeInfo.BYTE_TYPE_INFO) { - arrayInfo = PrimitiveArrayTypeInfo.BYTE_PRIMITIVE_ARRAY_TYPE_INFO; - } else if (returnType == BasicTypeInfo.SHORT_TYPE_INFO) { - arrayInfo = PrimitiveArrayTypeInfo.SHORT_PRIMITIVE_ARRAY_TYPE_INFO; - } else if (returnType == BasicTypeInfo.CHAR_TYPE_INFO) { - arrayInfo = PrimitiveArrayTypeInfo.CHAR_PRIMITIVE_ARRAY_TYPE_INFO; - } else if (returnType == BasicTypeInfo.DOUBLE_TYPE_INFO) { - arrayInfo = PrimitiveArrayTypeInfo.DOUBLE_PRIMITIVE_ARRAY_TYPE_INFO; - } else if (returnType == BasicTypeInfo.FLOAT_TYPE_INFO) { - arrayInfo = PrimitiveArrayTypeInfo.FLOAT_PRIMITIVE_ARRAY_TYPE_INFO; - } else if (returnType == BasicTypeInfo.LONG_TYPE_INFO) { - arrayInfo = PrimitiveArrayTypeInfo.LONG_PRIMITIVE_ARRAY_TYPE_INFO; - } else if (returnType == BasicTypeInfo.BOOLEAN_TYPE_INFO) { - arrayInfo = PrimitiveArrayTypeInfo.BOOLEAN_PRIMITIVE_ARRAY_TYPE_INFO; - } else if (returnType == BasicTypeInfo.VOID_TYPE_INFO) { - throw new IllegalArgumentException("Can not create an array of void."); - } - } - // basic array - else if (returnType instanceof BasicTypeInfo - && returnType != BasicTypeInfo.DATE_TYPE_INFO) { - if (returnType == BasicTypeInfo.INT_TYPE_INFO) { - arrayInfo = BasicArrayTypeInfo.INT_ARRAY_TYPE_INFO; - } else if (returnType == BasicTypeInfo.BYTE_TYPE_INFO) { - arrayInfo = BasicArrayTypeInfo.BYTE_ARRAY_TYPE_INFO; - } else if (returnType == BasicTypeInfo.SHORT_TYPE_INFO) { - arrayInfo = BasicArrayTypeInfo.SHORT_ARRAY_TYPE_INFO; - } else if (returnType == BasicTypeInfo.CHAR_TYPE_INFO) { - arrayInfo = BasicArrayTypeInfo.CHAR_ARRAY_TYPE_INFO; - } else if (returnType == BasicTypeInfo.DOUBLE_TYPE_INFO) { - arrayInfo = BasicArrayTypeInfo.DOUBLE_ARRAY_TYPE_INFO; - } else if (returnType == BasicTypeInfo.FLOAT_TYPE_INFO) { - arrayInfo = BasicArrayTypeInfo.FLOAT_ARRAY_TYPE_INFO; - } else if (returnType == BasicTypeInfo.LONG_TYPE_INFO) { - arrayInfo = BasicArrayTypeInfo.LONG_ARRAY_TYPE_INFO; - } else if (returnType == BasicTypeInfo.BOOLEAN_TYPE_INFO) { - arrayInfo = BasicArrayTypeInfo.BOOLEAN_ARRAY_TYPE_INFO; - } else if (returnType == BasicTypeInfo.STRING_TYPE_INFO) { - arrayInfo = BasicArrayTypeInfo.STRING_ARRAY_TYPE_INFO; - } else if (returnType == BasicTypeInfo.VOID_TYPE_INFO) { - throw new IllegalArgumentException("Can not create an array of void."); - } - } - // object array - else { - arrayInfo = ObjectArrayTypeInfo.getInfoFor(loadClass("[L" + returnType.getTypeClass().getName() + ";"), - returnType); - } - - // further dimensions - if (arrayDimensionCount > 1) { - String arrayPrefix = "["; - for (int i = 1; i < arrayDimensionCount; i++) { - arrayPrefix += "["; - arrayInfo = ObjectArrayTypeInfo.getInfoFor(loadClass(arrayPrefix + "L" + - returnType.getTypeClass().getName() + ";"), arrayInfo); - } - } - returnType = arrayInfo; - } - - // remove possible ',' - if (sb.length() > 0 && sb.charAt(0) == ',') { - sb.deleteCharAt(0); - } - - // check if end - return returnType; - } - - private static Class loadClass(String fullyQualifiedName) { - try { - return Class.forName(fullyQualifiedName); - } catch (ClassNotFoundException e) { - throw new IllegalArgumentException("Class '" + fullyQualifiedName - + "' could not be found. Please note that inner classes must be declared static."); - } - } - -} diff --git a/flink-core/src/test/java/org/apache/flink/api/common/typeinfo/TypeInformationTest.java b/flink-core/src/test/java/org/apache/flink/api/common/typeinfo/TypeInformationTest.java index 14888665765e5..d9af0689365b8 100644 --- a/flink-core/src/test/java/org/apache/flink/api/common/typeinfo/TypeInformationTest.java +++ b/flink-core/src/test/java/org/apache/flink/api/common/typeinfo/TypeInformationTest.java @@ -61,7 +61,7 @@ public void testOfGenericClassForGenericType() { @Test public void testOfTypeHint() { assertEquals(BasicTypeInfo.STRING_TYPE_INFO, TypeInformation.of(String.class)); - assertEquals(BasicTypeInfo.STRING_TYPE_INFO, TypeInformation.of(new TypeHint(){})); + assertEquals(BasicTypeInfo.STRING_TYPE_INFO, Types.STRING); TypeInformation> tupleInfo = new TupleTypeInfo<>(BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.DOUBLE_TYPE_INFO, BasicTypeInfo.BOOLEAN_TYPE_INFO); diff --git a/flink-core/src/test/java/org/apache/flink/api/java/typeutils/TypeExtractorTest.java b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/TypeExtractorTest.java index 804cf88ae47c5..b763f54987537 100644 --- a/flink-core/src/test/java/org/apache/flink/api/java/typeutils/TypeExtractorTest.java +++ b/flink-core/src/test/java/org/apache/flink/api/java/typeutils/TypeExtractorTest.java @@ -46,6 +46,7 @@ import org.apache.flink.api.common.typeinfo.SqlTimeTypeInfo; import org.apache.flink.api.common.typeinfo.TypeHint; import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.common.typeinfo.Types; import org.apache.flink.api.common.typeutils.CompositeType.FlatFieldDescriptor; import org.apache.flink.api.common.typeutils.TypeSerializer; import org.apache.flink.api.java.functions.KeySelector; @@ -84,7 +85,7 @@ public void reduce(Iterable values, Collector out) throws Exce } }; - TypeInformation ti = TypeExtractor.getGroupReduceReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Boolean")); + TypeInformation ti = TypeExtractor.getGroupReduceReturnTypes(function, (TypeInformation) Types.BOOLEAN); Assert.assertTrue(ti.isBasicType()); Assert.assertEquals(BasicTypeInfo.BOOLEAN_TYPE_INFO, ti); @@ -113,7 +114,7 @@ public Tuple9 ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple9")); + TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint>(){})); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(9, ti.getArity()); @@ -180,7 +181,7 @@ public void flatMap(Tuple3, Tuple1, Tuple2> } }; - TypeInformation ti = TypeExtractor.getFlatMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple3, Tuple1, Tuple2>")); + TypeInformation ti = TypeExtractor.getFlatMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint, Tuple1, Tuple2>>(){})); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(3, ti.getArity()); Assert.assertTrue(ti instanceof TupleTypeInfo); @@ -249,7 +250,7 @@ public void flatMap(Tuple0 value, Collector out) throws Exception { }; TypeInformation ti = TypeExtractor.getFlatMapReturnTypes(function, - (TypeInformation) TypeInfoParser.parse("Tuple0")); + (TypeInformation) TypeInformation.of(new TypeHint(){})); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(0, ti.getArity()); @@ -269,7 +270,7 @@ public void join(CustomTuple first, String second, Collector out) t } }; - TypeInformation ti = TypeExtractor.getFlatJoinReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple2"), (TypeInformation) TypeInfoParser.parse("String")); + TypeInformation ti = TypeExtractor.getFlatJoinReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint>(){}), (TypeInformation) Types.STRING); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(2, ti.getArity()); @@ -323,8 +324,8 @@ public CustomType cross(CustomType first, Integer second) throws Exception { }; TypeInformation ti = TypeExtractor.getCrossReturnTypes(function, - (TypeInformation) TypeInfoParser.parse("org.apache.flink.api.java.typeutils.TypeExtractorTest$CustomType"), - (TypeInformation) TypeInfoParser.parse("Integer")); + (TypeInformation) TypeInformation.of(new TypeHint(){}), + (TypeInformation) Types.INT); Assert.assertFalse(ti.isBasicType()); Assert.assertFalse(ti.isTupleType()); @@ -394,7 +395,7 @@ public Tuple2 map(Tuple2 value) throws Excep }; TypeInformation ti = TypeExtractor.getMapReturnTypes(function, - (TypeInformation) TypeInfoParser.parse("Tuple2")); + (TypeInformation) TypeInformation.of(new TypeHint>(){})); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(2, ti.getArity()); @@ -451,7 +452,7 @@ public StringValue getKey(StringValue value) { } }; - TypeInformation ti = TypeExtractor.getKeySelectorTypes(function, (TypeInformation) TypeInfoParser.parse("StringValue")); + TypeInformation ti = TypeExtractor.getKeySelectorTypes(function, (TypeInformation) TypeInformation.of(new TypeHint(){})); Assert.assertFalse(ti.isBasicType()); Assert.assertFalse(ti.isTupleType()); @@ -481,7 +482,7 @@ public Tuple2 map(Tuple2 value) th } }; - TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple2")); + TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint>(){})); Assert.assertFalse(ti.isBasicType()); Assert.assertTrue(ti.isTupleType()); @@ -520,7 +521,7 @@ public LongKeyValue map(LongKeyValue value) throws Exception { } }; - TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple2")); + TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint>(){})); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(2, ti.getArity()); @@ -563,7 +564,7 @@ public ChainedTwo map(ChainedTwo value) throws Exception { } }; - TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple3")); + TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint>(){})); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(3, ti.getArity()); @@ -605,7 +606,7 @@ public ChainedThree map(ChainedThree value) throws Exception { } }; - TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple3")); + TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint>(){})); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(3, ti.getArity()); @@ -631,7 +632,7 @@ public ChainedFour map(ChainedFour value) throws Exception { } }; - TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple3")); + TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint>(){})); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(3, ti.getArity()); @@ -656,11 +657,11 @@ public Tuple2 map(String value) throws Exception { } }; - TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("String"), "name", true); + TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) Types.STRING, "name", true); Assert.assertTrue(ti instanceof MissingTypeInfo); try { - TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("String")); + TypeExtractor.getMapReturnTypes(function, (TypeInformation) Types.STRING); Assert.fail("Expected an exception"); } catch (InvalidTypesException e) { @@ -680,11 +681,11 @@ public Tuple map(String value) throws Exception { } }; - TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("String"), "name", true); + TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) Types.STRING, "name", true); Assert.assertTrue(ti instanceof MissingTypeInfo); try { - TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("String")); + TypeExtractor.getMapReturnTypes(function, (TypeInformation) Types.STRING); Assert.fail("Expected an exception"); } catch (InvalidTypesException e) { @@ -712,7 +713,7 @@ public SameTypeVariable map(SameTypeVariable value) throws Excep } }; - TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple2")); + TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint>(){})); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(2, ti.getArity()); @@ -744,7 +745,7 @@ public Nested map(Nested value) throws Excepti } }; - TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple2>")); + TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint>>(){})); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(2, ti.getArity()); @@ -783,7 +784,7 @@ public Nested2 map(Nested2 value) throws Exception { } }; - TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple2>, Tuple2>>>")); + TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint>, Tuple2>>>>(){})); // Should be // Tuple2>, Tuple2>>> @@ -823,11 +824,11 @@ public String map(Object value) throws Exception { } }; - TypeInformation ti = TypeExtractor.getMapReturnTypes(function, TypeInfoParser.parse("String"), "name", true); + TypeInformation ti = TypeExtractor.getMapReturnTypes(function, Types.STRING, "name", true); Assert.assertTrue(ti instanceof MissingTypeInfo); try { - TypeExtractor.getMapReturnTypes(function, TypeInfoParser.parse("String")); + TypeExtractor.getMapReturnTypes(function, Types.STRING); Assert.fail("Expected an exception"); } catch (InvalidTypesException e) { @@ -842,7 +843,7 @@ public void testFunctionDependingOnInputAsSuperclass() { private static final long serialVersionUID = 1L; }; - TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Boolean")); + TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) Types.BOOLEAN); Assert.assertTrue(ti.isBasicType()); Assert.assertEquals(BasicTypeInfo.BOOLEAN_TYPE_INFO, ti); @@ -906,7 +907,7 @@ public void testFunctionDependingOnInputWithTupleInput() { public void testFunctionDependingOnInputWithCustomTupleInput() { IdentityMapper> function = new IdentityMapper>(); - TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple2")); + TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint>(){})); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(2, ti.getArity()); @@ -994,7 +995,7 @@ public String map(String value) throws Exception { public void testFunctionWithNoGenericSuperclass() { RichMapFunction function = new Mapper2(); - TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("String")); + TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) Types.STRING); Assert.assertTrue(ti.isBasicType()); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, ti); @@ -1015,7 +1016,7 @@ public void testFunctionDependingPartialOnInput() { private static final long serialVersionUID = 1L; }; - TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("DoubleValue")); + TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint(){})); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(2, ti.getArity()); @@ -1156,11 +1157,11 @@ public Value map(StringValue value) throws Exception { } }; - TypeInformation ti =TypeExtractor.getMapReturnTypes(function, (TypeInformation)TypeInfoParser.parse("StringValue"), "name", true); + TypeInformation ti =TypeExtractor.getMapReturnTypes(function, (TypeInformation)TypeInformation.of(new TypeHint(){}), "name", true); Assert.assertTrue(ti instanceof MissingTypeInfo); try { - TypeExtractor.getMapReturnTypes(function, (TypeInformation)TypeInfoParser.parse("StringValue")); + TypeExtractor.getMapReturnTypes(function, (TypeInformation)TypeInformation.of(new TypeHint(){})); Assert.fail("Expected an exception"); } catch (InvalidTypesException e) { @@ -1181,7 +1182,7 @@ public void coGroup(Iterable first, Iterable second, Collect } }; - TypeInformation ti = TypeExtractor.getCoGroupReturnTypes(function, (TypeInformation) TypeInfoParser.parse("String[]"), (TypeInformation) TypeInfoParser.parse("String[]")); + TypeInformation ti = TypeExtractor.getCoGroupReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint(){}), (TypeInformation) TypeInformation.of(new TypeHint(){})); Assert.assertFalse(ti.isBasicType()); Assert.assertFalse(ti.isTupleType()); @@ -1224,7 +1225,7 @@ public CustomArrayObject[] map(CustomArrayObject[] value) throws Exception { }; TypeInformation ti = TypeExtractor.getMapReturnTypes(function, - (TypeInformation) TypeInfoParser.parse("org.apache.flink.api.java.typeutils.TypeExtractorTest$CustomArrayObject[]")); + (TypeInformation) TypeInformation.of(new TypeHint(){})); Assert.assertTrue(ti instanceof ObjectArrayTypeInfo); Assert.assertEquals(CustomArrayObject.class, ((ObjectArrayTypeInfo) ti).getComponentInfo().getTypeClass()); @@ -1242,7 +1243,7 @@ public Tuple2[] map(Tuple2[] value) throws Excep } }; - TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple2[]")); + TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint[]>(){})); Assert.assertTrue(ti instanceof ObjectArrayTypeInfo); ObjectArrayTypeInfo oati = (ObjectArrayTypeInfo) ti; @@ -1262,7 +1263,7 @@ public class CustomArrayObject2 extends Tuple1 { public void testCustomArrayWithTypeVariable() { RichMapFunction[], ?> function = new IdentityMapper[]>(); - TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple1[]")); + TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint[]>(){})); Assert.assertTrue(ti instanceof ObjectArrayTypeInfo); ObjectArrayTypeInfo oati = (ObjectArrayTypeInfo) ti; @@ -1287,7 +1288,7 @@ public void testParameterizedArrays() { private static final long serialVersionUID = 1L; }; - TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Boolean[]")); + TypeInformation ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint(){})); Assert.assertTrue(ti instanceof ObjectArrayTypeInfo); ObjectArrayTypeInfo oati = (ObjectArrayTypeInfo) ti; Assert.assertEquals(BasicTypeInfo.BOOLEAN_TYPE_INFO, oati.getComponentInfo()); @@ -1346,14 +1347,14 @@ public String map(Tuple2 value) throws Exception { }; try { - TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple2")); + TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint>(){})); Assert.fail("exception expected"); } catch (InvalidTypesException e) { // right } try { - TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("Tuple3")); + TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInformation.of(new TypeHint>(){})); Assert.fail("exception expected"); } catch (InvalidTypesException e) { // right @@ -1369,7 +1370,7 @@ public String map(StringValue value) throws Exception { }; try { - TypeExtractor.getMapReturnTypes(function2, (TypeInformation) TypeInfoParser.parse("IntValue")); + TypeExtractor.getMapReturnTypes(function2, (TypeInformation) TypeInformation.of(new TypeHint(){})); Assert.fail("exception expected"); } catch (InvalidTypesException e) { // right @@ -1385,7 +1386,7 @@ public String map(Tuple1[] value) throws Exception { }; try { - TypeExtractor.getMapReturnTypes(function3, (TypeInformation) TypeInfoParser.parse("Integer[]")); + TypeExtractor.getMapReturnTypes(function3, (TypeInformation) TypeInformation.of(new TypeHint(){})); Assert.fail("exception expected"); } catch (InvalidTypesException e) { // right @@ -1405,12 +1406,12 @@ public void flatMap(Tuple2 value, Collector> out) throws Exce @Test public void testTypeErasure() { TypeInformation ti = TypeExtractor.getFlatMapReturnTypes(new DummyFlatMapFunction(), - (TypeInformation) TypeInfoParser.parse("Tuple2"), "name", true); + (TypeInformation) TypeInformation.of(new TypeHint>(){}), "name", true); Assert.assertTrue(ti instanceof MissingTypeInfo); try { TypeExtractor.getFlatMapReturnTypes(new DummyFlatMapFunction(), - (TypeInformation) TypeInfoParser.parse("Tuple2")); + (TypeInformation) TypeInformation.of(new TypeHint>(){})); Assert.fail("Expected an exception"); } @@ -1571,7 +1572,7 @@ public Tuple2 map(Tuple1 vertex) { @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testDuplicateValue() { - TypeInformation ti = TypeExtractor.getMapReturnTypes((MapFunction) new DuplicateValue(), TypeInfoParser.parse("Tuple1")); + TypeInformation ti = TypeExtractor.getMapReturnTypes((MapFunction) new DuplicateValue(), TypeInformation.of(new TypeHint>(){})); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(2, ti.getArity()); TupleTypeInfo tti = (TupleTypeInfo) ti; @@ -1591,7 +1592,7 @@ public Tuple2 map(Tuple1> vertex) { @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testDuplicateValueNested() { - TypeInformation ti = TypeExtractor.getMapReturnTypes((MapFunction) new DuplicateValueNested(), TypeInfoParser.parse("Tuple1>")); + TypeInformation ti = TypeExtractor.getMapReturnTypes((MapFunction) new DuplicateValueNested(), TypeInformation.of(new TypeHint>>(){})); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(2, ti.getArity()); TupleTypeInfo tti = (TupleTypeInfo) ti; @@ -1618,7 +1619,7 @@ public Edge map(Edge value) throws Exception { @Test public void testInputInference1() { EdgeMapper em = new EdgeMapper(); - TypeInformation ti = TypeExtractor.getMapReturnTypes((MapFunction) em, TypeInfoParser.parse("Tuple3")); + TypeInformation ti = TypeExtractor.getMapReturnTypes((MapFunction) em, TypeInformation.of(new TypeHint>(){})); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(3, ti.getArity()); TupleTypeInfo tti = (TupleTypeInfo) ti; @@ -1641,7 +1642,7 @@ public Edge map(V value) throws Exception { @Test public void testInputInference2() { EdgeMapper2 em = new EdgeMapper2(); - TypeInformation ti = TypeExtractor.getMapReturnTypes((MapFunction) em, TypeInfoParser.parse("Boolean")); + TypeInformation ti = TypeExtractor.getMapReturnTypes((MapFunction) em, Types.BOOLEAN); Assert.assertTrue(ti.isTupleType()); Assert.assertEquals(3, ti.getArity()); TupleTypeInfo tti = (TupleTypeInfo) ti; @@ -1663,7 +1664,7 @@ public V map(Edge value) throws Exception { @Test public void testInputInference3() { EdgeMapper3 em = new EdgeMapper3(); - TypeInformation ti = TypeExtractor.getMapReturnTypes((MapFunction) em, TypeInfoParser.parse("Tuple3")); + TypeInformation ti = TypeExtractor.getMapReturnTypes((MapFunction) em, TypeInformation.of(new TypeHint>(){})); Assert.assertTrue(ti.isBasicType()); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, ti); } @@ -1681,7 +1682,7 @@ public V map(Edge[] value) throws Exception { @Test public void testInputInference4() { EdgeMapper4 em = new EdgeMapper4(); - TypeInformation ti = TypeExtractor.getMapReturnTypes((MapFunction) em, TypeInfoParser.parse("Tuple3[]")); + TypeInformation ti = TypeExtractor.getMapReturnTypes((MapFunction) em, TypeInformation.of(new TypeHint[]>(){})); Assert.assertTrue(ti.isBasicType()); Assert.assertEquals(BasicTypeInfo.STRING_TYPE_INFO, ti); } @@ -1762,7 +1763,7 @@ public Tuple2[][] map( return null; } }; - TypeInformation ti = TypeExtractor.getMapReturnTypes((MapFunction)function, TypeInfoParser.parse("Tuple2[][]")); + TypeInformation ti = TypeExtractor.getMapReturnTypes((MapFunction)function, TypeInformation.of(new TypeHint[][]>(){})); Assert.assertEquals("ObjectArrayTypeInfo>>", ti.toString()); // primitive array @@ -1775,7 +1776,7 @@ public int[][][] map( return null; } }; - ti = TypeExtractor.getMapReturnTypes((MapFunction)function, TypeInfoParser.parse("int[][][]")); + ti = TypeExtractor.getMapReturnTypes((MapFunction)function, TypeInformation.of(new TypeHint(){})); Assert.assertEquals("ObjectArrayTypeInfo>", ti.toString()); // basic array @@ -1788,7 +1789,7 @@ public Integer[][][] map( return null; } }; - ti = TypeExtractor.getMapReturnTypes((MapFunction)function, TypeInfoParser.parse("Integer[][][]")); + ti = TypeExtractor.getMapReturnTypes((MapFunction)function, TypeInformation.of(new TypeHint(){})); Assert.assertEquals("ObjectArrayTypeInfo>>", ti.toString()); // pojo array @@ -1802,16 +1803,14 @@ public CustomType[][][] map( } }; ti = TypeExtractor.getMapReturnTypes((MapFunction)function, - TypeInfoParser.parse("org.apache.flink.api.java.typeutils.TypeExtractorTest$CustomType<" - + "myField1=String,myField2=int" - + ">[][][]")); + TypeInformation.of(new TypeHint(){})); Assert.assertEquals("ObjectArrayTypeInfo" + ">>>", ti.toString()); // generic array - ti = TypeExtractor.getMapReturnTypes((MapFunction) new MapperWithMultiDimGenericArray(), TypeInfoParser.parse("String[][][]")); + ti = TypeExtractor.getMapReturnTypes((MapFunction) new MapperWithMultiDimGenericArray(), TypeInformation.of(new TypeHint(){})); Assert.assertEquals("ObjectArrayTypeInfo>>>", ti.toString()); } diff --git a/flink-java/src/test/java/org/apache/flink/api/java/sca/UdfAnalyzerExamplesTest.java b/flink-java/src/test/java/org/apache/flink/api/java/sca/UdfAnalyzerExamplesTest.java index 1b0cbec363c34..e7b87a90fcfe0 100644 --- a/flink-java/src/test/java/org/apache/flink/api/java/sca/UdfAnalyzerExamplesTest.java +++ b/flink-java/src/test/java/org/apache/flink/api/java/sca/UdfAnalyzerExamplesTest.java @@ -25,6 +25,9 @@ import org.apache.flink.api.common.functions.JoinFunction; import org.apache.flink.api.common.functions.MapFunction; import org.apache.flink.api.common.functions.ReduceFunction; +import org.apache.flink.api.common.typeinfo.TypeHint; +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.common.typeinfo.Types; import org.apache.flink.api.java.functions.FunctionAnnotation.ForwardedFields; import org.apache.flink.api.java.functions.FunctionAnnotation.ForwardedFieldsFirst; import org.apache.flink.api.java.functions.FunctionAnnotation.ForwardedFieldsSecond; @@ -161,8 +164,8 @@ public void reduce(Iterable edgesIter, Collector out) throws Except @Test public void testEnumTrianglesBasicExamplesTriadBuilder() { compareAnalyzerResultWithAnnotationsSingleInputWithKeys(GroupReduceFunction.class, TriadBuilder.class, - "Tuple2", - "Tuple3", + TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){}), new String[] { "0" }); } @@ -180,8 +183,8 @@ public Edge map(Tuple2 t) throws Exception { @Test public void testEnumTrianglesBasicExamplesTupleEdgeConverter() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, TupleEdgeConverter.class, - "Tuple2", - "Tuple2"); + TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){})); } private static class EdgeDuplicator implements FlatMapFunction { @@ -196,8 +199,8 @@ public void flatMap(Edge edge, Collector out) throws Exception { @Test public void testEnumTrianglesOptExamplesEdgeDuplicator() { compareAnalyzerResultWithAnnotationsSingleInput(FlatMapFunction.class, EdgeDuplicator.class, - "Tuple2", - "Tuple2"); + TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){})); } private static class DegreeCounter implements GroupReduceFunction { @@ -242,8 +245,8 @@ public void reduce(Iterable edgesIter, Collector out) { @Test public void testEnumTrianglesOptExamplesDegreeCounter() { compareAnalyzerResultWithAnnotationsSingleInputWithKeys(GroupReduceFunction.class, DegreeCounter.class, - "Tuple2", - "Tuple2", + TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){}), new String[] { "0" }); } @@ -321,8 +324,8 @@ public Tuple3 reduce(Tuple3 val1, Tu @Test public void testKMeansExamplesCentroidAccumulator() { compareAnalyzerResultWithAnnotationsSingleInputWithKeys(ReduceFunction.class, CentroidAccumulator.class, - "Tuple3, Long>", - "Tuple3, Long>", + TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){}), new String[] { "0" }); } @@ -337,8 +340,8 @@ public Centroid map(Tuple3 value) { @Test public void testKMeansExamplesCentroidAverager() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, CentroidAverager.class, - "Tuple3, Long>", - "org.apache.flink.api.java.sca.UdfAnalyzerExamplesTest$Centroid"); + TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint(){})); } // -------------------------------------------------------------------------------------------- @@ -360,8 +363,8 @@ public void flatMap(Tuple2 edge, Collector> out) @Test public void testConnectedComponentsExamplesUndirectEdge() { compareAnalyzerResultWithAnnotationsSingleInput(FlatMapFunction.class, UndirectEdge.class, - "Tuple2", - "Tuple2"); + TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){})); } @ForwardedFieldsFirst("*") @@ -377,9 +380,9 @@ public void join(Tuple2 candidate, Tuple2 old, Collector @Test public void testConnectedComponentsExamplesComponentIdFilter() { compareAnalyzerResultWithAnnotationsDualInput(FlatJoinFunction.class, ComponentIdFilter.class, - "Tuple2", - "Tuple2", - "Tuple2"); + TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){})); } @ForwardedFields("*->f0;*->f1") @@ -393,8 +396,7 @@ public Tuple2 map(T vertex) { @Test public void testConnectedComponentsExamplesDuplicateValue() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, DuplicateValue.class, - "Long", - "Tuple2"); + Types.LONG, TypeInformation.of(new TypeHint>(){})); } @ForwardedFieldsFirst("f1->f1") @@ -409,9 +411,9 @@ public Tuple2 join(Tuple2 vertexWithComponent, Tuple2", - "Tuple2", - "Tuple2"); + TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){})); } // -------------------------------------------------------------------------------------------- @@ -435,9 +437,9 @@ public void coGroup(Iterable> ranks, Iterable", - "Tuple1", - "Tuple3", + TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){}), new String[] { "1" }, new String[] { "0" }); } @@ -465,8 +467,8 @@ public void reduce(Iterable> values, Collector", - "Tuple2", + TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){}), new String[] { "0" }); } @@ -551,8 +553,8 @@ public Gradient reduce(Gradient gradient1, Gradient gradient2) throws Exception @Test public void testLogisticRegressionExamplesSumGradient() { compareAnalyzerResultWithAnnotationsSingleInputWithKeys(ReduceFunction.class, SumGradient.class, - "Tuple1", - "Tuple1", + TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){}), new String[] { "0" }); } @@ -584,8 +586,8 @@ public PointWithLabel map(String value) throws Exception { @Test public void testLogisticRegressionExamplesPointParser() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, PointParser.class, - "String", - "Tuple2"); + Types.STRING, + TypeInformation.of(new TypeHint>(){})); } // -------------------------------------------------------------------------------------------- @@ -620,8 +622,8 @@ public void flatMap(String value, Collector> out) throws @Test public void testCanopyExamplesMassageBOW() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, PointParser.class, - "String", - "Tuple2"); + Types.STRING, + TypeInformation.of(new TypeHint>(){})); } @ForwardedFields("0") @@ -642,8 +644,8 @@ public void reduce(Iterable> values, Collector @Test public void testCanopyExamplesDocumentReducer() { compareAnalyzerResultWithAnnotationsSingleInputWithKeys(GroupReduceFunction.class, DocumentReducer.class, - "Tuple2", - "Tuple5", + TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){}), new String[] { "0" }); } @@ -669,8 +671,8 @@ public Document map(Document value) throws Exception { @Test public void testCanopyExamplesMapToCenter() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, MapToCenter.class, - "Tuple5", - "Tuple5"); + TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){})); } // -------------------------------------------------------------------------------------------- @@ -725,8 +727,8 @@ public void reduce(Iterable> values, Collector< @Test public void testKMeansppExamplesRecordToDocConverter() { compareAnalyzerResultWithAnnotationsSingleInputWithKeys(GroupReduceFunction.class, RecordToDocConverter.class, - "Tuple3", - "org.apache.flink.api.java.sca.UdfAnalyzerExamplesTest$DocumentWithFreq", + TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint(){}), new String[] { "0" }); } } diff --git a/flink-java/src/test/java/org/apache/flink/api/java/sca/UdfAnalyzerTest.java b/flink-java/src/test/java/org/apache/flink/api/java/sca/UdfAnalyzerTest.java index 7e8883871f930..430ea3bb29bff 100644 --- a/flink-java/src/test/java/org/apache/flink/api/java/sca/UdfAnalyzerTest.java +++ b/flink-java/src/test/java/org/apache/flink/api/java/sca/UdfAnalyzerTest.java @@ -30,7 +30,9 @@ import org.apache.flink.api.common.operators.Keys; import org.apache.flink.api.common.operators.SingleInputSemanticProperties; import org.apache.flink.api.common.typeinfo.BasicTypeInfo; +import org.apache.flink.api.common.typeinfo.TypeHint; import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.common.typeinfo.Types; import org.apache.flink.api.java.functions.FunctionAnnotation; import org.apache.flink.api.java.functions.FunctionAnnotation.ForwardedFields; import org.apache.flink.api.java.functions.FunctionAnnotation.ForwardedFieldsFirst; @@ -41,7 +43,7 @@ import org.apache.flink.api.java.tuple.Tuple3; import org.apache.flink.api.java.tuple.Tuple4; import org.apache.flink.api.java.tuple.Tuple8; -import org.apache.flink.api.java.typeutils.TypeInfoParser; +import org.apache.flink.api.java.typeutils.GenericTypeInfo; import org.apache.flink.util.Collector; import org.junit.Assert; @@ -69,8 +71,8 @@ public String map(Tuple2 value) throws Exception { @Test public void testSingleFieldExtract() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map1.class, "Tuple2", - "String"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map1.class, + TypeInformation.of(new TypeHint>(){}), Types.STRING); } @ForwardedFields("f0->f0;f0->f1") @@ -82,8 +84,8 @@ public Tuple2 map(Tuple2 value) throws Exceptio @Test public void testForwardIntoTuple() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map2.class, "Tuple2", - "Tuple2"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map2.class, + TypeInformation.of(new TypeHint>(){}), TypeInformation.of(new TypeHint>(){})); } private static class Map3 implements MapFunction { @@ -96,7 +98,8 @@ public Integer map(String[] value) throws Exception { @Test public void testForwardWithArrayAttrAccess() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map3.class, "String[]", "Integer"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map3.class, + TypeInformation.of(new TypeHint(){}), Types.INT); } private static class Map4 implements MapFunction { @@ -109,7 +112,7 @@ public String map(MyPojo value) throws Exception { @Test public void testForwardWithGenericTypePublicAttrAccess() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map4.class, - "org.apache.flink.api.java.sca.UdfAnalyzerTest$MyPojo", "String"); + TypeInformation.of(new TypeHint>(){}), Types.STRING); } @ForwardedFields("field2->*") @@ -123,7 +126,7 @@ public String map(MyPojo value) throws Exception { @Test public void testForwardWithPojoPublicAttrAccess() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map5.class, - "org.apache.flink.api.java.sca.UdfAnalyzerTest$MyPojo", "String"); + TypeInformation.of(new TypeHint(){}), Types.STRING); } @ForwardedFields("field->*") @@ -137,7 +140,7 @@ public String map(MyPojo value) throws Exception { @Test public void testForwardWithPojoPrivateAttrAccess() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map6.class, - "org.apache.flink.api.java.sca.UdfAnalyzerTest$MyPojo", "String"); + TypeInformation.of(new TypeHint(){}), Types.STRING); } @ForwardedFields("f0->f1") @@ -153,8 +156,8 @@ public Tuple2 map(Tuple2 value) throws Exceptio @Test public void testForwardIntoTupleWithCondition() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map7.class, "Tuple2", - "Tuple2"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map7.class, + TypeInformation.of(new TypeHint>(){}), TypeInformation.of(new TypeHint>(){})); } private static class Map8 implements MapFunction, String> { @@ -169,8 +172,8 @@ public String map(Tuple2 value) throws Exception { @Test public void testSingleFieldExtractWithCondition() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map8.class, "Tuple2", - "String"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map8.class, + TypeInformation.of(new TypeHint>(){}), Types.STRING); } @ForwardedFields("*->f0") @@ -185,7 +188,8 @@ public Tuple1 map(String value) throws Exception { @Test public void testForwardIntoTupleWithInstanceVar() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map9.class, "String", "Tuple1"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map9.class, Types.STRING, + TypeInformation.of(new TypeHint>(){})); } @ForwardedFields("*->f0.f0") @@ -200,8 +204,8 @@ public Tuple1> map(String value) throws Exception { @Test public void testForwardIntoTupleWithInstanceVar2() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map10.class, "String", - "Tuple1>"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map10.class, Types.STRING, + TypeInformation.of(new TypeHint>>(){})); } @ForwardedFields("*->f1") @@ -222,8 +226,8 @@ private void modify() { @Test public void testForwardIntoTupleWithInstanceVarChangedByOtherMethod() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map11.class, "String", - "Tuple2"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map11.class, Types.STRING, + TypeInformation.of(new TypeHint>(){})); } @ForwardedFields("f0->f0.f0;f0->f1.f0") @@ -236,8 +240,9 @@ public Tuple2, Tuple1> map(Tuple2 value) @Test public void testForwardIntoNestedTuple() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map12.class, "Tuple2", - "Tuple2,Tuple1>"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map12.class, + TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint, Tuple1>>(){})); } @ForwardedFields("f0->f1.f0") @@ -253,8 +258,9 @@ public Tuple2, Tuple1> map(Tuple2 value) @Test public void testForwardIntoNestedTupleWithVarAndModification() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map13.class, "Tuple2", - "Tuple2,Tuple1>"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map13.class, + TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint, Tuple1>>(){})); } @ForwardedFields("f0") @@ -268,8 +274,8 @@ public Tuple2 map(Tuple2 value) throws Exceptio @Test public void testForwardIntoTupleWithAssignment() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map14.class, "Tuple2", - "Tuple2"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map14.class, + TypeInformation.of(new TypeHint>(){}), TypeInformation.of(new TypeHint>(){})); } @ForwardedFields("f0.f0->f0") @@ -284,7 +290,8 @@ public Tuple2 map(Tuple2, Integer> value) throws @Test public void testForwardIntoTupleWithInputPath() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map15.class, - "Tuple2,Integer>", "Tuple2"); + TypeInformation.of(new TypeHint, Integer>>(){}), + TypeInformation.of(new TypeHint>(){})); } @ForwardedFields("field->field2;field2->field") @@ -300,8 +307,7 @@ public MyPojo map(MyPojo value) throws Exception { @Test public void testForwardIntoPojoByGettersAndSetters() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map16.class, - "org.apache.flink.api.java.sca.UdfAnalyzerTest$MyPojo", - "org.apache.flink.api.java.sca.UdfAnalyzerTest$MyPojo"); + TypeInformation.of(new TypeHint(){}), TypeInformation.of(new TypeHint(){})); } private static class Map17 implements MapFunction> { @@ -319,7 +325,8 @@ public Tuple1 map(String value) throws Exception { @Test public void testForwardIntoTupleWithInstanceVarAndCondition() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map17.class, "String", "Tuple1"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map17.class, Types.STRING, + TypeInformation.of(new TypeHint>(){})); } private static class Map18 implements MapFunction, ArrayList> { @@ -333,8 +340,8 @@ public ArrayList map(Tuple1 value) throws Exception { @Test public void testForwardIntoUnsupportedObject() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map18.class, "Tuple1", - "java.util.ArrayList"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map18.class, + TypeInformation.of(new TypeHint>(){}), TypeInformation.of(new TypeHint(){})); } @ForwardedFields("*->f0") @@ -351,7 +358,8 @@ public Tuple1 map(Integer value) throws Exception { @Test public void testForwardWithNewTupleToNewTupleAssignment() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map19.class, "Integer", "Tuple1"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map19.class, Types.INT, + TypeInformation.of(new TypeHint>(){})); } @ForwardedFields("f0;f1") @@ -371,7 +379,8 @@ public Tuple4 map(Tuple4", "Tuple4"); + TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){})); } @ForwardedFields("f0->f1;f1->f0") @@ -387,8 +396,8 @@ public Tuple2 map(Tuple2 value) throws Excep @Test public void testForwardWithSetMethod() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map21.class, "Tuple2", - "Tuple2"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map21.class, + TypeInformation.of(new TypeHint>(){}), TypeInformation.of(new TypeHint>(){})); } @ForwardedFields("f0->f1;f1->f0") @@ -404,8 +413,8 @@ public Tuple2 map(Tuple2 value) throws Excep @Test public void testForwardIntoNewTupleWithSetMethod() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map22.class, "Tuple2", - "Tuple2"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map22.class, + TypeInformation.of(new TypeHint>(){}), TypeInformation.of(new TypeHint>(){})); } @ForwardedFields("*") @@ -426,8 +435,8 @@ public Tuple1 map(Tuple1 value) throws Exception { @Test public void testForwardWithGetMethod2() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map23.class, "Tuple1", - "Tuple1"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map23.class, + TypeInformation.of(new TypeHint>(){}), TypeInformation.of(new TypeHint>(){})); } private static class Map24 implements MapFunction, Tuple2> { @@ -442,8 +451,8 @@ public Tuple2 map(Tuple2 value) throws Excep @Test public void testForwardWithSetMethod2() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map24.class, "Tuple2", - "Tuple2"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map24.class, + TypeInformation.of(new TypeHint>(){}), TypeInformation.of(new TypeHint>(){})); } @ForwardedFields("f1->f0;f1") @@ -457,8 +466,8 @@ public Tuple2 map(Tuple2 value) throws Excep @Test public void testForwardWithModifiedInput() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map25.class, "Tuple2", - "Tuple2"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map25.class, + TypeInformation.of(new TypeHint>(){}), TypeInformation.of(new TypeHint>(){})); } @ForwardedFields("*->1") @@ -482,8 +491,8 @@ public Tuple2 map(Integer value) throws Exception { @Test public void testForwardWithTuplesGetSetFieldMethods() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map26.class, "Integer", - "Tuple2"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map26.class, Types.INT, + TypeInformation.of(new TypeHint>(){})); } @ForwardedFields("2->3;3->7") @@ -515,8 +524,8 @@ public Tuple8", - "Tuple8"); + TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){})); } private static class Map28 implements MapFunction { @@ -531,7 +540,7 @@ public Integer map(Integer value) throws Exception { @Test public void testForwardWithBranching1() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map28.class, "Integer", "Integer"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map28.class, Types.INT, Types.INT); } @ForwardedFields("0") @@ -555,7 +564,8 @@ public Tuple3 map(Tuple3 value) @Test public void testForwardWithBranching2() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map29.class, - "Tuple3", "Tuple3"); + TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){})); } private static class Map30 implements MapFunction, String> { @@ -573,8 +583,8 @@ public String map(Tuple2 value) throws Exception { @Test public void testForwardWithBranching3() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map30.class, "Tuple2", - "String"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map30.class, + TypeInformation.of(new TypeHint>(){}), Types.STRING); } @ForwardedFields("1->1;1->0") @@ -591,8 +601,8 @@ public ExtendingTuple map(Tuple2 value) throws Exception { @Test public void testForwardWithInheritance() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map31.class, "Tuple2", - "Tuple2"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map31.class, + TypeInformation.of(new TypeHint>(){}), TypeInformation.of(new TypeHint>(){})); } @ForwardedFields("*") @@ -620,8 +630,8 @@ public Tuple8 map @Test public void testForwardWithUnboxingAndBoxing() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map32.class, - "Tuple8", - "Tuple8"); + TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){})); } private static class Map33 implements MapFunction, Tuple2> { @@ -640,8 +650,8 @@ public Tuple2 map(Tuple2 value) throws Exception { @Test public void testForwardWithBranching4() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map33.class, "Tuple2", - "Tuple2"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map33.class, TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){})); } @ForwardedFields("1") @@ -663,8 +673,8 @@ else if (value.f0 == 1L && value.f1 == 2L) { @Test public void testForwardWithBranching5() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map34.class, "Tuple2", - "Tuple2"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map34.class, TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){})); } private static class Map35 implements MapFunction> { @@ -678,8 +688,8 @@ public Tuple2 map(String[] value) throws Exception { @Test public void testForwardWithArrayModification() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map35.class, "String[]", - "Tuple2"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map35.class, TypeInformation.of(new TypeHint(){}), + TypeInformation.of(new TypeHint>(){})); } private static class Map36 implements MapFunction, Tuple3> { @@ -696,8 +706,8 @@ public Tuple3 map(Tuple3 value) @Test public void testForwardWithBranching6() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map36.class, "Tuple3", - "Tuple3"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map36.class, TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){})); } private static class Map37 implements MapFunction>, Tuple1>> { @@ -711,8 +721,8 @@ public Tuple1> map(Tuple1> value) throws Exception @Test public void testForwardWithGetAndModification() { - compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map37.class, "Tuple1>", - "Tuple1>"); + compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map37.class, TypeInformation.of(new TypeHint>>(){}), + TypeInformation.of(new TypeHint>>(){})); } @ForwardedFields("field") @@ -727,8 +737,8 @@ public MyPojo2 map(MyPojo2 value) throws Exception { @Test public void testForwardWithInheritance2() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map38.class, - "org.apache.flink.api.java.sca.UdfAnalyzerTest$MyPojo2", - "org.apache.flink.api.java.sca.UdfAnalyzerTest$MyPojo2"); + TypeInformation.of(new TypeHint(){}), + TypeInformation.of(new TypeHint(){})); } private static class Map39 implements MapFunction { @@ -743,8 +753,8 @@ public MyPojo map(MyPojo value) throws Exception { @Test public void testForwardWithGenericTypeOutput() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map39.class, - "org.apache.flink.api.java.sca.UdfAnalyzerTest$MyPojo", - "org.apache.flink.api.java.sca.UdfAnalyzerTest$MyPojo"); + TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){})); } @ForwardedFields("field2") @@ -766,8 +776,8 @@ private MyPojo recursiveFunction(MyPojo value) { @Test public void testForwardWithRecursion() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map40.class, - "org.apache.flink.api.java.sca.UdfAnalyzerTest$MyPojo", - "org.apache.flink.api.java.sca.UdfAnalyzerTest$MyPojo"); + TypeInformation.of(new TypeHint(){}), + TypeInformation.of(new TypeHint(){})); } @ForwardedFields("field;field2") @@ -784,8 +794,8 @@ public MyPojo map(MyPojo value) throws Exception { @Test public void testForwardWithGetRuntimeContext() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map41.class, - "org.apache.flink.api.java.sca.UdfAnalyzerTest$MyPojo", - "org.apache.flink.api.java.sca.UdfAnalyzerTest$MyPojo"); + TypeInformation.of(new TypeHint(){}), + TypeInformation.of(new TypeHint(){})); } @ForwardedFields("*") @@ -798,8 +808,8 @@ public void flatMap(Tuple1 value, Collector> out) throw @Test public void testForwardWithCollector() { - compareAnalyzerResultWithAnnotationsSingleInput(FlatMapFunction.class, FlatMap1.class, "Tuple1", - "Tuple1"); + compareAnalyzerResultWithAnnotationsSingleInput(FlatMapFunction.class, FlatMap1.class, TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){})); } @ForwardedFields("0->1;1->0") @@ -817,8 +827,8 @@ public void flatMap(Tuple2 edge, Collector> out) @Test public void testForwardWith2Collectors() { - compareAnalyzerResultWithAnnotationsSingleInput(FlatMapFunction.class, FlatMap2.class, "Tuple2", - "Tuple2"); + compareAnalyzerResultWithAnnotationsSingleInput(FlatMapFunction.class, FlatMap2.class, TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){})); } private static class FlatMap3 implements FlatMapFunction, Tuple1> { @@ -835,8 +845,8 @@ private void addToCollector(Collector> out) { @Test public void testForwardWithCollectorPassing() { - compareAnalyzerResultWithAnnotationsSingleInput(FlatMapFunction.class, FlatMap3.class, "Tuple1", - "Tuple1"); + compareAnalyzerResultWithAnnotationsSingleInput(FlatMapFunction.class, FlatMap3.class, TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){})); } @ForwardedFieldsFirst("f1->f1") @@ -850,8 +860,8 @@ public Tuple2 join(Tuple2 vertexWithComponent, Tuple2", - "Tuple2", "Tuple2"); + compareAnalyzerResultWithAnnotationsDualInput(JoinFunction.class, Join1.class, TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){}), TypeInformation.of(new TypeHint>(){})); } @ForwardedFieldsFirst("*") @@ -866,8 +876,8 @@ public void join(Tuple2 candidate, Tuple2 old, Collector @Test public void testForwardWithDualInputAndCollector() { - compareAnalyzerResultWithAnnotationsDualInput(FlatJoinFunction.class, Join2.class, "Tuple2", - "Tuple2", "Tuple2"); + compareAnalyzerResultWithAnnotationsDualInput(FlatJoinFunction.class, Join2.class, TypeInformation.of(new TypeHint>(){}), + TypeInformation.of(new TypeHint>(){}), TypeInformation.of(new TypeHint>(){})); } @ForwardedFields("0") @@ -881,7 +891,7 @@ public void reduce(Iterable> values, Collector", "Tuple2", new String[] { "0" }); + TypeInformation.of(new TypeHint>(){}), TypeInformation.of(new TypeHint>(){}), new String[] { "0" }); } @ForwardedFields("1->0") @@ -907,7 +917,7 @@ public void reduce(Iterable> values, Collector", "Tuple2", new String[] { "0", "1" }); + TypeInformation.of(new TypeHint>(){}), TypeInformation.of(new TypeHint>(){}), new String[] { "0", "1" }); } @ForwardedFields("field2") @@ -923,8 +933,8 @@ public void reduce(Iterable values, Collector out) throws Except @Test public void testForwardWithIterable3() { compareAnalyzerResultWithAnnotationsSingleInputWithKeys(GroupReduceFunction.class, GroupReduce3.class, - "org.apache.flink.api.java.sca.UdfAnalyzerTest$MyPojo", - "org.apache.flink.api.java.sca.UdfAnalyzerTest$MyPojo", new String[] { "field2" }); + TypeInformation.of(new TypeHint(){}), + TypeInformation.of(new TypeHint(){}), new String[] { "field2" }); } @ForwardedFields("f0->*") @@ -942,7 +952,7 @@ public void reduce(Iterable> values, Collector out) thr @Test public void testForwardWithAtLeastOneIterationAssumption() { compareAnalyzerResultWithAnnotationsSingleInputWithKeys(GroupReduceFunction.class, GroupReduce4.class, - "Tuple2", "Long", new String[] { "f0" }); + TypeInformation.of(new TypeHint>(){}), Types.LONG, new String[] { "f0" }); } @ForwardedFields("f0->*") @@ -967,7 +977,7 @@ public void reduce(Iterable> values, Collector out) thr public void testForwardWithAtLeastOneIterationAssumptionForJavac() { // this test simulates javac behaviour in Eclipse IDE compareAnalyzerResultWithAnnotationsSingleInputWithKeys(GroupReduceFunction.class, GroupReduce4Javac.class, - "Tuple2", "Long", new String[] { "f0" }); + TypeInformation.of(new TypeHint>(){}), Types.LONG, new String[] { "f0" }); } private static class GroupReduce5 implements GroupReduceFunction, Long> { @@ -987,7 +997,7 @@ public void reduce(Iterable> values, Collector out) thr @Test public void testForwardWithAtLeastOneIterationAssumption2() { compareAnalyzerResultWithAnnotationsSingleInputWithKeys(GroupReduceFunction.class, GroupReduce5.class, - "Tuple2", "Long", new String[] { "f1" }); + TypeInformation.of(new TypeHint>(){}), Types.LONG, new String[] { "f1" }); } private static class GroupReduce6 implements GroupReduceFunction, Long> { @@ -1005,7 +1015,7 @@ public void reduce(Iterable> values, Collector out) thr @Test public void testForwardWithAtLeastOneIterationAssumption3() { compareAnalyzerResultWithAnnotationsSingleInputWithKeys(GroupReduceFunction.class, GroupReduce6.class, - "Tuple2", "Long", new String[] { "f0" }); + TypeInformation.of(new TypeHint>(){}), Types.LONG, new String[] { "f0" }); } private static class GroupReduce7 implements GroupReduceFunction, Long> { @@ -1023,7 +1033,7 @@ public void reduce(Iterable> values, Collector out) thr @Test public void testForwardWithAtLeastOneIterationAssumption4() { compareAnalyzerResultWithAnnotationsSingleInputWithKeys(GroupReduceFunction.class, GroupReduce7.class, - "Tuple2", "Long", new String[] { "f0" }); + TypeInformation.of(new TypeHint>(){}), Types.LONG, new String[] { "f0" }); } @ForwardedFields("f0->*") @@ -1042,7 +1052,7 @@ public void reduce(Iterable> values, Collector out) thr @Test public void testForwardWithAtLeastOneIterationAssumption5() { compareAnalyzerResultWithAnnotationsSingleInputWithKeys(GroupReduceFunction.class, GroupReduce8.class, - "Tuple2", "Long", new String[] { "f0" }); + TypeInformation.of(new TypeHint>(){}), Types.LONG, new String[] { "f0" }); } @ForwardedFields("f0") @@ -1061,7 +1071,7 @@ public void reduce(Iterable> values, Collector", "Tuple2", new String[] { "f0" }); + TypeInformation.of(new TypeHint>(){}), TypeInformation.of(new TypeHint>(){}), new String[] { "f0" }); } private static class GroupReduce10 implements GroupReduceFunction, Boolean> { @@ -1082,7 +1092,7 @@ public void reduce(Iterable> values, Collector out) @Test public void testForwardWithAtLeastOneIterationAssumption7() { compareAnalyzerResultWithAnnotationsSingleInputWithKeys(GroupReduceFunction.class, GroupReduce10.class, - "Tuple2", "Boolean", new String[] { "f0" }); + TypeInformation.of(new TypeHint>(){}), Types.BOOLEAN, new String[] { "f0" }); } @ForwardedFields("field") @@ -1096,9 +1106,9 @@ public MyPojo reduce(MyPojo value1, MyPojo value2) throws Exception { @Test public void testForwardWithReduce() { compareAnalyzerResultWithAnnotationsSingleInputWithKeys(ReduceFunction.class, Reduce1.class, - "org.apache.flink.api.java.sca.UdfAnalyzerTest$MyPojo", - "org.apache.flink.api.java.sca.UdfAnalyzerTest$MyPojo", - new String[] { "field" }); + TypeInformation.of(new TypeHint(){}), + TypeInformation.of(new TypeHint(){}), + new String[] { "field" }); } @ForwardedFields("field") @@ -1115,9 +1125,9 @@ public MyPojo reduce(MyPojo value1, MyPojo value2) throws Exception { @Test public void testForwardWithBranchingReduce() { compareAnalyzerResultWithAnnotationsSingleInputWithKeys(ReduceFunction.class, Reduce2.class, - "org.apache.flink.api.java.sca.UdfAnalyzerTest$MyPojo", - "org.apache.flink.api.java.sca.UdfAnalyzerTest$MyPojo", - new String[] { "field" }); + TypeInformation.of(new TypeHint(){}), + TypeInformation.of(new TypeHint(){}), + new String[] { "field" }); } private static class NullReturnMapper1 implements MapFunction { @@ -1215,7 +1225,7 @@ public boolean filter(Tuple2 value) throws Exception { public void testFilterModificationException1() { try { final UdfAnalyzer ua = new UdfAnalyzer(FilterFunction.class, FilterMod1.class, "operator", - TypeInfoParser.parse("Tuple2"), null, null, null, null, true); + TypeInformation.of(new TypeHint>(){}), null, null, null, null, true); ua.analyze(); Assert.fail(); } @@ -1237,7 +1247,7 @@ public boolean filter(Tuple2 value) throws Exception { public void testFilterModificationException2() { try { final UdfAnalyzer ua = new UdfAnalyzer(FilterFunction.class, FilterMod2.class, "operator", - TypeInfoParser.parse("Tuple2"), null, null, null, null, true); + TypeInformation.of(new TypeHint>(){}), null, null, null, null, true); ua.analyze(); Assert.fail(); } @@ -1303,17 +1313,14 @@ public String getSecondField() { } } - public static void compareAnalyzerResultWithAnnotationsSingleInput(Class baseClass, Class clazz, String in, - String out) { - compareAnalyzerResultWithAnnotationsSingleInputWithKeys(baseClass, clazz, in, out, null); + public static void compareAnalyzerResultWithAnnotationsSingleInput(Class baseClass, Class clazz, + TypeInformation inType, TypeInformation outType) { + compareAnalyzerResultWithAnnotationsSingleInputWithKeys(baseClass, clazz, inType, outType, null); } @SuppressWarnings({ "rawtypes", "unchecked" }) public static void compareAnalyzerResultWithAnnotationsSingleInputWithKeys(Class baseClass, Class clazz, - String in, String out, String[] keys) { - final TypeInformation inType = TypeInfoParser.parse(in); - final TypeInformation outType = TypeInfoParser.parse(out); - + TypeInformation inType, TypeInformation outType, String[] keys) { // expected final Set annotations = FunctionAnnotation.readSingleForwardAnnotations(clazz); SingleInputSemanticProperties expected = SemanticPropUtil.getSemanticPropsSingle(annotations, inType, @@ -1331,18 +1338,14 @@ public static void compareAnalyzerResultWithAnnotationsSingleInputWithKeys(Class assertEquals(expected.toString(), actual.toString()); } - public static void compareAnalyzerResultWithAnnotationsDualInput(Class baseClass, Class clazz, String in1, - String in2, String out) { - compareAnalyzerResultWithAnnotationsDualInputWithKeys(baseClass, clazz, in1, in2, out, null, null); + public static void compareAnalyzerResultWithAnnotationsDualInput(Class baseClass, Class clazz, + TypeInformation in1Type, TypeInformation in2Type, TypeInformation outType) { + compareAnalyzerResultWithAnnotationsDualInputWithKeys(baseClass, clazz, in1Type, in2Type, outType, null, null); } @SuppressWarnings({ "rawtypes", "unchecked" }) public static void compareAnalyzerResultWithAnnotationsDualInputWithKeys(Class baseClass, Class clazz, - String in1, String in2, String out, String[] keys1, String[] keys2) { - final TypeInformation in1Type = TypeInfoParser.parse(in1); - final TypeInformation in2Type = TypeInfoParser.parse(in2); - final TypeInformation outType = TypeInfoParser.parse(out); - + TypeInformation in1Type, TypeInformation in2Type, TypeInformation outType, String[] keys1, String[] keys2) { // expected final Set annotations = FunctionAnnotation.readDualForwardAnnotations(clazz); final DualInputSemanticProperties expected = SemanticPropUtil.getSemanticPropsDual(annotations, in1Type, diff --git a/flink-libraries/flink-gelly/src/test/java/org/apache/flink/graph/asm/dataset/ChecksumHashCodeTest.java b/flink-libraries/flink-gelly/src/test/java/org/apache/flink/graph/asm/dataset/ChecksumHashCodeTest.java index a31ce2eccf806..06f486de64b4f 100644 --- a/flink-libraries/flink-gelly/src/test/java/org/apache/flink/graph/asm/dataset/ChecksumHashCodeTest.java +++ b/flink-libraries/flink-gelly/src/test/java/org/apache/flink/graph/asm/dataset/ChecksumHashCodeTest.java @@ -18,8 +18,7 @@ package org.apache.flink.graph.asm.dataset; -import org.apache.flink.api.common.typeinfo.TypeHint; -import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.common.typeinfo.Types; import org.apache.flink.api.java.DataSet; import org.apache.flink.api.java.ExecutionEnvironment; import org.apache.flink.graph.asm.dataset.ChecksumHashCode.Checksum; @@ -62,7 +61,7 @@ public void testList() throws Exception { @Test public void testEmptyList() throws Exception { - DataSet dataset = env.fromCollection(Collections.emptyList(), TypeInformation.of(new TypeHint(){})); + DataSet dataset = env.fromCollection(Collections.emptyList(), Types.LONG); Checksum checksum = new ChecksumHashCode().run(dataset).execute(); diff --git a/flink-libraries/flink-gelly/src/test/java/org/apache/flink/graph/asm/dataset/CollectTest.java b/flink-libraries/flink-gelly/src/test/java/org/apache/flink/graph/asm/dataset/CollectTest.java index cfeadceb91b99..027b809546ed0 100644 --- a/flink-libraries/flink-gelly/src/test/java/org/apache/flink/graph/asm/dataset/CollectTest.java +++ b/flink-libraries/flink-gelly/src/test/java/org/apache/flink/graph/asm/dataset/CollectTest.java @@ -18,8 +18,7 @@ package org.apache.flink.graph.asm.dataset; -import org.apache.flink.api.common.typeinfo.TypeHint; -import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.common.typeinfo.Types; import org.apache.flink.api.java.DataSet; import org.apache.flink.api.java.ExecutionEnvironment; @@ -61,7 +60,7 @@ public void testList() throws Exception { @Test public void testEmptyList() throws Exception { - DataSet dataset = env.fromCollection(Collections.emptyList(), TypeInformation.of(new TypeHint(){})); + DataSet dataset = env.fromCollection(Collections.emptyList(), Types.LONG); List collected = new Collect().run(dataset).execute(); diff --git a/flink-libraries/flink-gelly/src/test/java/org/apache/flink/graph/asm/dataset/CountTest.java b/flink-libraries/flink-gelly/src/test/java/org/apache/flink/graph/asm/dataset/CountTest.java index 0167a5f4a5838..dc92c551f77f5 100644 --- a/flink-libraries/flink-gelly/src/test/java/org/apache/flink/graph/asm/dataset/CountTest.java +++ b/flink-libraries/flink-gelly/src/test/java/org/apache/flink/graph/asm/dataset/CountTest.java @@ -18,8 +18,7 @@ package org.apache.flink.graph.asm.dataset; -import org.apache.flink.api.common.typeinfo.TypeHint; -import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.common.typeinfo.Types; import org.apache.flink.api.java.DataSet; import org.apache.flink.api.java.ExecutionEnvironment; @@ -60,7 +59,7 @@ public void testList() throws Exception { @Test public void testEmptyList() throws Exception { - DataSet dataset = env.fromCollection(Collections.emptyList(), TypeInformation.of(new TypeHint(){})); + DataSet dataset = env.fromCollection(Collections.emptyList(), Types.LONG); long count = new Count().run(dataset).execute(); From 7efd18f323ad8218fa6ab96461a6dde60dc7e4c5 Mon Sep 17 00:00:00 2001 From: yanghua Date: Thu, 10 May 2018 17:33:28 +0800 Subject: [PATCH 2/4] fixed a incompatibility error reported by japicmp plugin --- flink-core/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/flink-core/pom.xml b/flink-core/pom.xml index efd7b12152498..9826be01b994a 100644 --- a/flink-core/pom.xml +++ b/flink-core/pom.xml @@ -177,6 +177,7 @@ under the License. org.apache.flink.api.common.typeinfo.TypeHint + org.apache.flink.api.java.typeutils.TypeInfoParser From fe6fa2ffb0fe749c43fe540714b5bcb7e3d86df6 Mon Sep 17 00:00:00 2001 From: yanghua Date: Fri, 11 May 2018 22:03:28 +0800 Subject: [PATCH 3/4] refactor code and fixed a type error --- .../common/typeinfo/TypeInformationTest.java | 2 +- .../flink/api/java/sca/UdfAnalyzerTest.java | 32 +++++++++++-------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/flink-core/src/test/java/org/apache/flink/api/common/typeinfo/TypeInformationTest.java b/flink-core/src/test/java/org/apache/flink/api/common/typeinfo/TypeInformationTest.java index d9af0689365b8..14888665765e5 100644 --- a/flink-core/src/test/java/org/apache/flink/api/common/typeinfo/TypeInformationTest.java +++ b/flink-core/src/test/java/org/apache/flink/api/common/typeinfo/TypeInformationTest.java @@ -61,7 +61,7 @@ public void testOfGenericClassForGenericType() { @Test public void testOfTypeHint() { assertEquals(BasicTypeInfo.STRING_TYPE_INFO, TypeInformation.of(String.class)); - assertEquals(BasicTypeInfo.STRING_TYPE_INFO, Types.STRING); + assertEquals(BasicTypeInfo.STRING_TYPE_INFO, TypeInformation.of(new TypeHint(){})); TypeInformation> tupleInfo = new TupleTypeInfo<>(BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.DOUBLE_TYPE_INFO, BasicTypeInfo.BOOLEAN_TYPE_INFO); diff --git a/flink-java/src/test/java/org/apache/flink/api/java/sca/UdfAnalyzerTest.java b/flink-java/src/test/java/org/apache/flink/api/java/sca/UdfAnalyzerTest.java index 430ea3bb29bff..1384cda016933 100644 --- a/flink-java/src/test/java/org/apache/flink/api/java/sca/UdfAnalyzerTest.java +++ b/flink-java/src/test/java/org/apache/flink/api/java/sca/UdfAnalyzerTest.java @@ -62,6 +62,10 @@ @SuppressWarnings("serial") public class UdfAnalyzerTest { + private static TypeInformation> stringIntTuple2TypeInfo = TypeInformation.of(new TypeHint>(){}); + + private static TypeInformation> stringStringTuple2TypeInfo = TypeInformation.of(new TypeHint>(){}); + @ForwardedFields("f0->*") private static class Map1 implements MapFunction, String> { public String map(Tuple2 value) throws Exception { @@ -72,7 +76,7 @@ public String map(Tuple2 value) throws Exception { @Test public void testSingleFieldExtract() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map1.class, - TypeInformation.of(new TypeHint>(){}), Types.STRING); + stringIntTuple2TypeInfo, Types.STRING); } @ForwardedFields("f0->f0;f0->f1") @@ -85,7 +89,7 @@ public Tuple2 map(Tuple2 value) throws Exceptio @Test public void testForwardIntoTuple() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map2.class, - TypeInformation.of(new TypeHint>(){}), TypeInformation.of(new TypeHint>(){})); + stringIntTuple2TypeInfo, stringStringTuple2TypeInfo); } private static class Map3 implements MapFunction { @@ -112,7 +116,7 @@ public String map(MyPojo value) throws Exception { @Test public void testForwardWithGenericTypePublicAttrAccess() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map4.class, - TypeInformation.of(new TypeHint>(){}), Types.STRING); + new GenericTypeInfo<>(MyPojo.class), Types.STRING); } @ForwardedFields("field2->*") @@ -157,7 +161,7 @@ public Tuple2 map(Tuple2 value) throws Exceptio @Test public void testForwardIntoTupleWithCondition() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map7.class, - TypeInformation.of(new TypeHint>(){}), TypeInformation.of(new TypeHint>(){})); + stringIntTuple2TypeInfo, stringStringTuple2TypeInfo); } private static class Map8 implements MapFunction, String> { @@ -173,7 +177,7 @@ public String map(Tuple2 value) throws Exception { @Test public void testSingleFieldExtractWithCondition() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map8.class, - TypeInformation.of(new TypeHint>(){}), Types.STRING); + stringStringTuple2TypeInfo, Types.STRING); } @ForwardedFields("*->f0") @@ -227,7 +231,7 @@ private void modify() { @Test public void testForwardIntoTupleWithInstanceVarChangedByOtherMethod() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map11.class, Types.STRING, - TypeInformation.of(new TypeHint>(){})); + stringStringTuple2TypeInfo); } @ForwardedFields("f0->f0.f0;f0->f1.f0") @@ -241,7 +245,7 @@ public Tuple2, Tuple1> map(Tuple2 value) @Test public void testForwardIntoNestedTuple() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map12.class, - TypeInformation.of(new TypeHint>(){}), + stringIntTuple2TypeInfo, TypeInformation.of(new TypeHint, Tuple1>>(){})); } @@ -259,7 +263,7 @@ public Tuple2, Tuple1> map(Tuple2 value) @Test public void testForwardIntoNestedTupleWithVarAndModification() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map13.class, - TypeInformation.of(new TypeHint>(){}), + stringIntTuple2TypeInfo, TypeInformation.of(new TypeHint, Tuple1>>(){})); } @@ -275,7 +279,7 @@ public Tuple2 map(Tuple2 value) throws Exceptio @Test public void testForwardIntoTupleWithAssignment() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map14.class, - TypeInformation.of(new TypeHint>(){}), TypeInformation.of(new TypeHint>(){})); + stringIntTuple2TypeInfo, stringStringTuple2TypeInfo); } @ForwardedFields("f0.f0->f0") @@ -291,7 +295,7 @@ public Tuple2 map(Tuple2, Integer> value) throws public void testForwardIntoTupleWithInputPath() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map15.class, TypeInformation.of(new TypeHint, Integer>>(){}), - TypeInformation.of(new TypeHint>(){})); + stringStringTuple2TypeInfo); } @ForwardedFields("field->field2;field2->field") @@ -584,7 +588,7 @@ public String map(Tuple2 value) throws Exception { @Test public void testForwardWithBranching3() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map30.class, - TypeInformation.of(new TypeHint>(){}), Types.STRING); + stringStringTuple2TypeInfo, Types.STRING); } @ForwardedFields("1->1;1->0") @@ -602,7 +606,7 @@ public ExtendingTuple map(Tuple2 value) throws Exception { @Test public void testForwardWithInheritance() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map31.class, - TypeInformation.of(new TypeHint>(){}), TypeInformation.of(new TypeHint>(){})); + stringStringTuple2TypeInfo, stringStringTuple2TypeInfo); } @ForwardedFields("*") @@ -1225,7 +1229,7 @@ public boolean filter(Tuple2 value) throws Exception { public void testFilterModificationException1() { try { final UdfAnalyzer ua = new UdfAnalyzer(FilterFunction.class, FilterMod1.class, "operator", - TypeInformation.of(new TypeHint>(){}), null, null, null, null, true); + stringStringTuple2TypeInfo, null, null, null, null, true); ua.analyze(); Assert.fail(); } @@ -1247,7 +1251,7 @@ public boolean filter(Tuple2 value) throws Exception { public void testFilterModificationException2() { try { final UdfAnalyzer ua = new UdfAnalyzer(FilterFunction.class, FilterMod2.class, "operator", - TypeInformation.of(new TypeHint>(){}), null, null, null, null, true); + stringStringTuple2TypeInfo, null, null, null, null, true); ua.analyze(); Assert.fail(); } From 50bc1f25a810417f80a1be84b0865e883d7410a5 Mon Sep 17 00:00:00 2001 From: yanghua Date: Sun, 13 May 2018 19:42:44 +0800 Subject: [PATCH 4/4] changed fields to constants --- .../flink/api/java/sca/UdfAnalyzerTest.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/flink-java/src/test/java/org/apache/flink/api/java/sca/UdfAnalyzerTest.java b/flink-java/src/test/java/org/apache/flink/api/java/sca/UdfAnalyzerTest.java index 1384cda016933..dcea16d197257 100644 --- a/flink-java/src/test/java/org/apache/flink/api/java/sca/UdfAnalyzerTest.java +++ b/flink-java/src/test/java/org/apache/flink/api/java/sca/UdfAnalyzerTest.java @@ -62,9 +62,9 @@ @SuppressWarnings("serial") public class UdfAnalyzerTest { - private static TypeInformation> stringIntTuple2TypeInfo = TypeInformation.of(new TypeHint>(){}); + private static final TypeInformation> STRING_INT_TUPLE2_TYPE_INFO = TypeInformation.of(new TypeHint>(){}); - private static TypeInformation> stringStringTuple2TypeInfo = TypeInformation.of(new TypeHint>(){}); + private static final TypeInformation> STRING_STRING_TUPLE2_TYPE_INFO = TypeInformation.of(new TypeHint>(){}); @ForwardedFields("f0->*") private static class Map1 implements MapFunction, String> { @@ -76,7 +76,7 @@ public String map(Tuple2 value) throws Exception { @Test public void testSingleFieldExtract() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map1.class, - stringIntTuple2TypeInfo, Types.STRING); + STRING_INT_TUPLE2_TYPE_INFO, Types.STRING); } @ForwardedFields("f0->f0;f0->f1") @@ -89,7 +89,7 @@ public Tuple2 map(Tuple2 value) throws Exceptio @Test public void testForwardIntoTuple() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map2.class, - stringIntTuple2TypeInfo, stringStringTuple2TypeInfo); + STRING_INT_TUPLE2_TYPE_INFO, STRING_STRING_TUPLE2_TYPE_INFO); } private static class Map3 implements MapFunction { @@ -161,7 +161,7 @@ public Tuple2 map(Tuple2 value) throws Exceptio @Test public void testForwardIntoTupleWithCondition() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map7.class, - stringIntTuple2TypeInfo, stringStringTuple2TypeInfo); + STRING_INT_TUPLE2_TYPE_INFO, STRING_STRING_TUPLE2_TYPE_INFO); } private static class Map8 implements MapFunction, String> { @@ -177,7 +177,7 @@ public String map(Tuple2 value) throws Exception { @Test public void testSingleFieldExtractWithCondition() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map8.class, - stringStringTuple2TypeInfo, Types.STRING); + STRING_STRING_TUPLE2_TYPE_INFO, Types.STRING); } @ForwardedFields("*->f0") @@ -231,7 +231,7 @@ private void modify() { @Test public void testForwardIntoTupleWithInstanceVarChangedByOtherMethod() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map11.class, Types.STRING, - stringStringTuple2TypeInfo); + STRING_STRING_TUPLE2_TYPE_INFO); } @ForwardedFields("f0->f0.f0;f0->f1.f0") @@ -245,7 +245,7 @@ public Tuple2, Tuple1> map(Tuple2 value) @Test public void testForwardIntoNestedTuple() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map12.class, - stringIntTuple2TypeInfo, + STRING_INT_TUPLE2_TYPE_INFO, TypeInformation.of(new TypeHint, Tuple1>>(){})); } @@ -263,7 +263,7 @@ public Tuple2, Tuple1> map(Tuple2 value) @Test public void testForwardIntoNestedTupleWithVarAndModification() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map13.class, - stringIntTuple2TypeInfo, + STRING_INT_TUPLE2_TYPE_INFO, TypeInformation.of(new TypeHint, Tuple1>>(){})); } @@ -279,7 +279,7 @@ public Tuple2 map(Tuple2 value) throws Exceptio @Test public void testForwardIntoTupleWithAssignment() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map14.class, - stringIntTuple2TypeInfo, stringStringTuple2TypeInfo); + STRING_INT_TUPLE2_TYPE_INFO, STRING_STRING_TUPLE2_TYPE_INFO); } @ForwardedFields("f0.f0->f0") @@ -295,7 +295,7 @@ public Tuple2 map(Tuple2, Integer> value) throws public void testForwardIntoTupleWithInputPath() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map15.class, TypeInformation.of(new TypeHint, Integer>>(){}), - stringStringTuple2TypeInfo); + STRING_STRING_TUPLE2_TYPE_INFO); } @ForwardedFields("field->field2;field2->field") @@ -588,7 +588,7 @@ public String map(Tuple2 value) throws Exception { @Test public void testForwardWithBranching3() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map30.class, - stringStringTuple2TypeInfo, Types.STRING); + STRING_STRING_TUPLE2_TYPE_INFO, Types.STRING); } @ForwardedFields("1->1;1->0") @@ -606,7 +606,7 @@ public ExtendingTuple map(Tuple2 value) throws Exception { @Test public void testForwardWithInheritance() { compareAnalyzerResultWithAnnotationsSingleInput(MapFunction.class, Map31.class, - stringStringTuple2TypeInfo, stringStringTuple2TypeInfo); + STRING_STRING_TUPLE2_TYPE_INFO, STRING_STRING_TUPLE2_TYPE_INFO); } @ForwardedFields("*") @@ -1229,7 +1229,7 @@ public boolean filter(Tuple2 value) throws Exception { public void testFilterModificationException1() { try { final UdfAnalyzer ua = new UdfAnalyzer(FilterFunction.class, FilterMod1.class, "operator", - stringStringTuple2TypeInfo, null, null, null, null, true); + STRING_STRING_TUPLE2_TYPE_INFO, null, null, null, null, true); ua.analyze(); Assert.fail(); } @@ -1251,7 +1251,7 @@ public boolean filter(Tuple2 value) throws Exception { public void testFilterModificationException2() { try { final UdfAnalyzer ua = new UdfAnalyzer(FilterFunction.class, FilterMod2.class, "operator", - stringStringTuple2TypeInfo, null, null, null, null, true); + STRING_STRING_TUPLE2_TYPE_INFO, null, null, null, null, true); ua.analyze(); Assert.fail(); }