Skip to content

Commit 2776aed

Browse files
lbristol88tswast
authored andcommitted
Adding clustering_fields property to TableListItem (googleapis#7692)
* Added property clustering_fields to TableListItem along with test * Updated tests for clustering fields.
1 parent 7124c60 commit 2776aed

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

bigquery/google/cloud/bigquery/table.py

+17
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,23 @@ def friendly_name(self):
10211021

10221022
view_use_legacy_sql = property(_view_use_legacy_sql_getter)
10231023

1024+
@property
1025+
def clustering_fields(self):
1026+
"""Union[List[str], None]: Fields defining clustering for the table
1027+
1028+
(Defaults to :data:`None`).
1029+
1030+
Clustering fields are immutable after table creation.
1031+
1032+
.. note::
1033+
1034+
As of 2018-06-29, clustering fields cannot be set on a table
1035+
which does not also have time partioning defined.
1036+
"""
1037+
prop = self._properties.get("clustering")
1038+
if prop is not None:
1039+
return list(prop.get("fields", ()))
1040+
10241041
@classmethod
10251042
def from_string(cls, full_table_id):
10261043
"""Construct a table from fully-qualified table ID.

bigquery/tests/unit/test_table.py

+3
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,7 @@ def test_ctor(self):
11481148
"expirationMs": "10000",
11491149
},
11501150
"labels": {"some-stuff": "this-is-a-label"},
1151+
"clustering": {"fields": ["string"]},
11511152
}
11521153

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

11741176
with warnings.catch_warnings(record=True) as warned:
11751177
self.assertEqual(table.partitioning_type, "DAY")
@@ -1222,6 +1224,7 @@ def test_ctor_missing_properties(self):
12221224
self.assertEqual(table.table_id, "testtable")
12231225
self.assertIsNone(table.created)
12241226
self.assertIsNone(table.expires)
1227+
self.assertIsNone(table.clustering_fields)
12251228
self.assertIsNone(table.full_table_id)
12261229
self.assertIsNone(table.friendly_name)
12271230
self.assertIsNone(table.table_type)

0 commit comments

Comments
 (0)