我正在尝试使用flink-streaming状态后端,遵循本指南:https://ci.apache.org/projects/flink/flink-docs-master/apis/streaming/state.html,但我收到错误: 无法解析符号'ValueState'
看了一下之后,我意识到 ValueState 不在我的依赖项中。相反,只有 OperatorState 位于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
我猜我要么没有正确版本的flink来按照指南显示的方式使用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 {
}
}
非常感谢您的帮助!
劳伦。
答案 0 :(得分:0)
你是对的Flink版本0.10.x
还没有ValueState
。如果您切换到至少版本1.0.0
,那么您应该没事。