diff --git a/bigquery/google/cloud/bigquery/table.py b/bigquery/google/cloud/bigquery/table.py index bf5fbc65b5a3..e9f06998d2ce 100644 --- a/bigquery/google/cloud/bigquery/table.py +++ b/bigquery/google/cloud/bigquery/table.py @@ -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. diff --git a/bigquery/tests/unit/test_table.py b/bigquery/tests/unit/test_table.py index 965dd5f0f195..557d57741382 100644 --- a/bigquery/tests/unit/test_table.py +++ b/bigquery/tests/unit/test_table.py @@ -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) @@ -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") @@ -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)