E5F6 Adding `clustering_fields` property to TableListItem by lbristol88 · Pull Request #7692 · googleapis/google-cloud-python · GitHub
[go: up one dir, main page]

Skip to content
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.
Loading
Jump to
Jump to file
10BC0
Failed to load files.
Loading
Diff view
Diff view
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