【发布时间】:2017-10-07 20:38:03
【问题描述】:
我正在尝试修改 Apache Beam 的 MinimalWordCount python 示例以从 BigQuery 表中读取。我已经进行了以下修改,并且我似乎使查询正常工作,但示例。
这里的原始示例:
with beam.Pipeline(options=pipeline_options) as p:
# Read the text file[pattern] into a PCollection.
lines = p | ReadFromText(known_args.input)
# Count the occurrences of each word.
counts = (
lines
| 'Split' >> (beam.FlatMap(lambda x: re.findall(r'[A-Za-z\']+', x))
.with_output_types(unicode))
| 'PairWithOne' >> beam.Map(lambda x: (x, 1))
| 'GroupAndSum' >> beam.CombinePerKey(sum))
# Format the counts into a PCollection of strings.
output = counts | 'Format' >> beam.Map(lambda (w, c): '%s: %s' % (w, c))
# Write the output using a "Write" transform that has side effects.
# pylint: disable=expression-not-assigned
output | WriteToText(known_args.output)
而不是 ReadFromText 我正在尝试调整它以从 BigQuery 表中的列中读取。为此,我已将 lines = p | ReadFromText(known_args.input) 替换为以下代码:
query = 'SELECT text_column FROM `bigquery.table.goes.here` '
lines = p | 'ReadFromBigQuery' >> beam.io.Read(beam.io.BigQuerySource(query=query, use_standard_sql=True))
当我重新运行管道时,出现错误:“WARNING:root:A task failed with exception. expected string or buffer [while running 'Split']”
我认识到“拆分”操作需要一个字符串,但显然没有得到一个字符串。如何修改“ReadFromBigQuery”以使其传递字符串/缓冲区?我是否需要提供表架构或其他东西来将“ReadFromBigQuery”的结果转换为字符串缓冲区?
【问题讨论】:
标签: python google-cloud-platform google-cloud-dataflow apache-beam