Skip to content

Commit

Permalink
bigquery: add clustering
Browse files Browse the repository at this point in the history
  • Loading branch information
shollyman committed Jul 31, 2019
1 parent bb4c89a commit c505e81
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
19 changes: 19 additions & 0 deletions third_party/terraform/resources/resource_bigquery_table.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,14 @@ func resourceBigQueryTable() *schema.Resource {
},
},

// Clustering: [Optional] Ordered set of up to 4 columns for clustering this table.
"clustering": &schema.Schema{
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
},

// CreationTime: [Output-only] The time when this table was created, in
// milliseconds since the epoch.
"creation_time": {
Expand Down Expand Up @@ -435,6 +443,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
}

Expand Down Expand Up @@ -514,6 +529,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 {
Expand Down
11 changes: 10 additions & 1 deletion third_party/terraform/tests/resource_bigquery_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,22 @@ resource "google_bigquery_table" "test" {
type = "DAY"
field = "ts"
require_partition_filter = true
}
}
clustering = ["some_number", "some_state"]
schema = <<EOH
[
{
"name": "ts",
"type": "TIMESTAMP"
},
{
"name": "some_string",
"type": "STRING"
},
{
"name": "some_number",
"type": "INTEGER"
},
{
"name": "city",
Expand Down

0 comments on commit c505e81

Please sign in to comment.