【问题标题】:BigQuery: Array<string> field with WriteToBigQueryBigQuery:带有 WriteToBigQuery 的 Array<string> 字段
【发布时间】:2018-12-04 15:46:30
【问题描述】:

我正在用 Python 创建一个 Google 数据流模板:

query = "#standardSQL" +  """
SELECT
  Frame.Serial,
  Frame.Fecha,
  Frame.Longitud,
  Frame.Latitud,
  ARRAY_AGG (CONCAT (ID, '-', Valor) ORDER BY ID) AS Resumen
FROM <...>


TABLE_SCHEMA = 'Serial:STRING,Fecha:DATETIME,Longitud:STRING,Latitud:STRING,Resumen:STRING'

| 'Read from BQ' >> beam.io.Read(beam.io.BigQuerySource(query=query,dataset="xxx",use_standard_sql=True))

| 'Write transform to BigQuery' >> WriteToBigQuery('table',TABLE_SCHEMA)

问题

这失败了,因为 Resumen 字段是一个数组:

为非重复字段指定的数组。


我测试了什么

  1. 直接在 BigQuery UI 中使用以下语句创建表:

    CREATE TABLE test (Resumen ARRAY&lt;STRING&gt;)

    这行得通。该表是使用以下内容创建的:

    • 类型:string
    • 模式:Repeated
  2. 更改 TABLE_SCHEMA 并运行管道:

    TABLE_SCHEMA ='Serial:STRING,Fecha:DATETIME,Longitud:STRING,Latitud:STRING,Resumen:ARRAY&lt;STRING&gt;'

    出现错误:

    "Invalid value for: ARRAY\u003cSTRING\u003e is not a valid value".
    

TABLE_SCHEMA 应该如何创建表并与beam.io.WriteToBigQuery() 一起使用?

【问题讨论】:

    标签: google-bigquery google-cloud-dataflow apache-beam


    【解决方案1】:

    如果您在单个字符串中指定 BQ 架构,则似乎不支持重复或嵌套字段:https://beam.apache.org/documentation/io/built-in/google-bigquery/#creating-a-table-schema

    您需要明确描述您的架构并将字段模式设置为repeatedhttps://github.com/apache/beam/blob/master/sdks/python/apache_beam/examples/cookbook/bigquery_schema.py#L95

    # A repeated field.
    children_schema = bigquery.TableFieldSchema()
    children_schema.name = 'children'
    children_schema.type = 'string'
    children_schema.mode = 'repeated'
    table_schema.fields.append(children_schema)
    

    【讨论】:

      猜你喜欢
      • 2020-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-21
      • 1970-01-01
      • 2018-08-03
      • 2019-11-23
      相关资源
      最近更新 更多