目前尚未实施。但是,您可以自己实现/扩展它(请参阅attached notebook 以获取我的 apache_beam 版本的示例+测试)。
这是基于超类FileSink 的note in the docstring,提到你应该覆盖open 函数:
适用于我的 apache_beam 版本的新类('0.3.0-incubating.dev'):
import apache_beam as beam
from apache_beam.io import TextFileSink
from apache_beam.io.fileio import ChannelFactory,CompressionTypes
from apache_beam import coders
class TextFileSinkWithHeader(TextFileSink):
def __init__(self,
file_path_prefix,
file_name_suffix='',
append_trailing_newlines=True,
num_shards=0,
shard_name_template=None,
coder=coders.ToStringCoder(),
compression_type=CompressionTypes.NO_COMPRESSION,
header=None):
super(TextFileSinkWithHeader, self).__init__(
file_path_prefix,
file_name_suffix=file_name_suffix,
num_shards=num_shards,
shard_name_template=shard_name_template,
coder=coder,
compression_type=compression_type,
append_trailing_newlines=append_trailing_newlines)
self.header = header
def open(self, temp_path):
channel_factory = ChannelFactory.open(
temp_path,
'wb',
mime_type=self.mime_type)
channel_factory.write(self.header+"\n")
return channel_factory
您随后可以按如下方式使用它:
beam.io.Write(TextFileSinkWithHeader('./names_w_headers',header="names"))
有关完整概述,请参阅 the notebook。