FLink开发遇到java 泛型报错

FLink 开发遇到java报错

/Library/jdk1.8.0_372.jdk/Contents/Home/bin/java -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=52448:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 -classpath /Library/jdk1.8.0_372.jdk/Contents/Home/jre/lib/charsets.jar:/Library/jdk1.8.0_372.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/jdk1.8.0_372.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/jdk1.8.0_372.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/jdk1.8.0_372.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/jdk1.8.0_372.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/jdk1.8.0_372.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/jdk1.8.0_372.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/jdk1.8.0_372.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/jdk1.8.0_372.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Library/jdk1.8.0_372.jdk/Contents/Home/jre/lib/jce.jar:/Library/jdk1.8.0_372.jdk/Contents/Home/jre/lib/jfr.jar:/Library/jdk1.8.0_372.jdk/Contents/Home/jre/lib/jsse.jar:/Library/jdk1.8.0_372.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/jdk1.8.0_372.jdk/Contents/Home/jre/lib/resources.jar:/Library/jdk1.8.0_372.jdk/Contents/Home/jre/lib/rt.jar:/Users/rockybx/Documents/idea_project/untitled/target/classes:/Users/rockybx/.m2/repository/org/apache/flink/flink-java/1.14.5/flink-java-1.14.5.jar:/Users/rockybx/.m2/repository/org/apache/flink/flink-core/1.14.5/flink-core-1.14.5.jar:/Users/rockybx/.m2/repository/org/apache/flink/flink-annotations/1.14.5/flink-annotations-1.14.5.jar:/Users/rockybx/.m2/repository/org/apache/flink/flink-metrics-core/1.14.5/flink-metrics-core-1.14.5.jar:/Users/rockybx/.m2/repository/org/apache/flink/flink-shaded-asm-7/7.1-14.0/flink-shaded-asm-7-7.1-14.0.jar:/Users/rockybx/.m2/repository/com/esotericsoftware/kryo/kryo/2.24.0/kryo-2.24.0.jar:/Users/rockybx/.m2/repository/com/esotericsoftware/minlog/minlog/1.2/minlog-1.2.jar:/Users/rockybx/.m2/repository/org/objenesis/objenesis/2.1/objenesis-2.1.jar:/Users/rockybx/.m2/repository/commons-collections/commons-collections/3.2.2/commons-collections-3.2.2.jar:/Users/rockybx/.m2/repository/org/apache/commons/commons-compress/1.21/commons-compress-1.21.jar:/Users/rockybx/.m2/repository/org/apache/commons/commons-lang3/3.3.2/commons-lang3-3.3.2.jar:/Users/rockybx/.m2/repository/org/apache/commons/commons-math3/3.5/commons-math3-3.5.jar:/Users/rockybx/.m2/repository/org/slf4j/slf4j-api/1.7.15/slf4j-api-1.7.15.jar:/Users/rockybx/.m2/repository/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar:/Users/rockybx/.m2/repository/org/apache/flink/flink-shaded-force-shading/14.0/flink-shaded-force-shading-14.0.jar:/Users/rockybx/.m2/repository/org/apache/flink/flink-streaming-java_2.12/1.14.5/flink-streaming-java_2.12-1.14.5.jar:/Users/rockybx/.m2/repository/org/apache/flink/flink-file-sink-common/1.14.5/flink-file-sink-common-1.14.5.jar:/Users/rockybx/.m2/repository/org/apache/flink/flink-runtime/1.14.5/flink-runtime-1.14.5.jar:/Users/rockybx/.m2/repository/org/apache/flink/flink-rpc-core/1.14.5/flink-rpc-core-1.14.5.jar:/Users/rockybx/.m2/repository/org/apache/flink/flink-rpc-akka-loader/1.14.5/flink-rpc-akka-loader-1.14.5.jar:/Users/rockybx/.m2/repository/org/apache/flink/flink-queryable-state-client-java/1.14.5/flink-queryable-state-client-java-1.14.5.jar:/Users/rockybx/.m2/repository/org/apache/flink/flink-hadoop-fs/1.14.5/flink-hadoop-fs-1.14.5.jar:/Users/rockybx/.m2/repository/commons-io/commons-io/2.8.0/commons-io-2.8.0.jar:/Users/rockybx/.m2/repository/org/apache/flink/flink-shaded-netty/4.1.65.Final-14.0/flink-shaded-netty-4.1.65.Final-14.0.jar:/Users/rockybx/.m2/repository/org/apache/flink/flink-shaded-jackson/2.12.4-14.0/flink-shaded-jackson-2.12.4-14.0.jar:/Users/rockybx/.m2/repository/org/apache/flink/flink-shaded-zookeeper-3/3.4.14-14.0/flink-shaded-zookeeper-3-3.4.14-14.0.jar:/Users/rockybx/.m2/repository/org/javassist/javassist/3.24.0-GA/javassist-3.24.0-GA.jar:/Users/rockybx/.m2/repository/org/xerial/snappy/snappy-java/1.1.8.3/snappy-java-1.1.8.3.jar:/Users/rockybx/.m2/repository/org/lz4/lz4-java/1.8.0/lz4-java-1.8.0.jar:/Users/rockybx/.m2/repository/org/apache/flink/flink-scala_2.12/1.14.5/flink-scala_2.12-1.14.5.jar:/Users/rockybx/.m2/repository/org/scala-lang/scala-reflect/2.12.7/scala-reflect-2.12.7.jar:/Users/rockybx/.m2/repository/org/scala-lang/scala-library/2.12.7/scala-library-2.12.7.jar:/Users/rockybx/.m2/repository/org/scala-lang/scala-compiler/2.12.7/scala-compiler-2.12.7.jar:/Users/rockybx/.m2/repository/org/scala-lang/modules/scala-xml_2.12/1.0.6/scala-xml_2.12-1.0.6.jar:/Users/rockybx/.m2/repository/com/twitter/chill_2.12/0.7.6/chill_2.12-0.7.6.jar:/Users/rockybx/.m2/repository/com/twitter/chill-java/0.7.6/chill-java-0.7.6.jar:/Users/rockybx/.m2/repository/org/apache/flink/flink-shaded-guava/30.1.1-jre-14.0/flink-shaded-guava-30.1.1-jre-14.0.jar:/Users/rockybx/.m2/repository/org/apache/flink/flink-clients_2.12/1.14.5/flink-clients_2.12-1.14.5.jar:/Users/rockybx/.m2/repository/org/apache/flink/flink-optimizer/1.14.5/flink-optimizer-1.14.5.jar:/Users/rockybx/.m2/repository/commons-cli/commons-cli/1.3.1/commons-cli-1.3.1.jar:/Users/rockybx/.m2/repository/org/apache/flink/flink-walkthrough-common_2.12/1.14.5/flink-walkthrough-common_2.12-1.14.5.jar:/Users/rockybx/.m2/repository/org/projectlombok/lombok/1.18.28/lombok-1.18.28.jar org.example.FLinkCK
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" org.apache.flink.api.common.functions.InvalidTypesException: The return type of function 'main(FLinkCK.java:43)' could not be determined automatically, due to type erasure. You can give type information hints by using the returns(...) method on the result of the transformation call, or by letting your function implement the 'ResultTypeQueryable' interface.
	at org.apache.flink.api.dag.Transformation.getOutputType(Transformation.java:496)
	at org.apache.flink.streaming.api.datastream.DataStream.getType(DataStream.java:193)
	at org.apache.flink.streaming.api.datastream.KeyedStream.<init>(KeyedStream.java:116)
	at org.apache.flink.streaming.api.datastream.DataStream.keyBy(DataStream.java:293)
	at org.example.FLinkCK.main(FLinkCK.java:44)
