使用Python在BigQuery中创建表的范围分区

2024-05-16 22:37:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用整数范围分区来创建一个表,该表将使用创建表时指定的字段进行升序分区。但是,当我试图按照文档的指导原则指定要对附加数据进行分区的字段时,被测试的函数给出了以下错误:

table.partitioning\u type=bigquery.RangePartitioning(field='country\u NUMBER')

enter image description here

如果我取出上面的代码,这个函数就会工作。那么,我可以得到一些关于在这个任务中使用范围整数分区的正确方法的说明吗


Tags: 数据函数文档fieldtype错误table整数
1条回答
网友
1楼 · 发布于 2024-05-16 22:37:12

对于范围分区,您不仅需要定义字段,还需要定义范围(无论您使用的是什么语言)

从文档中:

...
  "rangePartitioning": {
    "field": "customer_id",
    "range": {
      "end": "100",
      "interval": "10",
      "start": "0"
    }
  },
...

所以在Python中,仅提供field是不够的,还需要为range_提供一个对象,该对象带有PartitionRange


有关完整示例,请查看源代码:

    table = bigquery.Table(table_id, schema=schema)
    table.range_partitioning = bigquery.RangePartitioning(
        # To use integer range partitioning, select a top-level REQUIRED /
        # NULLABLE column with INTEGER / INT64 data type.
        field="zipcode",
        range_=bigquery.PartitionRange(start=0, end=100000, interval=10),
    )
    table = client.create_table(table)  # Make an API request.

相关问题 更多 >