Skip to content

Commit

Permalink
Adding clustering_fields property to TableListItem (googleapis#7692)
Browse files Browse the repository at this point in the history
* Added property clustering_fields to TableListItem along with test

* Updated tests for clustering fields.
  • Loading branch information
lbristol88 authored and tswast committed Apr 11, 2019
1 parent 7124c60 commit 2776aed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions bigquery/google/cloud/bigquery/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,23 @@ def friendly_name(self):

view_use_legacy_sql = property(_view_use_legacy_sql_getter)

@property
def clustering_fields(self):
"""Union[List[str], None]: Fields defining clustering for the table
(Defaults to :data:`None`).
Clustering fields are immutable after table creation.
.. note::
As of 2018-06-29, clustering fields cannot be set on a table
which does not also have time partioning defined.
"""
prop = self._properties.get("clustering")
if prop is not None:
return list(prop.get("fields", ()))

@classmethod
def from_string(cls, full_table_id):
"""Construct a table from fully-qualified table ID.
Expand Down
3 changes: 3 additions & 0 deletions bigquery/tests/unit/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,7 @@ def test_ctor(self):
"expirationMs": "10000",
},
"labels": {"some-stuff": "this-is-a-label"},
"clustering": {"fields": ["string"]},
}

table = self._make_one(resource)
Expand All @@ -1170,6 +1171,7 @@ def test_ctor(self):
self.assertEqual(table.time_partitioning.field, "mycolumn")
self.assertEqual(table.labels["some-stuff"], "this-is-a-label")
self.assertIsNone(table.view_use_legacy_sql)
self.assertEqual(table.clustering_fields, ["string"])

with warnings.catch_warnings(record=True) as warned:
self.assertEqual(table.partitioning_type, "DAY")
Expand Down Expand Up @@ -1222,6 +1224,7 @@ def test_ctor_missing_properties(self):
self.assertEqual(table.table_id, "testtable")
self.assertIsNone(table.created)
self.assertIsNone(table.expires)
self.assertIsNone(table.clustering_fields)
self.assertIsNone(table.full_table_id)
self.assertIsNone(table.friendly_name)
self.assertIsNone(table.table_type)
Expand Down

0 comments on commit 2776aed

Please sign in to comment.