使用java的ApacheFlink中的数据集广播功能

tsm1rwdh  于 2021-06-25  发布在  Flink
关注(0)|答案(1)|浏览(356)

我正在尝试实现ApacheFlink-broadcasting。。我们如何使用java实现数据集的广播。
请帮忙。

y53ybaqx

y53ybaqx1#

《flink dataset api编程指南》提供了有关如何在java中广播数据集的示例:

// 1. The DataSet to be broadcasted
DataSet<Integer> toBroadcast = env.fromElements(1, 2, 3);

DataSet<String> data = env.fromElements("a", "b");

data.map(new RichMapFunction<String, String>() {
    @Override
    public void open(Configuration parameters) throws Exception {
      // 3. Access the broadcasted DataSet as a Collection
      Collection<Integer> broadcastSet = getRuntimeContext().getBroadcastVariable("broadcastSetName");
    }

    @Override
    public String map(String value) throws Exception {
      ...
    }
}).withBroadcastSet(toBroadcast, "broadcastSetName"); // 2. Broadcast the DataSet

相关问题