【发布时间】:2017-07-21 16:08:49
【问题描述】:
我正在尝试使用 Beam 管道将 SequenceMatcher 函数应用于大量单词。除了 WriteToText 部分,我(希望)已经弄清楚了一切。
我已经定义了一个自定义 ParDo(这里称为 ProcessDataDoFn),它接受 main_input 和 side_input,处理它们并输出像这样的字典
{u'key': (u'string', float)}
我的管道很简单
class ProcessDataDoFn(beam.DoFn):
def process(self, element, side_input):
... Series of operations ...
return output_dictionary
with beam.Pipeline(options=options) as p:
# Main input
main_input = p | 'ReadMainInput' >> beam.io.Read(
beam.io.BigQuerySource(
query=CUSTOM_SQL,
use_standard_sql=True
))
# Side input
side_input = p | 'ReadSideInput' >> beam.io.Read(
beam.io.BigQuerySource(
project=PROJECT_ID,
dataset=DATASET,
table=TABLE
))
output = (
main_input
| 'ProcessData' >> beam.ParDo(
ProcessDataDoFn(),
side_input=beam.pvalue.AsList(side_input))
| 'WriteOutput' >> beam.io.WriteToText(GCS_BUCKET)
)
现在的问题是,如果我这样离开管道,它只会输出 output_dictionary 的键。如果我将 ProcessDataDoFn 的返回更改为 json.dumps(ouput_dictionary),则 Json 写入正确,但像这样
{
'
k
e
y
'
:
[
'
s
t
r
i
n
g
'
,
f
l
o
a
t
]
如何正确输出结果?
【问题讨论】:
-
在您的代码中,该类被声明为
ProcessData,那么当您在管道中使用它时,它就是ProcessDataDoFn。我确定这只是问题中的一个错字,但有助于纠正它。 -
谢谢,现在应该修好了。
标签: python json dictionary google-cloud-dataflow apache-beam