2017-08-13 6 views
0

コードに含まれていないがマックでコマンド+ F9を使用してジェネリック型パラメータがFLINK-CEPにパターンを検出するための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()) ; 
    } 
); 

の下に表示され、次のエラーが

を示しています
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を構築し、コントロール+ Rの出力を示し介して実行して、

  • なぜこれはいつも起こっているのだろうか?

  • これを行う方法はありますか?

PS:ただし、私はeclipse JDT Pluginを使用していますが、ログにエラーが表示されています。 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> 

提案は、あなたのjdkバージョンを確認し、

+1

残念ながら、私も同じ問題に直面しています。問題は、Eclipse JDTコンパイラを使用してプロジェクトを構築する必要があり、IntelliJまたはEclipse以外の他のIDEを使用している可能性があるため、コードを変更してください。それ以外の場合は、型情報を削除するデフォルトのコンパイラが使用されます。 今のところ毎週Mavenを使用したビルドが唯一の解決策です(AFAIK) –

答えて

2

私はJava 8 Lambdasが非常に便利だと知っています。しかし、それらはリフレクションを介してほとんど型情報を提供しません。そのため、Flinkは基になるシリアライザの生成に問題があります。 IDEでFlinkプログラムを実行するには、ジェネリックタイプが関係する場合はいつでも、lambdaの代わりにJavaの匿名クラスを使用することをお勧めします。

0

は最初、事前に最もwelcome.Thanksある1.8されていますか?そしてまたあなたさんは、プラグインの下に参照してください1.0.0するtycho-compiler-jdtのバージョンをアップグレードする:あなたがしなければならない、これはMavenを使用してCLIでプロジェクトをビルドした後https://ci.apache.org/projects/flink/flink-docs-release-1.4/dev/java8.html

:あなたがソースを参照することができ

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

。プログラムがmaven経由でビルドされたら、IntelliJ内から実行することもできます。

+0

ご返信ありがとうございます。 1.0.0へのバージョンアップは私にとってはうまくいかなかったし、はい、私はJDK 1.8をインストールしました。 –

+0

'.m2'ディレクトリを削除してプロジェクトを再構築して更新しようとすると、問題が解決する可能性があります。 – Sharma

関連する問題