Skip to content

Commit 6449b1c

Browse files
committed
Prep spanner release.
1 parent e4661b0 commit 6449b1c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+12402
-18
lines changed

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Cloud Platform services:
4242
- `Google Cloud Vision`_ (`Vision README`_)
4343
- `Google Cloud Bigtable - HappyBase`_ (`HappyBase README`_)
4444
- `Google Cloud Runtime Configuration`_ (`Runtime Config README`_)
45+
- `Cloud Spanner`_ (`Cloud Spanner README`_)
4546

4647
**Alpha** indicates that the client library for a particular service is
4748
still a work-in-progress and is more likely to get backwards-incompatible
@@ -79,6 +80,8 @@ updates. See `versioning`_ for more details.
7980
.. _HappyBase README: https://github.com/GoogleCloudPlatform/google-cloud-python-happybase
8081
.. _Google Cloud Runtime Configuration: https://cloud.google.com/deployment-manager/runtime-configurator/
8182
.. _Runtime Config README: https://github.com/GoogleCloudPlatform/google-cloud-python/tree/master/runtimeconfig
83+
.. _Cloud Spanner: https://cloud.google.com/spanner/
84+
.. _Cloud Spanner README: https://github.com/GoogleCloudPlatform/google-cloud-python/tree/master/spanner
8285
.. _versioning: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/CONTRIBUTING.rst#versioning
8386

8487
If you need support for other Google APIs, check out the

