import com.typesafe.config.ConfigFactory
import org.apache.flink.api.java.utils.ParameterTool
import org.apache.flink.streaming.api.TimeCharacteristic
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment
import org.apache.flink.streaming.api.windowing.assigners._
import org.apache.flink.streaming.api.windowing.evictors.CountEvictor
import org.apache.flink.streaming.api.windowing.time.Time
import org.project.async.core.job.FlinkKafkaConnector
import org.project.functions.TestWindowFunction
import org.apache.flink.streaming.api.scala.function.ProcessWindowFunction // USED SCALA API
import org.apache.flink.streaming.api.windowing.windows.TimeWindow
import org.apache.flink.util.Collector
val env = StreamExecutionEnvironment.getExecutionEnvironment
env.setStreamTimeCharacteristic(TimeCharacteristic.IngestionTime)
val source = env.fromElements(("hello", 1), ("hello", 2))
val window1 = source
.keyBy(_._1)
.window(EventTimeSessionWindows.withGap(Time.seconds(1)))
.evictor(CountEvictor.of(2))
.process(new TestWindowFunction)
====TestWindowFunction.scala=====
class TestWindowFunction
extends ProcessWindowFunction[(String, Int), (String, String, Int), String, TimeWindow] {
override def process(
key: String,
window: Context,
input: Iterable[(String, Int)],
out: Collector[(String, String, Int)]): Unit = {
input.foreach(e => out.collect((e._1, e._1, e._2)))
}
}
=================ERROR===============
Task.scala:47: error: type mismatch;
[ERROR] found : org.project.functions.TestWindowFunction
[ERROR] required: org.apache.flink.streaming.api.functions.windowing.ProcessWindowFunction[(String, Int),?,String,org.apache.flink.streaming.api.windowing.windows.TimeWindow]
[ERROR] .process(new TestWindowFunction)
[ERROR] ^
[ERROR] one error found我正在尝试使用窗口功能来收集某段时间内的事件,但是我得到了这个编译错误,我不能在这个问题下,我引用下面的问题,我仍然不能解决它。
链接:Apache Flink: ProcessWindowFunction implementation
这段代码中可能有什么错误呢?
Flink版本:1.10.0
发布于 2020-06-26 20:24:01
Scala需要这些导入
import org.apache.flink.api.scala._
import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment并且您不应该使用
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment在这种情况下,如果有疑问,我的解决方案是删除所有导入,然后让IntelliJ帮助我(小心地)重新添加它们。
https://stackoverflow.com/questions/62592456
复制相似问题