Caused by: org.apache.flink.api.common.functions.InvalidTypesException: The generic type parameters of 'Tuple2' are missing. In many cases lambda methods don't provide enough information for automatic type extraction when Java generics are involved. An easy workaround is to use an (anonymous) class instead that implements the 'org.apache.flink.api.common.functions.MapFunction' interface. Otherwise the type has to be specified explicitly using type information.
	at org.apache.flink.api.java.typeutils.TypeExtractionUtils.validateLambdaType(TypeExtractionUtils.java:371)
	at org.apache.flink.api.java.typeutils.TypeExtractor.getUnaryOperatorReturnType(TypeExtractor.java:565)
	at org.apache.flink.api.java.typeutils.TypeExtractor.getMapReturnTypes(TypeExtractor.java:151)
	at org.apache.flink.streaming.api.datastream.DataStream.map(DataStream.java:576)
	at org.example.FLinkCK.main(FLinkCK.java:43)

Process finished with exit code 1

java泛型报错
解决方案:


 SingleOutputStreamOperator<Tuple2<String, Integer>> reduce = streamOperator.map(data -> Tuple2.of(data.getUser(), 1)).
         returns(Types.TUPLE(Types.STRING, Types.INT))
        .keyBy(new KeySelector<Tuple2<String, Integer>, String>() {
                    @Override
                    public String getKey(Tuple2<String, Integer> value) throws Exception {
                        return value.f0;
                    }
                })
                .window(TumblingEventTimeWindows.of(Time.seconds(5)))
                .reduce((v1, v2) -> Tuple2.of(v1.f0, v1.f1 + v2.f1));
        reduce.print();

你可能感兴趣的:(flink,java,python)