bigtable/google/cloud/bigtable/client.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
1919
In the hierarchy of API concepts
2020
21-
* a :class:`Client` owns an :class:`.Instance`
22-
* an :class:`.Instance` owns a :class:`~google.cloud.bigtable.table.Table`
21+
* a :class:`~google.cloud.bigtable.client.Client` owns an
22+
:class:`~google.cloud.bigtable.instance.Instance`
23+
* an :class:`~google.cloud.bigtable.instance.Instance` owns a
24+
:class:`~google.cloud.bigtable.table.Table`
2325
* a :class:`~google.cloud.bigtable.table.Table` owns a
2426
:class:`~.column_family.ColumnFamily`
25-
* a :class:`~google.cloud.bigtable.table.Table` owns a :class:`~.row.Row`
26-
(and all the cells in the row)
27+
* a :class:`~google.cloud.bigtable.table.Table` owns a
28+
:class:`~google.cloud.bigtable.row.Row` (and all the cells in the row)
2729
"""
2830

2931

@@ -342,7 +344,7 @@ def instance(self, instance_id, location=_EXISTING_INSTANCE_LOCATION_ID,
342344
:param serve_nodes: (Optional) The number of nodes in the instance's
343345
cluster; used to set up the instance's cluster.
344346
345-
:rtype: :class:`.Instance`
347+
:rtype: :class:`~google.cloud.bigtable.instance.Instance`
346348
:returns: an instance owned by this client.
347349
"""
348350
return Instance(instance_id, self, location,
@@ -353,8 +355,9 @@ def list_instances(self):
353355
354356
:rtype: tuple
355357
:returns: A pair of results, the first is a list of
356-
:class:`.Instance` objects returned and the second is a
357-
list of strings (the failed locations in the request).
358+
:class:`~google.cloud.bigtable.instance.Instance` objects
359+
returned and the second is a list of strings (the failed
360+
locations in the request).
358361
"""
359362
request_pb = bigtable_instance_admin_pb2.ListInstancesRequest(
360363
parent=self.project_name)

bigtable/google/cloud/bigtable/cluster.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class Cluster(object):
7272
:type cluster_id: str
7373
:param cluster_id: The ID of the cluster.
7474
75-
:type instance: :class:`.instance.Instance`
75+
:type instance: :class:`~google.cloud.bigtable.instance.Instance`
7676
:param instance: The instance where the cluster resides.
7777
7878
:type serve_nodes: int
@@ -104,7 +104,7 @@ def from_pb(cls, cluster_pb, instance):
104104
:type cluster_pb: :class:`instance_pb2.Cluster`
105105
:param cluster_pb: A cluster protobuf object.
106106
107-
:type instance: :class:`.instance.Instance>`
107+
:type instance: :class:`~google.cloud.bigtable.instance.Instance>`
108108
:param instance: The instance that owns the cluster.
109109
110110
:rtype: :class:`Cluster`

bigtable/google/cloud/bigtable/table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Table(object):
4949
:type table_id: str
5050
:param table_id: The ID of the table.
5151
52-
:type instance: :class:`Instance <.instance.Instance>`
52+
:type instance: :class:`~google.cloud.bigtable.instance.Instance`
5353
:param instance: The instance that owns the table.
5454
"""
5555

datastore/google/cloud/datastore/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ def get(self, key, missing=None, deferred=None, transaction=None):
253253
:param deferred: (Optional) If a list is passed, the keys returned
254254
by the backend as "deferred" will be copied into it.
255255
256-
:type transaction: :class:`~.transaction.Transaction`
256+
:type transaction:
257+
:class:`~google.cloud.datastore.transaction.Transaction`
257258
:param transaction: (Optional) Transaction to use for read consistency.
258259
If not passed, uses current transaction, if set.
259260
@@ -281,7 +282,8 @@ def get_multi(self, keys, missing=None, deferred=None, transaction=None):
281282
by the backend as "deferred" will be copied into it.
282283
If the list is not empty, an error will occur.
283284
284-
:type transaction: :class:`~.transaction.Transaction`
285+
:type transaction:
286+
:class:`~google.cloud.datastore.transaction.Transaction`
285287
:param transaction: (Optional) Transaction to use for read consistency.
286288
If not passed, uses current transaction, if set.
287289

docs/index.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,32 @@
197197
runtimeconfig-config
198198
runtimeconfig-variable
199199

200+
.. toctree::
201+
:maxdepth: 0
202+
:hidden:
203+
:caption: Spanner
204+
205+
spanner-usage
206+
spanner-client-usage
207+
spanner-instance-usage
208+
spanner-database-usage
209+
spanner-session-crud-usage
210+
spanner-session-implicit-txn-usage
211+
spanner-session-pool-usage
212+
spanner-batch-usage
213+
spanner-snapshot-usage
214+
spanner-transaction-usage
215+
216+
spanner-client-api
217+
spanner-instance-api
218+
spanner-database-api
219+
spanner-session-api
220+
spanner-keyset-api
221+
spanner-snapshot-api
222+
spanner-batch-api
223+
spanner-transaction-api
224+
spanner-streamed-api
225+
200226
.. toctree::
201227
:maxdepth: 0
202228
:hidden:

docs/spanner-batch-api.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Batch API
2+
=========
3+
4+
.. automodule:: google.cloud.spanner.batch
5+
:members:
6+
:show-inheritance:
7+
8+

docs/spanner-batch-usage.rst

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
Batching Modifications
2+
######################
3+
4+
A :class:`~google.cloud.spanner.batch.Batch` represents a set of data
5+
modification operations to be performed on tables in a dataset. Use of a
6+
``Batch`` does not require creating an explicit
7+
:class:`~google.cloud.spanner.snapshot.Snapshot` or
8+
:class:`~google.cloud.spanner.transaction.Transaction`. Until
9+
:meth:`~google.cloud.spanner.batch.Batch.commit` is called on a ``Batch``,
10+
no changes are propagated to the back-end.
11+
12+
13+
Starting a Batch
14+
----------------
15+
16+
.. code:: python
17+
18+
batch = session.batch()
19+
20+
21+
Inserting records using a Batch
22+
-------------------------------
23+
24+
:meth:`Batch.insert` adds one or more new records to a table. Fails if
25+
any of the records already exists.
26+
27+
.. code:: python
28+
29+
batch.insert(
30+
'citizens', columns=['email', 'first_name', 'last_name', 'age'],
31+
values=[
32+
['phred@exammple.com', 'Phred', 'Phlyntstone', 32],
33+
['bharney@example.com', 'Bharney', 'Rhubble', 31],
34+
])
35+
36+
.. note::
37+
38+
Ensure that data being sent for ``STRING`` columns uses a text string
39+
(``str`` in Python 3; ``unicode`` in Python 2).
40+
41+
Additionally, if you are writing data intended for a ``BYTES`` column, you
42+
must base64 encode it.
43+
44+
45+
Update records using a Batch
46+
-------------------------------
47+
48+
:meth:`Batch.update` updates one or more existing records in a table. Fails
49+
if any of the records does not already exist.
50+
51+
.. code:: python
52+
53+
batch.update(
54+
'citizens', columns=['email', 'age'],
55+
values=[
56+
['phred@exammple.com', 33],
57+
['bharney@example.com', 32],
58+
])
59+
60+
.. note::
61+
62+
Ensure that data being sent for ``STRING`` columns uses a text string
63+
(``str`` in Python 3; ``unicode`` in Python 2).
64+
65+
Additionally, if you are writing data intended for a ``BYTES`` column, you
66+
must base64 encode it.
67+
68+
69+
Insert or update records using a Batch
70+
--------------------------------------
71+
72+
:meth:`Batch.insert_or_update` inserts *or* updates one or more records in a
73+
table. Existing rows have values for the supplied columns overwritten; other
74+
column values are preserved.
75+
76+
.. code:: python
77+
78+
batch.insert_or_update(
79+
'citizens', columns=['email', 'first_name', 'last_name', 'age'],
80+
values=[
81+
['phred@exammple.com', 'Phred', 'Phlyntstone', 31],
82+
['wylma@example.com', 'Wylma', 'Phlyntstone', 29],
83+
])
84+
85+
.. note::
86+
87+
Ensure that data being sent for ``STRING`` columns uses a text string
88+
(``str`` in Python 3; ``unicode`` in Python 2).
89+
90+
Additionally, if you are writing data intended for a ``BYTES`` column, you
91+
must base64 encode it.
92+
93+
94+
Replace records using a Batch
95+
-----------------------------
96+
97+
:meth:`Batch.replace` inserts *or* updates one or more records in a
98+
table. Existing rows have values for the supplied columns overwritten; other
99+
column values are set to null.
100+
101+
.. code:: python
102+
103+
batch.replace(
104+
'citizens', columns=['email', 'first_name', 'last_name', 'age'],
105+
values=[
106+
['bharney@example.com', 'Bharney', 'Rhubble', 30],
107+
['bhettye@example.com', 'Bhettye', 'Rhubble', 30],
108+
])
109+
110+
.. note::
111+
112+
Ensure that data being sent for ``STRING`` columns uses a text string
113+
(``str`` in Python 3; ``unicode`` in Python 2).
114+
115+
Additionally, if you are writing data intended for a ``BYTES`` column, you
116+
must base64 encode it.
117+
118+
119+
Delete records using a Batch
120+
----------------------------
121+
122+
:meth:`Batch.delete` removes one or more records from a table. Non-existent
123+
rows do not cause errors.
124+
125+
.. code:: python
126+
127+
batch.delete('citizens',
128+
keyset['bharney@example.com', 'nonesuch@example.com'])
129+
130+
131+
Commit changes for a Batch
132+
--------------------------
133+
134+
After describing the modifications to be made to table data via the
135+
:meth:`Batch.insert`, :meth:`Batch.update`, :meth:`Batch.insert_or_update`,
136+
:meth:`Batch.replace`, and :meth:`Batch.delete` methods above, send them to
137+
the back-end by calling :meth:`Batch.commit`, which makes the ``Commit``
138+
API call.
139+
140+
.. code:: python
141+
142+
batch.commit()
143+
144+
145+
Use a Batch as a Context Manager
146+
--------------------------------
147+
148+
Rather than calling :meth:`Batch.commit` manually, you can use the
149+
:class:`Batch` instance as a context manager, and have it called automatically
150+
if the ``with`` block exits without raising an exception.
151+
152+
.. code:: python
153+
154+
with session.batch() as batch:
155+
156+
batch.insert(
157+
'citizens', columns=['email', 'first_name', 'last_name', 'age'],
158+
values=[
159+
['phred@exammple.com', 'Phred', 'Phlyntstone', 32],
160+
['bharney@example.com', 'Bharney', 'Rhubble', 31],
161+
])
162+
163+
batch.update(
164+
'citizens', columns=['email', 'age'],
165+
values=[
166+
['phred@exammple.com', 33],
167+
['bharney@example.com', 32],
168+
])
169+
170+
...
171+
172+
batch.delete('citizens',
173+
keyset['bharney@example.com', 'nonesuch@example.com'])
174+
175+
176+
Next Step
177+
---------
178+
179+
Next, learn about :doc:`spanner-snapshot-usage`.

docs/spanner-client-api.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Spanner Client
2+
==============
3+
4+
.. automodule:: google.cloud.spanner.client
5+
:members:
6+
:show-inheritance:
7+

0 commit comments

Comments
 (0)