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 timePartitioning.requirePartitionFilter field to google_bigquery_table resource #2288

Closed
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
18 changes: 17 additions & 1 deletion google/resource_bigquery_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,22 @@ func resourceBigQueryTable() *schema.Resource {
ValidateFunc: validation.StringInSlice([]string{"DAY"}, false),
},

// Type: [Optional] The field used to determine how to create a time-based
// 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.
"field": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},

// RequirePartitionFilter: [Optional] If set to true, queries over this table
// require a partition filter that can be used for partition elimination to be
// specified.
"require_partition_filter": {
Type: schema.TypeBool,
Optional: true,
},
},
},
},
Expand Down Expand Up @@ -436,6 +444,10 @@ func expandTimePartitioning(configured interface{}) *bigquery.TimePartitioning {
tp.ExpirationMs = int64(v.(int))
}

if v, ok := raw["require_partition_filter"]; ok {
tp.RequirePartitionFilter = v.(bool)
}

return tp
}

Expand All @@ -450,6 +462,10 @@ func flattenTimePartitioning(tp *bigquery.TimePartitioning) []map[string]interfa
result["expiration_ms"] = tp.ExpirationMs
}

if tp.RequirePartitionFilter == true {
result["require_partition_filter"] = tp.RequirePartitionFilter
}

return []map[string]interface{}{result}
}

Expand Down
3 changes: 2 additions & 1 deletion google/resource_bigquery_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ resource "google_bigquery_table" "test" {

time_partitioning {
type = "DAY"
field = "ts"
field = "ts"
require_partition_filter = true
}

schema = <<EOH
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/bigquery_table.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ The `time_partitioning` block supports:
* `type` - (Required) The only type supported is DAY, which will generate
one partition per day based on data loading time.

* `require_partition_filter` - (Optional) If set to true, queries over this table
require a partition filter that can be used for partition elimination to be
specified.

The `view` block supports:

* `query` - (Required) A query that BigQuery executes when the view is referenced.
Expand Down