首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Flink-CEP中缺少“Map”的泛型类型参数。

Flink-CEP中缺少“Map”的泛型类型参数。
EN

Stack Overflow用户
提问于 2017-08-13 18:41:18
回答 2查看 2K关注 0票数 3

下面显示了在Flink-CEP中检测模式的代码

代码语言:javascript
复制
// 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中使用命令+ F9进行生成,则会显示以下错误

代码语言:javascript
复制
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插件,即使这样,它在日志中也显示了错误。POM.XML的内容如下

代码语言:javascript
复制
<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预先提出的

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-08-15 14:48:02

我知道Java 8 Lambdas非常方便。但是,它们几乎没有通过反射提供任何类型信息,这就是Flink在生成底层序列化程序时遇到问题的原因。为了在IDE中运行Flink程序,我建议在涉及泛型类型时使用Java匿名类而不是lambdas。

票数 3
EN

Stack Overflow用户

发布于 2017-08-14 05:31:51

首先,检查您的jdk版本,是1.8吗?还可以升级tycho-compiler-jdt的版本以1.0.0您的san,请参阅下面的插件:

代码语言:javascript
复制
<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中运行它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45663700

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档