【问题标题】:Writing apache beam pCollection to bigquery causes type Error将 apache beam pCollection 写入 bigquery 会导致类型错误
【发布时间】:2022-08-19 04:35:37
【问题描述】:

我有一个简单的光束管道,如下:

    with beam.Pipeline() as pipeline:
    output = (
            pipeline
            | \'Read CSV\' >> beam.io.ReadFromText(\'raw_files/myfile.csv\',
                                                 skip_header_lines=True)
            | \'Split strings\' >> beam.Map(lambda x: x.split(\',\'))
            | \'Convert records to dictionary\' >> beam.Map(to_json)
            | beam.io.WriteToBigQuery(project=\'gcp_project_id\',
                                      dataset=\'datasetID\',
                                      table=\'tableID\',
                                      create_disposition=bigquery.CreateDisposition.CREATE_NEVER,
                                      write_disposition=bigquery.WriteDisposition.WRITE_APPEND
                                      )
            )

但是在运行时我得到一个 typeError,说明如下:

line 2147, in __init__
self.table_reference = bigquery_tools.parse_table_reference(if isinstance(table, 
TableReference):
    TypeError: isinstance() arg 2 must be a type or tuple of types

我尝试定义一个 TableReference 对象并将其传递给 WriteToBigQuery 类,但仍然面临同样的问题。我在这里错过了什么吗?我一直被困在这一步,感觉就像永远一样,我不知道该怎么办。任何帮助表示赞赏!

  • 您的代码似乎是正确的,您使用的是哪个版本的 Apache Beam? table_reference 参数不是强制性的,通常与项目、数据集和表参数一起使用,它应该可以工作。
  • 尝试升级到最新版本的 Python Beam sdk,如果不是这样(2.40.0):beam.apache.org/get-started/downloads
  • @MazlumTosun 我已经有了最新版本(2.40.0)。我正在使用 Pycharm,所以正在下载所有最新的包。
  • 这是一个奇怪的错误,但您确定在安装 Beam 时安装了 GCP 模块吗?即 pip install apache-beam[gcp]

标签: google-bigquery apache-beam


【解决方案1】:

这可能是因为您在没有 GCP 模块的情况下安装了 Apache Beam。请确保执行以下操作(在虚拟环境中)。

pip install apache-beam[gcp]

这是一个奇怪的错误,所以请随意file a Github issue 反对 Apache Beam 项目。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-21
    • 1970-01-01
    • 1970-01-01
    • 2020-03-31
    • 2017-12-15
    • 2021-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多