Skip to content

Commit

Permalink
BigQuery: table clustering/partitioning support. (hashicorp#1025)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored and Ty Larrabee committed Aug 16, 2019
1 parent 28429fc commit 3fbff05
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
21 changes: 21 additions & 0 deletions google-beta/resource_bigquery_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,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": {
Expand Down Expand Up @@ -431,6 +441,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 @@ -510,6 +527,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
10 changes: 9 additions & 1 deletion google-beta/resource_bigquery_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,21 @@ resource "google_bigquery_table" "test" {
field = "ts"
require_partition_filter = true
}
clustering = ["some_int", "some_string"]
schema = <<EOH
[
{
"name": "ts",
"type": "TIMESTAMP"
},
{
"name": "some_string",
"type": "STRING"
},
{
"name": "some_int",
"type": "INTEGER"
},
{
"name": "city",
"type": "RECORD",
Expand Down

0 comments on commit 3fbff05

Please sign in to comment.