Skip to content
Permalink
Browse files
feat: expose require_partition_filter for hive_partition (#257)
  • Loading branch information
HemangChothani committed Sep 7, 2020
1 parent a125160 commit aa1613c1bf48c7efb999cb8b8c422c80baf1950b
Showing with 19 additions and 0 deletions.
  1. +15 −0 google/cloud/bigquery/external_config.py
  2. +4 −0 tests/unit/test_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.
@@ -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)

0 comments on commit aa1613c

Please sign in to comment.