|
15 | 15 | """User friendly container for Google Cloud Bigtable Table.""" |
16 | 16 |
|
17 | 17 |
|
| 18 | +from gcloud.bigtable._generated import ( |
| 19 | + bigtable_table_service_messages_pb2 as messages_pb2) |
18 | 20 | from gcloud.bigtable.column_family import ColumnFamily |
19 | 21 | from gcloud.bigtable.row import Row |
20 | 22 |
|
21 | 23 |
|
22 | 24 | class Table(object): |
23 | 25 | """Representation of a Google Cloud Bigtable Table. |
24 | 26 |
|
| 27 | + .. note:: |
| 28 | +
|
| 29 | + We don't define any properties on a table other than the name. As |
| 30 | + the proto says, in a request: |
| 31 | +
|
| 32 | + The ``name`` field of the Table and all of its ColumnFamilies must |
| 33 | + be left blank, and will be populated in the response. |
| 34 | +
|
| 35 | + This leaves only the ``current_operation`` and ``granularity`` |
| 36 | + fields. The ``current_operation`` is only used for responses while |
| 37 | + ``granularity`` is an enum with only one value. |
| 38 | +
|
| 39 | + We can use a :class:`Table` to: |
| 40 | +
|
| 41 | + * :meth:`create` the table |
| 42 | +
|
25 | 43 | :type table_id: str |
26 | 44 | :param table_id: The ID of the table. |
27 | 45 |
|
@@ -64,3 +82,40 @@ def __eq__(self, other): |
64 | 82 |
|
65 | 83 | def __ne__(self, other): |
66 | 84 | return not self.__eq__(other) |
| 85 | + |
| 86 | + def create(self, initial_split_keys=None): |
| 87 | + """Creates this table. |
| 88 | +
|
| 89 | + .. note:: |
| 90 | +
|
| 91 | + Though a :class:`._generated.bigtable_table_data_pb2.Table` is also |
| 92 | + allowed (as the ``table`` property) in a create table request, we |
| 93 | + do not support it in this method. As mentioned in the |
| 94 | + :class:`Table` docstring, the name is the only useful property in |
| 95 | + the table proto. |
| 96 | +
|
| 97 | + .. note:: |
| 98 | +
|
| 99 | + A create request returns a |
| 100 | + :class:`._generated.bigtable_table_data_pb2.Table` but we don't use |
| 101 | + this response. The proto definition allows for the inclusion of a |
| 102 | + ``current_operation`` in the response, but it does not appear that |
| 103 | + the Cloud Bigtable API returns any operation. |
| 104 | +
|
| 105 | + :type initial_split_keys: list |
| 106 | + :param initial_split_keys: (Optional) List of row keys that will be |
| 107 | + used to initially split the table into |
| 108 | + several tablets (Tablets are similar to |
| 109 | + HBase regions). Given two split keys, |
| 110 | + ``"s1"`` and ``"s2"``, three tablets will be |
| 111 | + created, spanning the key ranges: |
| 112 | + ``[, s1)``, ``[s1, s2)``, ``[s2, )``. |
| 113 | + """ |
| 114 | + request_pb = messages_pb2.CreateTableRequest( |
| 115 | + initial_split_keys=initial_split_keys or [], |
| 116 | + name=self._cluster.name, |
| 117 | + table_id=self.table_id, |
| 118 | + ) |
| 119 | + client = self._cluster._client |
| 120 | + # We expect a `._generated.bigtable_table_data_pb2.Table` |
| 121 | + client._table_stub.CreateTable(request_pb, client.timeout_seconds) |
0 commit comments