亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 Apach Beam 執行集差

使用 Apach Beam 執行集差

回首憶惘然 2023-05-23 10:13:23
我有兩個列表a,b它們之間有一些共同的元素,我想找到那些共同的元素及其數量,為此我編寫了以下程序。import functoolsimport apache_beam as beamfrom apache_beam.runners.interactive.interactive_runner import InteractiveRunnerfrom apache_beam.runners.direct.direct_runner import DirectRunnerfrom apache_beam.options.pipeline_options import PipelineOptionsoptions = PipelineOptions()p = beam.Pipeline(InteractiveRunner(underlying_runner=DirectRunner()), options=options)def form_pair(element, side_input):  for i,e in enumerate(side_input):    if e == element:      return i,ea = ['a','b', 'c', 'c', 'b']b = ['a','a','b', 'c', 'b', 'b','d', 'e', 'f']x0 = p | "0" >> beam.Create(a) | "1" >> beam.Distinct()x1 = beam.pvalue.AsList(x0)x3 = p | "2" >> beam.Create(b)x4 = x3 | "3" >> beam.Map(functools.partial(form_pair, side_input=x1))x5 = x4 | "4" >> beam.combiners.Count.PerKey()r = p.run().wait_until_finish()print(r.get(x5))這給了我以下錯誤TypeError: 'AsList' object is not iterable [while running '3']
查看完整描述

1 回答

?
尚方寶劍之說

TA貢獻1788條經驗 獲得超4個贊

我傳遞的側面輸入功能beam.Map不正確這是正確的方法

x4 = x3 | "3" >> beam.Map(form_pair, x1)而不是x4 = x3 | "3" >> beam.Map(functools.partial(form_pair, side_input=x1))which 是錯誤的。


查看完整回答
反對 回復 2023-05-23
  • 1 回答
  • 0 關注
  • 110 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號