java - 基于窗口和元素计数从数据流写入 GCS
问题描述
我正在尝试实现一个解决方案,我需要使用数据流将来自 pubsub 的数据(json)消息写入 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 类的 PCollection,因为它具有 getKey 方法。
请注意 :: 是 Java 8 中包含的新运算符,用于引用类的方法。
推荐阅读
- ruby - Rails 5.2 中的路由
- excel - 当单元格内容更改时,将单元格内容放入 Excel 工作表页眉或页脚
- php - Laravel POST 方法作为 GET 方法发送。代码 405
- state-machine - sysml - 与警卫一起做活动
- reactjs - React Redux - 递增状态变量不起作用
- android - ActionMode 标题字体
- java - 为什么Server Liferay 7.x 无法启动?
- bash - 在多个文件上运行命令
- javascript - 关闭后fancybox没有重新打开
- python - 已安装莳萝 - 抛出模块部分缺失的错误