flink 1.12.0 提示keyBy警告 Symbol keyBy is deprecated. use [[DataStream.keyBy(KeySelector)]] instead
一、问题描述
flink 1.12相对于1.10个别接口有更新,所以,需要依据代码进行微调。例如keyBy方法
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-HyrtAct5-1627635607595)(tmp.assets/1627635349912.png)]
二、问题原因
keyBy方法实现更新,1.12版本
def keyBy[K: TypeInformation](fun: KeySelector[T, K]): KeyedStream[T, K] = {
val cleanFun = clean(fun)
val keyType: TypeInformation[K] = implicitly[TypeInformation[K]]
asScalaStream(new JavaKeyedStream(stream, cleanFun, keyType))
}
进一步探究KeySelector
package org.apache.flink.api.java.functions;
import org.apache.flink.annotation.Public;
import org.apache.flink.api.common.functions.Function;
import java.io.Serializable;
@Public
@FunctionalInterface
public interface KeySelector<IN, KEY> extends Function, Serializable {
KEY getKey(IN value) throws Exception;
}
三、解决实例
val Stream1: KeyedStream[behavior, Tuple] = dataStream
.keyBy("name")
替换为
valStream2: KeyedStream[behavior, Long] = dataStream
.keyBy(data => data.name)
|