【问题标题】:Make existing bigquery table clustered使现有的 bigquery 表聚集在一起
【发布时间】:2018-08-29 12:29:58
【问题描述】:

我在 bigquery 中有一个相当大的现有分区表。我想让表聚集起来,至少对于新分区。

从文档:https://cloud.google.com/bigquery/docs/creating-clustered-tables,据说我们可以Creating a clustered table when you load data,我尝试使用集群字段加载新分区:job_config.clustering_fields = ["event_type"]

加载成功完成,但是新分区似乎没有集群(我不确定如何检查它是否是集群的,但是当我查询该特定分区时,它总是会扫描所有行)。

有没有为现有分区表创建集群字段的好方法?

非常感谢任何评论、建议或回答。

非常感谢, 约书亚

【问题讨论】:

    标签: google-bigquery clustered-index


    【解决方案1】:

    BigQuery 支持将现有的非聚集表更改为聚集表,反之亦然。您还可以更新聚簇表的聚簇列集。

    您可以通过以下方式更改集群规范:

    调用tables.updatetables.patch API 方法。

    使用 --clustering_fields 标志调用 bq 命令行工具的 bq update 命令。

    参考

    https://cloud.google.com/bigquery/docs/creating-clustered-tables#modifying-cluster-spec

    【讨论】:

    • 我可以确认bq update --clustering_fields={clustering_variable} {dataset_name}.{table_name} 可以解决问题。
    【解决方案2】:

    此答案不再有效/正确

    https://cloud.google.com/bigquery/docs/creating-clustered-tables#modifying-cluster-spec


    您只能在创建表时指定聚簇列
    所以,显然你不能指望现有的非集群表,尤其是新分区成为集群

    “解决方法”是创建要正确分区/集群的新表,并将数据从 Google Cloud Storage (GCS) 加载到其中。您可以先将原始表中的数据导出到 GCS 中,这样整个过程都是免费的

    【讨论】:

    • 谢谢!是的,我想我现在可以使用这个工作了:)
    • 您好,我有两张表,一张是非集群表和具有相同字段的集群表。如果两个表都存在,如何将数据从非集群表复制到集群表。 ?
    • 我认为这个答案并不完全正确。根据官方文档:By calling the tables.update or tables.patch methods, table clustering specifications can be changed or removed. The set of clustered columns in a clustered table can also be changed to a different set of columns. When a table is converted from non-clustered to clustered or the clustered column set is changed, automatic re-clustering only works from that time onward. 我的理解是您也可以稍后指定一个聚类列。只是之前添加的数据不会被聚类
    • 答案是在 2018 年 8 月给出的,当时情况有所不同 :o)
    • 现在可以了吗?我正在尝试使用集群信息更新现有表,但 API 以 "Cannot add, update, or remove clustering without partitioning field." 错误响应(这对我来说真的没有意义)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-24
    • 2014-12-06
    • 1970-01-01
    • 2018-05-14
    • 2012-11-02
    • 1970-01-01
    相关资源
    最近更新 更多