我試圖使用弗林克-流狀態的後端,這個指南:https://ci.apache.org/projects/flink/flink-docs-master/apis/streaming/state.html,但我得到的錯誤:無法解析符號「ValueState」。不能解析符號ValueState
看了一下之後,我意識到ValueState不在我的依賴關係中。相反,只有運營商位於org.apache.flink.api.common.state(flink-core)中。
不過,如果我看在Github上,我看到ValueState在該包:https://github.com/apache/flink/tree/master/flink-core/src/main/java/org/apache/flink/api/common/state
我猜我要麼沒有弗林克的正確版本使用StateBackend引導顯示的方式,或者也許我有正確的版本,但ValueState已被移至另一個Maven依賴項。
下面是我的pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>flink-streaming</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>flink-streaming</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!--<flink.version>0.10.2</flink.version>-->
<flink.version>0.10.2</flink.version>
<scala.version>2.11.8</scala.version>
<scala.dependency.version>2.11</scala.dependency.version>
</properties>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-scala_${scala.dependency.version}</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-clients_${scala.dependency.version}</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-scala_${scala.dependency.version}</artifactId>
<version>${flink.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmArgs>
<jvmArg>-Xms64m</jvmArg>
<jvmArg>-Xmx1024m</jvmArg>
</jvmArgs>
</configuration>
</plugin>
</plugins>
</build>
這裏是我的代碼:
import org.apache.flink.api.common.functions.RichFlatMapFunction;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.util.Collector;
public class CountWindowAverage extends RichFlatMapFunction<Tuple2<Long,Long>, Tuple2<Long,Long>> {
private transient ValueState<Tuple2<Long,Long>> sum;
@Override
public void flatMap(Tuple2<Long,Long> input, Collector<Tuple2<Long,Long>> out) throws Exception {
}
}
非常感謝提前對你的幫助!
Laurent。
非常感謝! :) –
我發現知道在Flink中使用哪個版本相當困難。官方文檔和大多數教程從未告訴任何關於所需的依賴關係,所以你必須在網上找到一個例子,這往往是過時的... –
這個部分在doc:https://ci.apache.org/projects /flink/flink-docs-release-1.0/apis/common/index.html#linking-with-flink要使用其他庫,例如CEP庫或Flink ML,他們還在其子部分的開頭提供了maven座標文件。請注意,您可以切換到「Scala」選項卡以獲取有關Scala而不是Java的信息。 – aljoscha