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

Add time partitioning field to google_bigquery_table resource #1240

17 changes: 17 additions & 0 deletions google/resource_bigquery_table.go
Expand Up @@ -141,6 +141,14 @@ func resourceBigQueryTable() *schema.Resource {
Required: true,
ValidateFunc: validation.StringInSlice([]string{"DAY"}, false),
},

// Type: [Optional] The field used to determine how to create a time-based
// partition. If time-based partitioning is enabled without this value, the
// table is partitioned based on the load time.
"field": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
Expand Down Expand Up @@ -419,6 +427,10 @@ func expandTimePartitioning(configured interface{}) *bigquery.TimePartitioning {
raw := configured.([]interface{})[0].(map[string]interface{})
tp := &bigquery.TimePartitioning{Type: raw["type"].(string)}

if v, ok := raw["field"]; ok {
tp.Field = v.(string)
}

if v, ok := raw["expiration_ms"]; ok {
tp.ExpirationMs = int64(v.(int))
}
Expand All @@ -428,6 +440,11 @@ func expandTimePartitioning(configured interface{}) *bigquery.TimePartitioning {

func flattenTimePartitioning(tp *bigquery.TimePartitioning) []map[string]interface{} {
result := map[string]interface{}{"type": tp.Type}
result["field"] = tp.Type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be tp.Field?


if tp.Type != "" {
result["field"] = tp.Type
}

if tp.ExpirationMs != 0 {
result["expiration_ms"] = tp.ExpirationMs
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/bigquery_table.html.markdown
Expand Up @@ -81,6 +81,10 @@ The `time_partitioning` block supports:
* `expiration_ms` - (Optional) Number of milliseconds for which to keep the
storage for a partition.

* `field` - (Optional) The field used to determine how to create a time-based
partition. If time-based partitioning is enabled without this value, the
table is partitioned based on the load time.

* `type` - (Required) The only type supported is DAY, which will generate
one partition per day based on data loading time.

Expand Down