【问题标题】:Writing to GCS from dataflow based on windowing and element count基于窗口和元素计数从数据流写入 GCS
【发布时间】:2019-01-27 22:12:51
【问题描述】:

我正在尝试实现一个解决方案,我需要使用数据流将来自 pubsub 的数据 (json) 消息写入 GCS。我的问题与one

完全相同

我需要根据窗口或元素计数来编写。 以下是上述问题中写入的代码示例:

windowedValues.apply(FileIO.<String, String>writeDynamic()
        .by(Event::getKey)
        .via(TextIO.sink())
        .to("gs://data_pipeline_events_test/events/")
        .withDestinationCoder(StringUtf8Coder.of())
        .withNumShards(1)
        .withNaming(key -> FileIO.Write.defaultNaming(key, ".json")));

解决方案建议使用 FileIO.WriteDynamic 函数。但我无法理解 .by(Event::getKey) 的作用以及它的来源。 非常感谢您对此的任何帮助。

【问题讨论】:

    标签: java google-cloud-storage google-cloud-dataflow google-cloud-pubsub dataflow


    【解决方案1】:

    它根据事件的键将元素分组。

    据我了解,事件来自使用 KV 类的 PCollection,因为它具有 getKey 方法。

    注意 :: 是 Java 8 中包含的一个新运算符,用于引用类的方法。

    【讨论】:

      猜你喜欢
      • 2018-12-02
      • 1970-01-01
      • 1970-01-01
      • 2019-03-05
      • 1970-01-01
      • 1970-01-01
      • 2021-12-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多