基于窗口和元素计数从数据流写入 GCS
Writing to GCS from dataflow based on windowing and element count
我正在尝试实现一个解决方案,我需要使用数据流将数据 (json) 消息从 pubsub 写入 GCS。我的问题与此完全相似
我需要根据窗口或元素计数来编写。
这是上述问题的写入代码示例:
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) 的作用以及它的来源。
非常感谢对此的任何帮助。
它根据事件的键将元素分成组。
据我了解,事件来自使用 KV class 的 PCollection,因为它具有 getKey 方法。
请注意,:: 是 Java 8 中包含的新运算符,用于引用 class 的方法。
我正在尝试实现一个解决方案,我需要使用数据流将数据 (json) 消息从 pubsub 写入 GCS。我的问题与此完全相似
我需要根据窗口或元素计数来编写。 这是上述问题的写入代码示例:
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) 的作用以及它的来源。 非常感谢对此的任何帮助。
它根据事件的键将元素分成组。
据我了解,事件来自使用 KV class 的 PCollection,因为它具有 getKey 方法。
请注意,:: 是 Java 8 中包含的新运算符,用于引用 class 的方法。