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

feat: expose require_partition_filter for hive_partition #257

Merged
merged 1 commit into from Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions google/cloud/bigquery/external_config.py
Expand Up @@ -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.

Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_external_config.py
Expand Up @@ -181,6 +181,7 @@ def test_from_api_repr_hive_partitioning(self):
"hivePartitioningOptions": {
"sourceUriPrefix": "http://foo/bar",
"mode": "STRINGS",
"requirePartitionFilter": True,
},
},
)
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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)
Expand Down