为了账号安全,请及时绑定邮箱和手机立即绑定

在 Apache Beam 上将 PCollection 作为侧面输入传递时发生 KeyError

在 Apache Beam 上将 PCollection 作为侧面输入传递时发生 KeyError

慕森卡 2023-09-12 15:46:07
我将side_inputPCollection 作为侧面输入传递给ParDo转换,但得到相同的 KeyErrorimport apache_beam as beamfrom apache_beam.options.pipeline_options import PipelineOptionsfrom beam_nuggets.io import relational_dbfrom processors.appendcol import AppendColfrom side_inputs.config import sideinput_bq_configfrom source.config import source_configwith beam.Pipeline(options=PipelineOptions()) as si:  side_input = si | "Reading from BQ side input" >> relational_db.ReadFromDB(    source_config=sideinput_bq_config,    table_name='abc',    query="SELECT * FROM abc"  )with beam.Pipeline(options=PipelineOptions()) as p:  PCollection = p | "Reading records from database" >> relational_db.ReadFromDB(    source_config=source_config,    table_name='xyzzy',    query="SELECT * FROM xyzzy", ) | beam.ParDo(   AppendCol(), beam.pvalue.AsIter(side_input) )下面是错误Traceback (most recent call last):  File "athena/etl.py", line 40, in <module>    extract()  File "athena/etl.py", line 22, in extract    PCollection = p | "Reading records from database" >> relational_db.ReadFromDB(  File "/Users/souvikdey/.pyenv/versions/3.8.5/envs/athena-venv/lib/python3.8/site-packages/apache_beam/pipeline.py", line 555, in __exit__    self.result = self.run()  File "/Users/souvikdey/.pyenv/versions/3.8.5/envs/athena-venv/lib/python3.8/site-packages/apache_beam/pipeline.py", line 534, in run    return self.runner.run_pipeline(self, self._options)  File "/Users/souvikdey/.pyenv/versions/3.8.5/envs/athena-venv/lib/python3.8/site-packages/apache_beam/runners/direct/direct_runner.py", line 119, in run_pipeline    return runner.run_pipeline(pipeline, options)  File "/Users/souvikdey/.pyenv/versions/3.8.5/envs/athena-venv/lib/python3.8/site-packages/apache_beam/runners/portability/fn_api_runner/fn_runner.py", line 175, in run_pipeline    self._latest_run_result = self.run_via_runner_api(我正在从 PostgreSQL 表中读取数据,PCollection 的每个元素都是一个字典。
查看完整描述

1 回答

?
猛跑小猪

TA贡献1858条经验 获得超8个赞

我认为问题在于你有两个独立的管道试图一起工作。您应该将所有转换作为单个管道的一部分执行:


with beam.Pipeline(options=PipelineOptions()) as p:

  side_input = p | "Reading from BQ side input" >> relational_db.ReadFromDB(

    source_config=sideinput_bq_config,

    table_name='abc',

    query="SELECT * FROM abc")


  my_pcoll = p | "Reading records from database" >> relational_db.ReadFromDB(

        source_config=source_config,

        table_name='xyzzy',

        query="SELECT * FROM xyzzy",

    ) | beam.ParDo(

        AppendCol(), beam.pvalue.AsIter(side_input))


查看完整回答
反对 回复 2023-09-12
  • 1 回答
  • 0 关注
  • 86 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信