【问题标题】:Flink KeyBy fieldsFlink KeyBy 字段
【发布时间】:2022-02-02 20:37:45
【问题描述】:

我正在尝试对给定字段使用 keyby 函数,但是 IntelliJ 告诉我此选项已弃用。

// map each job event to a 2-tuple
DataStream<Tuple2<Long, Long>> mappedEvents =  events.map(new AppendOneMapper()).slotSharingGroup("2");

// group the stream of tuples by jobId
KeyedStream<Tuple2<Long, Long>, Tuple> keyedEvents = mappedEvents.keyBy(0);

我将如何使用新方法正确地做到这一点?

【问题讨论】:

标签: java apache-flink deprecated


【解决方案1】:

不推荐使用带有整数或字符串的 KeyBy。 来自文档:“已弃用。使用 keyBy(KeySelector)。”

org.apache.flink.api.java.functions
Interface KeySelector<IN,KEY>
Type Parameters:
IN - Type of objects to extract the key from.
KEY - Type of key.

KeySelector 是一个函数式接口,所以你可以插入 lambda 表达式。

替换

.keyBy(key)

.keyBy(event -> event.getKey())

【讨论】:

    猜你喜欢
    • 2022-12-02
    • 1970-01-01
    • 1970-01-01
    • 2020-12-24
    • 1970-01-01
    • 2018-02-27
    • 1970-01-01
    • 2019-05-26
    • 1970-01-01
    相关资源
    最近更新 更多