Apache flink 无论如何都可以转换数据集-:“;独特的();是否在Flink的数据流中使用?

Apache flink 无论如何都可以转换数据集-:“;独特的();是否在Flink的数据流中使用?,apache-flink,flink-streaming,flink-sql,flink-batch,Apache Flink,Flink Streaming,Flink Sql,Flink Batch,我想知道,无论如何,Flink的datastream API是否可以用于从传入的记录(可能在特定的时间窗口内)中删除重复项,就像Dataset API中提供了一个称为“Distinct”的转换一样。或者无论如何,若dataset可以转换为datastream,则假定dataset在Flink中转换为datastream进行内部处理 请帮我做这件事。提前谢谢!干杯 我不知道有任何内置原语,但如果窗口中的所有数据都能放入内存,那么您可以自己轻松构建此函数 DataStream<...>

我想知道,无论如何,Flink的datastream API是否可以用于从传入的记录(可能在特定的时间窗口内)中删除重复项,就像Dataset API中提供了一个称为“Distinct”的转换一样。或者无论如何,若dataset可以转换为datastream,则假定dataset在Flink中转换为datastream进行内部处理


请帮我做这件事。提前谢谢!干杯

我不知道有任何内置原语,但如果窗口中的所有数据都能放入内存,那么您可以自己轻松构建此函数

DataStream<...> stream = ...
stream.windowAll(TumblingEventTimeWindows.of(Time.seconds(5)))
    .process(new DistinctFunction<>());

public class DistinctFunction<T, W extends Window> extends ProcessAllWindowFunction<T, T, W> implements Function {
    public void process(final Context context, Iterable<T> input, Collector<R> out) throws Exception {
        Set<T> elements = new HashSet<>();
        input.forEach(elements::add);
        elements.forEach(out::collect);
    }
}
DataStream=。。。
stream.windowAll(TumblingEventTimeWindows.of(Time.seconds(5)))
.process(新的DistinctFunction());
公共类DistinctFunction扩展ProcessAllWindowFunction实现函数{
公共void进程(最终上下文、Iterable输入、收集器输出)抛出异常{
Set elements=newhashset();
input.forEach(元素::add);
elements.forEach(out::collect);
}
}

当然,如果您有一个密钥,它的可伸缩性会更好,因为只有窗口中一个密钥的数据需要保存在内存中。

感谢您的建议,Arvid,我将尝试将其集成到应用程序中并检查。。。