'Map' 的泛型类型参数在 Flink-CEP 中缺失
The generic type parameters of 'Map' are missing in Flink-CEP
Flink-CEP中pattern检测代码如下
// Generate temperature warnings for each matched warning pattern
DataStream<TemperatureEvent> warnings = tempPatternStream.select(
(Map<String, MonitoringEvent> pattern) -> {
TemperatureEvent first = (TemperatureEvent) pattern.get("first");
return new TemperatureEvent(first.getRackID(), first.getTemperature()) ;
}
);
如果在 Mac 中使用 command + F9 构建,会显示以下错误
Exception in thread "main" org.apache.flink.api.common.functions.InvalidTypesException: The generic type parameters of 'Map' are missing.
It seems that your compiler has not stored them into the .class file.
Currently, only the Eclipse JDT compiler preserves the type information necessary to use the lambdas feature type-safely.
See the documentation for more information about how to compile jobs containing lambda expressions.
at org.apache.flink.api.java.typeutils.TypeExtractor.validateLambdaGenericParameter(TypeExtractor.java:1316)
at org.apache.flink.api.java.typeutils.TypeExtractor.validateLambdaGenericParameters(TypeExtractor.java:1302)
at org.apache.flink.api.java.typeutils.TypeExtractor.getUnaryOperatorReturnType(TypeExtractor.java:346)
at org.apache.flink.cep.PatternStream.select(PatternStream.java:64)
at org.stsffap.cep.monitoring.CEPMonitoring.main(CEPMonitoring.java:85
但是构建 usign mvn clean install
然后 运行 通过 Control + R 显示输出,
我想知道为什么总是这样?
有什么办法吗?
PS:但是我使用的是 eclipse JDT 插件,即便如此它也在日志中显示错误。 POM.XML的内容是
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerId>jdt</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-jdt</artifactId>
<version>0.21.0</version>
</dependency>
</dependencies>
</plugin>
建议最多welcome.Thanks提前
首先,检查你的jdk
版本,是1.8
?并将 tycho-compiler-jdt
的版本升级到 1.0.0
你的 san 参考下面的插件:
<plugin>
<!-- Use compiler plugin with tycho as the adapter to the JDT compiler. -->
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerId>jdt</compilerId>
</configuration>
<dependencies>
<!-- This dependency provides the implementation of compiler "jdt": -->
<dependency>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-jdt</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</plugin>
你可以参考来源:https://ci.apache.org/projects/flink/flink-docs-release-1.4/dev/java8.html
之后你要做的就是使用 maven 在 cli 上构建项目。通过 maven 构建程序后,您还可以从 IntelliJ 中 运行 它。
我知道Java 8个Lambda很方便。然而,它们几乎不通过反射提供类型信息,这就是为什么 Flink 在生成底层序列化程序时存在问题。为了也 运行 你的 Flink 程序在 IDE 中,我建议使用 Java 匿名 类 而不是 lambdas,只要涉及泛型类型。
Flink-CEP中pattern检测代码如下
// Generate temperature warnings for each matched warning pattern
DataStream<TemperatureEvent> warnings = tempPatternStream.select(
(Map<String, MonitoringEvent> pattern) -> {
TemperatureEvent first = (TemperatureEvent) pattern.get("first");
return new TemperatureEvent(first.getRackID(), first.getTemperature()) ;
}
);
如果在 Mac 中使用 command + F9 构建,会显示以下错误
Exception in thread "main" org.apache.flink.api.common.functions.InvalidTypesException: The generic type parameters of 'Map' are missing.
It seems that your compiler has not stored them into the .class file.
Currently, only the Eclipse JDT compiler preserves the type information necessary to use the lambdas feature type-safely.
See the documentation for more information about how to compile jobs containing lambda expressions.
at org.apache.flink.api.java.typeutils.TypeExtractor.validateLambdaGenericParameter(TypeExtractor.java:1316)
at org.apache.flink.api.java.typeutils.TypeExtractor.validateLambdaGenericParameters(TypeExtractor.java:1302)
at org.apache.flink.api.java.typeutils.TypeExtractor.getUnaryOperatorReturnType(TypeExtractor.java:346)
at org.apache.flink.cep.PatternStream.select(PatternStream.java:64)
at org.stsffap.cep.monitoring.CEPMonitoring.main(CEPMonitoring.java:85
但是构建 usign mvn clean install
然后 运行 通过 Control + R 显示输出,
我想知道为什么总是这样?
有什么办法吗?
PS:但是我使用的是 eclipse JDT 插件,即便如此它也在日志中显示错误。 POM.XML的内容是
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerId>jdt</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-jdt</artifactId>
<version>0.21.0</version>
</dependency>
</dependencies>
</plugin>
建议最多welcome.Thanks提前
首先,检查你的jdk
版本,是1.8
?并将 tycho-compiler-jdt
的版本升级到 1.0.0
你的 san 参考下面的插件:
<plugin>
<!-- Use compiler plugin with tycho as the adapter to the JDT compiler. -->
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerId>jdt</compilerId>
</configuration>
<dependencies>
<!-- This dependency provides the implementation of compiler "jdt": -->
<dependency>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-jdt</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</plugin>
你可以参考来源:https://ci.apache.org/projects/flink/flink-docs-release-1.4/dev/java8.html
之后你要做的就是使用 maven 在 cli 上构建项目。通过 maven 构建程序后,您还可以从 IntelliJ 中 运行 它。
我知道Java 8个Lambda很方便。然而,它们几乎不通过反射提供类型信息,这就是为什么 Flink 在生成底层序列化程序时存在问题。为了也 运行 你的 Flink 程序在 IDE 中,我建议使用 Java 匿名 类 而不是 lambdas,只要涉及泛型类型。