Skip to content

Commit 7735980

Browse files
committed
Updating Bigtable docs.
Addressing review comments, fixing broken links and making style changes.
1 parent 6ff91a8 commit 7735980

18 files changed

Lines changed: 234 additions & 128 deletions

docs/bigtable-client-intro.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ Authorization
2727
- For an overview of authentication in ``gcloud-python``,
2828
see :doc:`gcloud-auth`.
2929

30-
- In addition to any authentication configuration, you should also set the
30+
- In addition to any authentication configuration, you can also set the
3131
:envvar:`GCLOUD_PROJECT` environment variable for the project you'd like
3232
to interact with. If you are Google App Engine or Google Compute Engine
33-
this will be detected automatically.
33+
this will be detected automatically. (Setting this environment
34+
variable is not required, you may instead pass the ``project`` explicitly
35+
when constructing a :class:`Client <gcloud.storage.client.Client>`).
3436

3537
- After configuring your environment, create a
3638
:class:`Client <gcloud.storage.client.Client>`
@@ -59,7 +61,7 @@ API requests, you'll need to pass the ``admin`` argument:
5961

6062
.. code:: python
6163
62-
client = Client(admin=True)
64+
client = bigtable.Client(admin=True)
6365
6466
Read-Only Mode
6567
--------------
@@ -69,7 +71,7 @@ you can pass the ``read_only`` argument:
6971

7072
.. code:: python
7173
72-
client = Client(read_only=True)
74+
client = bigtable.Client(read_only=True)
7375
7476
This will ensure that the
7577
:data:`READ_ONLY_SCOPE <gcloud.bigtable.client.READ_ONLY_SCOPE>` is used

docs/bigtable-cluster-api.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ with :meth:`Client.list_zones() <gcloud.bigtable.client.Client.list_zones>`:
3030
You can choose a :class:`string <str>` from among the result to pass to
3131
the :class:`Cluster <gcloud.bigtable.cluster.Cluster>` constructor.
3232

33-
As of right now, the available zones are
33+
The available zones (as of February 2016) are
3434

3535
.. code:: python
3636
@@ -50,7 +50,8 @@ To create a :class:`Cluster <gcloud.bigtable.cluster.Cluster>` object:
5050
5151
Both ``display_name`` and ``serve_nodes`` are optional. When not provided,
5252
``display_name`` defaults to the ``cluster_id`` value and ``serve_nodes``
53-
defaults to the minimum allowed: ``3``.
53+
defaults to the minimum allowed:
54+
:data:`DEFAULT_SERVE_NODES <gcloud.bigtable.cluster.DEFAULT_SERVE_NODES>`.
5455

5556
Even if this :class:`Cluster <gcloud.bigtable.cluster.Cluster>` already
5657
has been created with the API, you'll want this object to use as a
@@ -69,7 +70,9 @@ with :meth:`create() <gcloud.bigtable.cluster.Cluster.create>`:
6970
cluster.display_name = 'My very own cluster'
7071
cluster.create()
7172
72-
If you would like more than the minimum number of nodes (``3``) in your cluster:
73+
If you would like more than the minimum number of nodes
74+
(:data:`DEFAULT_SERVE_NODES <gcloud.bigtable.cluster.DEFAULT_SERVE_NODES>`)
75+
in your cluster:
7376

7477
.. code:: python
7578
@@ -104,8 +107,9 @@ by making a `GetOperation`_ request with
104107
.. note::
105108

106109
Once an :class:`Operation <gcloud.bigtable.cluster.Operation>` object
107-
has returned :data:`True` from ``finished()``, the object should not
108-
be re-used. Subsequent calls to
110+
has returned :data:`True` from
111+
:meth:`finished() <gcloud.bigtable.cluster.Operation.finished>`, the
112+
object should not be re-used. Subsequent calls to
109113
:meth:`finished() <gcloud.bigtable.cluster.Operation.finished>`
110114
will result in a :class:`ValueError <exceptions.ValueError>`.
111115

docs/bigtable-column-family.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ during periodic garbage collection (which executes opportunistically in the
1010
background).
1111

1212
The types
13-
:class:`GarbageCollectionRule <gcloud.bigtable.column_family.GarbageCollectionRule>`,
13+
:class:`MaxAgeGCRule <gcloud.bigtable.column_family.MaxAgeGCRule>`,
14+
:class:`MaxVersionsGCRule <gcloud.bigtable.column_family.MaxVersionsGCRule>`,
1415
:class:`GarbageCollectionRuleUnion <gcloud.bigtable.column_family.GarbageCollectionRuleUnion>` and
1516
:class:`GarbageCollectionRuleIntersection <gcloud.bigtable.column_family.GarbageCollectionRuleIntersection>`
1617
can all be used as the optional ``gc_rule`` argument in the

