From aa1613c1bf48c7efb999cb8b8c422c80baf1950b Mon Sep 17 00:00:00 2001 From: HemangChothani <50404902+HemangChothani@users.noreply.github.com> Date: Mon, 7 Sep 2020 10:24:32 +0530 Subject: [PATCH] feat: expose require_partition_filter for hive_partition (#257) --- google/cloud/bigquery/external_config.py | 15 +++++++++++++++ tests/unit/test_external_config.py | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/google/cloud/bigquery/external_config.py b/google/cloud/bigquery/external_config.py index d702d9d83..112dfdba4 100644 --- a/google/cloud/bigquery/external_config.py +++ b/google/cloud/bigquery/external_config.py @@ -586,6 +586,21 @@ def source_uri_prefix(self): def source_uri_prefix(self, value): self._properties["sourceUriPrefix"] = value + @property + def require_partition_filter(self): + """Optional[bool]: If set to true, queries over the partitioned table require a + partition filter that can be used for partition elimination to be + specified. + + See + https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#HivePartitioningOptions.FIELDS.mode + """ + return self._properties.get("requirePartitionFilter") + + @require_partition_filter.setter + def require_partition_filter(self, value): + self._properties["requirePartitionFilter"] = value + def to_api_repr(self): """Build an API representation of this object. diff --git a/tests/unit/test_external_config.py b/tests/unit/test_external_config.py index 6028d069b..4b6ef5118 100644 --- a/tests/unit/test_external_config.py +++ b/tests/unit/test_external_config.py @@ -181,6 +181,7 @@ def test_from_api_repr_hive_partitioning(self): "hivePartitioningOptions": { "sourceUriPrefix": "http://foo/bar", "mode": "STRINGS", + "requirePartitionFilter": True, }, }, ) @@ -194,6 +195,7 @@ def test_from_api_repr_hive_partitioning(self): ) self.assertEqual(ec.hive_partitioning.source_uri_prefix, "http://foo/bar") self.assertEqual(ec.hive_partitioning.mode, "STRINGS") + self.assertEqual(ec.hive_partitioning.require_partition_filter, True) # converting back to API representation should yield the same result got_resource = ec.to_api_repr() @@ -210,6 +212,7 @@ def test_to_api_repr_hive_partitioning(self): hive_partitioning = external_config.HivePartitioningOptions() hive_partitioning.source_uri_prefix = "http://foo/bar" hive_partitioning.mode = "STRINGS" + hive_partitioning.require_partition_filter = False ec = external_config.ExternalConfig("FORMAT_FOO") ec.hive_partitioning = hive_partitioning @@ -221,6 +224,7 @@ def test_to_api_repr_hive_partitioning(self): "hivePartitioningOptions": { "sourceUriPrefix": "http://foo/bar", "mode": "STRINGS", + "requirePartitionFilter": False, }, } self.assertEqual(got_resource, expected_resource)