gpt4 book ai didi

maven - Flink-CEP 中缺少 'Map' 的泛型类型参数

转载 作者:行者123 更新时间:2023-12-04 14:25:34 24 4
gpt4 key购买 nike

Flink-CEP中检测模式的代码如下所示

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

但是构建使用 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>

非常欢迎提出建议。提前致谢

最佳答案

我知道 Java 8 Lambda 非常方便。然而,它们几乎不通过反射提供类型信息,这就是为什么 Flink 在生成底层序列化程序时存在问题。为了在 IDE 中也能运行您的 Flink 程序,只要涉及泛型类型,我建议使用 Java 匿名类而不是 lambda。

关于maven - Flink-CEP 中缺少 'Map' 的泛型类型参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45663700/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com