docs/bigtable-data-api.rst

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ column families, you are ready to store and retrieve data.
77
Cells vs. Columns vs. Column Families
88
+++++++++++++++++++++++++++++++++++++
99

10-
* As we saw before, a table can have many column families.
11-
* As we'll see below, a table also has many rows (specified by row keys).
10+
* As explained in the :doc:`table overview <bigtable-table-api>`, tables can
11+
have many column families.
12+
* As described below, a table can also have many rows which are
13+
specified by row keys.
1214
* Within a row, data is stored in a cell. A cell simply has a value (as
1315
bytes) and a timestamp. The number of cells in each row can be
1416
different, depending on what was stored in each row.
@@ -51,7 +53,7 @@ methods.
5153
* The **conditional** way is via `CheckAndMutateRow`_. This method
5254
first checks if some filter is matched in a a given row, then
5355
applies one of two sets of mutations, depending on if a match
54-
occurred or not. (These mutations sets are called the "true
56+
occurred or not. (These mutation sets are called the "true
5557
mutations" and "false mutations".)
5658
* The **append** way is via `ReadModifyWriteRow`_. This simply
5759
appends (as bytes) or increments (as an integer) data in a presumed
@@ -142,7 +144,7 @@ Direct mutations can be added via one of four methods
142144
Conditional Mutations
143145
---------------------
144146

145-
Making **conditional** conditional modifications is essentially identical
147+
Making **conditional** modifications is essentially identical
146148
to **direct** modifications, but we need to specify a filter to match
147149
against in the row:
148150

@@ -157,13 +159,15 @@ The only other difference from **direct** modifications are that each mutation
157159
added must specify a ``state``: will the mutation be applied if the filter
158160
matches or if it fails to match.
159161

160-
For example
162+
For example:
161163

162164
.. code:: python
163165
164166
row.set_cell(column_family_id, column, value,
165167
timestamp=timestamp, state=True)
166168
169+
will add to the set of true mutations.
170+
167171
.. note::
168172

169173
If ``state`` is passed when no ``filter_`` is set on a
@@ -176,15 +180,15 @@ Append Mutations
176180

177181
Append mutations can be added via one of two methods
178182

179-
* :meth:`append_cell_value <gcloud.bigtable.row.Row.append_cell_value>` appends
180-
a bytes value to an existing cell:
183+
* :meth:`append_cell_value() <gcloud.bigtable.row.Row.append_cell_value>`
184+
appends a bytes value to an existing cell:
181185

182186
.. code:: python
183187
184188
row.append_cell_value(column_family_id, column, bytes_value)
185189
186-
* :meth:`increment_cell_value <gcloud.bigtable.row.Row.increment_cell_value>` increments
187-
an integer value in an existing cell:
190+
* :meth:`increment_cell_value() <gcloud.bigtable.row.Row.increment_cell_value>`
191+
increments an integer value in an existing cell:
188192

189193
.. code:: python
190194
@@ -228,7 +232,33 @@ To make a `ReadRows`_ API request for a single row key, use
228232

229233
.. code:: python
230234
231-
row_data = table.read_row(row_key)
235+
>>> row_data = table.read_row(row_key)
236+
>>> row_data.cells
237+
{
238+
u'fam1': {
239+
b'col1': [
240+
<gcloud.bigtable.row_data.Cell at 0x7f80d150ef10>,
241+
<gcloud.bigtable.row_data.Cell at 0x7f80d150ef10>,
242+
],
243+
b'col2': [
244+
<gcloud.bigtable.row_data.Cell at 0x7f80d150ef10>,
245+
],
246+
},
247+
u'fam2': {
248+
b'col3': [
249+
<gcloud.bigtable.row_data.Cell at 0x7f80d150ef10>,
250+
<gcloud.bigtable.row_data.Cell at 0x7f80d150ef10>,
251+
<gcloud.bigtable.row_data.Cell at 0x7f80d150ef10>,
252+
],
253+
},
254+
}
255+
>>> cell = row_data.cells[u'fam1'][b'col1'][0]
256+
>>> cell
257+
<gcloud.bigtable.row_data.Cell at 0x7f80d150ef10>
258+
>>> cell.value
259+
b'val1'
260+
>>> cell.timestamp
261+
datetime.datetime(2016, 2, 27, 3, 41, 18, 122823, tzinfo=<UTC>)
232262
233263
Rather than returning a :class:`Row <gcloud.bigtable.row.Row>`, this method
234264
returns a :class:`PartialRowData <gcloud.bigtable.row_data.PartialRowData>`
@@ -257,10 +287,6 @@ To make a `ReadRows`_ API request for a stream of rows, use
257287
row_data = table.read_rows()
258288
259289
Using gRPC over HTTP/2, a continual stream of responses will be delivered.
260-
We have a custom
261-
:class:`PartialRowsData <gcloud.bigtable.row_data.PartialRowsData>`
262-
class to allow consuming and parsing these streams as they come.
263-
264290
In particular
265291

266292
* :meth:`consume_next() <gcloud.bigtable.row_data.PartialRowsData.consume_next>`

docs/bigtable-row.rst

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,66 @@
11
Bigtable Row
22
============
33

4-
A
4+
It is possible to use a :class:`RowFilter <gcloud.bigtable.row.RowFilter>`
5+
when adding mutations to a :class:`Row <gcloud.bigtable.row.Row>` and when
6+
reading row data with :meth:`read_row() <gcloud.bigtable.table.Table.read_row>`
7+
:meth:`read_rows() <gcloud.bigtable.table.Table.read_rows>`.
8+
9+
As laid out in the `RowFilter definition`_, the following basic filters
10+
are provided:
11+
12+
* :class:`SinkFilter <.row.SinkFilter>`
13+
* :class:`PassAllFilter <.row.PassAllFilter>`
14+
* :class:`BlockAllFilter <.row.BlockAllFilter>`
15+
* :class:`RowKeyRegexFilter <.row.RowKeyRegexFilter>`
16+
* :class:`RowSampleFilter <.row.RowSampleFilter>`
17+
* :class:`FamilyNameRegexFilter <.row.FamilyNameRegexFilter>`
18+
* :class:`ColumnQualifierRegexFilter <.row.ColumnQualifierRegexFilter>`
19+
* :class:`TimestampRangeFilter <.row.TimestampRangeFilter>`
20+
* :class:`ColumnRangeFilter <.row.ColumnRangeFilter>`
21+
* :class:`ValueRegexFilter <.row.ValueRegexFilter>`
22+
* :class:`ValueRangeFilter <.row.ValueRangeFilter>`
23+
* :class:`CellsRowOffsetFilter <.row.CellsRowOffsetFilter>`
24+
* :class:`CellsRowLimitFilter <.row.CellsRowLimitFilter>`
25+
* :class:`CellsColumnLimitFilter <.row.CellsColumnLimitFilter>`
26+
* :class:`StripValueTransformerFilter <.row.StripValueTransformerFilter>`
27+
* :class:`ApplyLabelFilter <.row.ApplyLabelFilter>`
28+
29+
In addition, these filters can be combined into composite filters with
30+
31+
* :class:`RowFilterChain <.row.RowFilterChain>`
32+
* :class:`RowFilterUnion <.row.RowFilterUnion>`
33+
* :class:`ConditionalRowFilter <.row.ConditionalRowFilter>`
34+
35+
These rules can be nested arbitrarily, with a basic filter at the lowest
36+
level. For example:
37+
38+
.. code:: python
39+
40+
# Filter in a specified column (matching any column family).
41+
col1_filter = ColumnQualifierRegexFilter(b'columnbia')
42+
43+
# Create a filter to label results.
44+
label1 = u'label-red'
45+
label1_filter = ApplyLabelFilter(label1)
46+
47+
# Combine the filters to label all the cells in columnbia.
48+
chain1 = RowFilterChain(filters=[col1_filter, label1_filter])
49+
50+
# Create a similar filter to label cells blue.
51+
col2_filter = ColumnQualifierRegexFilter(b'columnseeya')
52+
label2 = u'label-blue'
53+
label2_filter = ApplyLabelFilter(label2)
54+
chain2 = RowFilterChain(filters=[col2_filter, label2_filter])
55+
56+
# Bring our two labeled columns together.
57+
row_filter = RowFilterUnion(filters=[chain1, chain2])
558
659
----
760

861
.. automodule:: gcloud.bigtable.row
962
:members:
1063
:undoc-members:
1164
:show-inheritance:
65+
66+
.. _RowFilter definition: https://github.com/GoogleCloudPlatform/cloud-bigtable-client/blob/1ff247c2e3b7cd0a2dd49071b2d95beaf6563092/bigtable-protos/src/main/proto/google/bigtable/v1/bigtable_data.proto#L195

docs/bigtable-table-api.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ If you want a comprehensive list of all existing tables in a cluster, make a
1414

1515
.. code:: python
1616
17-
tables = cluster.list_tables()
17+
>>> cluster.list_tables()
18+
[<gcloud.bigtable.table.Table at 0x7ff6a1de8f50>,
19+
<gcloud.bigtable.table.Table at 0x7ff6a1de8350>]
1820
1921
Table Factory
2022
-------------
@@ -107,8 +109,7 @@ or similar):
107109
This rule helps the backend determine when and how to clean up old cells
108110
in the column family.
109111

110-
See the :doc:`Column Families doc <bigtable-column-family>`
111-
for more information about
112+
See :doc:`bigtable-column-family` for more information about
112113
:class:`GarbageCollectionRule <gcloud.bigtable.column_family.GarbageCollectionRule>`
113114
and related classes.
114115

docs/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
bigtable-table-api
6666
bigtable-data-api
6767
Client <bigtable-client>
68-
bigtable-client
6968
bigtable-cluster
7069
bigtable-table
7170
bigtable-column-family

gcloud/bigtable/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
"""
2828

2929

30+
from pkg_resources import get_distribution
31+
3032
from grpc.beta import implementations
3133

3234
from gcloud.bigtable._generated import bigtable_cluster_data_pb2 as data_pb2
@@ -75,7 +77,8 @@
7577
DEFAULT_TIMEOUT_SECONDS = 10
7678
"""The default timeout to use for API requests."""
7779

78-
DEFAULT_USER_AGENT = 'gcloud-bigtable-python'
80+
DEFAULT_USER_AGENT = 'gcloud-python/{0}'.format(
81+
get_distribution('gcloud').version)
7982
"""The default user agent for API requests."""
8083

8184

gcloud/bigtable/cluster.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
_OPERATION_NAME_RE = re.compile(r'^operations/projects/([^/]+)/zones/([^/]+)/'
3535
r'clusters/([a-z][-a-z0-9]*)/operations/'
3636
r'(?P<operation_id>\d+)$')
37-
_DEFAULT_SERVE_NODES = 3
3837
_TYPE_URL_BASE = 'type.googleapis.com/google.bigtable.'
3938
_ADMIN_TYPE_URL_BASE = _TYPE_URL_BASE + 'admin.cluster.v1.'
4039
_CLUSTER_CREATE_METADATA = _ADMIN_TYPE_URL_BASE + 'CreateClusterMetadata'
@@ -46,6 +45,9 @@
4645
_UNDELETE_CREATE_METADATA: messages_pb2.UndeleteClusterMetadata,
4746
}
4847

48+
DEFAULT_SERVE_NODES = 3
49+
"""Default number of nodes to use when creating a cluster."""
50+
4951

5052
def _prepare_create_request(cluster):
5153
"""Creates a protobuf request for a CreateCluster request.
@@ -216,11 +218,11 @@ class Cluster(object):
216218
217219
:type serve_nodes: int
218220
:param serve_nodes: (Optional) The number of nodes in the cluster.
219-
Defaults to 3 (``_DEFAULT_SERVE_NODES``).
221+
Defaults to :data:`DEFAULT_SERVE_NODES`.
220222
"""
221223

222224
def __init__(self, zone, cluster_id, client,
223-
display_name=None, serve_nodes=_DEFAULT_SERVE_NODES):
225+
display_name=None, serve_nodes=DEFAULT_SERVE_NODES):
224226
self.zone = zone
225227
self.cluster_id = cluster_id
226228
self.display_name = display_name or cluster_id
@@ -259,8 +261,10 @@ def from_pb(cls, cluster_pb, client):
259261
:rtype: :class:`Cluster`
260262
:returns: The cluster parsed from the protobuf response.
261263
:raises: :class:`ValueError <exceptions.ValueError>` if the cluster
262-
name does not match :data:`_CLUSTER_NAME_RE` or if the parsed
263-
project ID does not match the project ID on the client.
264+
name does not match
265+
``projects/{project}/zones/{zone}/clusters/{cluster_id}``
266+
or if the parsed project ID does not match the project ID
267+
on the client.
264268
"""
265269
match = _CLUSTER_NAME_RE.match(cluster_pb.name)
266270
if match is None:
@@ -277,9 +281,8 @@ def from_pb(cls, cluster_pb, client):
277281
def copy(self):
278282
"""Make a copy of this cluster.
279283
280-
Copies the local data stored as simple types but does not copy the
281-
current state of any operations with the Cloud Bigtable API. Also
282-
copies the client attached to this instance.
284+
Copies the local data stored as simple types and copies the client
285+
attached to this instance.
283286
284287
:rtype: :class:`.Cluster`
285288
:returns: A copy of the current cluster.

gcloud/bigtable/column_family.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def __eq__(self, other):
157157
return other.rules == self.rules
158158

159159
def to_pb(self):
160-
"""Converts the union into a single gc rule as a protobuf.
160+
"""Converts the union into a single GC rule as a protobuf.
161161
162162
:rtype: :class:`.data_pb2.GcRule`
163163
:returns: The converted current object.
@@ -183,7 +183,7 @@ def __eq__(self, other):
183183
return other.rules == self.rules
184184

185185
def to_pb(self):
186-
"""Converts the intersection into a single gc rule as a protobuf.
186+
"""Converts the intersection into a single GC rule as a protobuf.
187187
188188
:rtype: :class:`.data_pb2.GcRule`
189189
:returns: The converted current object.

0 commit comments

Comments
 (0)