From 3511196d59bd659146157c5a5b68b8111b2c30cd Mon Sep 17 00:00:00 2001 From: Alvaro Ferreira Date: Fri, 26 Mar 2021 10:27:53 +0100 Subject: [PATCH 1/3] Add require_partition_filter --- google/resource_bigquery_table.go | 16 ++++++++++++++++ google/resource_bigquery_table_test.go | 2 ++ 2 files changed, 18 insertions(+) diff --git a/google/resource_bigquery_table.go b/google/resource_bigquery_table.go index 8f9d2fde0fb..051c31070fa 100644 --- a/google/resource_bigquery_table.go +++ b/google/resource_bigquery_table.go @@ -522,6 +522,14 @@ func resourceBigQueryTable() *schema.Resource { Optional: true, Description: `When set, what mode of hive partitioning to use when reading data.`, }, + // 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, + Description: `If set to true, queries over this table require a partition filter that can be used for partition elimination to be specified.`, + }, // SourceUriPrefix: [Optional] [Experimental] When hive partition detection is requested, a common for all source uris must be required. // The prefix must end immediately before the partition key encoding begins. "source_uri_prefix": { @@ -1399,6 +1407,10 @@ func expandHivePartitioningOptions(configured interface{}) *bigquery.HivePartiti opts.Mode = v.(string) } + if v, ok := raw["require_partition_filter"]; ok { + opts.RequirePartitionFilter = v.(bool) + } + if v, ok := raw["source_uri_prefix"]; ok { opts.SourceUriPrefix = v.(string) } @@ -1413,6 +1425,10 @@ func flattenHivePartitioningOptions(opts *bigquery.HivePartitioningOptions) []ma result["mode"] = opts.Mode } + if opts.RequirePartitionFilter { + result["require_partition_filter"] = tp.RequirePartitionFilter + } + if opts.SourceUriPrefix != "" { result["source_uri_prefix"] = opts.SourceUriPrefix } diff --git a/google/resource_bigquery_table_test.go b/google/resource_bigquery_table_test.go index 3d8fdcc9835..60cf75979ce 100644 --- a/google/resource_bigquery_table_test.go +++ b/google/resource_bigquery_table_test.go @@ -973,6 +973,7 @@ resource "google_bigquery_table" "test" { hive_partitioning_options { mode = "AUTO" source_uri_prefix = "gs://${google_storage_bucket.test.name}/" + require_partition_filter = true } } @@ -1011,6 +1012,7 @@ resource "google_bigquery_table" "test" { hive_partitioning_options { mode = "CUSTOM" source_uri_prefix = "gs://${google_storage_bucket.test.name}/{key1:STRING}" + require_partition_filter = true } schema = < Date: Fri, 26 Mar 2021 10:38:25 +0100 Subject: [PATCH 2/3] Fix flattenHivePartitioningOptions func --- google/resource_bigquery_table.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google/resource_bigquery_table.go b/google/resource_bigquery_table.go index 051c31070fa..97d74bdb98a 100644 --- a/google/resource_bigquery_table.go +++ b/google/resource_bigquery_table.go @@ -1426,7 +1426,7 @@ func flattenHivePartitioningOptions(opts *bigquery.HivePartitioningOptions) []ma } if opts.RequirePartitionFilter { - result["require_partition_filter"] = tp.RequirePartitionFilter + result["require_partition_filter"] = opts.RequirePartitionFilter } if opts.SourceUriPrefix != "" { From 7465c2008c98aa6690e667828c331a46817a2dcb Mon Sep 17 00:00:00 2001 From: Alvaro Ferreira Date: Fri, 26 Mar 2021 17:15:31 +0100 Subject: [PATCH 3/3] Add description into docs --- website/docs/r/bigquery_table.html.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/website/docs/r/bigquery_table.html.markdown b/website/docs/r/bigquery_table.html.markdown index fadcc883d28..036940cd14b 100644 --- a/website/docs/r/bigquery_table.html.markdown +++ b/website/docs/r/bigquery_table.html.markdown @@ -240,6 +240,10 @@ The `hive_partitioning_options` block supports: partitioning on an unsupported format will lead to an error. Currently supported formats are: JSON, CSV, ORC, Avro and Parquet. * CUSTOM: when set to `CUSTOM`, you must encode the partition key schema within the `source_uri_prefix` by setting `source_uri_prefix` to `gs://bucket/path_to_table/{key1:TYPE1}/{key2:TYPE2}/{key3:TYPE3}`. + +* `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. * `source_uri_prefix` (Optional) - When hive partition detection is requested, a common for all source uris must be required. The prefix must end immediately