3

Code for detecting pattern in Flink-CEP is shown below

// 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()) ;
    }
);

if build using command + F9 in Mac, following error is shown

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

However building usign mvn clean install and then running via Control + R shows output,

  • I am wondering why this is happening all the time ?

  • Is there any way around to do it?

PS : however I am using eclipse JDT Plugin , even then it is showing error in log . Contents of POM.XML are

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

Suggestions are most welcome.Thanks in advance

Amarjit Dhillon
  • 2,718
  • 3
  • 23
  • 62
  • 2
    Unfortunately, I am also facing the same issue, the problem is you need to build your project using the Eclipse JDT compiler and as you are probably using IntelliJ or some other IDE except Eclipse, you need to build using maven every time you modify your code as otherwise the default compiler would be used which would remove the type information. For now, building with maven everytime is the only solution (AFAIK) – Biplob Biswas Aug 15 '17 at 08:25

2 Answers2

3

I know that Java 8 Lambdas are very convenient. However, they provide almost no type information via reflection, which is why Flink has problems with generating the underlying serializers. In order to also run your Flink programs in the IDE, I would recommend to use Java anonymous classes instead of lambdas, whenever generic types are involved.

twalthr
  • 2,584
  • 16
  • 15
0

first, check your jdk version, is 1.8? and also upgrade the version of tycho-compiler-jdt to 1.0.0 your san refer below plugin :

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

you can refer source : https://ci.apache.org/projects/flink/flink-docs-release-1.4/dev/java8.html

after this you have to do is to build the project on the cli using maven. Once the program has been built via maven, you can also run it from within IntelliJ.

Anshul Sharma
  • 3,432
  • 1
  • 12
  • 17