1919 bigtable_pb2 as data_messages_v2_pb2 )
2020from gcloud .bigtable ._generated_v2 import (
2121 bigtable_table_admin_pb2 as table_admin_messages_v2_pb2 )
22+ from gcloud .bigtable ._generated_v2 import (
23+ table_pb2 as table_v2_pb2 )
2224from gcloud .bigtable .column_family import _gc_rule_from_pb
2325from gcloud .bigtable .column_family import ColumnFamily
2426from gcloud .bigtable .row import AppendRow
@@ -32,14 +34,9 @@ class Table(object):
3234
3335 .. note::
3436
35- We don't define any properties on a table other than the name. As
36- the proto says, in a request:
37-
38- The ``name`` field of the Table and all of its ColumnFamilies must
39- be left blank, and will be populated in the response.
40-
41- This leaves only the ``current_operation`` and ``granularity``
42- fields. The ``current_operation`` is only used for responses while
37+ We don't define any properties on a table other than the name.
38+ The only other fields are ``column_families`` and ``granularity``,
39+ The ``column_families`` are not stored locally and
4340 ``granularity`` is an enum with only one value.
4441
4542 We can use a :class:`Table` to:
@@ -52,7 +49,7 @@ class Table(object):
5249 :type table_id: str
5350 :param table_id: The ID of the table.
5451
55- :type instance: :class:`Cluster <.instance.Instance>`
52+ :type instance: :class:`Instance <.instance.Instance>`
5653 :param instance: The instance that owns the table.
5754 """
5855
@@ -71,7 +68,7 @@ def name(self):
7168
7269 The table name is of the form
7370
74- ``"projects/../zones/../clusters /../tables/{table_id}"``
71+ ``"projects/../instances /../tables/{table_id}"``
7572
7673 :rtype: str
7774 :returns: The table name.
@@ -136,24 +133,14 @@ def __eq__(self, other):
136133 def __ne__ (self , other ):
137134 return not self .__eq__ (other )
138135
139- def create (self , initial_split_keys = None ):
136+ def create (self , initial_split_keys = None , column_families = () ):
140137 """Creates this table.
141138
142- .. note::
143-
144- Though a :class:`._generated_v2.table_pb2.Table` is also
145- allowed (as the ``table`` property) in a create table request, we
146- do not support it in this method. As mentioned in the
147- :class:`Table` docstring, the name is the only useful property in
148- the table proto.
149-
150139 .. note::
151140
152141 A create request returns a
153142 :class:`._generated_v2.table_pb2.Table` but we don't use
154- this response. The proto definition allows for the inclusion of a
155- ``current_operation`` in the response, but it does not appear that
156- the Cloud Bigtable API returns any operation.
143+ this response.
157144
158145 :type initial_split_keys: list
159146 :param initial_split_keys: (Optional) List of row keys that will be
@@ -163,15 +150,28 @@ def create(self, initial_split_keys=None):
163150 ``"s1"`` and ``"s2"``, three tablets will be
164151 created, spanning the key ranges:
165152 ``[, s1)``, ``[s1, s2)``, ``[s2, )``.
153+
154+ :type column_families: list
155+ :param column_families: (Optional) List or other iterable of
156+ :class:`.ColumnFamily` instances.
166157 """
167- split_pb = table_admin_messages_v2_pb2 .CreateTableRequest .Split
168158 if initial_split_keys is not None :
159+ split_pb = table_admin_messages_v2_pb2 .CreateTableRequest .Split
169160 initial_split_keys = [
170161 split_pb (key = key ) for key in initial_split_keys ]
162+
163+ table_pb = None
164+ if column_families :
165+ table_pb = table_v2_pb2 .Table ()
166+ for col_fam in column_families :
167+ curr_id = col_fam .column_family_id
168+ table_pb .column_families [curr_id ].MergeFrom (col_fam .to_pb ())
169+
171170 request_pb = table_admin_messages_v2_pb2 .CreateTableRequest (
172171 initial_splits = initial_split_keys or [],
173172 parent = self ._instance .name ,
174173 table_id = self .table_id ,
174+ table = table_pb ,
175175 )
176176 client = self ._instance ._client
177177 # We expect a `._generated_v2.table_pb2.Table`
0 commit comments