Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigQuery: table clustering/partitioning support. #4223

Merged
merged 1 commit into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions google/resource_bigquery_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
tysen marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 9 additions & 1 deletion google/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"
tysen marked this conversation as resolved.
Show resolved Hide resolved
},
{
"name": "some_int",
"type": "INTEGER"
},
{
"name": "city",
"type": "RECORD",
Expand Down