【问题标题】:How to I stage a GCP/Apache Beam Dataflow template?如何暂存 GCP/Apache Beam 数据流模板?
【发布时间】:2020-01-08 00:28:36
【问题描述】:

好的,我必须在这里遗漏一些东西。我需要什么来将管道暂存为模板?当我尝试通过these instructions 暂存我的模板时,它运行模块但没有暂存任何内容。它似乎按预期运行而没有错误,但我没有看到任何文件实际上被添加到存储桶位置听在我的 --template_location 中。我的python代码应该出现在那里吗?我猜对了?我已经确定我已经安装了所有的梁和谷歌云 SDK,但也许我错过了什么?您需要做什么来暂存此数据流模板?我也可以手动将文件放入存储桶中并从那里运行吗?以下是我目前正在玩的模板:

import json
import apache_beam as beam
from apache_beam.options.pipeline_options import PipelineOptions
from apache_beam.io.gcp.bigquery import parse_table_schema_from_json

GC_PROJECT = 'my-proj'
BUCKET = 'test-bucket'
STAGING_BUCKET = '%s/test' % BUCKET
TEMP_BUCKET = '%s/test' % BUCKET
# RUNNER = 'DataflowRunner'
RUNNER = 'DirectRunner'

# pipeline_args = ['--save_main_session']
pipeline_args = []
pipeline_args.append('--project=%s' % GC_PROJECT)
pipeline_args.append('--runner=%s' % RUNNER)
pipeline_args.append('--staging_location=gs://%s' % STAGING_BUCKET)
pipeline_args.append('--temp_location=gs://%s' % TEMP_BUCKET)

BQ_DATASET = 'lake'
BQ_TABLE = 'whatever'

SCHEMA_OBJ = [
    {"name": "id", "type": "STRING", "description": ""},
    {"name": "value", "type": "STRING", "description": ""}
]


class ContactUploadOptions(PipelineOptions):
    @classmethod
    def _add_argparse_args(cls, parser):
        parser.add_value_provider_argument(
            '--infile',
            type=str,
            help='path of input file',
            default='gs://%s/data_files/test.csv' % BUCKET)

def run(argv=None):
    print('running')
    p = beam.Pipeline(options=PipelineOptions(pipeline_args))
    lines = (p
             | beam.Create([
                {"id": "some random name", "value": "i dont know"},
                {"id": "id2", "value": "whatever man"}]))

    schema_str = '{"fields": ' + json.dumps(SCHEMA_OBJ) + '}'
    schema = parse_table_schema_from_json(schema_str)
    output_destination = '%s.%s' % (BQ_DATASET, BQ_TABLE)
    (lines
        | 'Write lines to BigQuery' >> beam.io.WriteToBigQuery(
            output_destination,
            schema=schema,
            create_disposition=beam.io.BigQueryDisposition.CREATE_IF_NEEDED,
            write_disposition=beam.io.BigQueryDisposition.WRITE_APPEND))

    p.run().wait_until_finish()


if __name__ == '__main__':
    run(pipeline_args)


另外,如果有人可以链接一些 sdk 文档/资源来解释上面的暂存说明应该如何/为什么起作用,那就太棒了!

【问题讨论】:

  • 今天早上我正在尝试重置我的 python 环境和依赖项以尝试修复此问题,然后可能尝试手动暂存模板。如果失败了,我可能会尝试 Java
  • 你遇到了什么错误?
  • @VikramShinde 没有错误,但我认为这只是我的一个愚蠢的错误,没有正确传递我的运行时参数。所以它正在工作,但从未考虑过我通过命令行传入的模板位置

标签: python google-cloud-platform google-cloud-dataflow apache-beam


【解决方案1】:

临时位置是在运行作业时加载临时文件的位置。您没有提到将创建模板的“template_location”。

请参阅creating template 和running template 的链接

【讨论】:

  • ooohhh 是的,我明白你在说什么,是的,哈哈,好吧,我的运行时参数没有被考虑,这意味着 template_location 从来没有看过,因此从来没有上演过我的模板......我试一试.
  • 你好维克拉姆,你有时间可以看看这个stackoverflow.com/questions/59894035/…
猜你喜欢
  • 2020-05-01
  • 1970-01-01
  • 2021-05-20
  • 2020-03-04
  • 2020-12-22
  • 2020-03-22
  • 1970-01-01
  • 1970-01-01
  • 2021-04-29
相关资源
最近更新 更多