You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Python创建BigQuery表时设置默认Collation

在BigQuery中通过Python设置表的默认排序规则

你可以直接通过BigQuery Python客户端的Table对象的default_collation属性配置表的默认排序规则,只需在创建表前添加对应赋值语句即可。

修改后的代码示例

schema = client.schema_from_json(file_name)
table = bq.Table(table_id, schema=schema)
table.time_partitioning = bq.TimePartitioning(
    type_=bq.TimePartitioningType.MONTH,
    field=partition_field,
)
# 设置表的默认排序规则,示例使用unicode_ci(不区分大小写的Unicode排序)
table.default_collation = "unicode_ci"
table = client.create_table(table)

补充说明

  • 可根据需求替换unicode_ci为BigQuery支持的其他排序规则,比如unicode(区分大小写的Unicode排序)、utf8_bin(基于UTF-8编码值的二进制排序)等。
  • 若需给单个字段单独设置排序规则,可在JSON schema文件中给对应字段添加"collation": "目标规则值"的配置,表级默认规则会作用于未单独指定排序规则的字段。

内容的提问来源于stack exchange,提问作者Amulya Holla

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 19:09:27