From 9712996bbb86ff2e5a2cdae63a05c960b3ca2325 Mon Sep 17 00:00:00 2001 From: shollyman Date: Wed, 14 Aug 2019 20:41:33 +0000 Subject: [PATCH] BigQuery: table clustering/partitioning support. Signed-off-by: Modular Magician --- google/resource_bigquery_table.go | 21 +++++++++++++++++++++ google/resource_bigquery_table_test.go | 10 +++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/google/resource_bigquery_table.go b/google/resource_bigquery_table.go index 4e56dbbb07b..3ef4ff2d98c 100644 --- a/google/resource_bigquery_table.go +++ b/google/resource_bigquery_table.go @@ -300,6 +300,16 @@ func resourceBigQueryTable() *schema.Resource { }, }, + // Clustering: [Optional] Specifies column names to use for data clustering. Up to four + // top-level columns are allowed, and should be specified in descending priority order. + "clustering": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + MaxItems: 4, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + // CreationTime: [Output-only] The time when this table was created, in // milliseconds since the epoch. "creation_time": { @@ -432,6 +442,13 @@ func resourceTable(d *schema.ResourceData, meta interface{}) (*bigquery.Table, e table.TimePartitioning = expandTimePartitioning(v) } + if v, ok := d.GetOk("clustering"); ok { + table.Clustering = &bigquery.Clustering{ + Fields: convertStringArr(v.([]interface{})), + ForceSendFields: []string{"Fields"}, + } + } + return table, nil } @@ -511,6 +528,10 @@ func resourceBigQueryTableRead(d *schema.ResourceData, meta interface{}) error { } } + if res.Clustering != nil { + d.Set("clustering", res.Clustering.Fields) + } + if res.Schema != nil { schema, err := flattenSchema(res.Schema) if err != nil { diff --git a/google/resource_bigquery_table_test.go b/google/resource_bigquery_table_test.go index 2aa023f0c45..72968c7b65e 100644 --- a/google/resource_bigquery_table_test.go +++ b/google/resource_bigquery_table_test.go @@ -179,13 +179,21 @@ resource "google_bigquery_table" "test" { field = "ts" require_partition_filter = true } - + clustering = ["some_int", "some_string"] schema = <