如何使用 Google Cloud Dataflow 将压缩文件写入 Google Cloud Storage?

How do I write compressed files to Google Cloud Storage using Google Cloud Dataflow?

我正在尝试将 Gzip 文件写入 Google 数据流程序中的 Google 云存储桶。常见问题解答说

Does the TextIO source and sink support compressed files, such as GZip?
Yes. Cloud Dataflow can read files compressed with gzip and bzip2.

这是否意味着他们不支持写入 GZip 文件?

正确,我们目前没有对编写 gzip 文件的内置支持。 但是,user-defined data format API, in particular FileBasedSink 应该可以让您自己编写这样的接收器变得简单。

在新的 Beam 库中,您现在可以更轻松地做到这一点:

PDone d = c2.apply(TextIO.write()
  .to("gs://path")
  .withWritableByteChannelFactory(FileBasedSink.CompressionType.GZIP));