Google Cloud Dataflow - 从 PubSub 到 Parquet

Google Cloud Dataflow - From PubSub to Parquet

我正在尝试使用 Google 云数据流将 Google PubSub 消息写入 Google 云存储。 PubSub 消息采用 json 格式,我想要执行的唯一操作是从 json 到 parquet 文件的转换。

在官方文档中我找到了google提供的模板,它从Pub/Sub主题中读取数据并将Avro文件写入指定的云存储桶(https://cloud.google.com/dataflow/docs/guides/templates/provided-streaming#pubsub-to-cloud-storage-avro)。问题是模板源代码是用Java写的,而我更喜欢用Python SDK。

这些是我通常使用 Dataflow 和 Beam 进行的第一次测试,没有很多 material 在线可以从中获取提示。任何建议、链接、指导、代码片段都将不胜感激。

为了进一步为社区做贡献,我总结了我们的讨论作为答案。

由于您是从 Dataflow 开始,我可以指出一些有用的主题和建议:

  1. PTransform WriteToParquet() builtin method in Apache Beam is very useful. It writes to a Parquet file from a PCollection of records. Also, in order to use it and write to a parquet file, you would need to specify the schema as indicated in the documentation. In addition, this article 将帮助您更好地理解如何使用此方法以及如何将其写入 Google Cloud Storage(GCS) 存储桶。

  2. Google 提供 this code 解释如何从 PubSub 读取消息并将它们写入 Google 云存储。此 QuickStart 从 PubSub 读取消息并将消息从每个 window 写入存储桶。

  3. 由于您想从 PubSub 读取消息,将消息写入 Parquet 并将文件存储在 GCS 存储桶中,我建议您执行以下过程作为管道的步骤:阅读您的消息,写入镶木地板文件并将其存储在 GCS 中。

我鼓励您阅读以上链接。然后,如果您有任何其他问题,可以 post 另一个线程以获得更具体的帮助。