diff --git a/docs/spanner/gapic/v1/api.rst b/docs/spanner/gapic/v1/api.rst new file mode 100644 index 000000000000..79e4835f2222 --- /dev/null +++ b/docs/spanner/gapic/v1/api.rst @@ -0,0 +1,6 @@ +Spanner Client API +================== + +.. automodule:: google.cloud.spanner_v1 + :members: + :inherited-members: diff --git a/docs/spanner/gapic/v1/transactions.rst b/docs/spanner/gapic/v1/transactions.rst new file mode 100644 index 000000000000..d34af43b4ae9 --- /dev/null +++ b/docs/spanner/gapic/v1/transactions.rst @@ -0,0 +1,241 @@ +.. + This page is pulled from the TransactionOption type, where this entire + kaboodle is auto-generated. Sphinx does not particularly appreciate + entire narrative documentation, complete with headers, in an arbitrary + class docstring, and complains about this, so I (lukesneeringer@) + manually copied it over here. + + This should probably be updated when the Spanner code is re-generated. + This will be easy to remember because the source that needs to be copied + will be dropped in transaction_pb2.py and Sphinx will complain loudly + about it. + + Internal Google ticket: b/65243734 + +:orphan: + +.. _spanner-txn: + +Transactions +============ + +Each session can have at most one active transaction at a time. After +the active transaction is completed, the session can immediately be +re-used for the next transaction. It is not necessary to create a new +session for each transaction. + +Transaction Modes +================= + +Cloud Spanner supports two transaction modes: + +1. Locking read-write. This type of transaction is the only way to write + data into Cloud Spanner. These transactions rely on pessimistic + locking and, if necessary, two-phase commit. Locking read-write + transactions may abort, requiring the application to retry. + +2. Snapshot read-only. This transaction type provides guaranteed + consistency across several reads, but does not allow writes. Snapshot + read-only transactions can be configured to read at timestamps in the + past. Snapshot read-only transactions do not need to be committed. + +For transactions that only read, snapshot read-only transactions provide +simpler semantics and are almost always faster. In particular, read-only +transactions do not take locks, so they do not conflict with read-write +transactions. As a consequence of not taking locks, they also do not +abort, so retry loops are not needed. + +Transactions may only read/write data in a single database. They may, +however, read/write data in different tables within that database. + +Locking Read-Write Transactions +------------------------------- + +Locking transactions may be used to atomically read-modify-write data +anywhere in a database. This type of transaction is externally +consistent. + +Clients should attempt to minimize the amount of time a transaction is +active. Faster transactions commit with higher probability and cause +less contention. Cloud Spanner attempts to keep read locks active as +long as the transaction continues to do reads, and the transaction has +not been terminated by [Commit][google.spanner.v1.Spanner.Commit] or +[Rollback][google.spanner.v1.Spanner.Rollback]. Long periods of +inactivity at the client may cause Cloud Spanner to release a +transaction's locks and abort it. + +Reads performed within a transaction acquire locks on the data being +read. Writes can only be done at commit time, after all reads have been +completed. Conceptually, a read-write transaction consists of zero or +more reads or SQL queries followed by +[Commit][google.spanner.v1.Spanner.Commit]. At any time before +[Commit][google.spanner.v1.Spanner.Commit], the client can send a +[Rollback][google.spanner.v1.Spanner.Rollback] request to abort the +transaction. + +Semantics +~~~~~~~~~ + +Cloud Spanner can commit the transaction if all read locks it acquired +are still valid at commit time, and it is able to acquire write locks +for all writes. Cloud Spanner can abort the transaction for any reason. +If a commit attempt returns ``ABORTED``, Cloud Spanner guarantees that +the transaction has not modified any user data in Cloud Spanner. + +Unless the transaction commits, Cloud Spanner makes no guarantees about +how long the transaction's locks were held for. It is an error to use +Cloud Spanner locks for any sort of mutual exclusion other than between +Cloud Spanner transactions themselves. + +Retrying Aborted Transactions +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +When a transaction aborts, the application can choose to retry the whole +transaction again. To maximize the chances of successfully committing +the retry, the client should execute the retry in the same session as +the original attempt. The original session's lock priority increases +with each consecutive abort, meaning that each attempt has a slightly +better chance of success than the previous. + +Under some circumstances (e.g., many transactions attempting to modify +the same row(s)), a transaction can abort many times in a short period +before successfully committing. Thus, it is not a good idea to cap the +number of retries a transaction can attempt; instead, it is better to +limit the total amount of wall time spent retrying. + +Idle Transactions +~~~~~~~~~~~~~~~~~ + +A transaction is considered idle if it has no outstanding reads or SQL +queries and has not started a read or SQL query within the last 10 +seconds. Idle transactions can be aborted by Cloud Spanner so that they +don't hold on to locks indefinitely. In that case, the commit will fail +with error ``ABORTED``. + +If this behavior is undesirable, periodically executing a simple SQL +query in the transaction (e.g., ``SELECT 1``) prevents the transaction +from becoming idle. + +Snapshot Read-Only Transactions +------------------------------- + +Snapshot read-only transactions provides a simpler method than locking +read-write transactions for doing several consistent reads. However, +this type of transaction does not support writes. + +Snapshot transactions do not take locks. Instead, they work by choosing +a Cloud Spanner timestamp, then executing all reads at that timestamp. +Since they do not acquire locks, they do not block concurrent read-write +transactions. + +Unlike locking read-write transactions, snapshot read-only transactions +never abort. They can fail if the chosen read timestamp is garbage +collected; however, the default garbage collection policy is generous +enough that most applications do not need to worry about this in +practice. + +Snapshot read-only transactions do not need to call +[Commit][google.spanner.v1.Spanner.Commit] or +[Rollback][google.spanner.v1.Spanner.Rollback] (and in fact are not +permitted to do so). + +To execute a snapshot transaction, the client specifies a timestamp +bound, which tells Cloud Spanner how to choose a read timestamp. + +The types of timestamp bound are: + +- Strong (the default). +- Bounded staleness. +- Exact staleness. + +If the Cloud Spanner database to be read is geographically distributed, +stale read-only transactions can execute more quickly than strong or +read-write transaction, because they are able to execute far from the +leader replica. + +Each type of timestamp bound is discussed in detail below. + +Strong +~~~~~~ + +Strong reads are guaranteed to see the effects of all transactions that +have committed before the start of the read. Furthermore, all rows +yielded by a single read are consistent with each other -- if any part +of the read observes a transaction, all parts of the read see the +transaction. + +Strong reads are not repeatable: two consecutive strong read-only +transactions might return inconsistent results if there are concurrent +writes. If consistency across reads is required, the reads should be +executed within a transaction or at an exact read timestamp. + +See +[TransactionOptions.ReadOnly.strong][google.spanner.v1.TransactionOptions.ReadOnly.strong]. + +Exact Staleness +~~~~~~~~~~~~~~~ + +These timestamp bounds execute reads at a user-specified timestamp. +Reads at a timestamp are guaranteed to see a consistent prefix of the +global transaction history: they observe modifications done by all +transactions with a commit timestamp <= the read timestamp, and observe +none of the modifications done by transactions with a larger commit +timestamp. They will block until all conflicting transactions that may +be assigned commit timestamps <= the read timestamp have finished. + +The timestamp can either be expressed as an absolute Cloud Spanner +commit timestamp or a staleness relative to the current time. + +These modes do not require a "negotiation phase" to pick a timestamp. As +a result, they execute slightly faster than the equivalent boundedly +stale concurrency modes. On the other hand, boundedly stale reads +usually return fresher results. + +See +[TransactionOptions.ReadOnly.read\_timestamp][google.spanner.v1.TransactionOptions.ReadOnly.read\_timestamp] +and +[TransactionOptions.ReadOnly.exact\_staleness][google.spanner.v1.TransactionOptions.ReadOnly.exact\_staleness]. + +Bounded Staleness +~~~~~~~~~~~~~~~~~ + +Bounded staleness modes allow Cloud Spanner to pick the read timestamp, +subject to a user-provided staleness bound. Cloud Spanner chooses the +newest timestamp within the staleness bound that allows execution of the +reads at the closest available replica without blocking. + +All rows yielded are consistent with each other -- if any part of the +read observes a transaction, all parts of the read see the transaction. +Boundedly stale reads are not repeatable: two stale reads, even if they +use the same staleness bound, can execute at different timestamps and +thus return inconsistent results. + +Boundedly stale reads execute in two phases: the first phase negotiates +a timestamp among all replicas needed to serve the read. In the second +phase, reads are executed at the negotiated timestamp. + +As a result of the two phase execution, bounded staleness reads are +usually a little slower than comparable exact staleness reads. However, +they are typically able to return fresher results, and are more likely +to execute at the closest replica. + +Because the timestamp negotiation requires up-front knowledge of which +rows will be read, it can only be used with single-use read-only +transactions. + +See +[TransactionOptions.ReadOnly.max\_staleness][google.spanner.v1.TransactionOptions.ReadOnly.max\_staleness] +and +[TransactionOptions.ReadOnly.min\_read\_timestamp][google.spanner.v1.TransactionOptions.ReadOnly.min\_read\_timestamp]. + +Old Read Timestamps and Garbage Collection +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Cloud Spanner continuously garbage collects deleted and overwritten data +in the background to reclaim storage space. This process is known as +"version GC". By default, version GC reclaims versions after they are +one hour old. Because of this, Cloud Spanner cannot perform reads at +read timestamps more than one hour in the past. This restriction also +applies to in-progress reads and/or SQL queries whose timestamp become +too old while executing. Reads and SQL queries with too-old read +timestamps fail with the error ``FAILED_PRECONDITION``. diff --git a/docs/spanner/gapic/v1/types.rst b/docs/spanner/gapic/v1/types.rst new file mode 100644 index 000000000000..28956e60c769 --- /dev/null +++ b/docs/spanner/gapic/v1/types.rst @@ -0,0 +1,5 @@ +Spanner Client Types +=================================== + +.. automodule:: google.cloud.spanner_v1.types + :members: diff --git a/docs/spanner/transaction-usage.rst b/docs/spanner/transaction-usage.rst index 0577bc2093b8..85eeccb9555d 100644 --- a/docs/spanner/transaction-usage.rst +++ b/docs/spanner/transaction-usage.rst @@ -5,6 +5,9 @@ A :class:`~google.cloud.spanner.transaction.Transaction` represents a transaction: when the transaction commits, it will send any accumulated mutations to the server. +To understand more about how transactions work, visit :ref:`spanner-txn`. +To learn more about how to use them in the Python client, continue reading. + Begin a Transaction ------------------- diff --git a/docs/spanner/usage.rst b/docs/spanner/usage.rst index e63c8b11a482..734813ab7940 100644 --- a/docs/spanner/usage.rst +++ b/docs/spanner/usage.rst @@ -23,6 +23,8 @@ Spanner transaction-api streamed-api + gapic/v1/api + gapic/v1/types gapic/v1/admin_database_api gapic/v1/admin_database_types gapic/v1/admin_instance_api diff --git a/spanner/google/cloud/spanner/_helpers.py b/spanner/google/cloud/spanner/_helpers.py index ef3d2530287c..1ec019dd7737 100644 --- a/spanner/google/cloud/spanner/_helpers.py +++ b/spanner/google/cloud/spanner/_helpers.py @@ -22,7 +22,7 @@ from google.gax import CallOptions from google.protobuf.struct_pb2 import ListValue from google.protobuf.struct_pb2 import Value -from google.cloud.proto.spanner.v1 import type_pb2 +from google.cloud.spanner_v1.proto import type_pb2 from google.cloud._helpers import _date_from_iso8601_date from google.cloud._helpers import _datetime_to_rfc3339 @@ -187,7 +187,7 @@ def _parse_value_pb(value_pb, field_type): :type value_pb: :class:`~google.protobuf.struct_pb2.Value` :param value_pb: protobuf to convert - :type field_type: :class:`~google.cloud.proto.spanner.v1.type_pb2.Type` + :type field_type: :class:`~google.cloud.spanner_v1.proto.type_pb2.Type` :param field_type: type code for the value :rtype: varies on field_type @@ -233,7 +233,7 @@ def _parse_list_value_pbs(rows, row_type): :type rows: list of :class:`~google.protobuf.struct_pb2.ListValue` :param rows: row data returned from a read/query - :type row_type: :class:`~google.cloud.proto.spanner.v1.type_pb2.StructType` + :type row_type: :class:`~google.cloud.spanner_v1.proto.type_pb2.StructType` :param row_type: row schema specification :rtype: list of list of cell data diff --git a/spanner/google/cloud/spanner/batch.py b/spanner/google/cloud/spanner/batch.py index 552d7960b1ab..7ce25d99a0ac 100644 --- a/spanner/google/cloud/spanner/batch.py +++ b/spanner/google/cloud/spanner/batch.py @@ -14,8 +14,8 @@ """Context manager for Cloud Spanner batched writes.""" -from google.cloud.proto.spanner.v1.mutation_pb2 import Mutation -from google.cloud.proto.spanner.v1.transaction_pb2 import TransactionOptions +from google.cloud.spanner_v1.proto.mutation_pb2 import Mutation +from google.cloud.spanner_v1.proto.transaction_pb2 import TransactionOptions # pylint: disable=ungrouped-imports from google.cloud._helpers import _pb_timestamp_to_datetime @@ -182,7 +182,7 @@ def _make_write_pb(table, columns, values): :type values: list of lists :param values: Values to be modified. - :rtype: :class:`google.cloud.proto.spanner.v1.mutation_pb2.Mutation.Write` + :rtype: :class:`google.cloud.spanner_v1.proto.mutation_pb2.Mutation.Write` :returns: Write protobuf """ return Mutation.Write( diff --git a/spanner/google/cloud/spanner/database.py b/spanner/google/cloud/spanner/database.py index 728acadc6137..abf0b3a1579c 100644 --- a/spanner/google/cloud/spanner/database.py +++ b/spanner/google/cloud/spanner/database.py @@ -20,7 +20,7 @@ import google.auth.credentials from google.gax.errors import GaxError from google.gax.grpc import exc_to_code -from google.cloud.gapic.spanner.v1.spanner_client import SpannerClient +from google.cloud.spanner_v1.gapic.spanner_client import SpannerClient from grpc import StatusCode import six diff --git a/spanner/google/cloud/spanner/keyset.py b/spanner/google/cloud/spanner/keyset.py index fe0d5cd1485d..89e95fc26d89 100644 --- a/spanner/google/cloud/spanner/keyset.py +++ b/spanner/google/cloud/spanner/keyset.py @@ -14,8 +14,8 @@ """Wrap representation of Spanner keys / ranges.""" -from google.cloud.proto.spanner.v1.keys_pb2 import KeyRange as KeyRangePB -from google.cloud.proto.spanner.v1.keys_pb2 import KeySet as KeySetPB +from google.cloud.spanner_v1.proto.keys_pb2 import KeyRange as KeyRangePB +from google.cloud.spanner_v1.proto.keys_pb2 import KeySet as KeySetPB from google.cloud.spanner._helpers import _make_list_value_pb from google.cloud.spanner._helpers import _make_list_value_pbs @@ -55,7 +55,7 @@ def __init__(self, start_open=None, start_closed=None, def to_pb(self): """Construct a KeyRange protobuf. - :rtype: :class:`~google.cloud.proto.spanner.v1.keys_pb2.KeyRange` + :rtype: :class:`~google.cloud.spanner_v1.proto.keys_pb2.KeyRange` :returns: protobuf corresponding to this instance. """ kwargs = {} @@ -97,7 +97,7 @@ def __init__(self, keys=(), ranges=(), all_=False): def to_pb(self): """Construct a KeySet protobuf. - :rtype: :class:`~google.cloud.proto.spanner.v1.keys_pb2.KeySet` + :rtype: :class:`~google.cloud.spanner_v1.proto.keys_pb2.KeySet` :returns: protobuf corresponding to this instance. """ if self.all_: diff --git a/spanner/google/cloud/spanner/snapshot.py b/spanner/google/cloud/spanner/snapshot.py index 89bd840000dc..33c29411c010 100644 --- a/spanner/google/cloud/spanner/snapshot.py +++ b/spanner/google/cloud/spanner/snapshot.py @@ -15,8 +15,8 @@ """Model a set of read-only queries to a database as a snapshot.""" from google.protobuf.struct_pb2 import Struct -from google.cloud.proto.spanner.v1.transaction_pb2 import TransactionOptions -from google.cloud.proto.spanner.v1.transaction_pb2 import TransactionSelector +from google.cloud.spanner_v1.proto.transaction_pb2 import TransactionOptions +from google.cloud.spanner_v1.proto.transaction_pb2 import TransactionSelector from google.cloud._helpers import _datetime_to_pb_timestamp from google.cloud._helpers import _timedelta_to_duration_pb @@ -118,7 +118,7 @@ def execute_sql(self, sql, params=None, param_types=None, query_mode=None, required if parameters are passed. :type query_mode: - :class:`google.cloud.proto.spanner.v1.ExecuteSqlRequest.QueryMode` + :class:`google.cloud.spanner_v1.proto.ExecuteSqlRequest.QueryMode` :param query_mode: Mode governing return of results / query plan. See https://cloud.google.com/spanner/reference/rpc/google.spanner.v1#google.spanner.v1.ExecuteSqlRequest.QueryMode1 diff --git a/spanner/google/cloud/spanner/streamed.py b/spanner/google/cloud/spanner/streamed.py index c7d950d766d7..66acc1b055c6 100644 --- a/spanner/google/cloud/spanner/streamed.py +++ b/spanner/google/cloud/spanner/streamed.py @@ -17,7 +17,7 @@ from google.protobuf.struct_pb2 import ListValue from google.protobuf.struct_pb2 import Value from google.cloud import exceptions -from google.cloud.proto.spanner.v1 import type_pb2 +from google.cloud.spanner_v1.proto import type_pb2 import six # pylint: disable=ungrouped-imports @@ -31,7 +31,7 @@ class StreamedResultSet(object): :type response_iterator: :param response_iterator: Iterator yielding - :class:`google.cloud.proto.spanner.v1.result_set_pb2.PartialResultSet` + :class:`google.cloud.spanner_v1.proto.result_set_pb2.PartialResultSet` instances. :type source: :class:`~google.cloud.spanner.snapshot.Snapshot` @@ -61,7 +61,7 @@ def rows(self): def fields(self): """Field descriptors for result set columns. - :rtype: list of :class:`~google.cloud.proto.spanner.v1.type_pb2.Field` + :rtype: list of :class:`~google.cloud.spanner_v1.proto.type_pb2.Field` :returns: list of fields describing column names / types. """ return self._metadata.row_type.fields @@ -80,7 +80,7 @@ def stats(self): """Result set statistics :rtype: - :class:`~google.cloud.proto.spanner.v1.result_set_pb2.ResultSetStats` + :class:`~google.cloud.spanner_v1.proto.result_set_pb2.ResultSetStats` :returns: structure describing status about the response """ return self._stats @@ -222,7 +222,7 @@ class Unmergeable(ValueError): :type rhs: :class:`google.protobuf.struct_pb2.Value` :param rhs: remaining value to be merged - :type type_: :class:`google.cloud.proto.spanner.v1.type_pb2.Type` + :type type_: :class:`google.cloud.spanner_v1.proto.type_pb2.Type` :param type_: field type of values being merged """ def __init__(self, lhs, rhs, type_): diff --git a/spanner/google/cloud/spanner/transaction.py b/spanner/google/cloud/spanner/transaction.py index 7ac4251dea7d..c6a8e639dce7 100644 --- a/spanner/google/cloud/spanner/transaction.py +++ b/spanner/google/cloud/spanner/transaction.py @@ -14,8 +14,8 @@ """Spanner read-write transaction support.""" -from google.cloud.proto.spanner.v1.transaction_pb2 import TransactionSelector -from google.cloud.proto.spanner.v1.transaction_pb2 import TransactionOptions +from google.cloud.spanner_v1.proto.transaction_pb2 import TransactionSelector +from google.cloud.spanner_v1.proto.transaction_pb2 import TransactionOptions from google.cloud._helpers import _pb_timestamp_to_datetime from google.cloud.spanner._helpers import _options_with_prefix diff --git a/spanner/google/cloud/spanner/types.py b/spanner/google/cloud/spanner/types.py index 9e22da94c51f..2930940ef143 100644 --- a/spanner/google/cloud/spanner/types.py +++ b/spanner/google/cloud/spanner/types.py @@ -14,7 +14,7 @@ """Types exported from this package.""" -from google.cloud.proto.spanner.v1 import type_pb2 +from google.cloud.spanner_v1.proto import type_pb2 # Scalar paramter types diff --git a/spanner/google/cloud/spanner_v1/__init__.py b/spanner/google/cloud/spanner_v1/__init__.py new file mode 100644 index 000000000000..732ad4de3b21 --- /dev/null +++ b/spanner/google/cloud/spanner_v1/__init__.py @@ -0,0 +1,30 @@ +# Copyright 2017, Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import absolute_import + +from google.cloud.spanner_v1 import types +from google.cloud.spanner_v1.gapic import enums +from google.cloud.spanner_v1.gapic import spanner_client + + +class SpannerClient(spanner_client.SpannerClient): + __doc__ = spanner_client.SpannerClient.__doc__ + enums = enums + + +__all__ = ( + 'enums', + 'types', + 'SpannerClient', ) diff --git a/spanner/google/cloud/spanner_v1/gapic/__init__.py b/spanner/google/cloud/spanner_v1/gapic/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/spanner/google/cloud/spanner_v1/gapic/enums.py b/spanner/google/cloud/spanner_v1/gapic/enums.py new file mode 100644 index 000000000000..fa318193486f --- /dev/null +++ b/spanner/google/cloud/spanner_v1/gapic/enums.py @@ -0,0 +1,105 @@ +# Copyright 2017, Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Wrappers for protocol buffer enum types.""" + + +class NullValue(object): + """ + ``NullValue`` is a singleton enumeration to represent the null value for the + ``Value`` type union. + + The JSON representation for ``NullValue`` is JSON ``null``. + + Attributes: + NULL_VALUE (int): Null value. + """ + NULL_VALUE = 0 + + +class TypeCode(object): + """ + ``TypeCode`` is used as part of ``Type`` to + indicate the type of a Cloud Spanner value. + + Each legal value of a type can be encoded to or decoded from a JSON + value, using the encodings described below. All Cloud Spanner values can + be ``null``, regardless of type; ``null``s are always encoded as a JSON + ``null``. + + Attributes: + TYPE_CODE_UNSPECIFIED (int): Not specified. + BOOL (int): Encoded as JSON ``true`` or ``false``. + INT64 (int): Encoded as ``string``, in decimal format. + FLOAT64 (int): Encoded as ``number``, or the strings ``\"NaN\"``, ``\"Infinity\"``, or + ``\"-Infinity\"``. + TIMESTAMP (int): Encoded as ``string`` in RFC 3339 timestamp format. The time zone + must be present, and must be ``\"Z\"``. + DATE (int): Encoded as ``string`` in RFC 3339 date format. + STRING (int): Encoded as ``string``. + BYTES (int): Encoded as a base64-encoded ``string``, as described in RFC 4648, + section 4. + ARRAY (int): Encoded as ``list``, where the list elements are represented + according to ``array_element_type``. + STRUCT (int): Encoded as ``list``, where list element ``i`` is represented according + to [struct_type.fields[i]][google.spanner.v1.StructType.fields]. + """ + TYPE_CODE_UNSPECIFIED = 0 + BOOL = 1 + INT64 = 2 + FLOAT64 = 3 + TIMESTAMP = 4 + DATE = 5 + STRING = 6 + BYTES = 7 + ARRAY = 8 + STRUCT = 9 + + +class PlanNode(object): + class Kind(object): + """ + The kind of ``PlanNode``. Distinguishes between the two different kinds of + nodes that can appear in a query plan. + + Attributes: + KIND_UNSPECIFIED (int): Not specified. + RELATIONAL (int): Denotes a Relational operator node in the expression tree. Relational + operators represent iterative processing of rows during query execution. + For example, a ``TableScan`` operation that reads rows from a table. + SCALAR (int): Denotes a Scalar node in the expression tree. Scalar nodes represent + non-iterable entities in the query plan. For example, constants or + arithmetic operators appearing inside predicate expressions or references + to column names. + """ + KIND_UNSPECIFIED = 0 + RELATIONAL = 1 + SCALAR = 2 + + +class ExecuteSqlRequest(object): + class QueryMode(object): + """ + Mode in which the query must be processed. + + Attributes: + NORMAL (int): The default mode where only the query result, without any information + about the query plan is returned. + PLAN (int): This mode returns only the query plan, without any result rows or + execution statistics information. + PROFILE (int): This mode returns both the query plan and the execution statistics along + with the result rows. + """ + NORMAL = 0 + PLAN = 1 + PROFILE = 2 diff --git a/spanner/google/cloud/spanner_v1/gapic/spanner_client.py b/spanner/google/cloud/spanner_v1/gapic/spanner_client.py new file mode 100644 index 000000000000..8f2f4c3039b9 --- /dev/null +++ b/spanner/google/cloud/spanner_v1/gapic/spanner_client.py @@ -0,0 +1,880 @@ +# Copyright 2017, Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# EDITING INSTRUCTIONS +# This file was generated from the file +# https://github.com/google/googleapis/blob/master/google/spanner/v1/spanner.proto, +# and updates to that file get reflected here through a refresh process. +# For the short term, the refresh process will only be runnable by Google engineers. +# +# The only allowed edits are to method and file documentation. A 3-way +# merge preserves those additions if the generated source changes. +"""Accesses the google.spanner.v1 Spanner API.""" + +import collections +import json +import os +import pkg_resources +import platform + +from google.gax import api_callable +from google.gax import config +from google.gax import path_template +from google.gax.utils import oneof +import google.gax + +from google.cloud.spanner_v1.gapic import enums +from google.cloud.spanner_v1.gapic import spanner_client_config +from google.cloud.spanner_v1.proto import keys_pb2 +from google.cloud.spanner_v1.proto import mutation_pb2 +from google.cloud.spanner_v1.proto import spanner_pb2 +from google.cloud.spanner_v1.proto import transaction_pb2 +from google.protobuf import struct_pb2 + + +class SpannerClient(object): + """ + Cloud Spanner API + + The Cloud Spanner API can be used to manage sessions and execute + transactions on data stored in Cloud Spanner databases. + """ + + SERVICE_ADDRESS = 'spanner.googleapis.com' + """The default address of the service.""" + + DEFAULT_SERVICE_PORT = 443 + """The default port of the service.""" + + # The scopes needed to make gRPC calls to all of the methods defined in + # this service + _ALL_SCOPES = ( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/spanner.data', ) + + _DATABASE_PATH_TEMPLATE = path_template.PathTemplate( + 'projects/{project}/instances/{instance}/databases/{database}') + _SESSION_PATH_TEMPLATE = path_template.PathTemplate( + 'projects/{project}/instances/{instance}/databases/{database}/sessions/{session}' + ) + + @classmethod + def database_path(cls, project, instance, database): + """Returns a fully-qualified database resource name string.""" + return cls._DATABASE_PATH_TEMPLATE.render({ + 'project': project, + 'instance': instance, + 'database': database, + }) + + @classmethod + def session_path(cls, project, instance, database, session): + """Returns a fully-qualified session resource name string.""" + return cls._SESSION_PATH_TEMPLATE.render({ + 'project': project, + 'instance': instance, + 'database': database, + 'session': session, + }) + + @classmethod + def match_project_from_database_name(cls, database_name): + """Parses the project from a database resource. + + Args: + database_name (str): A fully-qualified path representing a database + resource. + + Returns: + A string representing the project. + """ + return cls._DATABASE_PATH_TEMPLATE.match(database_name).get('project') + + @classmethod + def match_instance_from_database_name(cls, database_name): + """Parses the instance from a database resource. + + Args: + database_name (str): A fully-qualified path representing a database + resource. + + Returns: + A string representing the instance. + """ + return cls._DATABASE_PATH_TEMPLATE.match(database_name).get('instance') + + @classmethod + def match_database_from_database_name(cls, database_name): + """Parses the database from a database resource. + + Args: + database_name (str): A fully-qualified path representing a database + resource. + + Returns: + A string representing the database. + """ + return cls._DATABASE_PATH_TEMPLATE.match(database_name).get('database') + + @classmethod + def match_project_from_session_name(cls, session_name): + """Parses the project from a session resource. + + Args: + session_name (str): A fully-qualified path representing a session + resource. + + Returns: + A string representing the project. + """ + return cls._SESSION_PATH_TEMPLATE.match(session_name).get('project') + + @classmethod + def match_instance_from_session_name(cls, session_name): + """Parses the instance from a session resource. + + Args: + session_name (str): A fully-qualified path representing a session + resource. + + Returns: + A string representing the instance. + """ + return cls._SESSION_PATH_TEMPLATE.match(session_name).get('instance') + + @classmethod + def match_database_from_session_name(cls, session_name): + """Parses the database from a session resource. + + Args: + session_name (str): A fully-qualified path representing a session + resource. + + Returns: + A string representing the database. + """ + return cls._SESSION_PATH_TEMPLATE.match(session_name).get('database') + + @classmethod + def match_session_from_session_name(cls, session_name): + """Parses the session from a session resource. + + Args: + session_name (str): A fully-qualified path representing a session + resource. + + Returns: + A string representing the session. + """ + return cls._SESSION_PATH_TEMPLATE.match(session_name).get('session') + + def __init__(self, + channel=None, + credentials=None, + ssl_credentials=None, + scopes=None, + client_config=None, + lib_name=None, + lib_version='', + metrics_headers=()): + """Constructor. + + Args: + channel (~grpc.Channel): A ``Channel`` instance through + which to make calls. + credentials (~google.auth.credentials.Credentials): The authorization + credentials to attach to requests. These credentials identify this + application to the service. + ssl_credentials (~grpc.ChannelCredentials): A + ``ChannelCredentials`` instance for use with an SSL-enabled + channel. + scopes (Sequence[str]): A list of OAuth2 scopes to attach to requests. + client_config (dict): + A dictionary for call options for each method. See + :func:`google.gax.construct_settings` for the structure of + this data. Falls back to the default config if not specified + or the specified config is missing data points. + lib_name (str): The API library software used for calling + the service. (Unless you are writing an API client itself, + leave this as default.) + lib_version (str): The API library software version used + for calling the service. (Unless you are writing an API client + itself, leave this as default.) + metrics_headers (dict): A dictionary of values for tracking + client library metrics. Ultimately serializes to a string + (e.g. 'foo/1.2.3 bar/3.14.1'). This argument should be + considered private. + """ + # Unless the calling application specifically requested + # OAuth scopes, request everything. + if scopes is None: + scopes = self._ALL_SCOPES + + # Initialize an empty client config, if none is set. + if client_config is None: + client_config = {} + + # Initialize metrics_headers as an ordered dictionary + # (cuts down on cardinality of the resulting string slightly). + metrics_headers = collections.OrderedDict(metrics_headers) + metrics_headers['gl-python'] = platform.python_version() + + # The library may or may not be set, depending on what is + # calling this client. Newer client libraries set the library name + # and version. + if lib_name: + metrics_headers[lib_name] = lib_version + + # Finally, track the GAPIC package version. + metrics_headers['gapic'] = pkg_resources.get_distribution( + 'google-cloud-spanner', ).version + + # Load the configuration defaults. + defaults = api_callable.construct_settings( + 'google.spanner.v1.Spanner', + spanner_client_config.config, + client_config, + config.STATUS_CODE_NAMES, + metrics_headers=metrics_headers, ) + self.spanner_stub = config.create_stub( + spanner_pb2.SpannerStub, + channel=channel, + service_path=self.SERVICE_ADDRESS, + service_port=self.DEFAULT_SERVICE_PORT, + credentials=credentials, + scopes=scopes, + ssl_credentials=ssl_credentials) + + self._create_session = api_callable.create_api_call( + self.spanner_stub.CreateSession, + settings=defaults['create_session']) + self._get_session = api_callable.create_api_call( + self.spanner_stub.GetSession, settings=defaults['get_session']) + self._delete_session = api_callable.create_api_call( + self.spanner_stub.DeleteSession, + settings=defaults['delete_session']) + self._execute_sql = api_callable.create_api_call( + self.spanner_stub.ExecuteSql, settings=defaults['execute_sql']) + self._execute_streaming_sql = api_callable.create_api_call( + self.spanner_stub.ExecuteStreamingSql, + settings=defaults['execute_streaming_sql']) + self._read = api_callable.create_api_call( + self.spanner_stub.Read, settings=defaults['read']) + self._streaming_read = api_callable.create_api_call( + self.spanner_stub.StreamingRead, + settings=defaults['streaming_read']) + self._begin_transaction = api_callable.create_api_call( + self.spanner_stub.BeginTransaction, + settings=defaults['begin_transaction']) + self._commit = api_callable.create_api_call( + self.spanner_stub.Commit, settings=defaults['commit']) + self._rollback = api_callable.create_api_call( + self.spanner_stub.Rollback, settings=defaults['rollback']) + + # Service calls + def create_session(self, database, options=None): + """ + Creates a new session. A session can be used to perform + transactions that read and/or modify data in a Cloud Spanner database. + Sessions are meant to be reused for many consecutive + transactions. + + Sessions can only execute one transaction at a time. To execute + multiple concurrent read-write/write-only transactions, create + multiple sessions. Note that standalone reads and queries use a + transaction internally, and count toward the one transaction + limit. + + Cloud Spanner limits the number of sessions that can exist at any given + time; thus, it is a good idea to delete idle and/or unneeded sessions. + Aside from explicit deletes, Cloud Spanner can delete sessions for which no + operations are sent for more than an hour. If a session is deleted, + requests to it return ``NOT_FOUND``. + + Idle sessions can be kept alive by sending a trivial SQL query + periodically, e.g., ``\"SELECT 1\"``. + + Example: + >>> from google.cloud import spanner_v1 + >>> + >>> client = spanner_v1.SpannerClient() + >>> + >>> database = client.database_path('[PROJECT]', '[INSTANCE]', '[DATABASE]') + >>> + >>> response = client.create_session(database) + + Args: + database (str): Required. The database in which the new session is created. + options (~google.gax.CallOptions): Overrides the default + settings for this call, e.g, timeout, retries etc. + + Returns: + A :class:`~google.cloud.spanner_v1.types.Session` instance. + + Raises: + :exc:`google.gax.errors.GaxError` if the RPC is aborted. + :exc:`ValueError` if the parameters are invalid. + """ + request = spanner_pb2.CreateSessionRequest(database=database) + return self._create_session(request, options) + + def get_session(self, name, options=None): + """ + Gets a session. Returns ``NOT_FOUND`` if the session does not exist. + This is mainly useful for determining whether a session is still + alive. + + Example: + >>> from google.cloud import spanner_v1 + >>> + >>> client = spanner_v1.SpannerClient() + >>> + >>> name = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', '[SESSION]') + >>> + >>> response = client.get_session(name) + + Args: + name (str): Required. The name of the session to retrieve. + options (~google.gax.CallOptions): Overrides the default + settings for this call, e.g, timeout, retries etc. + + Returns: + A :class:`~google.cloud.spanner_v1.types.Session` instance. + + Raises: + :exc:`google.gax.errors.GaxError` if the RPC is aborted. + :exc:`ValueError` if the parameters are invalid. + """ + request = spanner_pb2.GetSessionRequest(name=name) + return self._get_session(request, options) + + def delete_session(self, name, options=None): + """ + Ends a session, releasing server resources associated with it. + + Example: + >>> from google.cloud import spanner_v1 + >>> + >>> client = spanner_v1.SpannerClient() + >>> + >>> name = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', '[SESSION]') + >>> + >>> client.delete_session(name) + + Args: + name (str): Required. The name of the session to delete. + options (~google.gax.CallOptions): Overrides the default + settings for this call, e.g, timeout, retries etc. + + Raises: + :exc:`google.gax.errors.GaxError` if the RPC is aborted. + :exc:`ValueError` if the parameters are invalid. + """ + request = spanner_pb2.DeleteSessionRequest(name=name) + self._delete_session(request, options) + + def execute_sql(self, + session, + sql, + transaction=None, + params=None, + param_types=None, + resume_token=None, + query_mode=None, + options=None): + """ + Executes an SQL query, returning all rows in a single reply. This + method cannot be used to return a result set larger than 10 MiB; + if the query yields more data than that, the query fails with + a ``FAILED_PRECONDITION`` error. + + Queries inside read-write transactions might return ``ABORTED``. If + this occurs, the application should restart the transaction from + the beginning. See ``Transaction`` for more details. + + Larger result sets can be fetched in streaming fashion by calling + ``ExecuteStreamingSql`` instead. + + Example: + >>> from google.cloud import spanner_v1 + >>> + >>> client = spanner_v1.SpannerClient() + >>> + >>> session = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', '[SESSION]') + >>> sql = '' + >>> + >>> response = client.execute_sql(session, sql) + + Args: + session (str): Required. The session in which the SQL query should be performed. + sql (str): Required. The SQL query string. + transaction (Union[dict, ~google.cloud.spanner_v1.types.TransactionSelector]): The transaction to use. If none is provided, the default is a + temporary read-only transaction with strong concurrency. + If a dict is provided, it must be of the same form as the protobuf + message :class:`~google.cloud.spanner_v1.types.TransactionSelector` + params (Union[dict, ~google.cloud.spanner_v1.types.Struct]): The SQL query string can contain parameter placeholders. A parameter + placeholder consists of ``'@'`` followed by the parameter + name. Parameter names consist of any combination of letters, + numbers, and underscores. + + Parameters can appear anywhere that a literal value is expected. The same + parameter name can be used more than once, for example: + ``\"WHERE id > @msg_id AND id < @msg_id + 100\"`` + + It is an error to execute an SQL query with unbound parameters. + + Parameter values are specified using ``params``, which is a JSON + object whose keys are parameter names, and whose values are the + corresponding parameter values. + If a dict is provided, it must be of the same form as the protobuf + message :class:`~google.cloud.spanner_v1.types.Struct` + param_types (dict[str -> Union[dict, ~google.cloud.spanner_v1.types.Type]]): It is not always possible for Cloud Spanner to infer the right SQL type + from a JSON value. For example, values of type ``BYTES`` and values + of type ``STRING`` both appear in ``params`` as JSON strings. + + In these cases, ``param_types`` can be used to specify the exact + SQL type for some or all of the SQL query parameters. See the + definition of ``Type`` for more information + about SQL types. + If a dict is provided, it must be of the same form as the protobuf + message :class:`~google.cloud.spanner_v1.types.Type` + resume_token (bytes): If this request is resuming a previously interrupted SQL query + execution, ``resume_token`` should be copied from the last + ``PartialResultSet`` yielded before the interruption. Doing this + enables the new SQL query execution to resume where the last one left + off. The rest of the request parameters must exactly match the + request that yielded this token. + query_mode (~google.cloud.spanner_v1.types.QueryMode): Used to control the amount of debugging information returned in + ``ResultSetStats``. + options (~google.gax.CallOptions): Overrides the default + settings for this call, e.g, timeout, retries etc. + + Returns: + A :class:`~google.cloud.spanner_v1.types.ResultSet` instance. + + Raises: + :exc:`google.gax.errors.GaxError` if the RPC is aborted. + :exc:`ValueError` if the parameters are invalid. + """ + request = spanner_pb2.ExecuteSqlRequest( + session=session, + sql=sql, + transaction=transaction, + params=params, + param_types=param_types, + resume_token=resume_token, + query_mode=query_mode) + return self._execute_sql(request, options) + + def execute_streaming_sql(self, + session, + sql, + transaction=None, + params=None, + param_types=None, + resume_token=None, + query_mode=None, + options=None): + """ + Like ``ExecuteSql``, except returns the result + set as a stream. Unlike ``ExecuteSql``, there + is no limit on the size of the returned result set. However, no + individual row in the result set can exceed 100 MiB, and no + column value can exceed 10 MiB. + + Example: + >>> from google.cloud import spanner_v1 + >>> + >>> client = spanner_v1.SpannerClient() + >>> + >>> session = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', '[SESSION]') + >>> sql = '' + >>> + >>> for element in client.execute_streaming_sql(session, sql): + ... # process element + ... pass + + Args: + session (str): Required. The session in which the SQL query should be performed. + sql (str): Required. The SQL query string. + transaction (Union[dict, ~google.cloud.spanner_v1.types.TransactionSelector]): The transaction to use. If none is provided, the default is a + temporary read-only transaction with strong concurrency. + If a dict is provided, it must be of the same form as the protobuf + message :class:`~google.cloud.spanner_v1.types.TransactionSelector` + params (Union[dict, ~google.cloud.spanner_v1.types.Struct]): The SQL query string can contain parameter placeholders. A parameter + placeholder consists of ``'@'`` followed by the parameter + name. Parameter names consist of any combination of letters, + numbers, and underscores. + + Parameters can appear anywhere that a literal value is expected. The same + parameter name can be used more than once, for example: + ``\"WHERE id > @msg_id AND id < @msg_id + 100\"`` + + It is an error to execute an SQL query with unbound parameters. + + Parameter values are specified using ``params``, which is a JSON + object whose keys are parameter names, and whose values are the + corresponding parameter values. + If a dict is provided, it must be of the same form as the protobuf + message :class:`~google.cloud.spanner_v1.types.Struct` + param_types (dict[str -> Union[dict, ~google.cloud.spanner_v1.types.Type]]): It is not always possible for Cloud Spanner to infer the right SQL type + from a JSON value. For example, values of type ``BYTES`` and values + of type ``STRING`` both appear in ``params`` as JSON strings. + + In these cases, ``param_types`` can be used to specify the exact + SQL type for some or all of the SQL query parameters. See the + definition of ``Type`` for more information + about SQL types. + If a dict is provided, it must be of the same form as the protobuf + message :class:`~google.cloud.spanner_v1.types.Type` + resume_token (bytes): If this request is resuming a previously interrupted SQL query + execution, ``resume_token`` should be copied from the last + ``PartialResultSet`` yielded before the interruption. Doing this + enables the new SQL query execution to resume where the last one left + off. The rest of the request parameters must exactly match the + request that yielded this token. + query_mode (~google.cloud.spanner_v1.types.QueryMode): Used to control the amount of debugging information returned in + ``ResultSetStats``. + options (~google.gax.CallOptions): Overrides the default + settings for this call, e.g, timeout, retries etc. + + Returns: + Iterable[~google.cloud.spanner_v1.types.PartialResultSet]. + + Raises: + :exc:`google.gax.errors.GaxError` if the RPC is aborted. + :exc:`ValueError` if the parameters are invalid. + """ + request = spanner_pb2.ExecuteSqlRequest( + session=session, + sql=sql, + transaction=transaction, + params=params, + param_types=param_types, + resume_token=resume_token, + query_mode=query_mode) + return self._execute_streaming_sql(request, options) + + def read(self, + session, + table, + columns, + key_set, + transaction=None, + index=None, + limit=None, + resume_token=None, + options=None): + """ + Reads rows from the database using key lookups and scans, as a + simple key/value style alternative to + ``ExecuteSql``. This method cannot be used to + return a result set larger than 10 MiB; if the read matches more + data than that, the read fails with a ``FAILED_PRECONDITION`` + error. + + Reads inside read-write transactions might return ``ABORTED``. If + this occurs, the application should restart the transaction from + the beginning. See ``Transaction`` for more details. + + Larger result sets can be yielded in streaming fashion by calling + ``StreamingRead`` instead. + + Example: + >>> from google.cloud import spanner_v1 + >>> + >>> client = spanner_v1.SpannerClient() + >>> + >>> session = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', '[SESSION]') + >>> table = '' + >>> columns = [] + >>> key_set = {} + >>> + >>> response = client.read(session, table, columns, key_set) + + Args: + session (str): Required. The session in which the read should be performed. + table (str): Required. The name of the table in the database to be read. + columns (list[str]): The columns of ``table`` to be returned for each row matching + this request. + key_set (Union[dict, ~google.cloud.spanner_v1.types.KeySet]): Required. ``key_set`` identifies the rows to be yielded. ``key_set`` names the + primary keys of the rows in ``table`` to be yielded, unless ``index`` + is present. If ``index`` is present, then ``key_set`` instead names + index keys in ``index``. + + Rows are yielded in table primary key order (if ``index`` is empty) + or index key order (if ``index`` is non-empty). + + It is not an error for the ``key_set`` to name rows that do not + exist in the database. Read yields nothing for nonexistent rows. + If a dict is provided, it must be of the same form as the protobuf + message :class:`~google.cloud.spanner_v1.types.KeySet` + transaction (Union[dict, ~google.cloud.spanner_v1.types.TransactionSelector]): The transaction to use. If none is provided, the default is a + temporary read-only transaction with strong concurrency. + If a dict is provided, it must be of the same form as the protobuf + message :class:`~google.cloud.spanner_v1.types.TransactionSelector` + index (str): If non-empty, the name of an index on ``table``. This index is + used instead of the table primary key when interpreting ``key_set`` + and sorting result rows. See ``key_set`` for further information. + limit (long): If greater than zero, only the first ``limit`` rows are yielded. If ``limit`` + is zero, the default is no limit. + resume_token (bytes): If this request is resuming a previously interrupted read, + ``resume_token`` should be copied from the last + ``PartialResultSet`` yielded before the interruption. Doing this + enables the new read to resume where the last read left off. The + rest of the request parameters must exactly match the request + that yielded this token. + options (~google.gax.CallOptions): Overrides the default + settings for this call, e.g, timeout, retries etc. + + Returns: + A :class:`~google.cloud.spanner_v1.types.ResultSet` instance. + + Raises: + :exc:`google.gax.errors.GaxError` if the RPC is aborted. + :exc:`ValueError` if the parameters are invalid. + """ + request = spanner_pb2.ReadRequest( + session=session, + table=table, + columns=columns, + key_set=key_set, + transaction=transaction, + index=index, + limit=limit, + resume_token=resume_token) + return self._read(request, options) + + def streaming_read(self, + session, + table, + columns, + key_set, + transaction=None, + index=None, + limit=None, + resume_token=None, + options=None): + """ + Like ``Read``, except returns the result set as a + stream. Unlike ``Read``, there is no limit on the + size of the returned result set. However, no individual row in + the result set can exceed 100 MiB, and no column value can exceed + 10 MiB. + + Example: + >>> from google.cloud import spanner_v1 + >>> + >>> client = spanner_v1.SpannerClient() + >>> + >>> session = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', '[SESSION]') + >>> table = '' + >>> columns = [] + >>> key_set = {} + >>> + >>> for element in client.streaming_read(session, table, columns, key_set): + ... # process element + ... pass + + Args: + session (str): Required. The session in which the read should be performed. + table (str): Required. The name of the table in the database to be read. + columns (list[str]): The columns of ``table`` to be returned for each row matching + this request. + key_set (Union[dict, ~google.cloud.spanner_v1.types.KeySet]): Required. ``key_set`` identifies the rows to be yielded. ``key_set`` names the + primary keys of the rows in ``table`` to be yielded, unless ``index`` + is present. If ``index`` is present, then ``key_set`` instead names + index keys in ``index``. + + Rows are yielded in table primary key order (if ``index`` is empty) + or index key order (if ``index`` is non-empty). + + It is not an error for the ``key_set`` to name rows that do not + exist in the database. Read yields nothing for nonexistent rows. + If a dict is provided, it must be of the same form as the protobuf + message :class:`~google.cloud.spanner_v1.types.KeySet` + transaction (Union[dict, ~google.cloud.spanner_v1.types.TransactionSelector]): The transaction to use. If none is provided, the default is a + temporary read-only transaction with strong concurrency. + If a dict is provided, it must be of the same form as the protobuf + message :class:`~google.cloud.spanner_v1.types.TransactionSelector` + index (str): If non-empty, the name of an index on ``table``. This index is + used instead of the table primary key when interpreting ``key_set`` + and sorting result rows. See ``key_set`` for further information. + limit (long): If greater than zero, only the first ``limit`` rows are yielded. If ``limit`` + is zero, the default is no limit. + resume_token (bytes): If this request is resuming a previously interrupted read, + ``resume_token`` should be copied from the last + ``PartialResultSet`` yielded before the interruption. Doing this + enables the new read to resume where the last read left off. The + rest of the request parameters must exactly match the request + that yielded this token. + options (~google.gax.CallOptions): Overrides the default + settings for this call, e.g, timeout, retries etc. + + Returns: + Iterable[~google.cloud.spanner_v1.types.PartialResultSet]. + + Raises: + :exc:`google.gax.errors.GaxError` if the RPC is aborted. + :exc:`ValueError` if the parameters are invalid. + """ + request = spanner_pb2.ReadRequest( + session=session, + table=table, + columns=columns, + key_set=key_set, + transaction=transaction, + index=index, + limit=limit, + resume_token=resume_token) + return self._streaming_read(request, options) + + def begin_transaction(self, session, options_, options=None): + """ + Begins a new transaction. This step can often be skipped: + ``Read``, ``ExecuteSql`` and + ``Commit`` can begin a new transaction as a + side-effect. + + Example: + >>> from google.cloud import spanner_v1 + >>> + >>> client = spanner_v1.SpannerClient() + >>> + >>> session = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', '[SESSION]') + >>> options_ = {} + >>> + >>> response = client.begin_transaction(session, options_) + + Args: + session (str): Required. The session in which the transaction runs. + options_ (Union[dict, ~google.cloud.spanner_v1.types.TransactionOptions]): Required. Options for the new transaction. + If a dict is provided, it must be of the same form as the protobuf + message :class:`~google.cloud.spanner_v1.types.TransactionOptions` + options (~google.gax.CallOptions): Overrides the default + settings for this call, e.g, timeout, retries etc. + + Returns: + A :class:`~google.cloud.spanner_v1.types.Transaction` instance. + + Raises: + :exc:`google.gax.errors.GaxError` if the RPC is aborted. + :exc:`ValueError` if the parameters are invalid. + """ + request = spanner_pb2.BeginTransactionRequest( + session=session, options=options_) + return self._begin_transaction(request, options) + + def commit(self, + session, + mutations, + transaction_id=None, + single_use_transaction=None, + options=None): + """ + Commits a transaction. The request includes the mutations to be + applied to rows in the database. + + ``Commit`` might return an ``ABORTED`` error. This can occur at any time; + commonly, the cause is conflicts with concurrent + transactions. However, it can also happen for a variety of other + reasons. If ``Commit`` returns ``ABORTED``, the caller should re-attempt + the transaction from the beginning, re-using the same session. + + Example: + >>> from google.cloud import spanner_v1 + >>> + >>> client = spanner_v1.SpannerClient() + >>> + >>> session = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', '[SESSION]') + >>> mutations = [] + >>> + >>> response = client.commit(session, mutations) + + Args: + session (str): Required. The session in which the transaction to be committed is running. + mutations (list[Union[dict, ~google.cloud.spanner_v1.types.Mutation]]): The mutations to be executed when this transaction commits. All + mutations are applied atomically, in the order they appear in + this list. + If a dict is provided, it must be of the same form as the protobuf + message :class:`~google.cloud.spanner_v1.types.Mutation` + transaction_id (bytes): Commit a previously-started transaction. + single_use_transaction (Union[dict, ~google.cloud.spanner_v1.types.TransactionOptions]): Execute mutations in a temporary transaction. Note that unlike + commit of a previously-started transaction, commit with a + temporary transaction is non-idempotent. That is, if the + ``CommitRequest`` is sent to Cloud Spanner more than once (for + instance, due to retries in the application, or in the + transport library), it is possible that the mutations are + executed more than once. If this is undesirable, use + ``BeginTransaction`` and + ``Commit`` instead. + If a dict is provided, it must be of the same form as the protobuf + message :class:`~google.cloud.spanner_v1.types.TransactionOptions` + options (~google.gax.CallOptions): Overrides the default + settings for this call, e.g, timeout, retries etc. + + Returns: + A :class:`~google.cloud.spanner_v1.types.CommitResponse` instance. + + Raises: + :exc:`google.gax.errors.GaxError` if the RPC is aborted. + :exc:`ValueError` if the parameters are invalid. + """ + # Sanity check: We have some fields which are mutually exclusive; + # raise ValueError if more than one is sent. + oneof.check_oneof( + transaction_id=transaction_id, + single_use_transaction=single_use_transaction, ) + + request = spanner_pb2.CommitRequest( + session=session, + mutations=mutations, + transaction_id=transaction_id, + single_use_transaction=single_use_transaction) + return self._commit(request, options) + + def rollback(self, session, transaction_id, options=None): + """ + Rolls back a transaction, releasing any locks it holds. It is a good + idea to call this for any transaction that includes one or more + ``Read`` or ``ExecuteSql`` requests and + ultimately decides not to commit. + + ``Rollback`` returns ``OK`` if it successfully aborts the transaction, the + transaction was already aborted, or the transaction is not + found. ``Rollback`` never returns ``ABORTED``. + + Example: + >>> from google.cloud import spanner_v1 + >>> + >>> client = spanner_v1.SpannerClient() + >>> + >>> session = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', '[SESSION]') + >>> transaction_id = b'' + >>> + >>> client.rollback(session, transaction_id) + + Args: + session (str): Required. The session in which the transaction to roll back is running. + transaction_id (bytes): Required. The transaction to roll back. + options (~google.gax.CallOptions): Overrides the default + settings for this call, e.g, timeout, retries etc. + + Raises: + :exc:`google.gax.errors.GaxError` if the RPC is aborted. + :exc:`ValueError` if the parameters are invalid. + """ + request = spanner_pb2.RollbackRequest( + session=session, transaction_id=transaction_id) + self._rollback(request, options) diff --git a/spanner/google/cloud/spanner_v1/gapic/spanner_client_config.py b/spanner/google/cloud/spanner_v1/gapic/spanner_client_config.py new file mode 100644 index 000000000000..5f38663a35f9 --- /dev/null +++ b/spanner/google/cloud/spanner_v1/gapic/spanner_client_config.py @@ -0,0 +1,83 @@ +config = { + "interfaces": { + "google.spanner.v1.Spanner": { + "retry_codes": { + "idempotent": ["DEADLINE_EXCEEDED", "UNAVAILABLE"], + "non_idempotent": [], + "long_running": ["UNAVAILABLE"] + }, + "retry_params": { + "default": { + "initial_retry_delay_millis": 1000, + "retry_delay_multiplier": 1.3, + "max_retry_delay_millis": 32000, + "initial_rpc_timeout_millis": 60000, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 60000, + "total_timeout_millis": 600000 + }, + "long_running": { + "initial_retry_delay_millis": 1000, + "retry_delay_multiplier": 1.3, + "max_retry_delay_millis": 32000, + "initial_rpc_timeout_millis": 3600000, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 3600000, + "total_timeout_millis": 3600000 + } + }, + "methods": { + "CreateSession": { + "timeout_millis": 30000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "GetSession": { + "timeout_millis": 30000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "DeleteSession": { + "timeout_millis": 30000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "ExecuteSql": { + "timeout_millis": 30000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "ExecuteStreamingSql": { + "timeout_millis": 3600000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "Read": { + "timeout_millis": 30000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "StreamingRead": { + "timeout_millis": 3600000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "BeginTransaction": { + "timeout_millis": 30000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "Commit": { + "timeout_millis": 3600000, + "retry_codes_name": "long_running", + "retry_params_name": "long_running" + }, + "Rollback": { + "timeout_millis": 30000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + } + } + } + } +} diff --git a/spanner/google/cloud/spanner_v1/proto/__init__.py b/spanner/google/cloud/spanner_v1/proto/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/spanner/google/cloud/spanner_v1/proto/keys_pb2.py b/spanner/google/cloud/spanner_v1/proto/keys_pb2.py new file mode 100644 index 000000000000..c7f216240e96 --- /dev/null +++ b/spanner/google/cloud/spanner_v1/proto/keys_pb2.py @@ -0,0 +1,343 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/cloud/spanner_v1/proto/keys.proto + +import sys +_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database +from google.protobuf import descriptor_pb2 +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + +from google.api import annotations_pb2 as google_dot_api_dot_annotations__pb2 +from google.protobuf import struct_pb2 as google_dot_protobuf_dot_struct__pb2 + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='google/cloud/spanner_v1/proto/keys.proto', + package='google.spanner.v1', + syntax='proto3', + serialized_pb=_b('\n(google/cloud/spanner_v1/proto/keys.proto\x12\x11google.spanner.v1\x1a\x1cgoogle/api/annotations.proto\x1a\x1cgoogle/protobuf/struct.proto\"\xf4\x01\n\x08KeyRange\x12\x32\n\x0cstart_closed\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.ListValueH\x00\x12\x30\n\nstart_open\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.ListValueH\x00\x12\x30\n\nend_closed\x18\x03 \x01(\x0b\x32\x1a.google.protobuf.ListValueH\x01\x12.\n\x08\x65nd_open\x18\x04 \x01(\x0b\x32\x1a.google.protobuf.ListValueH\x01\x42\x10\n\x0estart_key_typeB\x0e\n\x0c\x65nd_key_type\"l\n\x06KeySet\x12(\n\x04keys\x18\x01 \x03(\x0b\x32\x1a.google.protobuf.ListValue\x12+\n\x06ranges\x18\x02 \x03(\x0b\x32\x1b.google.spanner.v1.KeyRange\x12\x0b\n\x03\x61ll\x18\x03 \x01(\x08\x42x\n\x15\x63om.google.spanner.v1B\tKeysProtoP\x01Z8google.golang.org/genproto/googleapis/spanner/v1;spanner\xaa\x02\x17Google.Cloud.Spanner.V1b\x06proto3') + , + dependencies=[google_dot_api_dot_annotations__pb2.DESCRIPTOR,google_dot_protobuf_dot_struct__pb2.DESCRIPTOR,]) +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + + + + +_KEYRANGE = _descriptor.Descriptor( + name='KeyRange', + full_name='google.spanner.v1.KeyRange', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='start_closed', full_name='google.spanner.v1.KeyRange.start_closed', index=0, + number=1, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='start_open', full_name='google.spanner.v1.KeyRange.start_open', index=1, + number=2, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='end_closed', full_name='google.spanner.v1.KeyRange.end_closed', index=2, + number=3, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='end_open', full_name='google.spanner.v1.KeyRange.end_open', index=3, + number=4, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + _descriptor.OneofDescriptor( + name='start_key_type', full_name='google.spanner.v1.KeyRange.start_key_type', + index=0, containing_type=None, fields=[]), + _descriptor.OneofDescriptor( + name='end_key_type', full_name='google.spanner.v1.KeyRange.end_key_type', + index=1, containing_type=None, fields=[]), + ], + serialized_start=124, + serialized_end=368, +) + + +_KEYSET = _descriptor.Descriptor( + name='KeySet', + full_name='google.spanner.v1.KeySet', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='keys', full_name='google.spanner.v1.KeySet.keys', index=0, + number=1, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='ranges', full_name='google.spanner.v1.KeySet.ranges', index=1, + number=2, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='all', full_name='google.spanner.v1.KeySet.all', index=2, + number=3, type=8, cpp_type=7, label=1, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=370, + serialized_end=478, +) + +_KEYRANGE.fields_by_name['start_closed'].message_type = google_dot_protobuf_dot_struct__pb2._LISTVALUE +_KEYRANGE.fields_by_name['start_open'].message_type = google_dot_protobuf_dot_struct__pb2._LISTVALUE +_KEYRANGE.fields_by_name['end_closed'].message_type = google_dot_protobuf_dot_struct__pb2._LISTVALUE +_KEYRANGE.fields_by_name['end_open'].message_type = google_dot_protobuf_dot_struct__pb2._LISTVALUE +_KEYRANGE.oneofs_by_name['start_key_type'].fields.append( + _KEYRANGE.fields_by_name['start_closed']) +_KEYRANGE.fields_by_name['start_closed'].containing_oneof = _KEYRANGE.oneofs_by_name['start_key_type'] +_KEYRANGE.oneofs_by_name['start_key_type'].fields.append( + _KEYRANGE.fields_by_name['start_open']) +_KEYRANGE.fields_by_name['start_open'].containing_oneof = _KEYRANGE.oneofs_by_name['start_key_type'] +_KEYRANGE.oneofs_by_name['end_key_type'].fields.append( + _KEYRANGE.fields_by_name['end_closed']) +_KEYRANGE.fields_by_name['end_closed'].containing_oneof = _KEYRANGE.oneofs_by_name['end_key_type'] +_KEYRANGE.oneofs_by_name['end_key_type'].fields.append( + _KEYRANGE.fields_by_name['end_open']) +_KEYRANGE.fields_by_name['end_open'].containing_oneof = _KEYRANGE.oneofs_by_name['end_key_type'] +_KEYSET.fields_by_name['keys'].message_type = google_dot_protobuf_dot_struct__pb2._LISTVALUE +_KEYSET.fields_by_name['ranges'].message_type = _KEYRANGE +DESCRIPTOR.message_types_by_name['KeyRange'] = _KEYRANGE +DESCRIPTOR.message_types_by_name['KeySet'] = _KEYSET + +KeyRange = _reflection.GeneratedProtocolMessageType('KeyRange', (_message.Message,), dict( + DESCRIPTOR = _KEYRANGE, + __module__ = 'google.cloud.spanner_v1.proto.keys_pb2' + , + __doc__ = """KeyRange represents a range of rows in a table or index. + + A range has a start key and an end key. These keys can be open or + closed, indicating if the range includes rows with that key. + + Keys are represented by lists, where the ith value in the list + corresponds to the ith component of the table or index primary key. + Individual values are encoded as described + [here][google.spanner.v1.TypeCode]. + + For example, consider the following table definition: + + :: + + CREATE TABLE UserEvents ( + UserName STRING(MAX), + EventDate STRING(10) + ) PRIMARY KEY(UserName, EventDate); + + The following keys name rows in this table: + + :: + + ["Bob", "2014-09-23"] + ["Alfred", "2015-06-12"] + + Since the ``UserEvents`` table's ``PRIMARY KEY`` clause names two + columns, each ``UserEvents`` key has two elements; the first is the + ``UserName``, and the second is the ``EventDate``. + + Key ranges with multiple components are interpreted lexicographically by + component using the table or index key's declared sort order. For + example, the following range returns all events for user ``"Bob"`` that + occurred in the year 2015: + + :: + + "start_closed": ["Bob", "2015-01-01"] + "end_closed": ["Bob", "2015-12-31"] + + Start and end keys can omit trailing key components. This affects the + inclusion and exclusion of rows that exactly match the provided key + components: if the key is closed, then rows that exactly match the + provided components are included; if the key is open, then rows that + exactly match are not included. + + For example, the following range includes all events for ``"Bob"`` that + occurred during and after the year 2000: + + :: + + "start_closed": ["Bob", "2000-01-01"] + "end_closed": ["Bob"] + + The next example retrieves all events for ``"Bob"``: + + :: + + "start_closed": ["Bob"] + "end_closed": ["Bob"] + + To retrieve events before the year 2000: + + :: + + "start_closed": ["Bob"] + "end_open": ["Bob", "2000-01-01"] + + The following range includes all rows in the table: + + :: + + "start_closed": [] + "end_closed": [] + + This range returns all users whose ``UserName`` begins with any + character from A to C: + + :: + + "start_closed": ["A"] + "end_open": ["D"] + + This range returns all users whose ``UserName`` begins with B: + + :: + + "start_closed": ["B"] + "end_open": ["C"] + + Key ranges honor column sort order. For example, suppose a table is + defined as follows: + + :: + + CREATE TABLE DescendingSortedTable { + Key INT64, + ... + ) PRIMARY KEY(Key DESC); + + The following range retrieves all rows with key values between 1 and 100 + inclusive: + + :: + + "start_closed": ["100"] + "end_closed": ["1"] + + Note that 100 is passed as the start, and 1 is passed as the end, + because ``Key`` is a descending column in the schema. + + + Attributes: + start_key_type: + The start key must be provided. It can be either closed or + open. + start_closed: + If the start is closed, then the range includes all rows whose + first ``len(start_closed)`` key columns exactly match + ``start_closed``. + start_open: + If the start is open, then the range excludes rows whose first + ``len(start_open)`` key columns exactly match ``start_open``. + end_key_type: + The end key must be provided. It can be either closed or open. + end_closed: + If the end is closed, then the range includes all rows whose + first ``len(end_closed)`` key columns exactly match + ``end_closed``. + end_open: + If the end is open, then the range excludes rows whose first + ``len(end_open)`` key columns exactly match ``end_open``. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.KeyRange) + )) +_sym_db.RegisterMessage(KeyRange) + +KeySet = _reflection.GeneratedProtocolMessageType('KeySet', (_message.Message,), dict( + DESCRIPTOR = _KEYSET, + __module__ = 'google.cloud.spanner_v1.proto.keys_pb2' + , + __doc__ = """``KeySet`` defines a collection of Cloud Spanner keys and/or key ranges. + All the keys are expected to be in the same table or index. The keys + need not be sorted in any particular way. + + If the same key is specified multiple times in the set (for example if + two ranges, two keys, or a key and a range overlap), Cloud Spanner + behaves as if the key were only specified once. + + + Attributes: + keys: + A list of specific keys. Entries in ``keys`` should have + exactly as many elements as there are columns in the primary + or index key with which this ``KeySet`` is used. Individual + key values are encoded as described + [here][google.spanner.v1.TypeCode]. + ranges: + A list of key ranges. See + [KeyRange][google.spanner.v1.KeyRange] for more information + about key range specifications. + all: + For convenience ``all`` can be set to ``true`` to indicate + that this ``KeySet`` matches all keys in the table or index. + Note that any keys specified in ``keys`` or ``ranges`` are + only yielded once. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.KeySet) + )) +_sym_db.RegisterMessage(KeySet) + + +DESCRIPTOR.has_options = True +DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\025com.google.spanner.v1B\tKeysProtoP\001Z8google.golang.org/genproto/googleapis/spanner/v1;spanner\252\002\027Google.Cloud.Spanner.V1')) +try: + # THESE ELEMENTS WILL BE DEPRECATED. + # Please use the generated *_pb2_grpc.py files instead. + import grpc + from grpc.beta import implementations as beta_implementations + from grpc.beta import interfaces as beta_interfaces + from grpc.framework.common import cardinality + from grpc.framework.interfaces.face import utilities as face_utilities +except ImportError: + pass +# @@protoc_insertion_point(module_scope) diff --git a/spanner/google/cloud/spanner_v1/proto/keys_pb2_grpc.py b/spanner/google/cloud/spanner_v1/proto/keys_pb2_grpc.py new file mode 100644 index 000000000000..a89435267cb2 --- /dev/null +++ b/spanner/google/cloud/spanner_v1/proto/keys_pb2_grpc.py @@ -0,0 +1,3 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +import grpc + diff --git a/spanner/google/cloud/spanner_v1/proto/mutation_pb2.py b/spanner/google/cloud/spanner_v1/proto/mutation_pb2.py new file mode 100644 index 000000000000..b51344de6d41 --- /dev/null +++ b/spanner/google/cloud/spanner_v1/proto/mutation_pb2.py @@ -0,0 +1,299 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/cloud/spanner_v1/proto/mutation.proto + +import sys +_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database +from google.protobuf import descriptor_pb2 +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + +from google.api import annotations_pb2 as google_dot_api_dot_annotations__pb2 +from google.protobuf import struct_pb2 as google_dot_protobuf_dot_struct__pb2 +from google.cloud.spanner_v1.proto import keys_pb2 as google_dot_cloud_dot_spanner__v1_dot_proto_dot_keys__pb2 + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='google/cloud/spanner_v1/proto/mutation.proto', + package='google.spanner.v1', + syntax='proto3', + serialized_pb=_b('\n,google/cloud/spanner_v1/proto/mutation.proto\x12\x11google.spanner.v1\x1a\x1cgoogle/api/annotations.proto\x1a\x1cgoogle/protobuf/struct.proto\x1a(google/cloud/spanner_v1/proto/keys.proto\"\xc6\x03\n\x08Mutation\x12\x33\n\x06insert\x18\x01 \x01(\x0b\x32!.google.spanner.v1.Mutation.WriteH\x00\x12\x33\n\x06update\x18\x02 \x01(\x0b\x32!.google.spanner.v1.Mutation.WriteH\x00\x12=\n\x10insert_or_update\x18\x03 \x01(\x0b\x32!.google.spanner.v1.Mutation.WriteH\x00\x12\x34\n\x07replace\x18\x04 \x01(\x0b\x32!.google.spanner.v1.Mutation.WriteH\x00\x12\x34\n\x06\x64\x65lete\x18\x05 \x01(\x0b\x32\".google.spanner.v1.Mutation.DeleteH\x00\x1aS\n\x05Write\x12\r\n\x05table\x18\x01 \x01(\t\x12\x0f\n\x07\x63olumns\x18\x02 \x03(\t\x12*\n\x06values\x18\x03 \x03(\x0b\x32\x1a.google.protobuf.ListValue\x1a\x43\n\x06\x44\x65lete\x12\r\n\x05table\x18\x01 \x01(\t\x12*\n\x07key_set\x18\x02 \x01(\x0b\x32\x19.google.spanner.v1.KeySetB\x0b\n\toperationB|\n\x15\x63om.google.spanner.v1B\rMutationProtoP\x01Z8google.golang.org/genproto/googleapis/spanner/v1;spanner\xaa\x02\x17Google.Cloud.Spanner.V1b\x06proto3') + , + dependencies=[google_dot_api_dot_annotations__pb2.DESCRIPTOR,google_dot_protobuf_dot_struct__pb2.DESCRIPTOR,google_dot_cloud_dot_spanner__v1_dot_proto_dot_keys__pb2.DESCRIPTOR,]) +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + + + + +_MUTATION_WRITE = _descriptor.Descriptor( + name='Write', + full_name='google.spanner.v1.Mutation.Write', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='table', full_name='google.spanner.v1.Mutation.Write.table', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='columns', full_name='google.spanner.v1.Mutation.Write.columns', index=1, + number=2, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='values', full_name='google.spanner.v1.Mutation.Write.values', index=2, + number=3, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=459, + serialized_end=542, +) + +_MUTATION_DELETE = _descriptor.Descriptor( + name='Delete', + full_name='google.spanner.v1.Mutation.Delete', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='table', full_name='google.spanner.v1.Mutation.Delete.table', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='key_set', full_name='google.spanner.v1.Mutation.Delete.key_set', index=1, + number=2, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=544, + serialized_end=611, +) + +_MUTATION = _descriptor.Descriptor( + name='Mutation', + full_name='google.spanner.v1.Mutation', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='insert', full_name='google.spanner.v1.Mutation.insert', index=0, + number=1, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='update', full_name='google.spanner.v1.Mutation.update', index=1, + number=2, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='insert_or_update', full_name='google.spanner.v1.Mutation.insert_or_update', index=2, + number=3, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='replace', full_name='google.spanner.v1.Mutation.replace', index=3, + number=4, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='delete', full_name='google.spanner.v1.Mutation.delete', index=4, + number=5, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[_MUTATION_WRITE, _MUTATION_DELETE, ], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + _descriptor.OneofDescriptor( + name='operation', full_name='google.spanner.v1.Mutation.operation', + index=0, containing_type=None, fields=[]), + ], + serialized_start=170, + serialized_end=624, +) + +_MUTATION_WRITE.fields_by_name['values'].message_type = google_dot_protobuf_dot_struct__pb2._LISTVALUE +_MUTATION_WRITE.containing_type = _MUTATION +_MUTATION_DELETE.fields_by_name['key_set'].message_type = google_dot_cloud_dot_spanner__v1_dot_proto_dot_keys__pb2._KEYSET +_MUTATION_DELETE.containing_type = _MUTATION +_MUTATION.fields_by_name['insert'].message_type = _MUTATION_WRITE +_MUTATION.fields_by_name['update'].message_type = _MUTATION_WRITE +_MUTATION.fields_by_name['insert_or_update'].message_type = _MUTATION_WRITE +_MUTATION.fields_by_name['replace'].message_type = _MUTATION_WRITE +_MUTATION.fields_by_name['delete'].message_type = _MUTATION_DELETE +_MUTATION.oneofs_by_name['operation'].fields.append( + _MUTATION.fields_by_name['insert']) +_MUTATION.fields_by_name['insert'].containing_oneof = _MUTATION.oneofs_by_name['operation'] +_MUTATION.oneofs_by_name['operation'].fields.append( + _MUTATION.fields_by_name['update']) +_MUTATION.fields_by_name['update'].containing_oneof = _MUTATION.oneofs_by_name['operation'] +_MUTATION.oneofs_by_name['operation'].fields.append( + _MUTATION.fields_by_name['insert_or_update']) +_MUTATION.fields_by_name['insert_or_update'].containing_oneof = _MUTATION.oneofs_by_name['operation'] +_MUTATION.oneofs_by_name['operation'].fields.append( + _MUTATION.fields_by_name['replace']) +_MUTATION.fields_by_name['replace'].containing_oneof = _MUTATION.oneofs_by_name['operation'] +_MUTATION.oneofs_by_name['operation'].fields.append( + _MUTATION.fields_by_name['delete']) +_MUTATION.fields_by_name['delete'].containing_oneof = _MUTATION.oneofs_by_name['operation'] +DESCRIPTOR.message_types_by_name['Mutation'] = _MUTATION + +Mutation = _reflection.GeneratedProtocolMessageType('Mutation', (_message.Message,), dict( + + Write = _reflection.GeneratedProtocolMessageType('Write', (_message.Message,), dict( + DESCRIPTOR = _MUTATION_WRITE, + __module__ = 'google.cloud.spanner_v1.proto.mutation_pb2' + , + __doc__ = """Arguments to [insert][google.spanner.v1.Mutation.insert], + [update][google.spanner.v1.Mutation.update], + [insert\_or\_update][google.spanner.v1.Mutation.insert\_or\_update], and + [replace][google.spanner.v1.Mutation.replace] operations. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.Mutation.Write) + )) + , + + Delete = _reflection.GeneratedProtocolMessageType('Delete', (_message.Message,), dict( + DESCRIPTOR = _MUTATION_DELETE, + __module__ = 'google.cloud.spanner_v1.proto.mutation_pb2' + , + __doc__ = """Arguments to [delete][google.spanner.v1.Mutation.delete] operations. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.Mutation.Delete) + )) + , + DESCRIPTOR = _MUTATION, + __module__ = 'google.cloud.spanner_v1.proto.mutation_pb2' + , + __doc__ = """A modification to one or more Cloud Spanner rows. Mutations can be + applied to a Cloud Spanner database by sending them in a + [Commit][google.spanner.v1.Spanner.Commit] call. + + + Attributes: + table: + Required. The table whose rows will be deleted. + columns: + The names of the columns in + [table][google.spanner.v1.Mutation.Write.table] to be written. + The list of columns must contain enough columns to allow Cloud + Spanner to derive values for all primary key columns in the + row(s) to be modified. + values: + The values to be written. ``values`` can contain more than one + list of values. If it does, then multiple rows are written, + one for each entry in ``values``. Each list in ``values`` must + have exactly as many entries as there are entries in + [columns][google.spanner.v1.Mutation.Write.columns] above. + Sending multiple lists is equivalent to sending multiple + ``Mutation``\ s, each containing one ``values`` entry and + repeating [table][google.spanner.v1.Mutation.Write.table] and + [columns][google.spanner.v1.Mutation.Write.columns]. + Individual values in each list are encoded as described + [here][google.spanner.v1.TypeCode]. + key_set: + Required. The primary keys of the rows within + [table][google.spanner.v1.Mutation.Delete.table] to delete. + operation: + Required. The operation to perform. + insert: + Insert new rows in a table. If any of the rows already exist, + the write or transaction fails with error ``ALREADY_EXISTS``. + update: + Update existing rows in a table. If any of the rows does not + already exist, the transaction fails with error ``NOT_FOUND``. + insert_or_update: + Like [insert][google.spanner.v1.Mutation.insert], except that + if the row already exists, then its column values are + overwritten with the ones provided. Any column values not + explicitly written are preserved. + replace: + Like [insert][google.spanner.v1.Mutation.insert], except that + if the row already exists, it is deleted, and the column + values provided are inserted instead. Unlike [insert\_or\_upda + te][google.spanner.v1.Mutation.insert\_or\_update], this means + any values not explicitly written become ``NULL``. + delete: + Delete rows from a table. Succeeds whether or not the named + rows were present. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.Mutation) + )) +_sym_db.RegisterMessage(Mutation) +_sym_db.RegisterMessage(Mutation.Write) +_sym_db.RegisterMessage(Mutation.Delete) + + +DESCRIPTOR.has_options = True +DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\025com.google.spanner.v1B\rMutationProtoP\001Z8google.golang.org/genproto/googleapis/spanner/v1;spanner\252\002\027Google.Cloud.Spanner.V1')) +try: + # THESE ELEMENTS WILL BE DEPRECATED. + # Please use the generated *_pb2_grpc.py files instead. + import grpc + from grpc.beta import implementations as beta_implementations + from grpc.beta import interfaces as beta_interfaces + from grpc.framework.common import cardinality + from grpc.framework.interfaces.face import utilities as face_utilities +except ImportError: + pass +# @@protoc_insertion_point(module_scope) diff --git a/spanner/google/cloud/spanner_v1/proto/mutation_pb2_grpc.py b/spanner/google/cloud/spanner_v1/proto/mutation_pb2_grpc.py new file mode 100644 index 000000000000..a89435267cb2 --- /dev/null +++ b/spanner/google/cloud/spanner_v1/proto/mutation_pb2_grpc.py @@ -0,0 +1,3 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +import grpc + diff --git a/spanner/google/cloud/spanner_v1/proto/query_plan_pb2.py b/spanner/google/cloud/spanner_v1/proto/query_plan_pb2.py new file mode 100644 index 000000000000..cfa5bb03a4f5 --- /dev/null +++ b/spanner/google/cloud/spanner_v1/proto/query_plan_pb2.py @@ -0,0 +1,428 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/cloud/spanner_v1/proto/query_plan.proto + +import sys +_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database +from google.protobuf import descriptor_pb2 +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + +from google.api import annotations_pb2 as google_dot_api_dot_annotations__pb2 +from google.protobuf import struct_pb2 as google_dot_protobuf_dot_struct__pb2 + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='google/cloud/spanner_v1/proto/query_plan.proto', + package='google.spanner.v1', + syntax='proto3', + serialized_pb=_b('\n.google/cloud/spanner_v1/proto/query_plan.proto\x12\x11google.spanner.v1\x1a\x1cgoogle/api/annotations.proto\x1a\x1cgoogle/protobuf/struct.proto\"\xf8\x04\n\x08PlanNode\x12\r\n\x05index\x18\x01 \x01(\x05\x12.\n\x04kind\x18\x02 \x01(\x0e\x32 .google.spanner.v1.PlanNode.Kind\x12\x14\n\x0c\x64isplay_name\x18\x03 \x01(\t\x12:\n\x0b\x63hild_links\x18\x04 \x03(\x0b\x32%.google.spanner.v1.PlanNode.ChildLink\x12M\n\x14short_representation\x18\x05 \x01(\x0b\x32/.google.spanner.v1.PlanNode.ShortRepresentation\x12)\n\x08metadata\x18\x06 \x01(\x0b\x32\x17.google.protobuf.Struct\x12\x30\n\x0f\x65xecution_stats\x18\x07 \x01(\x0b\x32\x17.google.protobuf.Struct\x1a@\n\tChildLink\x12\x13\n\x0b\x63hild_index\x18\x01 \x01(\x05\x12\x0c\n\x04type\x18\x02 \x01(\t\x12\x10\n\x08variable\x18\x03 \x01(\t\x1a\xb2\x01\n\x13ShortRepresentation\x12\x13\n\x0b\x64\x65scription\x18\x01 \x01(\t\x12S\n\nsubqueries\x18\x02 \x03(\x0b\x32?.google.spanner.v1.PlanNode.ShortRepresentation.SubqueriesEntry\x1a\x31\n\x0fSubqueriesEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\x05:\x02\x38\x01\"8\n\x04Kind\x12\x14\n\x10KIND_UNSPECIFIED\x10\x00\x12\x0e\n\nRELATIONAL\x10\x01\x12\n\n\x06SCALAR\x10\x02\"<\n\tQueryPlan\x12/\n\nplan_nodes\x18\x01 \x03(\x0b\x32\x1b.google.spanner.v1.PlanNodeB}\n\x15\x63om.google.spanner.v1B\x0eQueryPlanProtoP\x01Z8google.golang.org/genproto/googleapis/spanner/v1;spanner\xaa\x02\x17Google.Cloud.Spanner.V1b\x06proto3') + , + dependencies=[google_dot_api_dot_annotations__pb2.DESCRIPTOR,google_dot_protobuf_dot_struct__pb2.DESCRIPTOR,]) +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + + + +_PLANNODE_KIND = _descriptor.EnumDescriptor( + name='Kind', + full_name='google.spanner.v1.PlanNode.Kind', + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name='KIND_UNSPECIFIED', index=0, number=0, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='RELATIONAL', index=1, number=1, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='SCALAR', index=2, number=2, + options=None, + type=None), + ], + containing_type=None, + options=None, + serialized_start=706, + serialized_end=762, +) +_sym_db.RegisterEnumDescriptor(_PLANNODE_KIND) + + +_PLANNODE_CHILDLINK = _descriptor.Descriptor( + name='ChildLink', + full_name='google.spanner.v1.PlanNode.ChildLink', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='child_index', full_name='google.spanner.v1.PlanNode.ChildLink.child_index', index=0, + number=1, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='type', full_name='google.spanner.v1.PlanNode.ChildLink.type', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='variable', full_name='google.spanner.v1.PlanNode.ChildLink.variable', index=2, + number=3, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=459, + serialized_end=523, +) + +_PLANNODE_SHORTREPRESENTATION_SUBQUERIESENTRY = _descriptor.Descriptor( + name='SubqueriesEntry', + full_name='google.spanner.v1.PlanNode.ShortRepresentation.SubqueriesEntry', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='key', full_name='google.spanner.v1.PlanNode.ShortRepresentation.SubqueriesEntry.key', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='value', full_name='google.spanner.v1.PlanNode.ShortRepresentation.SubqueriesEntry.value', index=1, + number=2, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=_descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('8\001')), + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=655, + serialized_end=704, +) + +_PLANNODE_SHORTREPRESENTATION = _descriptor.Descriptor( + name='ShortRepresentation', + full_name='google.spanner.v1.PlanNode.ShortRepresentation', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='description', full_name='google.spanner.v1.PlanNode.ShortRepresentation.description', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='subqueries', full_name='google.spanner.v1.PlanNode.ShortRepresentation.subqueries', index=1, + number=2, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[_PLANNODE_SHORTREPRESENTATION_SUBQUERIESENTRY, ], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=526, + serialized_end=704, +) + +_PLANNODE = _descriptor.Descriptor( + name='PlanNode', + full_name='google.spanner.v1.PlanNode', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='index', full_name='google.spanner.v1.PlanNode.index', index=0, + number=1, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='kind', full_name='google.spanner.v1.PlanNode.kind', index=1, + number=2, type=14, cpp_type=8, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='display_name', full_name='google.spanner.v1.PlanNode.display_name', index=2, + number=3, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='child_links', full_name='google.spanner.v1.PlanNode.child_links', index=3, + number=4, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='short_representation', full_name='google.spanner.v1.PlanNode.short_representation', index=4, + number=5, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='metadata', full_name='google.spanner.v1.PlanNode.metadata', index=5, + number=6, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='execution_stats', full_name='google.spanner.v1.PlanNode.execution_stats', index=6, + number=7, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[_PLANNODE_CHILDLINK, _PLANNODE_SHORTREPRESENTATION, ], + enum_types=[ + _PLANNODE_KIND, + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=130, + serialized_end=762, +) + + +_QUERYPLAN = _descriptor.Descriptor( + name='QueryPlan', + full_name='google.spanner.v1.QueryPlan', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='plan_nodes', full_name='google.spanner.v1.QueryPlan.plan_nodes', index=0, + number=1, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=764, + serialized_end=824, +) + +_PLANNODE_CHILDLINK.containing_type = _PLANNODE +_PLANNODE_SHORTREPRESENTATION_SUBQUERIESENTRY.containing_type = _PLANNODE_SHORTREPRESENTATION +_PLANNODE_SHORTREPRESENTATION.fields_by_name['subqueries'].message_type = _PLANNODE_SHORTREPRESENTATION_SUBQUERIESENTRY +_PLANNODE_SHORTREPRESENTATION.containing_type = _PLANNODE +_PLANNODE.fields_by_name['kind'].enum_type = _PLANNODE_KIND +_PLANNODE.fields_by_name['child_links'].message_type = _PLANNODE_CHILDLINK +_PLANNODE.fields_by_name['short_representation'].message_type = _PLANNODE_SHORTREPRESENTATION +_PLANNODE.fields_by_name['metadata'].message_type = google_dot_protobuf_dot_struct__pb2._STRUCT +_PLANNODE.fields_by_name['execution_stats'].message_type = google_dot_protobuf_dot_struct__pb2._STRUCT +_PLANNODE_KIND.containing_type = _PLANNODE +_QUERYPLAN.fields_by_name['plan_nodes'].message_type = _PLANNODE +DESCRIPTOR.message_types_by_name['PlanNode'] = _PLANNODE +DESCRIPTOR.message_types_by_name['QueryPlan'] = _QUERYPLAN + +PlanNode = _reflection.GeneratedProtocolMessageType('PlanNode', (_message.Message,), dict( + + ChildLink = _reflection.GeneratedProtocolMessageType('ChildLink', (_message.Message,), dict( + DESCRIPTOR = _PLANNODE_CHILDLINK, + __module__ = 'google.cloud.spanner_v1.proto.query_plan_pb2' + , + __doc__ = """Metadata associated with a parent-child relationship appearing in a + [PlanNode][google.spanner.v1.PlanNode]. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.PlanNode.ChildLink) + )) + , + + ShortRepresentation = _reflection.GeneratedProtocolMessageType('ShortRepresentation', (_message.Message,), dict( + + SubqueriesEntry = _reflection.GeneratedProtocolMessageType('SubqueriesEntry', (_message.Message,), dict( + DESCRIPTOR = _PLANNODE_SHORTREPRESENTATION_SUBQUERIESENTRY, + __module__ = 'google.cloud.spanner_v1.proto.query_plan_pb2' + # @@protoc_insertion_point(class_scope:google.spanner.v1.PlanNode.ShortRepresentation.SubqueriesEntry) + )) + , + DESCRIPTOR = _PLANNODE_SHORTREPRESENTATION, + __module__ = 'google.cloud.spanner_v1.proto.query_plan_pb2' + , + __doc__ = """Condensed representation of a node and its subtree. Only present for + ``SCALAR`` [PlanNode(s)][google.spanner.v1.PlanNode]. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.PlanNode.ShortRepresentation) + )) + , + DESCRIPTOR = _PLANNODE, + __module__ = 'google.cloud.spanner_v1.proto.query_plan_pb2' + , + __doc__ = """Node information for nodes appearing in a + [QueryPlan.plan\_nodes][google.spanner.v1.QueryPlan.plan\_nodes]. + + + Attributes: + child_index: + The node to which the link points. + type: + The type of the link. For example, in Hash Joins this could be + used to distinguish between the build child and the probe + child, or in the case of the child being an output variable, + to represent the tag associated with the output variable. + variable: + Only present if the child node is + [SCALAR][google.spanner.v1.PlanNode.Kind.SCALAR] and + corresponds to an output variable of the parent node. The + field carries the name of the output variable. For example, a + ``TableScan`` operator that reads rows from a table will have + child links to the ``SCALAR`` nodes representing the output + variables created for each column that is read by the + operator. The corresponding ``variable`` fields will be set to + the variable names assigned to the columns. + description: + A string representation of the expression subtree rooted at + this node. + subqueries: + A mapping of (subquery variable name) -> (subquery node id) + for cases where the ``description`` string of this node + references a ``SCALAR`` subquery contained in the expression + subtree rooted at this node. The referenced ``SCALAR`` + subquery may not necessarily be a direct child of this node. + index: + The ``PlanNode``'s index in [node + list][google.spanner.v1.QueryPlan.plan\_nodes]. + kind: + Used to determine the type of node. May be needed for + visualizing different kinds of nodes differently. For example, + If the node is a + [SCALAR][google.spanner.v1.PlanNode.Kind.SCALAR] node, it will + have a condensed representation which can be used to directly + embed a description of the node in its parent. + display_name: + The display name for the node. + child_links: + List of child node ``index``\ es and their relationship to + this parent. + short_representation: + Condensed representation for + [SCALAR][google.spanner.v1.PlanNode.Kind.SCALAR] nodes. + metadata: + Attributes relevant to the node contained in a group of key- + value pairs. For example, a Parameter Reference node could + have the following information in its metadata: :: { + "parameter_reference": "param1", "parameter_type": + "array" } + execution_stats: + The execution statistics associated with the node, contained + in a group of key-value pairs. Only present if the plan was + returned as a result of a profile query. For example, number + of executions, number of rows/time per execution etc. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.PlanNode) + )) +_sym_db.RegisterMessage(PlanNode) +_sym_db.RegisterMessage(PlanNode.ChildLink) +_sym_db.RegisterMessage(PlanNode.ShortRepresentation) +_sym_db.RegisterMessage(PlanNode.ShortRepresentation.SubqueriesEntry) + +QueryPlan = _reflection.GeneratedProtocolMessageType('QueryPlan', (_message.Message,), dict( + DESCRIPTOR = _QUERYPLAN, + __module__ = 'google.cloud.spanner_v1.proto.query_plan_pb2' + , + __doc__ = """Contains an ordered list of nodes appearing in the query plan. + + + Attributes: + plan_nodes: + The nodes in the query plan. Plan nodes are returned in pre- + order starting with the plan root. Each + [PlanNode][google.spanner.v1.PlanNode]'s ``id`` corresponds to + its index in ``plan_nodes``. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.QueryPlan) + )) +_sym_db.RegisterMessage(QueryPlan) + + +DESCRIPTOR.has_options = True +DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\025com.google.spanner.v1B\016QueryPlanProtoP\001Z8google.golang.org/genproto/googleapis/spanner/v1;spanner\252\002\027Google.Cloud.Spanner.V1')) +_PLANNODE_SHORTREPRESENTATION_SUBQUERIESENTRY.has_options = True +_PLANNODE_SHORTREPRESENTATION_SUBQUERIESENTRY._options = _descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('8\001')) +try: + # THESE ELEMENTS WILL BE DEPRECATED. + # Please use the generated *_pb2_grpc.py files instead. + import grpc + from grpc.beta import implementations as beta_implementations + from grpc.beta import interfaces as beta_interfaces + from grpc.framework.common import cardinality + from grpc.framework.interfaces.face import utilities as face_utilities +except ImportError: + pass +# @@protoc_insertion_point(module_scope) diff --git a/spanner/google/cloud/spanner_v1/proto/query_plan_pb2_grpc.py b/spanner/google/cloud/spanner_v1/proto/query_plan_pb2_grpc.py new file mode 100644 index 000000000000..a89435267cb2 --- /dev/null +++ b/spanner/google/cloud/spanner_v1/proto/query_plan_pb2_grpc.py @@ -0,0 +1,3 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +import grpc + diff --git a/spanner/google/cloud/spanner_v1/proto/result_set_pb2.py b/spanner/google/cloud/spanner_v1/proto/result_set_pb2.py new file mode 100644 index 000000000000..6eac4bcd2f10 --- /dev/null +++ b/spanner/google/cloud/spanner_v1/proto/result_set_pb2.py @@ -0,0 +1,399 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/cloud/spanner_v1/proto/result_set.proto + +import sys +_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database +from google.protobuf import descriptor_pb2 +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + +from google.api import annotations_pb2 as google_dot_api_dot_annotations__pb2 +from google.protobuf import struct_pb2 as google_dot_protobuf_dot_struct__pb2 +from google.cloud.spanner_v1.proto import query_plan_pb2 as google_dot_cloud_dot_spanner__v1_dot_proto_dot_query__plan__pb2 +from google.cloud.spanner_v1.proto import transaction_pb2 as google_dot_cloud_dot_spanner__v1_dot_proto_dot_transaction__pb2 +from google.cloud.spanner_v1.proto import type_pb2 as google_dot_cloud_dot_spanner__v1_dot_proto_dot_type__pb2 + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='google/cloud/spanner_v1/proto/result_set.proto', + package='google.spanner.v1', + syntax='proto3', + serialized_pb=_b('\n.google/cloud/spanner_v1/proto/result_set.proto\x12\x11google.spanner.v1\x1a\x1cgoogle/api/annotations.proto\x1a\x1cgoogle/protobuf/struct.proto\x1a.google/cloud/spanner_v1/proto/query_plan.proto\x1a/google/cloud/spanner_v1/proto/transaction.proto\x1a(google/cloud/spanner_v1/proto/type.proto\"\x9f\x01\n\tResultSet\x12\x36\n\x08metadata\x18\x01 \x01(\x0b\x32$.google.spanner.v1.ResultSetMetadata\x12(\n\x04rows\x18\x02 \x03(\x0b\x32\x1a.google.protobuf.ListValue\x12\x30\n\x05stats\x18\x03 \x01(\x0b\x32!.google.spanner.v1.ResultSetStats\"\xd1\x01\n\x10PartialResultSet\x12\x36\n\x08metadata\x18\x01 \x01(\x0b\x32$.google.spanner.v1.ResultSetMetadata\x12&\n\x06values\x18\x02 \x03(\x0b\x32\x16.google.protobuf.Value\x12\x15\n\rchunked_value\x18\x03 \x01(\x08\x12\x14\n\x0cresume_token\x18\x04 \x01(\x0c\x12\x30\n\x05stats\x18\x05 \x01(\x0b\x32!.google.spanner.v1.ResultSetStats\"y\n\x11ResultSetMetadata\x12/\n\x08row_type\x18\x01 \x01(\x0b\x32\x1d.google.spanner.v1.StructType\x12\x33\n\x0btransaction\x18\x02 \x01(\x0b\x32\x1e.google.spanner.v1.Transaction\"p\n\x0eResultSetStats\x12\x30\n\nquery_plan\x18\x01 \x01(\x0b\x32\x1c.google.spanner.v1.QueryPlan\x12,\n\x0bquery_stats\x18\x02 \x01(\x0b\x32\x17.google.protobuf.StructB}\n\x15\x63om.google.spanner.v1B\x0eResultSetProtoP\x01Z8google.golang.org/genproto/googleapis/spanner/v1;spanner\xaa\x02\x17Google.Cloud.Spanner.V1b\x06proto3') + , + dependencies=[google_dot_api_dot_annotations__pb2.DESCRIPTOR,google_dot_protobuf_dot_struct__pb2.DESCRIPTOR,google_dot_cloud_dot_spanner__v1_dot_proto_dot_query__plan__pb2.DESCRIPTOR,google_dot_cloud_dot_spanner__v1_dot_proto_dot_transaction__pb2.DESCRIPTOR,google_dot_cloud_dot_spanner__v1_dot_proto_dot_type__pb2.DESCRIPTOR,]) +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + + + + +_RESULTSET = _descriptor.Descriptor( + name='ResultSet', + full_name='google.spanner.v1.ResultSet', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='metadata', full_name='google.spanner.v1.ResultSet.metadata', index=0, + number=1, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='rows', full_name='google.spanner.v1.ResultSet.rows', index=1, + number=2, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='stats', full_name='google.spanner.v1.ResultSet.stats', index=2, + number=3, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=269, + serialized_end=428, +) + + +_PARTIALRESULTSET = _descriptor.Descriptor( + name='PartialResultSet', + full_name='google.spanner.v1.PartialResultSet', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='metadata', full_name='google.spanner.v1.PartialResultSet.metadata', index=0, + number=1, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='values', full_name='google.spanner.v1.PartialResultSet.values', index=1, + number=2, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='chunked_value', full_name='google.spanner.v1.PartialResultSet.chunked_value', index=2, + number=3, type=8, cpp_type=7, label=1, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='resume_token', full_name='google.spanner.v1.PartialResultSet.resume_token', index=3, + number=4, type=12, cpp_type=9, label=1, + has_default_value=False, default_value=_b(""), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='stats', full_name='google.spanner.v1.PartialResultSet.stats', index=4, + number=5, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=431, + serialized_end=640, +) + + +_RESULTSETMETADATA = _descriptor.Descriptor( + name='ResultSetMetadata', + full_name='google.spanner.v1.ResultSetMetadata', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='row_type', full_name='google.spanner.v1.ResultSetMetadata.row_type', index=0, + number=1, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='transaction', full_name='google.spanner.v1.ResultSetMetadata.transaction', index=1, + number=2, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=642, + serialized_end=763, +) + + +_RESULTSETSTATS = _descriptor.Descriptor( + name='ResultSetStats', + full_name='google.spanner.v1.ResultSetStats', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='query_plan', full_name='google.spanner.v1.ResultSetStats.query_plan', index=0, + number=1, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='query_stats', full_name='google.spanner.v1.ResultSetStats.query_stats', index=1, + number=2, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=765, + serialized_end=877, +) + +_RESULTSET.fields_by_name['metadata'].message_type = _RESULTSETMETADATA +_RESULTSET.fields_by_name['rows'].message_type = google_dot_protobuf_dot_struct__pb2._LISTVALUE +_RESULTSET.fields_by_name['stats'].message_type = _RESULTSETSTATS +_PARTIALRESULTSET.fields_by_name['metadata'].message_type = _RESULTSETMETADATA +_PARTIALRESULTSET.fields_by_name['values'].message_type = google_dot_protobuf_dot_struct__pb2._VALUE +_PARTIALRESULTSET.fields_by_name['stats'].message_type = _RESULTSETSTATS +_RESULTSETMETADATA.fields_by_name['row_type'].message_type = google_dot_cloud_dot_spanner__v1_dot_proto_dot_type__pb2._STRUCTTYPE +_RESULTSETMETADATA.fields_by_name['transaction'].message_type = google_dot_cloud_dot_spanner__v1_dot_proto_dot_transaction__pb2._TRANSACTION +_RESULTSETSTATS.fields_by_name['query_plan'].message_type = google_dot_cloud_dot_spanner__v1_dot_proto_dot_query__plan__pb2._QUERYPLAN +_RESULTSETSTATS.fields_by_name['query_stats'].message_type = google_dot_protobuf_dot_struct__pb2._STRUCT +DESCRIPTOR.message_types_by_name['ResultSet'] = _RESULTSET +DESCRIPTOR.message_types_by_name['PartialResultSet'] = _PARTIALRESULTSET +DESCRIPTOR.message_types_by_name['ResultSetMetadata'] = _RESULTSETMETADATA +DESCRIPTOR.message_types_by_name['ResultSetStats'] = _RESULTSETSTATS + +ResultSet = _reflection.GeneratedProtocolMessageType('ResultSet', (_message.Message,), dict( + DESCRIPTOR = _RESULTSET, + __module__ = 'google.cloud.spanner_v1.proto.result_set_pb2' + , + __doc__ = """Results from [Read][google.spanner.v1.Spanner.Read] or + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. + + + Attributes: + metadata: + Metadata about the result set, such as row type information. + rows: + Each element in ``rows`` is a row whose format is defined by [ + metadata.row\_type][google.spanner.v1.ResultSetMetadata.row\_t + ype]. The ith element in each row matches the ith field in [me + tadata.row\_type][google.spanner.v1.ResultSetMetadata.row\_typ + e]. Elements are encoded based on type as described + [here][google.spanner.v1.TypeCode]. + stats: + Query plan and execution statistics for the query that + produced this result set. These can be requested by setting [E + xecuteSqlRequest.query\_mode][google.spanner.v1.ExecuteSqlRequ + est.query\_mode]. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.ResultSet) + )) +_sym_db.RegisterMessage(ResultSet) + +PartialResultSet = _reflection.GeneratedProtocolMessageType('PartialResultSet', (_message.Message,), dict( + DESCRIPTOR = _PARTIALRESULTSET, + __module__ = 'google.cloud.spanner_v1.proto.result_set_pb2' + , + __doc__ = """Partial results from a streaming read or SQL query. Streaming reads and + SQL queries better tolerate large result sets, large rows, and large + values, but are a little trickier to consume. + + + Attributes: + metadata: + Metadata about the result set, such as row type information. + Only present in the first response. + values: + A streamed result set consists of a stream of values, which + might be split into many ``PartialResultSet`` messages to + accommodate large rows and/or large values. Every N complete + values defines a row, where N is equal to the number of + entries in [metadata.row\_type.fields][google.spanner.v1.Struc + tType.fields]. Most values are encoded based on type as + described [here][google.spanner.v1.TypeCode]. It is possible + that the last value in values is "chunked", meaning that the + rest of the value is sent in subsequent ``PartialResultSet``\ + (s). This is denoted by the [chunked\_value][google.spanner.v1 + .PartialResultSet.chunked\_value] field. Two or more chunked + values can be merged to form a complete value as follows: - + ``bool/number/null``: cannot be chunked - ``string``: + concatenate the strings - ``list``: concatenate the lists. If + the last element in a list is a ``string``, ``list``, or + ``object``, merge it with the first element in the next + list by applying these rules recursively. - ``object``: + concatenate the (field name, field value) pairs. If a field + name is duplicated, then apply these rules recursively to + merge the field values. Some examples of merging: :: + # Strings are concatenated. "foo", "bar" => "foobar" + # Lists of non-strings are concatenated. [2, 3], [4] => + [2, 3, 4] # Lists are concatenated, but the last and + first elements are merged # because they are strings. + ["a", "b"], ["c", "d"] => ["a", "bc", "d"] # Lists are + concatenated, but the last and first elements are merged # + because they are lists. Recursively, the last and first + elements # of the inner lists are merged because they are + strings. ["a", ["b", "c"]], [["d"], "e"] => ["a", ["b", + "cd"], "e"] # Non-overlapping object fields are combined. + {"a": "1"}, {"b": "2"} => {"a": "1", "b": 2"} # + Overlapping object fields are merged. {"a": "1"}, {"a": + "2"} => {"a": "12"} # Examples of merging objects + containing lists of strings. {"a": ["1"]}, {"a": ["2"]} => + {"a": ["12"]} For a more complete example, suppose a + streaming SQL query is yielding a result set whose rows + contain a single string field. The following + ``PartialResultSet``\ s might be yielded: :: { + "metadata": { ... } "values": ["Hello", "W"] + "chunked_value": true "resume_token": "Af65..." } + { "values": ["orl"] "chunked_value": true + "resume_token": "Bqp2..." } { "values": ["d"] + "resume_token": "Zx1B..." } This sequence of + ``PartialResultSet``\ s encodes two rows, one containing the + field value ``"Hello"``, and a second containing the field + value ``"World" = "W" + "orl" + "d"``. + chunked_value: + If true, then the final value in + [values][google.spanner.v1.PartialResultSet.values] is + chunked, and must be combined with more values from subsequent + ``PartialResultSet``\ s to obtain a complete field value. + resume_token: + Streaming calls might be interrupted for a variety of reasons, + such as TCP connection loss. If this occurs, the stream of + results can be resumed by re-sending the original request and + including ``resume_token``. Note that executing any other + transaction in the same session invalidates the token. + stats: + Query plan and execution statistics for the query that + produced this streaming result set. These can be requested by + setting [ExecuteSqlRequest.query\_mode][google.spanner.v1.Exec + uteSqlRequest.query\_mode] and are sent only once with the + last response in the stream. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.PartialResultSet) + )) +_sym_db.RegisterMessage(PartialResultSet) + +ResultSetMetadata = _reflection.GeneratedProtocolMessageType('ResultSetMetadata', (_message.Message,), dict( + DESCRIPTOR = _RESULTSETMETADATA, + __module__ = 'google.cloud.spanner_v1.proto.result_set_pb2' + , + __doc__ = """Metadata about a [ResultSet][google.spanner.v1.ResultSet] or + [PartialResultSet][google.spanner.v1.PartialResultSet]. + + + Attributes: + row_type: + Indicates the field names and types for the rows in the result + set. For example, a SQL query like ``"SELECT UserId, UserName + FROM Users"`` could return a ``row_type`` value like: :: + "fields": [ { "name": "UserId", "type": { "code": + "INT64" } }, { "name": "UserName", "type": { "code": + "STRING" } }, ] + transaction: + If the read or SQL query began a transaction as a side-effect, + the information about the new transaction is yielded here. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.ResultSetMetadata) + )) +_sym_db.RegisterMessage(ResultSetMetadata) + +ResultSetStats = _reflection.GeneratedProtocolMessageType('ResultSetStats', (_message.Message,), dict( + DESCRIPTOR = _RESULTSETSTATS, + __module__ = 'google.cloud.spanner_v1.proto.result_set_pb2' + , + __doc__ = """Additional statistics about a [ResultSet][google.spanner.v1.ResultSet] + or [PartialResultSet][google.spanner.v1.PartialResultSet]. + + + Attributes: + query_plan: + [QueryPlan][google.spanner.v1.QueryPlan] for the query + associated with this result. + query_stats: + Aggregated statistics from the execution of the query. Only + present when the query is profiled. For example, a query could + return the statistics as follows: :: { + "rows_returned": "3", "elapsed_time": "1.22 secs", + "cpu_time": "1.19 secs" } + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.ResultSetStats) + )) +_sym_db.RegisterMessage(ResultSetStats) + + +DESCRIPTOR.has_options = True +DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\025com.google.spanner.v1B\016ResultSetProtoP\001Z8google.golang.org/genproto/googleapis/spanner/v1;spanner\252\002\027Google.Cloud.Spanner.V1')) +try: + # THESE ELEMENTS WILL BE DEPRECATED. + # Please use the generated *_pb2_grpc.py files instead. + import grpc + from grpc.beta import implementations as beta_implementations + from grpc.beta import interfaces as beta_interfaces + from grpc.framework.common import cardinality + from grpc.framework.interfaces.face import utilities as face_utilities +except ImportError: + pass +# @@protoc_insertion_point(module_scope) diff --git a/spanner/google/cloud/spanner_v1/proto/result_set_pb2_grpc.py b/spanner/google/cloud/spanner_v1/proto/result_set_pb2_grpc.py new file mode 100644 index 000000000000..a89435267cb2 --- /dev/null +++ b/spanner/google/cloud/spanner_v1/proto/result_set_pb2_grpc.py @@ -0,0 +1,3 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +import grpc + diff --git a/spanner/google/cloud/spanner_v1/proto/spanner_pb2.py b/spanner/google/cloud/spanner_v1/proto/spanner_pb2.py new file mode 100644 index 000000000000..658bd4117e47 --- /dev/null +++ b/spanner/google/cloud/spanner_v1/proto/spanner_pb2.py @@ -0,0 +1,1466 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/cloud/spanner_v1/proto/spanner.proto + +import sys +_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database +from google.protobuf import descriptor_pb2 +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + +from google.api import annotations_pb2 as google_dot_api_dot_annotations__pb2 +from google.api import auth_pb2 as google_dot_api_dot_auth__pb2 +from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb2 +from google.protobuf import struct_pb2 as google_dot_protobuf_dot_struct__pb2 +from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2 +from google.cloud.spanner_v1.proto import keys_pb2 as google_dot_cloud_dot_spanner__v1_dot_proto_dot_keys__pb2 +from google.cloud.spanner_v1.proto import mutation_pb2 as google_dot_cloud_dot_spanner__v1_dot_proto_dot_mutation__pb2 +from google.cloud.spanner_v1.proto import result_set_pb2 as google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2 +from google.cloud.spanner_v1.proto import transaction_pb2 as google_dot_cloud_dot_spanner__v1_dot_proto_dot_transaction__pb2 +from google.cloud.spanner_v1.proto import type_pb2 as google_dot_cloud_dot_spanner__v1_dot_proto_dot_type__pb2 + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='google/cloud/spanner_v1/proto/spanner.proto', + package='google.spanner.v1', + syntax='proto3', + serialized_pb=_b('\n+google/cloud/spanner_v1/proto/spanner.proto\x12\x11google.spanner.v1\x1a\x1cgoogle/api/annotations.proto\x1a\x15google/api/auth.proto\x1a\x1bgoogle/protobuf/empty.proto\x1a\x1cgoogle/protobuf/struct.proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a(google/cloud/spanner_v1/proto/keys.proto\x1a,google/cloud/spanner_v1/proto/mutation.proto\x1a.google/cloud/spanner_v1/proto/result_set.proto\x1a/google/cloud/spanner_v1/proto/transaction.proto\x1a(google/cloud/spanner_v1/proto/type.proto\"(\n\x14\x43reateSessionRequest\x12\x10\n\x08\x64\x61tabase\x18\x01 \x01(\t\"\x17\n\x07Session\x12\x0c\n\x04name\x18\x01 \x01(\t\"!\n\x11GetSessionRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"$\n\x14\x44\x65leteSessionRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"\xb8\x03\n\x11\x45xecuteSqlRequest\x12\x0f\n\x07session\x18\x01 \x01(\t\x12;\n\x0btransaction\x18\x02 \x01(\x0b\x32&.google.spanner.v1.TransactionSelector\x12\x0b\n\x03sql\x18\x03 \x01(\t\x12\'\n\x06params\x18\x04 \x01(\x0b\x32\x17.google.protobuf.Struct\x12I\n\x0bparam_types\x18\x05 \x03(\x0b\x32\x34.google.spanner.v1.ExecuteSqlRequest.ParamTypesEntry\x12\x14\n\x0cresume_token\x18\x06 \x01(\x0c\x12\x42\n\nquery_mode\x18\x07 \x01(\x0e\x32..google.spanner.v1.ExecuteSqlRequest.QueryMode\x1aJ\n\x0fParamTypesEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12&\n\x05value\x18\x02 \x01(\x0b\x32\x17.google.spanner.v1.Type:\x02\x38\x01\".\n\tQueryMode\x12\n\n\x06NORMAL\x10\x00\x12\x08\n\x04PLAN\x10\x01\x12\x0b\n\x07PROFILE\x10\x02\"\xdb\x01\n\x0bReadRequest\x12\x0f\n\x07session\x18\x01 \x01(\t\x12;\n\x0btransaction\x18\x02 \x01(\x0b\x32&.google.spanner.v1.TransactionSelector\x12\r\n\x05table\x18\x03 \x01(\t\x12\r\n\x05index\x18\x04 \x01(\t\x12\x0f\n\x07\x63olumns\x18\x05 \x03(\t\x12*\n\x07key_set\x18\x06 \x01(\x0b\x32\x19.google.spanner.v1.KeySet\x12\r\n\x05limit\x18\x08 \x01(\x03\x12\x14\n\x0cresume_token\x18\t \x01(\x0c\"b\n\x17\x42\x65ginTransactionRequest\x12\x0f\n\x07session\x18\x01 \x01(\t\x12\x36\n\x07options\x18\x02 \x01(\x0b\x32%.google.spanner.v1.TransactionOptions\"\xc2\x01\n\rCommitRequest\x12\x0f\n\x07session\x18\x01 \x01(\t\x12\x18\n\x0etransaction_id\x18\x02 \x01(\x0cH\x00\x12G\n\x16single_use_transaction\x18\x03 \x01(\x0b\x32%.google.spanner.v1.TransactionOptionsH\x00\x12.\n\tmutations\x18\x04 \x03(\x0b\x32\x1b.google.spanner.v1.MutationB\r\n\x0btransaction\"F\n\x0e\x43ommitResponse\x12\x34\n\x10\x63ommit_timestamp\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\":\n\x0fRollbackRequest\x12\x0f\n\x07session\x18\x01 \x01(\t\x12\x16\n\x0etransaction_id\x18\x02 \x01(\x0c\x32\xe9\x0c\n\x07Spanner\x12\x98\x01\n\rCreateSession\x12\'.google.spanner.v1.CreateSessionRequest\x1a\x1a.google.spanner.v1.Session\"B\x82\xd3\xe4\x93\x02<\":/v1/{database=projects/*/instances/*/databases/*}/sessions\x12\x90\x01\n\nGetSession\x12$.google.spanner.v1.GetSessionRequest\x1a\x1a.google.spanner.v1.Session\"@\x82\xd3\xe4\x93\x02:\x12\x38/v1/{name=projects/*/instances/*/databases/*/sessions/*}\x12\x92\x01\n\rDeleteSession\x12\'.google.spanner.v1.DeleteSessionRequest\x1a\x16.google.protobuf.Empty\"@\x82\xd3\xe4\x93\x02:*8/v1/{name=projects/*/instances/*/databases/*/sessions/*}\x12\xa3\x01\n\nExecuteSql\x12$.google.spanner.v1.ExecuteSqlRequest\x1a\x1c.google.spanner.v1.ResultSet\"Q\x82\xd3\xe4\x93\x02K\"F/v1/{session=projects/*/instances/*/databases/*/sessions/*}:executeSql:\x01*\x12\xbe\x01\n\x13\x45xecuteStreamingSql\x12$.google.spanner.v1.ExecuteSqlRequest\x1a#.google.spanner.v1.PartialResultSet\"Z\x82\xd3\xe4\x93\x02T\"O/v1/{session=projects/*/instances/*/databases/*/sessions/*}:executeStreamingSql:\x01*0\x01\x12\x91\x01\n\x04Read\x12\x1e.google.spanner.v1.ReadRequest\x1a\x1c.google.spanner.v1.ResultSet\"K\x82\xd3\xe4\x93\x02\x45\"@/v1/{session=projects/*/instances/*/databases/*/sessions/*}:read:\x01*\x12\xac\x01\n\rStreamingRead\x12\x1e.google.spanner.v1.ReadRequest\x1a#.google.spanner.v1.PartialResultSet\"T\x82\xd3\xe4\x93\x02N\"I/v1/{session=projects/*/instances/*/databases/*/sessions/*}:streamingRead:\x01*0\x01\x12\xb7\x01\n\x10\x42\x65ginTransaction\x12*.google.spanner.v1.BeginTransactionRequest\x1a\x1e.google.spanner.v1.Transaction\"W\x82\xd3\xe4\x93\x02Q\"L/v1/{session=projects/*/instances/*/databases/*/sessions/*}:beginTransaction:\x01*\x12\x9c\x01\n\x06\x43ommit\x12 .google.spanner.v1.CommitRequest\x1a!.google.spanner.v1.CommitResponse\"M\x82\xd3\xe4\x93\x02G\"B/v1/{session=projects/*/instances/*/databases/*/sessions/*}:commit:\x01*\x12\x97\x01\n\x08Rollback\x12\".google.spanner.v1.RollbackRequest\x1a\x16.google.protobuf.Empty\"O\x82\xd3\xe4\x93\x02I\"D/v1/{session=projects/*/instances/*/databases/*/sessions/*}:rollback:\x01*B{\n\x15\x63om.google.spanner.v1B\x0cSpannerProtoP\x01Z8google.golang.org/genproto/googleapis/spanner/v1;spanner\xaa\x02\x17Google.Cloud.Spanner.V1b\x06proto3') + , + dependencies=[google_dot_api_dot_annotations__pb2.DESCRIPTOR,google_dot_api_dot_auth__pb2.DESCRIPTOR,google_dot_protobuf_dot_empty__pb2.DESCRIPTOR,google_dot_protobuf_dot_struct__pb2.DESCRIPTOR,google_dot_protobuf_dot_timestamp__pb2.DESCRIPTOR,google_dot_cloud_dot_spanner__v1_dot_proto_dot_keys__pb2.DESCRIPTOR,google_dot_cloud_dot_spanner__v1_dot_proto_dot_mutation__pb2.DESCRIPTOR,google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2.DESCRIPTOR,google_dot_cloud_dot_spanner__v1_dot_proto_dot_transaction__pb2.DESCRIPTOR,google_dot_cloud_dot_spanner__v1_dot_proto_dot_type__pb2.DESCRIPTOR,]) +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + + + +_EXECUTESQLREQUEST_QUERYMODE = _descriptor.EnumDescriptor( + name='QueryMode', + full_name='google.spanner.v1.ExecuteSqlRequest.QueryMode', + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name='NORMAL', index=0, number=0, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='PLAN', index=1, number=1, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='PROFILE', index=2, number=2, + options=None, + type=None), + ], + containing_type=None, + options=None, + serialized_start=973, + serialized_end=1019, +) +_sym_db.RegisterEnumDescriptor(_EXECUTESQLREQUEST_QUERYMODE) + + +_CREATESESSIONREQUEST = _descriptor.Descriptor( + name='CreateSessionRequest', + full_name='google.spanner.v1.CreateSessionRequest', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='database', full_name='google.spanner.v1.CreateSessionRequest.database', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=438, + serialized_end=478, +) + + +_SESSION = _descriptor.Descriptor( + name='Session', + full_name='google.spanner.v1.Session', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='name', full_name='google.spanner.v1.Session.name', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=480, + serialized_end=503, +) + + +_GETSESSIONREQUEST = _descriptor.Descriptor( + name='GetSessionRequest', + full_name='google.spanner.v1.GetSessionRequest', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='name', full_name='google.spanner.v1.GetSessionRequest.name', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=505, + serialized_end=538, +) + + +_DELETESESSIONREQUEST = _descriptor.Descriptor( + name='DeleteSessionRequest', + full_name='google.spanner.v1.DeleteSessionRequest', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='name', full_name='google.spanner.v1.DeleteSessionRequest.name', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=540, + serialized_end=576, +) + + +_EXECUTESQLREQUEST_PARAMTYPESENTRY = _descriptor.Descriptor( + name='ParamTypesEntry', + full_name='google.spanner.v1.ExecuteSqlRequest.ParamTypesEntry', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='key', full_name='google.spanner.v1.ExecuteSqlRequest.ParamTypesEntry.key', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='value', full_name='google.spanner.v1.ExecuteSqlRequest.ParamTypesEntry.value', index=1, + number=2, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=_descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('8\001')), + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=897, + serialized_end=971, +) + +_EXECUTESQLREQUEST = _descriptor.Descriptor( + name='ExecuteSqlRequest', + full_name='google.spanner.v1.ExecuteSqlRequest', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='session', full_name='google.spanner.v1.ExecuteSqlRequest.session', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='transaction', full_name='google.spanner.v1.ExecuteSqlRequest.transaction', index=1, + number=2, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='sql', full_name='google.spanner.v1.ExecuteSqlRequest.sql', index=2, + number=3, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='params', full_name='google.spanner.v1.ExecuteSqlRequest.params', index=3, + number=4, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='param_types', full_name='google.spanner.v1.ExecuteSqlRequest.param_types', index=4, + number=5, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='resume_token', full_name='google.spanner.v1.ExecuteSqlRequest.resume_token', index=5, + number=6, type=12, cpp_type=9, label=1, + has_default_value=False, default_value=_b(""), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='query_mode', full_name='google.spanner.v1.ExecuteSqlRequest.query_mode', index=6, + number=7, type=14, cpp_type=8, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[_EXECUTESQLREQUEST_PARAMTYPESENTRY, ], + enum_types=[ + _EXECUTESQLREQUEST_QUERYMODE, + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=579, + serialized_end=1019, +) + + +_READREQUEST = _descriptor.Descriptor( + name='ReadRequest', + full_name='google.spanner.v1.ReadRequest', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='session', full_name='google.spanner.v1.ReadRequest.session', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='transaction', full_name='google.spanner.v1.ReadRequest.transaction', index=1, + number=2, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='table', full_name='google.spanner.v1.ReadRequest.table', index=2, + number=3, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='index', full_name='google.spanner.v1.ReadRequest.index', index=3, + number=4, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='columns', full_name='google.spanner.v1.ReadRequest.columns', index=4, + number=5, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='key_set', full_name='google.spanner.v1.ReadRequest.key_set', index=5, + number=6, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='limit', full_name='google.spanner.v1.ReadRequest.limit', index=6, + number=8, type=3, cpp_type=2, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='resume_token', full_name='google.spanner.v1.ReadRequest.resume_token', index=7, + number=9, type=12, cpp_type=9, label=1, + has_default_value=False, default_value=_b(""), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1022, + serialized_end=1241, +) + + +_BEGINTRANSACTIONREQUEST = _descriptor.Descriptor( + name='BeginTransactionRequest', + full_name='google.spanner.v1.BeginTransactionRequest', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='session', full_name='google.spanner.v1.BeginTransactionRequest.session', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='options', full_name='google.spanner.v1.BeginTransactionRequest.options', index=1, + number=2, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1243, + serialized_end=1341, +) + + +_COMMITREQUEST = _descriptor.Descriptor( + name='CommitRequest', + full_name='google.spanner.v1.CommitRequest', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='session', full_name='google.spanner.v1.CommitRequest.session', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='transaction_id', full_name='google.spanner.v1.CommitRequest.transaction_id', index=1, + number=2, type=12, cpp_type=9, label=1, + has_default_value=False, default_value=_b(""), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='single_use_transaction', full_name='google.spanner.v1.CommitRequest.single_use_transaction', index=2, + number=3, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='mutations', full_name='google.spanner.v1.CommitRequest.mutations', index=3, + number=4, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + _descriptor.OneofDescriptor( + name='transaction', full_name='google.spanner.v1.CommitRequest.transaction', + index=0, containing_type=None, fields=[]), + ], + serialized_start=1344, + serialized_end=1538, +) + + +_COMMITRESPONSE = _descriptor.Descriptor( + name='CommitResponse', + full_name='google.spanner.v1.CommitResponse', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='commit_timestamp', full_name='google.spanner.v1.CommitResponse.commit_timestamp', index=0, + number=1, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1540, + serialized_end=1610, +) + + +_ROLLBACKREQUEST = _descriptor.Descriptor( + name='RollbackRequest', + full_name='google.spanner.v1.RollbackRequest', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='session', full_name='google.spanner.v1.RollbackRequest.session', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='transaction_id', full_name='google.spanner.v1.RollbackRequest.transaction_id', index=1, + number=2, type=12, cpp_type=9, label=1, + has_default_value=False, default_value=_b(""), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1612, + serialized_end=1670, +) + +_EXECUTESQLREQUEST_PARAMTYPESENTRY.fields_by_name['value'].message_type = google_dot_cloud_dot_spanner__v1_dot_proto_dot_type__pb2._TYPE +_EXECUTESQLREQUEST_PARAMTYPESENTRY.containing_type = _EXECUTESQLREQUEST +_EXECUTESQLREQUEST.fields_by_name['transaction'].message_type = google_dot_cloud_dot_spanner__v1_dot_proto_dot_transaction__pb2._TRANSACTIONSELECTOR +_EXECUTESQLREQUEST.fields_by_name['params'].message_type = google_dot_protobuf_dot_struct__pb2._STRUCT +_EXECUTESQLREQUEST.fields_by_name['param_types'].message_type = _EXECUTESQLREQUEST_PARAMTYPESENTRY +_EXECUTESQLREQUEST.fields_by_name['query_mode'].enum_type = _EXECUTESQLREQUEST_QUERYMODE +_EXECUTESQLREQUEST_QUERYMODE.containing_type = _EXECUTESQLREQUEST +_READREQUEST.fields_by_name['transaction'].message_type = google_dot_cloud_dot_spanner__v1_dot_proto_dot_transaction__pb2._TRANSACTIONSELECTOR +_READREQUEST.fields_by_name['key_set'].message_type = google_dot_cloud_dot_spanner__v1_dot_proto_dot_keys__pb2._KEYSET +_BEGINTRANSACTIONREQUEST.fields_by_name['options'].message_type = google_dot_cloud_dot_spanner__v1_dot_proto_dot_transaction__pb2._TRANSACTIONOPTIONS +_COMMITREQUEST.fields_by_name['single_use_transaction'].message_type = google_dot_cloud_dot_spanner__v1_dot_proto_dot_transaction__pb2._TRANSACTIONOPTIONS +_COMMITREQUEST.fields_by_name['mutations'].message_type = google_dot_cloud_dot_spanner__v1_dot_proto_dot_mutation__pb2._MUTATION +_COMMITREQUEST.oneofs_by_name['transaction'].fields.append( + _COMMITREQUEST.fields_by_name['transaction_id']) +_COMMITREQUEST.fields_by_name['transaction_id'].containing_oneof = _COMMITREQUEST.oneofs_by_name['transaction'] +_COMMITREQUEST.oneofs_by_name['transaction'].fields.append( + _COMMITREQUEST.fields_by_name['single_use_transaction']) +_COMMITREQUEST.fields_by_name['single_use_transaction'].containing_oneof = _COMMITREQUEST.oneofs_by_name['transaction'] +_COMMITRESPONSE.fields_by_name['commit_timestamp'].message_type = google_dot_protobuf_dot_timestamp__pb2._TIMESTAMP +DESCRIPTOR.message_types_by_name['CreateSessionRequest'] = _CREATESESSIONREQUEST +DESCRIPTOR.message_types_by_name['Session'] = _SESSION +DESCRIPTOR.message_types_by_name['GetSessionRequest'] = _GETSESSIONREQUEST +DESCRIPTOR.message_types_by_name['DeleteSessionRequest'] = _DELETESESSIONREQUEST +DESCRIPTOR.message_types_by_name['ExecuteSqlRequest'] = _EXECUTESQLREQUEST +DESCRIPTOR.message_types_by_name['ReadRequest'] = _READREQUEST +DESCRIPTOR.message_types_by_name['BeginTransactionRequest'] = _BEGINTRANSACTIONREQUEST +DESCRIPTOR.message_types_by_name['CommitRequest'] = _COMMITREQUEST +DESCRIPTOR.message_types_by_name['CommitResponse'] = _COMMITRESPONSE +DESCRIPTOR.message_types_by_name['RollbackRequest'] = _ROLLBACKREQUEST + +CreateSessionRequest = _reflection.GeneratedProtocolMessageType('CreateSessionRequest', (_message.Message,), dict( + DESCRIPTOR = _CREATESESSIONREQUEST, + __module__ = 'google.cloud.spanner_v1.proto.spanner_pb2' + , + __doc__ = """The request for + [CreateSession][google.spanner.v1.Spanner.CreateSession]. + + + Attributes: + database: + Required. The database in which the new session is created. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.CreateSessionRequest) + )) +_sym_db.RegisterMessage(CreateSessionRequest) + +Session = _reflection.GeneratedProtocolMessageType('Session', (_message.Message,), dict( + DESCRIPTOR = _SESSION, + __module__ = 'google.cloud.spanner_v1.proto.spanner_pb2' + , + __doc__ = """A session in the Cloud Spanner API. + + + Attributes: + name: + Required. The name of the session. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.Session) + )) +_sym_db.RegisterMessage(Session) + +GetSessionRequest = _reflection.GeneratedProtocolMessageType('GetSessionRequest', (_message.Message,), dict( + DESCRIPTOR = _GETSESSIONREQUEST, + __module__ = 'google.cloud.spanner_v1.proto.spanner_pb2' + , + __doc__ = """The request for [GetSession][google.spanner.v1.Spanner.GetSession]. + + + Attributes: + name: + Required. The name of the session to retrieve. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.GetSessionRequest) + )) +_sym_db.RegisterMessage(GetSessionRequest) + +DeleteSessionRequest = _reflection.GeneratedProtocolMessageType('DeleteSessionRequest', (_message.Message,), dict( + DESCRIPTOR = _DELETESESSIONREQUEST, + __module__ = 'google.cloud.spanner_v1.proto.spanner_pb2' + , + __doc__ = """The request for + [DeleteSession][google.spanner.v1.Spanner.DeleteSession]. + + + Attributes: + name: + Required. The name of the session to delete. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.DeleteSessionRequest) + )) +_sym_db.RegisterMessage(DeleteSessionRequest) + +ExecuteSqlRequest = _reflection.GeneratedProtocolMessageType('ExecuteSqlRequest', (_message.Message,), dict( + + ParamTypesEntry = _reflection.GeneratedProtocolMessageType('ParamTypesEntry', (_message.Message,), dict( + DESCRIPTOR = _EXECUTESQLREQUEST_PARAMTYPESENTRY, + __module__ = 'google.cloud.spanner_v1.proto.spanner_pb2' + # @@protoc_insertion_point(class_scope:google.spanner.v1.ExecuteSqlRequest.ParamTypesEntry) + )) + , + DESCRIPTOR = _EXECUTESQLREQUEST, + __module__ = 'google.cloud.spanner_v1.proto.spanner_pb2' + , + __doc__ = """The request for [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and + [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql]. + + + Attributes: + session: + Required. The session in which the SQL query should be + performed. + transaction: + The transaction to use. If none is provided, the default is a + temporary read-only transaction with strong concurrency. + sql: + Required. The SQL query string. + params: + The SQL query string can contain parameter placeholders. A + parameter placeholder consists of ``'@'`` followed by the + parameter name. Parameter names consist of any combination of + letters, numbers, and underscores. Parameters can appear + anywhere that a literal value is expected. The same parameter + name can be used more than once, for example: ``"WHERE id > + @msg_id AND id < @msg_id + 100"`` It is an error to execute + an SQL query with unbound parameters. Parameter values are + specified using ``params``, which is a JSON object whose keys + are parameter names, and whose values are the corresponding + parameter values. + param_types: + It is not always possible for Cloud Spanner to infer the right + SQL type from a JSON value. For example, values of type + ``BYTES`` and values of type ``STRING`` both appear in + [params][google.spanner.v1.ExecuteSqlRequest.params] as JSON + strings. In these cases, ``param_types`` can be used to + specify the exact SQL type for some or all of the SQL query + parameters. See the definition of + [Type][google.spanner.v1.Type] for more information about SQL + types. + resume_token: + If this request is resuming a previously interrupted SQL query + execution, ``resume_token`` should be copied from the last + [PartialResultSet][google.spanner.v1.PartialResultSet] yielded + before the interruption. Doing this enables the new SQL query + execution to resume where the last one left off. The rest of + the request parameters must exactly match the request that + yielded this token. + query_mode: + Used to control the amount of debugging information returned + in [ResultSetStats][google.spanner.v1.ResultSetStats]. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.ExecuteSqlRequest) + )) +_sym_db.RegisterMessage(ExecuteSqlRequest) +_sym_db.RegisterMessage(ExecuteSqlRequest.ParamTypesEntry) + +ReadRequest = _reflection.GeneratedProtocolMessageType('ReadRequest', (_message.Message,), dict( + DESCRIPTOR = _READREQUEST, + __module__ = 'google.cloud.spanner_v1.proto.spanner_pb2' + , + __doc__ = """The request for [Read][google.spanner.v1.Spanner.Read] and + [StreamingRead][google.spanner.v1.Spanner.StreamingRead]. + + + Attributes: + session: + Required. The session in which the read should be performed. + transaction: + The transaction to use. If none is provided, the default is a + temporary read-only transaction with strong concurrency. + table: + Required. The name of the table in the database to be read. + index: + If non-empty, the name of an index on + [table][google.spanner.v1.ReadRequest.table]. This index is + used instead of the table primary key when interpreting + [key\_set][google.spanner.v1.ReadRequest.key\_set] and sorting + result rows. See + [key\_set][google.spanner.v1.ReadRequest.key\_set] for further + information. + columns: + The columns of [table][google.spanner.v1.ReadRequest.table] to + be returned for each row matching this request. + key_set: + Required. ``key_set`` identifies the rows to be yielded. + ``key_set`` names the primary keys of the rows in + [table][google.spanner.v1.ReadRequest.table] to be yielded, + unless [index][google.spanner.v1.ReadRequest.index] is + present. If [index][google.spanner.v1.ReadRequest.index] is + present, then + [key\_set][google.spanner.v1.ReadRequest.key\_set] instead + names index keys in + [index][google.spanner.v1.ReadRequest.index]. Rows are + yielded in table primary key order (if + [index][google.spanner.v1.ReadRequest.index] is empty) or + index key order (if + [index][google.spanner.v1.ReadRequest.index] is non-empty). + It is not an error for the ``key_set`` to name rows that do + not exist in the database. Read yields nothing for nonexistent + rows. + limit: + If greater than zero, only the first ``limit`` rows are + yielded. If ``limit`` is zero, the default is no limit. + resume_token: + If this request is resuming a previously interrupted read, + ``resume_token`` should be copied from the last + [PartialResultSet][google.spanner.v1.PartialResultSet] yielded + before the interruption. Doing this enables the new read to + resume where the last read left off. The rest of the request + parameters must exactly match the request that yielded this + token. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.ReadRequest) + )) +_sym_db.RegisterMessage(ReadRequest) + +BeginTransactionRequest = _reflection.GeneratedProtocolMessageType('BeginTransactionRequest', (_message.Message,), dict( + DESCRIPTOR = _BEGINTRANSACTIONREQUEST, + __module__ = 'google.cloud.spanner_v1.proto.spanner_pb2' + , + __doc__ = """The request for + [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction]. + + + Attributes: + session: + Required. The session in which the transaction runs. + options: + Required. Options for the new transaction. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.BeginTransactionRequest) + )) +_sym_db.RegisterMessage(BeginTransactionRequest) + +CommitRequest = _reflection.GeneratedProtocolMessageType('CommitRequest', (_message.Message,), dict( + DESCRIPTOR = _COMMITREQUEST, + __module__ = 'google.cloud.spanner_v1.proto.spanner_pb2' + , + __doc__ = """The request for [Commit][google.spanner.v1.Spanner.Commit]. + + + Attributes: + session: + Required. The session in which the transaction to be committed + is running. + transaction: + Required. The transaction in which to commit. + transaction_id: + Commit a previously-started transaction. + single_use_transaction: + Execute mutations in a temporary transaction. Note that unlike + commit of a previously-started transaction, commit with a + temporary transaction is non-idempotent. That is, if the + ``CommitRequest`` is sent to Cloud Spanner more than once (for + instance, due to retries in the application, or in the + transport library), it is possible that the mutations are + executed more than once. If this is undesirable, use + [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction] + and [Commit][google.spanner.v1.Spanner.Commit] instead. + mutations: + The mutations to be executed when this transaction commits. + All mutations are applied atomically, in the order they appear + in this list. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.CommitRequest) + )) +_sym_db.RegisterMessage(CommitRequest) + +CommitResponse = _reflection.GeneratedProtocolMessageType('CommitResponse', (_message.Message,), dict( + DESCRIPTOR = _COMMITRESPONSE, + __module__ = 'google.cloud.spanner_v1.proto.spanner_pb2' + , + __doc__ = """The response for [Commit][google.spanner.v1.Spanner.Commit]. + + + Attributes: + commit_timestamp: + The Cloud Spanner timestamp at which the transaction + committed. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.CommitResponse) + )) +_sym_db.RegisterMessage(CommitResponse) + +RollbackRequest = _reflection.GeneratedProtocolMessageType('RollbackRequest', (_message.Message,), dict( + DESCRIPTOR = _ROLLBACKREQUEST, + __module__ = 'google.cloud.spanner_v1.proto.spanner_pb2' + , + __doc__ = """The request for [Rollback][google.spanner.v1.Spanner.Rollback]. + + + Attributes: + session: + Required. The session in which the transaction to roll back is + running. + transaction_id: + Required. The transaction to roll back. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.RollbackRequest) + )) +_sym_db.RegisterMessage(RollbackRequest) + + +DESCRIPTOR.has_options = True +DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\025com.google.spanner.v1B\014SpannerProtoP\001Z8google.golang.org/genproto/googleapis/spanner/v1;spanner\252\002\027Google.Cloud.Spanner.V1')) +_EXECUTESQLREQUEST_PARAMTYPESENTRY.has_options = True +_EXECUTESQLREQUEST_PARAMTYPESENTRY._options = _descriptor._ParseOptions(descriptor_pb2.MessageOptions(), _b('8\001')) +try: + # THESE ELEMENTS WILL BE DEPRECATED. + # Please use the generated *_pb2_grpc.py files instead. + import grpc + from grpc.beta import implementations as beta_implementations + from grpc.beta import interfaces as beta_interfaces + from grpc.framework.common import cardinality + from grpc.framework.interfaces.face import utilities as face_utilities + + + class SpannerStub(object): + """Cloud Spanner API + + The Cloud Spanner API can be used to manage sessions and execute + transactions on data stored in Cloud Spanner databases. + """ + + def __init__(self, channel): + """Constructor. + + Args: + channel: A grpc.Channel. + """ + self.CreateSession = channel.unary_unary( + '/google.spanner.v1.Spanner/CreateSession', + request_serializer=CreateSessionRequest.SerializeToString, + response_deserializer=Session.FromString, + ) + self.GetSession = channel.unary_unary( + '/google.spanner.v1.Spanner/GetSession', + request_serializer=GetSessionRequest.SerializeToString, + response_deserializer=Session.FromString, + ) + self.DeleteSession = channel.unary_unary( + '/google.spanner.v1.Spanner/DeleteSession', + request_serializer=DeleteSessionRequest.SerializeToString, + response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString, + ) + self.ExecuteSql = channel.unary_unary( + '/google.spanner.v1.Spanner/ExecuteSql', + request_serializer=ExecuteSqlRequest.SerializeToString, + response_deserializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2.ResultSet.FromString, + ) + self.ExecuteStreamingSql = channel.unary_stream( + '/google.spanner.v1.Spanner/ExecuteStreamingSql', + request_serializer=ExecuteSqlRequest.SerializeToString, + response_deserializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2.PartialResultSet.FromString, + ) + self.Read = channel.unary_unary( + '/google.spanner.v1.Spanner/Read', + request_serializer=ReadRequest.SerializeToString, + response_deserializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2.ResultSet.FromString, + ) + self.StreamingRead = channel.unary_stream( + '/google.spanner.v1.Spanner/StreamingRead', + request_serializer=ReadRequest.SerializeToString, + response_deserializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2.PartialResultSet.FromString, + ) + self.BeginTransaction = channel.unary_unary( + '/google.spanner.v1.Spanner/BeginTransaction', + request_serializer=BeginTransactionRequest.SerializeToString, + response_deserializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_transaction__pb2.Transaction.FromString, + ) + self.Commit = channel.unary_unary( + '/google.spanner.v1.Spanner/Commit', + request_serializer=CommitRequest.SerializeToString, + response_deserializer=CommitResponse.FromString, + ) + self.Rollback = channel.unary_unary( + '/google.spanner.v1.Spanner/Rollback', + request_serializer=RollbackRequest.SerializeToString, + response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString, + ) + + + class SpannerServicer(object): + """Cloud Spanner API + + The Cloud Spanner API can be used to manage sessions and execute + transactions on data stored in Cloud Spanner databases. + """ + + def CreateSession(self, request, context): + """Creates a new session. A session can be used to perform + transactions that read and/or modify data in a Cloud Spanner database. + Sessions are meant to be reused for many consecutive + transactions. + + Sessions can only execute one transaction at a time. To execute + multiple concurrent read-write/write-only transactions, create + multiple sessions. Note that standalone reads and queries use a + transaction internally, and count toward the one transaction + limit. + + Cloud Spanner limits the number of sessions that can exist at any given + time; thus, it is a good idea to delete idle and/or unneeded sessions. + Aside from explicit deletes, Cloud Spanner can delete sessions for which no + operations are sent for more than an hour. If a session is deleted, + requests to it return `NOT_FOUND`. + + Idle sessions can be kept alive by sending a trivial SQL query + periodically, e.g., `"SELECT 1"`. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def GetSession(self, request, context): + """Gets a session. Returns `NOT_FOUND` if the session does not exist. + This is mainly useful for determining whether a session is still + alive. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def DeleteSession(self, request, context): + """Ends a session, releasing server resources associated with it. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def ExecuteSql(self, request, context): + """Executes an SQL query, returning all rows in a single reply. This + method cannot be used to return a result set larger than 10 MiB; + if the query yields more data than that, the query fails with + a `FAILED_PRECONDITION` error. + + Queries inside read-write transactions might return `ABORTED`. If + this occurs, the application should restart the transaction from + the beginning. See [Transaction][google.spanner.v1.Transaction] for more details. + + Larger result sets can be fetched in streaming fashion by calling + [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] instead. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def ExecuteStreamingSql(self, request, context): + """Like [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], except returns the result + set as a stream. Unlike [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], there + is no limit on the size of the returned result set. However, no + individual row in the result set can exceed 100 MiB, and no + column value can exceed 10 MiB. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def Read(self, request, context): + """Reads rows from the database using key lookups and scans, as a + simple key/value style alternative to + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. This method cannot be used to + return a result set larger than 10 MiB; if the read matches more + data than that, the read fails with a `FAILED_PRECONDITION` + error. + + Reads inside read-write transactions might return `ABORTED`. If + this occurs, the application should restart the transaction from + the beginning. See [Transaction][google.spanner.v1.Transaction] for more details. + + Larger result sets can be yielded in streaming fashion by calling + [StreamingRead][google.spanner.v1.Spanner.StreamingRead] instead. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def StreamingRead(self, request, context): + """Like [Read][google.spanner.v1.Spanner.Read], except returns the result set as a + stream. Unlike [Read][google.spanner.v1.Spanner.Read], there is no limit on the + size of the returned result set. However, no individual row in + the result set can exceed 100 MiB, and no column value can exceed + 10 MiB. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def BeginTransaction(self, request, context): + """Begins a new transaction. This step can often be skipped: + [Read][google.spanner.v1.Spanner.Read], [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and + [Commit][google.spanner.v1.Spanner.Commit] can begin a new transaction as a + side-effect. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def Commit(self, request, context): + """Commits a transaction. The request includes the mutations to be + applied to rows in the database. + + `Commit` might return an `ABORTED` error. This can occur at any time; + commonly, the cause is conflicts with concurrent + transactions. However, it can also happen for a variety of other + reasons. If `Commit` returns `ABORTED`, the caller should re-attempt + the transaction from the beginning, re-using the same session. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def Rollback(self, request, context): + """Rolls back a transaction, releasing any locks it holds. It is a good + idea to call this for any transaction that includes one or more + [Read][google.spanner.v1.Spanner.Read] or [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] requests and + ultimately decides not to commit. + + `Rollback` returns `OK` if it successfully aborts the transaction, the + transaction was already aborted, or the transaction is not + found. `Rollback` never returns `ABORTED`. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + + def add_SpannerServicer_to_server(servicer, server): + rpc_method_handlers = { + 'CreateSession': grpc.unary_unary_rpc_method_handler( + servicer.CreateSession, + request_deserializer=CreateSessionRequest.FromString, + response_serializer=Session.SerializeToString, + ), + 'GetSession': grpc.unary_unary_rpc_method_handler( + servicer.GetSession, + request_deserializer=GetSessionRequest.FromString, + response_serializer=Session.SerializeToString, + ), + 'DeleteSession': grpc.unary_unary_rpc_method_handler( + servicer.DeleteSession, + request_deserializer=DeleteSessionRequest.FromString, + response_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString, + ), + 'ExecuteSql': grpc.unary_unary_rpc_method_handler( + servicer.ExecuteSql, + request_deserializer=ExecuteSqlRequest.FromString, + response_serializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2.ResultSet.SerializeToString, + ), + 'ExecuteStreamingSql': grpc.unary_stream_rpc_method_handler( + servicer.ExecuteStreamingSql, + request_deserializer=ExecuteSqlRequest.FromString, + response_serializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2.PartialResultSet.SerializeToString, + ), + 'Read': grpc.unary_unary_rpc_method_handler( + servicer.Read, + request_deserializer=ReadRequest.FromString, + response_serializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2.ResultSet.SerializeToString, + ), + 'StreamingRead': grpc.unary_stream_rpc_method_handler( + servicer.StreamingRead, + request_deserializer=ReadRequest.FromString, + response_serializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2.PartialResultSet.SerializeToString, + ), + 'BeginTransaction': grpc.unary_unary_rpc_method_handler( + servicer.BeginTransaction, + request_deserializer=BeginTransactionRequest.FromString, + response_serializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_transaction__pb2.Transaction.SerializeToString, + ), + 'Commit': grpc.unary_unary_rpc_method_handler( + servicer.Commit, + request_deserializer=CommitRequest.FromString, + response_serializer=CommitResponse.SerializeToString, + ), + 'Rollback': grpc.unary_unary_rpc_method_handler( + servicer.Rollback, + request_deserializer=RollbackRequest.FromString, + response_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString, + ), + } + generic_handler = grpc.method_handlers_generic_handler( + 'google.spanner.v1.Spanner', rpc_method_handlers) + server.add_generic_rpc_handlers((generic_handler,)) + + + class BetaSpannerServicer(object): + """The Beta API is deprecated for 0.15.0 and later. + + It is recommended to use the GA API (classes and functions in this + file not marked beta) for all further purposes. This class was generated + only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0.""" + """Cloud Spanner API + + The Cloud Spanner API can be used to manage sessions and execute + transactions on data stored in Cloud Spanner databases. + """ + def CreateSession(self, request, context): + """Creates a new session. A session can be used to perform + transactions that read and/or modify data in a Cloud Spanner database. + Sessions are meant to be reused for many consecutive + transactions. + + Sessions can only execute one transaction at a time. To execute + multiple concurrent read-write/write-only transactions, create + multiple sessions. Note that standalone reads and queries use a + transaction internally, and count toward the one transaction + limit. + + Cloud Spanner limits the number of sessions that can exist at any given + time; thus, it is a good idea to delete idle and/or unneeded sessions. + Aside from explicit deletes, Cloud Spanner can delete sessions for which no + operations are sent for more than an hour. If a session is deleted, + requests to it return `NOT_FOUND`. + + Idle sessions can be kept alive by sending a trivial SQL query + periodically, e.g., `"SELECT 1"`. + """ + context.code(beta_interfaces.StatusCode.UNIMPLEMENTED) + def GetSession(self, request, context): + """Gets a session. Returns `NOT_FOUND` if the session does not exist. + This is mainly useful for determining whether a session is still + alive. + """ + context.code(beta_interfaces.StatusCode.UNIMPLEMENTED) + def DeleteSession(self, request, context): + """Ends a session, releasing server resources associated with it. + """ + context.code(beta_interfaces.StatusCode.UNIMPLEMENTED) + def ExecuteSql(self, request, context): + """Executes an SQL query, returning all rows in a single reply. This + method cannot be used to return a result set larger than 10 MiB; + if the query yields more data than that, the query fails with + a `FAILED_PRECONDITION` error. + + Queries inside read-write transactions might return `ABORTED`. If + this occurs, the application should restart the transaction from + the beginning. See [Transaction][google.spanner.v1.Transaction] for more details. + + Larger result sets can be fetched in streaming fashion by calling + [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] instead. + """ + context.code(beta_interfaces.StatusCode.UNIMPLEMENTED) + def ExecuteStreamingSql(self, request, context): + """Like [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], except returns the result + set as a stream. Unlike [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], there + is no limit on the size of the returned result set. However, no + individual row in the result set can exceed 100 MiB, and no + column value can exceed 10 MiB. + """ + context.code(beta_interfaces.StatusCode.UNIMPLEMENTED) + def Read(self, request, context): + """Reads rows from the database using key lookups and scans, as a + simple key/value style alternative to + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. This method cannot be used to + return a result set larger than 10 MiB; if the read matches more + data than that, the read fails with a `FAILED_PRECONDITION` + error. + + Reads inside read-write transactions might return `ABORTED`. If + this occurs, the application should restart the transaction from + the beginning. See [Transaction][google.spanner.v1.Transaction] for more details. + + Larger result sets can be yielded in streaming fashion by calling + [StreamingRead][google.spanner.v1.Spanner.StreamingRead] instead. + """ + context.code(beta_interfaces.StatusCode.UNIMPLEMENTED) + def StreamingRead(self, request, context): + """Like [Read][google.spanner.v1.Spanner.Read], except returns the result set as a + stream. Unlike [Read][google.spanner.v1.Spanner.Read], there is no limit on the + size of the returned result set. However, no individual row in + the result set can exceed 100 MiB, and no column value can exceed + 10 MiB. + """ + context.code(beta_interfaces.StatusCode.UNIMPLEMENTED) + def BeginTransaction(self, request, context): + """Begins a new transaction. This step can often be skipped: + [Read][google.spanner.v1.Spanner.Read], [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and + [Commit][google.spanner.v1.Spanner.Commit] can begin a new transaction as a + side-effect. + """ + context.code(beta_interfaces.StatusCode.UNIMPLEMENTED) + def Commit(self, request, context): + """Commits a transaction. The request includes the mutations to be + applied to rows in the database. + + `Commit` might return an `ABORTED` error. This can occur at any time; + commonly, the cause is conflicts with concurrent + transactions. However, it can also happen for a variety of other + reasons. If `Commit` returns `ABORTED`, the caller should re-attempt + the transaction from the beginning, re-using the same session. + """ + context.code(beta_interfaces.StatusCode.UNIMPLEMENTED) + def Rollback(self, request, context): + """Rolls back a transaction, releasing any locks it holds. It is a good + idea to call this for any transaction that includes one or more + [Read][google.spanner.v1.Spanner.Read] or [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] requests and + ultimately decides not to commit. + + `Rollback` returns `OK` if it successfully aborts the transaction, the + transaction was already aborted, or the transaction is not + found. `Rollback` never returns `ABORTED`. + """ + context.code(beta_interfaces.StatusCode.UNIMPLEMENTED) + + + class BetaSpannerStub(object): + """The Beta API is deprecated for 0.15.0 and later. + + It is recommended to use the GA API (classes and functions in this + file not marked beta) for all further purposes. This class was generated + only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0.""" + """Cloud Spanner API + + The Cloud Spanner API can be used to manage sessions and execute + transactions on data stored in Cloud Spanner databases. + """ + def CreateSession(self, request, timeout, metadata=None, with_call=False, protocol_options=None): + """Creates a new session. A session can be used to perform + transactions that read and/or modify data in a Cloud Spanner database. + Sessions are meant to be reused for many consecutive + transactions. + + Sessions can only execute one transaction at a time. To execute + multiple concurrent read-write/write-only transactions, create + multiple sessions. Note that standalone reads and queries use a + transaction internally, and count toward the one transaction + limit. + + Cloud Spanner limits the number of sessions that can exist at any given + time; thus, it is a good idea to delete idle and/or unneeded sessions. + Aside from explicit deletes, Cloud Spanner can delete sessions for which no + operations are sent for more than an hour. If a session is deleted, + requests to it return `NOT_FOUND`. + + Idle sessions can be kept alive by sending a trivial SQL query + periodically, e.g., `"SELECT 1"`. + """ + raise NotImplementedError() + CreateSession.future = None + def GetSession(self, request, timeout, metadata=None, with_call=False, protocol_options=None): + """Gets a session. Returns `NOT_FOUND` if the session does not exist. + This is mainly useful for determining whether a session is still + alive. + """ + raise NotImplementedError() + GetSession.future = None + def DeleteSession(self, request, timeout, metadata=None, with_call=False, protocol_options=None): + """Ends a session, releasing server resources associated with it. + """ + raise NotImplementedError() + DeleteSession.future = None + def ExecuteSql(self, request, timeout, metadata=None, with_call=False, protocol_options=None): + """Executes an SQL query, returning all rows in a single reply. This + method cannot be used to return a result set larger than 10 MiB; + if the query yields more data than that, the query fails with + a `FAILED_PRECONDITION` error. + + Queries inside read-write transactions might return `ABORTED`. If + this occurs, the application should restart the transaction from + the beginning. See [Transaction][google.spanner.v1.Transaction] for more details. + + Larger result sets can be fetched in streaming fashion by calling + [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] instead. + """ + raise NotImplementedError() + ExecuteSql.future = None + def ExecuteStreamingSql(self, request, timeout, metadata=None, with_call=False, protocol_options=None): + """Like [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], except returns the result + set as a stream. Unlike [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], there + is no limit on the size of the returned result set. However, no + individual row in the result set can exceed 100 MiB, and no + column value can exceed 10 MiB. + """ + raise NotImplementedError() + def Read(self, request, timeout, metadata=None, with_call=False, protocol_options=None): + """Reads rows from the database using key lookups and scans, as a + simple key/value style alternative to + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. This method cannot be used to + return a result set larger than 10 MiB; if the read matches more + data than that, the read fails with a `FAILED_PRECONDITION` + error. + + Reads inside read-write transactions might return `ABORTED`. If + this occurs, the application should restart the transaction from + the beginning. See [Transaction][google.spanner.v1.Transaction] for more details. + + Larger result sets can be yielded in streaming fashion by calling + [StreamingRead][google.spanner.v1.Spanner.StreamingRead] instead. + """ + raise NotImplementedError() + Read.future = None + def StreamingRead(self, request, timeout, metadata=None, with_call=False, protocol_options=None): + """Like [Read][google.spanner.v1.Spanner.Read], except returns the result set as a + stream. Unlike [Read][google.spanner.v1.Spanner.Read], there is no limit on the + size of the returned result set. However, no individual row in + the result set can exceed 100 MiB, and no column value can exceed + 10 MiB. + """ + raise NotImplementedError() + def BeginTransaction(self, request, timeout, metadata=None, with_call=False, protocol_options=None): + """Begins a new transaction. This step can often be skipped: + [Read][google.spanner.v1.Spanner.Read], [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and + [Commit][google.spanner.v1.Spanner.Commit] can begin a new transaction as a + side-effect. + """ + raise NotImplementedError() + BeginTransaction.future = None + def Commit(self, request, timeout, metadata=None, with_call=False, protocol_options=None): + """Commits a transaction. The request includes the mutations to be + applied to rows in the database. + + `Commit` might return an `ABORTED` error. This can occur at any time; + commonly, the cause is conflicts with concurrent + transactions. However, it can also happen for a variety of other + reasons. If `Commit` returns `ABORTED`, the caller should re-attempt + the transaction from the beginning, re-using the same session. + """ + raise NotImplementedError() + Commit.future = None + def Rollback(self, request, timeout, metadata=None, with_call=False, protocol_options=None): + """Rolls back a transaction, releasing any locks it holds. It is a good + idea to call this for any transaction that includes one or more + [Read][google.spanner.v1.Spanner.Read] or [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] requests and + ultimately decides not to commit. + + `Rollback` returns `OK` if it successfully aborts the transaction, the + transaction was already aborted, or the transaction is not + found. `Rollback` never returns `ABORTED`. + """ + raise NotImplementedError() + Rollback.future = None + + + def beta_create_Spanner_server(servicer, pool=None, pool_size=None, default_timeout=None, maximum_timeout=None): + """The Beta API is deprecated for 0.15.0 and later. + + It is recommended to use the GA API (classes and functions in this + file not marked beta) for all further purposes. This function was + generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0""" + request_deserializers = { + ('google.spanner.v1.Spanner', 'BeginTransaction'): BeginTransactionRequest.FromString, + ('google.spanner.v1.Spanner', 'Commit'): CommitRequest.FromString, + ('google.spanner.v1.Spanner', 'CreateSession'): CreateSessionRequest.FromString, + ('google.spanner.v1.Spanner', 'DeleteSession'): DeleteSessionRequest.FromString, + ('google.spanner.v1.Spanner', 'ExecuteSql'): ExecuteSqlRequest.FromString, + ('google.spanner.v1.Spanner', 'ExecuteStreamingSql'): ExecuteSqlRequest.FromString, + ('google.spanner.v1.Spanner', 'GetSession'): GetSessionRequest.FromString, + ('google.spanner.v1.Spanner', 'Read'): ReadRequest.FromString, + ('google.spanner.v1.Spanner', 'Rollback'): RollbackRequest.FromString, + ('google.spanner.v1.Spanner', 'StreamingRead'): ReadRequest.FromString, + } + response_serializers = { + ('google.spanner.v1.Spanner', 'BeginTransaction'): google_dot_cloud_dot_spanner__v1_dot_proto_dot_transaction__pb2.Transaction.SerializeToString, + ('google.spanner.v1.Spanner', 'Commit'): CommitResponse.SerializeToString, + ('google.spanner.v1.Spanner', 'CreateSession'): Session.SerializeToString, + ('google.spanner.v1.Spanner', 'DeleteSession'): google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString, + ('google.spanner.v1.Spanner', 'ExecuteSql'): google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2.ResultSet.SerializeToString, + ('google.spanner.v1.Spanner', 'ExecuteStreamingSql'): google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2.PartialResultSet.SerializeToString, + ('google.spanner.v1.Spanner', 'GetSession'): Session.SerializeToString, + ('google.spanner.v1.Spanner', 'Read'): google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2.ResultSet.SerializeToString, + ('google.spanner.v1.Spanner', 'Rollback'): google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString, + ('google.spanner.v1.Spanner', 'StreamingRead'): google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2.PartialResultSet.SerializeToString, + } + method_implementations = { + ('google.spanner.v1.Spanner', 'BeginTransaction'): face_utilities.unary_unary_inline(servicer.BeginTransaction), + ('google.spanner.v1.Spanner', 'Commit'): face_utilities.unary_unary_inline(servicer.Commit), + ('google.spanner.v1.Spanner', 'CreateSession'): face_utilities.unary_unary_inline(servicer.CreateSession), + ('google.spanner.v1.Spanner', 'DeleteSession'): face_utilities.unary_unary_inline(servicer.DeleteSession), + ('google.spanner.v1.Spanner', 'ExecuteSql'): face_utilities.unary_unary_inline(servicer.ExecuteSql), + ('google.spanner.v1.Spanner', 'ExecuteStreamingSql'): face_utilities.unary_stream_inline(servicer.ExecuteStreamingSql), + ('google.spanner.v1.Spanner', 'GetSession'): face_utilities.unary_unary_inline(servicer.GetSession), + ('google.spanner.v1.Spanner', 'Read'): face_utilities.unary_unary_inline(servicer.Read), + ('google.spanner.v1.Spanner', 'Rollback'): face_utilities.unary_unary_inline(servicer.Rollback), + ('google.spanner.v1.Spanner', 'StreamingRead'): face_utilities.unary_stream_inline(servicer.StreamingRead), + } + server_options = beta_implementations.server_options(request_deserializers=request_deserializers, response_serializers=response_serializers, thread_pool=pool, thread_pool_size=pool_size, default_timeout=default_timeout, maximum_timeout=maximum_timeout) + return beta_implementations.server(method_implementations, options=server_options) + + + def beta_create_Spanner_stub(channel, host=None, metadata_transformer=None, pool=None, pool_size=None): + """The Beta API is deprecated for 0.15.0 and later. + + It is recommended to use the GA API (classes and functions in this + file not marked beta) for all further purposes. This function was + generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0""" + request_serializers = { + ('google.spanner.v1.Spanner', 'BeginTransaction'): BeginTransactionRequest.SerializeToString, + ('google.spanner.v1.Spanner', 'Commit'): CommitRequest.SerializeToString, + ('google.spanner.v1.Spanner', 'CreateSession'): CreateSessionRequest.SerializeToString, + ('google.spanner.v1.Spanner', 'DeleteSession'): DeleteSessionRequest.SerializeToString, + ('google.spanner.v1.Spanner', 'ExecuteSql'): ExecuteSqlRequest.SerializeToString, + ('google.spanner.v1.Spanner', 'ExecuteStreamingSql'): ExecuteSqlRequest.SerializeToString, + ('google.spanner.v1.Spanner', 'GetSession'): GetSessionRequest.SerializeToString, + ('google.spanner.v1.Spanner', 'Read'): ReadRequest.SerializeToString, + ('google.spanner.v1.Spanner', 'Rollback'): RollbackRequest.SerializeToString, + ('google.spanner.v1.Spanner', 'StreamingRead'): ReadRequest.SerializeToString, + } + response_deserializers = { + ('google.spanner.v1.Spanner', 'BeginTransaction'): google_dot_cloud_dot_spanner__v1_dot_proto_dot_transaction__pb2.Transaction.FromString, + ('google.spanner.v1.Spanner', 'Commit'): CommitResponse.FromString, + ('google.spanner.v1.Spanner', 'CreateSession'): Session.FromString, + ('google.spanner.v1.Spanner', 'DeleteSession'): google_dot_protobuf_dot_empty__pb2.Empty.FromString, + ('google.spanner.v1.Spanner', 'ExecuteSql'): google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2.ResultSet.FromString, + ('google.spanner.v1.Spanner', 'ExecuteStreamingSql'): google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2.PartialResultSet.FromString, + ('google.spanner.v1.Spanner', 'GetSession'): Session.FromString, + ('google.spanner.v1.Spanner', 'Read'): google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2.ResultSet.FromString, + ('google.spanner.v1.Spanner', 'Rollback'): google_dot_protobuf_dot_empty__pb2.Empty.FromString, + ('google.spanner.v1.Spanner', 'StreamingRead'): google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2.PartialResultSet.FromString, + } + cardinalities = { + 'BeginTransaction': cardinality.Cardinality.UNARY_UNARY, + 'Commit': cardinality.Cardinality.UNARY_UNARY, + 'CreateSession': cardinality.Cardinality.UNARY_UNARY, + 'DeleteSession': cardinality.Cardinality.UNARY_UNARY, + 'ExecuteSql': cardinality.Cardinality.UNARY_UNARY, + 'ExecuteStreamingSql': cardinality.Cardinality.UNARY_STREAM, + 'GetSession': cardinality.Cardinality.UNARY_UNARY, + 'Read': cardinality.Cardinality.UNARY_UNARY, + 'Rollback': cardinality.Cardinality.UNARY_UNARY, + 'StreamingRead': cardinality.Cardinality.UNARY_STREAM, + } + stub_options = beta_implementations.stub_options(host=host, metadata_transformer=metadata_transformer, request_serializers=request_serializers, response_deserializers=response_deserializers, thread_pool=pool, thread_pool_size=pool_size) + return beta_implementations.dynamic_stub(channel, 'google.spanner.v1.Spanner', cardinalities, options=stub_options) +except ImportError: + pass +# @@protoc_insertion_point(module_scope) diff --git a/spanner/google/cloud/spanner_v1/proto/spanner_pb2_grpc.py b/spanner/google/cloud/spanner_v1/proto/spanner_pb2_grpc.py new file mode 100644 index 000000000000..3eb3cbfc0c9e --- /dev/null +++ b/spanner/google/cloud/spanner_v1/proto/spanner_pb2_grpc.py @@ -0,0 +1,275 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +import grpc + +import google.cloud.spanner_v1.proto.result_set_pb2 as google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2 +import google.cloud.spanner_v1.proto.spanner_pb2 as google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2 +import google.cloud.spanner_v1.proto.transaction_pb2 as google_dot_cloud_dot_spanner__v1_dot_proto_dot_transaction__pb2 +import google.protobuf.empty_pb2 as google_dot_protobuf_dot_empty__pb2 + + +class SpannerStub(object): + """Cloud Spanner API + + The Cloud Spanner API can be used to manage sessions and execute + transactions on data stored in Cloud Spanner databases. + """ + + def __init__(self, channel): + """Constructor. + + Args: + channel: A grpc.Channel. + """ + self.CreateSession = channel.unary_unary( + '/google.spanner.v1.Spanner/CreateSession', + request_serializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.CreateSessionRequest.SerializeToString, + response_deserializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.Session.FromString, + ) + self.GetSession = channel.unary_unary( + '/google.spanner.v1.Spanner/GetSession', + request_serializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.GetSessionRequest.SerializeToString, + response_deserializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.Session.FromString, + ) + self.DeleteSession = channel.unary_unary( + '/google.spanner.v1.Spanner/DeleteSession', + request_serializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.DeleteSessionRequest.SerializeToString, + response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString, + ) + self.ExecuteSql = channel.unary_unary( + '/google.spanner.v1.Spanner/ExecuteSql', + request_serializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.ExecuteSqlRequest.SerializeToString, + response_deserializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2.ResultSet.FromString, + ) + self.ExecuteStreamingSql = channel.unary_stream( + '/google.spanner.v1.Spanner/ExecuteStreamingSql', + request_serializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.ExecuteSqlRequest.SerializeToString, + response_deserializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2.PartialResultSet.FromString, + ) + self.Read = channel.unary_unary( + '/google.spanner.v1.Spanner/Read', + request_serializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.ReadRequest.SerializeToString, + response_deserializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2.ResultSet.FromString, + ) + self.StreamingRead = channel.unary_stream( + '/google.spanner.v1.Spanner/StreamingRead', + request_serializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.ReadRequest.SerializeToString, + response_deserializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2.PartialResultSet.FromString, + ) + self.BeginTransaction = channel.unary_unary( + '/google.spanner.v1.Spanner/BeginTransaction', + request_serializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.BeginTransactionRequest.SerializeToString, + response_deserializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_transaction__pb2.Transaction.FromString, + ) + self.Commit = channel.unary_unary( + '/google.spanner.v1.Spanner/Commit', + request_serializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.CommitRequest.SerializeToString, + response_deserializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.CommitResponse.FromString, + ) + self.Rollback = channel.unary_unary( + '/google.spanner.v1.Spanner/Rollback', + request_serializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.RollbackRequest.SerializeToString, + response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString, + ) + + +class SpannerServicer(object): + """Cloud Spanner API + + The Cloud Spanner API can be used to manage sessions and execute + transactions on data stored in Cloud Spanner databases. + """ + + def CreateSession(self, request, context): + """Creates a new session. A session can be used to perform + transactions that read and/or modify data in a Cloud Spanner database. + Sessions are meant to be reused for many consecutive + transactions. + + Sessions can only execute one transaction at a time. To execute + multiple concurrent read-write/write-only transactions, create + multiple sessions. Note that standalone reads and queries use a + transaction internally, and count toward the one transaction + limit. + + Cloud Spanner limits the number of sessions that can exist at any given + time; thus, it is a good idea to delete idle and/or unneeded sessions. + Aside from explicit deletes, Cloud Spanner can delete sessions for which no + operations are sent for more than an hour. If a session is deleted, + requests to it return `NOT_FOUND`. + + Idle sessions can be kept alive by sending a trivial SQL query + periodically, e.g., `"SELECT 1"`. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def GetSession(self, request, context): + """Gets a session. Returns `NOT_FOUND` if the session does not exist. + This is mainly useful for determining whether a session is still + alive. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def DeleteSession(self, request, context): + """Ends a session, releasing server resources associated with it. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def ExecuteSql(self, request, context): + """Executes an SQL query, returning all rows in a single reply. This + method cannot be used to return a result set larger than 10 MiB; + if the query yields more data than that, the query fails with + a `FAILED_PRECONDITION` error. + + Queries inside read-write transactions might return `ABORTED`. If + this occurs, the application should restart the transaction from + the beginning. See [Transaction][google.spanner.v1.Transaction] for more details. + + Larger result sets can be fetched in streaming fashion by calling + [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] instead. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def ExecuteStreamingSql(self, request, context): + """Like [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], except returns the result + set as a stream. Unlike [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], there + is no limit on the size of the returned result set. However, no + individual row in the result set can exceed 100 MiB, and no + column value can exceed 10 MiB. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def Read(self, request, context): + """Reads rows from the database using key lookups and scans, as a + simple key/value style alternative to + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. This method cannot be used to + return a result set larger than 10 MiB; if the read matches more + data than that, the read fails with a `FAILED_PRECONDITION` + error. + + Reads inside read-write transactions might return `ABORTED`. If + this occurs, the application should restart the transaction from + the beginning. See [Transaction][google.spanner.v1.Transaction] for more details. + + Larger result sets can be yielded in streaming fashion by calling + [StreamingRead][google.spanner.v1.Spanner.StreamingRead] instead. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def StreamingRead(self, request, context): + """Like [Read][google.spanner.v1.Spanner.Read], except returns the result set as a + stream. Unlike [Read][google.spanner.v1.Spanner.Read], there is no limit on the + size of the returned result set. However, no individual row in + the result set can exceed 100 MiB, and no column value can exceed + 10 MiB. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def BeginTransaction(self, request, context): + """Begins a new transaction. This step can often be skipped: + [Read][google.spanner.v1.Spanner.Read], [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and + [Commit][google.spanner.v1.Spanner.Commit] can begin a new transaction as a + side-effect. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def Commit(self, request, context): + """Commits a transaction. The request includes the mutations to be + applied to rows in the database. + + `Commit` might return an `ABORTED` error. This can occur at any time; + commonly, the cause is conflicts with concurrent + transactions. However, it can also happen for a variety of other + reasons. If `Commit` returns `ABORTED`, the caller should re-attempt + the transaction from the beginning, re-using the same session. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def Rollback(self, request, context): + """Rolls back a transaction, releasing any locks it holds. It is a good + idea to call this for any transaction that includes one or more + [Read][google.spanner.v1.Spanner.Read] or [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] requests and + ultimately decides not to commit. + + `Rollback` returns `OK` if it successfully aborts the transaction, the + transaction was already aborted, or the transaction is not + found. `Rollback` never returns `ABORTED`. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + +def add_SpannerServicer_to_server(servicer, server): + rpc_method_handlers = { + 'CreateSession': grpc.unary_unary_rpc_method_handler( + servicer.CreateSession, + request_deserializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.CreateSessionRequest.FromString, + response_serializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.Session.SerializeToString, + ), + 'GetSession': grpc.unary_unary_rpc_method_handler( + servicer.GetSession, + request_deserializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.GetSessionRequest.FromString, + response_serializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.Session.SerializeToString, + ), + 'DeleteSession': grpc.unary_unary_rpc_method_handler( + servicer.DeleteSession, + request_deserializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.DeleteSessionRequest.FromString, + response_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString, + ), + 'ExecuteSql': grpc.unary_unary_rpc_method_handler( + servicer.ExecuteSql, + request_deserializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.ExecuteSqlRequest.FromString, + response_serializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2.ResultSet.SerializeToString, + ), + 'ExecuteStreamingSql': grpc.unary_stream_rpc_method_handler( + servicer.ExecuteStreamingSql, + request_deserializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.ExecuteSqlRequest.FromString, + response_serializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2.PartialResultSet.SerializeToString, + ), + 'Read': grpc.unary_unary_rpc_method_handler( + servicer.Read, + request_deserializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.ReadRequest.FromString, + response_serializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2.ResultSet.SerializeToString, + ), + 'StreamingRead': grpc.unary_stream_rpc_method_handler( + servicer.StreamingRead, + request_deserializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.ReadRequest.FromString, + response_serializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_result__set__pb2.PartialResultSet.SerializeToString, + ), + 'BeginTransaction': grpc.unary_unary_rpc_method_handler( + servicer.BeginTransaction, + request_deserializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.BeginTransactionRequest.FromString, + response_serializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_transaction__pb2.Transaction.SerializeToString, + ), + 'Commit': grpc.unary_unary_rpc_method_handler( + servicer.Commit, + request_deserializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.CommitRequest.FromString, + response_serializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.CommitResponse.SerializeToString, + ), + 'Rollback': grpc.unary_unary_rpc_method_handler( + servicer.Rollback, + request_deserializer=google_dot_cloud_dot_spanner__v1_dot_proto_dot_spanner__pb2.RollbackRequest.FromString, + response_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString, + ), + } + generic_handler = grpc.method_handlers_generic_handler( + 'google.spanner.v1.Spanner', rpc_method_handlers) + server.add_generic_rpc_handlers((generic_handler,)) diff --git a/spanner/google/cloud/spanner_v1/proto/transaction_pb2.py b/spanner/google/cloud/spanner_v1/proto/transaction_pb2.py new file mode 100644 index 000000000000..e82c4e5b5e59 --- /dev/null +++ b/spanner/google/cloud/spanner_v1/proto/transaction_pb2.py @@ -0,0 +1,460 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/cloud/spanner_v1/proto/transaction.proto + +import sys +_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database +from google.protobuf import descriptor_pb2 +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + +from google.api import annotations_pb2 as google_dot_api_dot_annotations__pb2 +from google.protobuf import duration_pb2 as google_dot_protobuf_dot_duration__pb2 +from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2 + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='google/cloud/spanner_v1/proto/transaction.proto', + package='google.spanner.v1', + syntax='proto3', + serialized_pb=_b('\n/google/cloud/spanner_v1/proto/transaction.proto\x12\x11google.spanner.v1\x1a\x1cgoogle/api/annotations.proto\x1a\x1egoogle/protobuf/duration.proto\x1a\x1fgoogle/protobuf/timestamp.proto\"\xe0\x03\n\x12TransactionOptions\x12\x45\n\nread_write\x18\x01 \x01(\x0b\x32/.google.spanner.v1.TransactionOptions.ReadWriteH\x00\x12\x43\n\tread_only\x18\x02 \x01(\x0b\x32..google.spanner.v1.TransactionOptions.ReadOnlyH\x00\x1a\x0b\n\tReadWrite\x1a\xa8\x02\n\x08ReadOnly\x12\x10\n\x06strong\x18\x01 \x01(\x08H\x00\x12\x38\n\x12min_read_timestamp\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.TimestampH\x00\x12\x32\n\rmax_staleness\x18\x03 \x01(\x0b\x32\x19.google.protobuf.DurationH\x00\x12\x34\n\x0eread_timestamp\x18\x04 \x01(\x0b\x32\x1a.google.protobuf.TimestampH\x00\x12\x34\n\x0f\x65xact_staleness\x18\x05 \x01(\x0b\x32\x19.google.protobuf.DurationH\x00\x12\x1d\n\x15return_read_timestamp\x18\x06 \x01(\x08\x42\x11\n\x0ftimestamp_boundB\x06\n\x04mode\"M\n\x0bTransaction\x12\n\n\x02id\x18\x01 \x01(\x0c\x12\x32\n\x0eread_timestamp\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"\xa4\x01\n\x13TransactionSelector\x12;\n\nsingle_use\x18\x01 \x01(\x0b\x32%.google.spanner.v1.TransactionOptionsH\x00\x12\x0c\n\x02id\x18\x02 \x01(\x0cH\x00\x12\x36\n\x05\x62\x65gin\x18\x03 \x01(\x0b\x32%.google.spanner.v1.TransactionOptionsH\x00\x42\n\n\x08selectorB\x7f\n\x15\x63om.google.spanner.v1B\x10TransactionProtoP\x01Z8google.golang.org/genproto/googleapis/spanner/v1;spanner\xaa\x02\x17Google.Cloud.Spanner.V1b\x06proto3') + , + dependencies=[google_dot_api_dot_annotations__pb2.DESCRIPTOR,google_dot_protobuf_dot_duration__pb2.DESCRIPTOR,google_dot_protobuf_dot_timestamp__pb2.DESCRIPTOR,]) +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + + + + +_TRANSACTIONOPTIONS_READWRITE = _descriptor.Descriptor( + name='ReadWrite', + full_name='google.spanner.v1.TransactionOptions.ReadWrite', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=328, + serialized_end=339, +) + +_TRANSACTIONOPTIONS_READONLY = _descriptor.Descriptor( + name='ReadOnly', + full_name='google.spanner.v1.TransactionOptions.ReadOnly', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='strong', full_name='google.spanner.v1.TransactionOptions.ReadOnly.strong', index=0, + number=1, type=8, cpp_type=7, label=1, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='min_read_timestamp', full_name='google.spanner.v1.TransactionOptions.ReadOnly.min_read_timestamp', index=1, + number=2, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='max_staleness', full_name='google.spanner.v1.TransactionOptions.ReadOnly.max_staleness', index=2, + number=3, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='read_timestamp', full_name='google.spanner.v1.TransactionOptions.ReadOnly.read_timestamp', index=3, + number=4, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='exact_staleness', full_name='google.spanner.v1.TransactionOptions.ReadOnly.exact_staleness', index=4, + number=5, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='return_read_timestamp', full_name='google.spanner.v1.TransactionOptions.ReadOnly.return_read_timestamp', index=5, + number=6, type=8, cpp_type=7, label=1, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + _descriptor.OneofDescriptor( + name='timestamp_bound', full_name='google.spanner.v1.TransactionOptions.ReadOnly.timestamp_bound', + index=0, containing_type=None, fields=[]), + ], + serialized_start=342, + serialized_end=638, +) + +_TRANSACTIONOPTIONS = _descriptor.Descriptor( + name='TransactionOptions', + full_name='google.spanner.v1.TransactionOptions', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='read_write', full_name='google.spanner.v1.TransactionOptions.read_write', index=0, + number=1, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='read_only', full_name='google.spanner.v1.TransactionOptions.read_only', index=1, + number=2, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[_TRANSACTIONOPTIONS_READWRITE, _TRANSACTIONOPTIONS_READONLY, ], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + _descriptor.OneofDescriptor( + name='mode', full_name='google.spanner.v1.TransactionOptions.mode', + index=0, containing_type=None, fields=[]), + ], + serialized_start=166, + serialized_end=646, +) + + +_TRANSACTION = _descriptor.Descriptor( + name='Transaction', + full_name='google.spanner.v1.Transaction', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='id', full_name='google.spanner.v1.Transaction.id', index=0, + number=1, type=12, cpp_type=9, label=1, + has_default_value=False, default_value=_b(""), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='read_timestamp', full_name='google.spanner.v1.Transaction.read_timestamp', index=1, + number=2, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=648, + serialized_end=725, +) + + +_TRANSACTIONSELECTOR = _descriptor.Descriptor( + name='TransactionSelector', + full_name='google.spanner.v1.TransactionSelector', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='single_use', full_name='google.spanner.v1.TransactionSelector.single_use', index=0, + number=1, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='id', full_name='google.spanner.v1.TransactionSelector.id', index=1, + number=2, type=12, cpp_type=9, label=1, + has_default_value=False, default_value=_b(""), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='begin', full_name='google.spanner.v1.TransactionSelector.begin', index=2, + number=3, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + _descriptor.OneofDescriptor( + name='selector', full_name='google.spanner.v1.TransactionSelector.selector', + index=0, containing_type=None, fields=[]), + ], + serialized_start=728, + serialized_end=892, +) + +_TRANSACTIONOPTIONS_READWRITE.containing_type = _TRANSACTIONOPTIONS +_TRANSACTIONOPTIONS_READONLY.fields_by_name['min_read_timestamp'].message_type = google_dot_protobuf_dot_timestamp__pb2._TIMESTAMP +_TRANSACTIONOPTIONS_READONLY.fields_by_name['max_staleness'].message_type = google_dot_protobuf_dot_duration__pb2._DURATION +_TRANSACTIONOPTIONS_READONLY.fields_by_name['read_timestamp'].message_type = google_dot_protobuf_dot_timestamp__pb2._TIMESTAMP +_TRANSACTIONOPTIONS_READONLY.fields_by_name['exact_staleness'].message_type = google_dot_protobuf_dot_duration__pb2._DURATION +_TRANSACTIONOPTIONS_READONLY.containing_type = _TRANSACTIONOPTIONS +_TRANSACTIONOPTIONS_READONLY.oneofs_by_name['timestamp_bound'].fields.append( + _TRANSACTIONOPTIONS_READONLY.fields_by_name['strong']) +_TRANSACTIONOPTIONS_READONLY.fields_by_name['strong'].containing_oneof = _TRANSACTIONOPTIONS_READONLY.oneofs_by_name['timestamp_bound'] +_TRANSACTIONOPTIONS_READONLY.oneofs_by_name['timestamp_bound'].fields.append( + _TRANSACTIONOPTIONS_READONLY.fields_by_name['min_read_timestamp']) +_TRANSACTIONOPTIONS_READONLY.fields_by_name['min_read_timestamp'].containing_oneof = _TRANSACTIONOPTIONS_READONLY.oneofs_by_name['timestamp_bound'] +_TRANSACTIONOPTIONS_READONLY.oneofs_by_name['timestamp_bound'].fields.append( + _TRANSACTIONOPTIONS_READONLY.fields_by_name['max_staleness']) +_TRANSACTIONOPTIONS_READONLY.fields_by_name['max_staleness'].containing_oneof = _TRANSACTIONOPTIONS_READONLY.oneofs_by_name['timestamp_bound'] +_TRANSACTIONOPTIONS_READONLY.oneofs_by_name['timestamp_bound'].fields.append( + _TRANSACTIONOPTIONS_READONLY.fields_by_name['read_timestamp']) +_TRANSACTIONOPTIONS_READONLY.fields_by_name['read_timestamp'].containing_oneof = _TRANSACTIONOPTIONS_READONLY.oneofs_by_name['timestamp_bound'] +_TRANSACTIONOPTIONS_READONLY.oneofs_by_name['timestamp_bound'].fields.append( + _TRANSACTIONOPTIONS_READONLY.fields_by_name['exact_staleness']) +_TRANSACTIONOPTIONS_READONLY.fields_by_name['exact_staleness'].containing_oneof = _TRANSACTIONOPTIONS_READONLY.oneofs_by_name['timestamp_bound'] +_TRANSACTIONOPTIONS.fields_by_name['read_write'].message_type = _TRANSACTIONOPTIONS_READWRITE +_TRANSACTIONOPTIONS.fields_by_name['read_only'].message_type = _TRANSACTIONOPTIONS_READONLY +_TRANSACTIONOPTIONS.oneofs_by_name['mode'].fields.append( + _TRANSACTIONOPTIONS.fields_by_name['read_write']) +_TRANSACTIONOPTIONS.fields_by_name['read_write'].containing_oneof = _TRANSACTIONOPTIONS.oneofs_by_name['mode'] +_TRANSACTIONOPTIONS.oneofs_by_name['mode'].fields.append( + _TRANSACTIONOPTIONS.fields_by_name['read_only']) +_TRANSACTIONOPTIONS.fields_by_name['read_only'].containing_oneof = _TRANSACTIONOPTIONS.oneofs_by_name['mode'] +_TRANSACTION.fields_by_name['read_timestamp'].message_type = google_dot_protobuf_dot_timestamp__pb2._TIMESTAMP +_TRANSACTIONSELECTOR.fields_by_name['single_use'].message_type = _TRANSACTIONOPTIONS +_TRANSACTIONSELECTOR.fields_by_name['begin'].message_type = _TRANSACTIONOPTIONS +_TRANSACTIONSELECTOR.oneofs_by_name['selector'].fields.append( + _TRANSACTIONSELECTOR.fields_by_name['single_use']) +_TRANSACTIONSELECTOR.fields_by_name['single_use'].containing_oneof = _TRANSACTIONSELECTOR.oneofs_by_name['selector'] +_TRANSACTIONSELECTOR.oneofs_by_name['selector'].fields.append( + _TRANSACTIONSELECTOR.fields_by_name['id']) +_TRANSACTIONSELECTOR.fields_by_name['id'].containing_oneof = _TRANSACTIONSELECTOR.oneofs_by_name['selector'] +_TRANSACTIONSELECTOR.oneofs_by_name['selector'].fields.append( + _TRANSACTIONSELECTOR.fields_by_name['begin']) +_TRANSACTIONSELECTOR.fields_by_name['begin'].containing_oneof = _TRANSACTIONSELECTOR.oneofs_by_name['selector'] +DESCRIPTOR.message_types_by_name['TransactionOptions'] = _TRANSACTIONOPTIONS +DESCRIPTOR.message_types_by_name['Transaction'] = _TRANSACTION +DESCRIPTOR.message_types_by_name['TransactionSelector'] = _TRANSACTIONSELECTOR + +TransactionOptions = _reflection.GeneratedProtocolMessageType('TransactionOptions', (_message.Message,), dict( + + ReadWrite = _reflection.GeneratedProtocolMessageType('ReadWrite', (_message.Message,), dict( + DESCRIPTOR = _TRANSACTIONOPTIONS_READWRITE, + __module__ = 'google.cloud.spanner_v1.proto.transaction_pb2' + , + __doc__ = """Options for read-write transactions. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.TransactionOptions.ReadWrite) + )) + , + + ReadOnly = _reflection.GeneratedProtocolMessageType('ReadOnly', (_message.Message,), dict( + DESCRIPTOR = _TRANSACTIONOPTIONS_READONLY, + __module__ = 'google.cloud.spanner_v1.proto.transaction_pb2' + , + __doc__ = """Options for read-only transactions. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.TransactionOptions.ReadOnly) + )) + , + DESCRIPTOR = _TRANSACTIONOPTIONS, + __module__ = 'google.cloud.spanner_v1.proto.transaction_pb2' + , + __doc__ = """See :ref:`spanner-txn` for more information on these. + + Attributes: + timestamp_bound: + How to choose the timestamp for the read-only transaction. + strong: + Read at a timestamp where all previously committed + transactions are visible. + min_read_timestamp: + Executes all reads at a timestamp >= ``min_read_timestamp``. + This is useful for requesting fresher data than some previous + read, or data that is fresh enough to observe the effects of + some previously committed transaction whose timestamp is + known. Note that this option can only be used in single-use + transactions. + max_staleness: + Read data at a timestamp >= ``NOW - max_staleness`` seconds. + Guarantees that all writes that have committed more than the + specified number of seconds ago are visible. Because Cloud + Spanner chooses the exact timestamp, this mode works even if + the client's local clock is substantially skewed from Cloud + Spanner commit timestamps. Useful for reading the freshest + data available at a nearby replica, while bounding the + possible staleness if the local replica has fallen behind. + Note that this option can only be used in single-use + transactions. + read_timestamp: + Executes all reads at the given timestamp. Unlike other modes, + reads at a specific timestamp are repeatable; the same read at + the same timestamp always returns the same data. If the + timestamp is in the future, the read will block until the + specified timestamp, modulo the read's deadline. Useful for + large scale consistent reads such as mapreduces, or for + coordinating many reads against a consistent snapshot of the + data. + exact_staleness: + Executes all reads at a timestamp that is ``exact_staleness`` + old. The timestamp is chosen soon after the read is started. + Guarantees that all writes that have committed more than the + specified number of seconds ago are visible. Because Cloud + Spanner chooses the exact timestamp, this mode works even if + the client's local clock is substantially skewed from Cloud + Spanner commit timestamps. Useful for reading at nearby + replicas without the distributed timestamp negotiation + overhead of ``max_staleness``. + return_read_timestamp: + If true, the Cloud Spanner-selected read timestamp is included + in the [Transaction][google.spanner.v1.Transaction] message + that describes the transaction. + mode: + Required. The type of transaction. + read_write: + Transaction may write. Authorization to begin a read-write + transaction requires + ``spanner.databases.beginOrRollbackReadWriteTransaction`` + permission on the ``session`` resource. + read_only: + Transaction will not write. Authorization to begin a read- + only transaction requires + ``spanner.databases.beginReadOnlyTransaction`` permission on + the ``session`` resource. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.TransactionOptions) + )) +_sym_db.RegisterMessage(TransactionOptions) +_sym_db.RegisterMessage(TransactionOptions.ReadWrite) +_sym_db.RegisterMessage(TransactionOptions.ReadOnly) + +Transaction = _reflection.GeneratedProtocolMessageType('Transaction', (_message.Message,), dict( + DESCRIPTOR = _TRANSACTION, + __module__ = 'google.cloud.spanner_v1.proto.transaction_pb2' + , + __doc__ = """A transaction. + + + Attributes: + id: + ``id`` may be used to identify the transaction in subsequent + [Read][google.spanner.v1.Spanner.Read], + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], + [Commit][google.spanner.v1.Spanner.Commit], or + [Rollback][google.spanner.v1.Spanner.Rollback] calls. Single- + use read-only transactions do not have IDs, because single-use + transactions do not support multiple requests. + read_timestamp: + For snapshot read-only transactions, the read timestamp chosen + for the transaction. Not returned by default: see [Transaction + Options.ReadOnly.return\_read\_timestamp][google.spanner.v1.Tr + ansactionOptions.ReadOnly.return\_read\_timestamp]. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.Transaction) + )) +_sym_db.RegisterMessage(Transaction) + +TransactionSelector = _reflection.GeneratedProtocolMessageType('TransactionSelector', (_message.Message,), dict( + DESCRIPTOR = _TRANSACTIONSELECTOR, + __module__ = 'google.cloud.spanner_v1.proto.transaction_pb2' + , + __doc__ = """This message is used to select the transaction in which a + [Read][google.spanner.v1.Spanner.Read] or + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] call runs. + + See [TransactionOptions][google.spanner.v1.TransactionOptions] for more + information about transactions. + + + Attributes: + selector: + If no fields are set, the default is a single use transaction + with strong concurrency. + single_use: + Execute the read or SQL query in a temporary transaction. This + is the most efficient way to execute a transaction that + consists of a single SQL query. + id: + Execute the read or SQL query in a previously-started + transaction. + begin: + Begin a new transaction and execute this read or SQL query in + it. The transaction ID of the new transaction is returned in [ + ResultSetMetadata.transaction][google.spanner.v1.ResultSetMeta + data.transaction], which is a + [Transaction][google.spanner.v1.Transaction]. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.TransactionSelector) + )) +_sym_db.RegisterMessage(TransactionSelector) + + +DESCRIPTOR.has_options = True +DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\025com.google.spanner.v1B\020TransactionProtoP\001Z8google.golang.org/genproto/googleapis/spanner/v1;spanner\252\002\027Google.Cloud.Spanner.V1')) +try: + # THESE ELEMENTS WILL BE DEPRECATED. + # Please use the generated *_pb2_grpc.py files instead. + import grpc + from grpc.beta import implementations as beta_implementations + from grpc.beta import interfaces as beta_interfaces + from grpc.framework.common import cardinality + from grpc.framework.interfaces.face import utilities as face_utilities +except ImportError: + pass +# @@protoc_insertion_point(module_scope) diff --git a/spanner/google/cloud/spanner_v1/proto/transaction_pb2_grpc.py b/spanner/google/cloud/spanner_v1/proto/transaction_pb2_grpc.py new file mode 100644 index 000000000000..a89435267cb2 --- /dev/null +++ b/spanner/google/cloud/spanner_v1/proto/transaction_pb2_grpc.py @@ -0,0 +1,3 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +import grpc + diff --git a/spanner/google/cloud/spanner_v1/proto/type_pb2.py b/spanner/google/cloud/spanner_v1/proto/type_pb2.py new file mode 100644 index 000000000000..8c2bd21f1f4e --- /dev/null +++ b/spanner/google/cloud/spanner_v1/proto/type_pb2.py @@ -0,0 +1,301 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/cloud/spanner_v1/proto/type.proto + +import sys +_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) +from google.protobuf.internal import enum_type_wrapper +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database +from google.protobuf import descriptor_pb2 +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + +from google.api import annotations_pb2 as google_dot_api_dot_annotations__pb2 + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='google/cloud/spanner_v1/proto/type.proto', + package='google.spanner.v1', + syntax='proto3', + serialized_pb=_b('\n(google/cloud/spanner_v1/proto/type.proto\x12\x11google.spanner.v1\x1a\x1cgoogle/api/annotations.proto\"\x9a\x01\n\x04Type\x12)\n\x04\x63ode\x18\x01 \x01(\x0e\x32\x1b.google.spanner.v1.TypeCode\x12\x33\n\x12\x61rray_element_type\x18\x02 \x01(\x0b\x32\x17.google.spanner.v1.Type\x12\x32\n\x0bstruct_type\x18\x03 \x01(\x0b\x32\x1d.google.spanner.v1.StructType\"\x7f\n\nStructType\x12\x33\n\x06\x66ields\x18\x01 \x03(\x0b\x32#.google.spanner.v1.StructType.Field\x1a<\n\x05\x46ield\x12\x0c\n\x04name\x18\x01 \x01(\t\x12%\n\x04type\x18\x02 \x01(\x0b\x32\x17.google.spanner.v1.Type*\x8e\x01\n\x08TypeCode\x12\x19\n\x15TYPE_CODE_UNSPECIFIED\x10\x00\x12\x08\n\x04\x42OOL\x10\x01\x12\t\n\x05INT64\x10\x02\x12\x0b\n\x07\x46LOAT64\x10\x03\x12\r\n\tTIMESTAMP\x10\x04\x12\x08\n\x04\x44\x41TE\x10\x05\x12\n\n\x06STRING\x10\x06\x12\t\n\x05\x42YTES\x10\x07\x12\t\n\x05\x41RRAY\x10\x08\x12\n\n\x06STRUCT\x10\tBx\n\x15\x63om.google.spanner.v1B\tTypeProtoP\x01Z8google.golang.org/genproto/googleapis/spanner/v1;spanner\xaa\x02\x17Google.Cloud.Spanner.V1b\x06proto3') + , + dependencies=[google_dot_api_dot_annotations__pb2.DESCRIPTOR,]) +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + +_TYPECODE = _descriptor.EnumDescriptor( + name='TypeCode', + full_name='google.spanner.v1.TypeCode', + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name='TYPE_CODE_UNSPECIFIED', index=0, number=0, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='BOOL', index=1, number=1, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='INT64', index=2, number=2, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='FLOAT64', index=3, number=3, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='TIMESTAMP', index=4, number=4, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='DATE', index=5, number=5, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='STRING', index=6, number=6, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='BYTES', index=7, number=7, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='ARRAY', index=8, number=8, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='STRUCT', index=9, number=9, + options=None, + type=None), + ], + containing_type=None, + options=None, + serialized_start=380, + serialized_end=522, +) +_sym_db.RegisterEnumDescriptor(_TYPECODE) + +TypeCode = enum_type_wrapper.EnumTypeWrapper(_TYPECODE) +TYPE_CODE_UNSPECIFIED = 0 +BOOL = 1 +INT64 = 2 +FLOAT64 = 3 +TIMESTAMP = 4 +DATE = 5 +STRING = 6 +BYTES = 7 +ARRAY = 8 +STRUCT = 9 + + + +_TYPE = _descriptor.Descriptor( + name='Type', + full_name='google.spanner.v1.Type', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='code', full_name='google.spanner.v1.Type.code', index=0, + number=1, type=14, cpp_type=8, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='array_element_type', full_name='google.spanner.v1.Type.array_element_type', index=1, + number=2, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='struct_type', full_name='google.spanner.v1.Type.struct_type', index=2, + number=3, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=94, + serialized_end=248, +) + + +_STRUCTTYPE_FIELD = _descriptor.Descriptor( + name='Field', + full_name='google.spanner.v1.StructType.Field', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='name', full_name='google.spanner.v1.StructType.Field.name', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='type', full_name='google.spanner.v1.StructType.Field.type', index=1, + number=2, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=317, + serialized_end=377, +) + +_STRUCTTYPE = _descriptor.Descriptor( + name='StructType', + full_name='google.spanner.v1.StructType', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='fields', full_name='google.spanner.v1.StructType.fields', index=0, + number=1, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[_STRUCTTYPE_FIELD, ], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=250, + serialized_end=377, +) + +_TYPE.fields_by_name['code'].enum_type = _TYPECODE +_TYPE.fields_by_name['array_element_type'].message_type = _TYPE +_TYPE.fields_by_name['struct_type'].message_type = _STRUCTTYPE +_STRUCTTYPE_FIELD.fields_by_name['type'].message_type = _TYPE +_STRUCTTYPE_FIELD.containing_type = _STRUCTTYPE +_STRUCTTYPE.fields_by_name['fields'].message_type = _STRUCTTYPE_FIELD +DESCRIPTOR.message_types_by_name['Type'] = _TYPE +DESCRIPTOR.message_types_by_name['StructType'] = _STRUCTTYPE +DESCRIPTOR.enum_types_by_name['TypeCode'] = _TYPECODE + +Type = _reflection.GeneratedProtocolMessageType('Type', (_message.Message,), dict( + DESCRIPTOR = _TYPE, + __module__ = 'google.cloud.spanner_v1.proto.type_pb2' + , + __doc__ = """``Type`` indicates the type of a Cloud Spanner value, as might be stored + in a table cell or returned from an SQL query. + + + Attributes: + code: + Required. The [TypeCode][google.spanner.v1.TypeCode] for this + type. + array_element_type: + If [code][google.spanner.v1.Type.code] == + [ARRAY][google.spanner.v1.TypeCode.ARRAY], then + ``array_element_type`` is the type of the array elements. + struct_type: + If [code][google.spanner.v1.Type.code] == + [STRUCT][google.spanner.v1.TypeCode.STRUCT], then + ``struct_type`` provides type information for the struct's + fields. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.Type) + )) +_sym_db.RegisterMessage(Type) + +StructType = _reflection.GeneratedProtocolMessageType('StructType', (_message.Message,), dict( + + Field = _reflection.GeneratedProtocolMessageType('Field', (_message.Message,), dict( + DESCRIPTOR = _STRUCTTYPE_FIELD, + __module__ = 'google.cloud.spanner_v1.proto.type_pb2' + , + __doc__ = """Message representing a single field of a struct. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.StructType.Field) + )) + , + DESCRIPTOR = _STRUCTTYPE, + __module__ = 'google.cloud.spanner_v1.proto.type_pb2' + , + __doc__ = """``StructType`` defines the fields of a + [STRUCT][google.spanner.v1.TypeCode.STRUCT] type. + + + Attributes: + name: + The name of the field. For reads, this is the column name. For + SQL queries, it is the column alias (e.g., ``"Word"`` in the + query ``"SELECT 'hello' AS Word"``), or the column name (e.g., + ``"ColName"`` in the query ``"SELECT ColName FROM Table"``). + Some columns might have an empty name (e.g., !"SELECT + UPPER(ColName)"\`). Note that a query result can contain + multiple fields with the same name. + type: + The type of the field. + fields: + The list of fields that make up this struct. Order is + significant, because values of this struct type are + represented as lists, where the order of field values matches + the order of fields in the + [StructType][google.spanner.v1.StructType]. In turn, the order + of fields matches the order of columns in a read request, or + the order of fields in the ``SELECT`` clause of a query. + """, + # @@protoc_insertion_point(class_scope:google.spanner.v1.StructType) + )) +_sym_db.RegisterMessage(StructType) +_sym_db.RegisterMessage(StructType.Field) + + +DESCRIPTOR.has_options = True +DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\025com.google.spanner.v1B\tTypeProtoP\001Z8google.golang.org/genproto/googleapis/spanner/v1;spanner\252\002\027Google.Cloud.Spanner.V1')) +try: + # THESE ELEMENTS WILL BE DEPRECATED. + # Please use the generated *_pb2_grpc.py files instead. + import grpc + from grpc.beta import implementations as beta_implementations + from grpc.beta import interfaces as beta_interfaces + from grpc.framework.common import cardinality + from grpc.framework.interfaces.face import utilities as face_utilities +except ImportError: + pass +# @@protoc_insertion_point(module_scope) diff --git a/spanner/google/cloud/spanner_v1/proto/type_pb2_grpc.py b/spanner/google/cloud/spanner_v1/proto/type_pb2_grpc.py new file mode 100644 index 000000000000..a89435267cb2 --- /dev/null +++ b/spanner/google/cloud/spanner_v1/proto/type_pb2_grpc.py @@ -0,0 +1,3 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +import grpc + diff --git a/spanner/google/cloud/spanner_v1/types.py b/spanner/google/cloud/spanner_v1/types.py new file mode 100644 index 000000000000..6bc36fc7ce50 --- /dev/null +++ b/spanner/google/cloud/spanner_v1/types.py @@ -0,0 +1,56 @@ +# Copyright 2017, Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import absolute_import +import sys + +from google.gax.utils.messages import get_messages + +from google.api import auth_pb2 +from google.api import http_pb2 +from google.cloud.spanner_v1.proto import keys_pb2 +from google.cloud.spanner_v1.proto import mutation_pb2 +from google.cloud.spanner_v1.proto import query_plan_pb2 +from google.cloud.spanner_v1.proto import result_set_pb2 +from google.cloud.spanner_v1.proto import spanner_pb2 +from google.cloud.spanner_v1.proto import transaction_pb2 +from google.cloud.spanner_v1.proto import type_pb2 +from google.protobuf import descriptor_pb2 +from google.protobuf import duration_pb2 +from google.protobuf import empty_pb2 +from google.protobuf import struct_pb2 +from google.protobuf import timestamp_pb2 + +names = [] +for module in ( + auth_pb2, + http_pb2, + keys_pb2, + mutation_pb2, + query_plan_pb2, + result_set_pb2, + spanner_pb2, + transaction_pb2, + type_pb2, + descriptor_pb2, + duration_pb2, + empty_pb2, + struct_pb2, + timestamp_pb2, ): + for name, message in get_messages(module).items(): + message.__module__ = 'google.cloud.spanner_v1.types' + setattr(sys.modules[__name__], name, message) + names.append(name) + +__all__ = tuple(sorted(names)) diff --git a/spanner/setup.py b/spanner/setup.py index 6af6aa5de497..d8f2f344c10f 100644 --- a/spanner/setup.py +++ b/spanner/setup.py @@ -51,7 +51,6 @@ REQUIREMENTS = [ - 'gapic-google-cloud-spanner-v1 >= 0.15.0, < 0.16dev', 'google-auth >= 1.1.0', 'google-cloud-core >= 0.27.0, < 0.28dev', 'google-gax>=0.15.15, <0.16dev', diff --git a/spanner/tests/system/test_system.py b/spanner/tests/system/test_system.py index 64177765cb2d..2393fd82b608 100644 --- a/spanner/tests/system/test_system.py +++ b/spanner/tests/system/test_system.py @@ -21,15 +21,15 @@ import time import unittest -from google.cloud.proto.spanner.v1.type_pb2 import ARRAY -from google.cloud.proto.spanner.v1.type_pb2 import BOOL -from google.cloud.proto.spanner.v1.type_pb2 import BYTES -from google.cloud.proto.spanner.v1.type_pb2 import DATE -from google.cloud.proto.spanner.v1.type_pb2 import FLOAT64 -from google.cloud.proto.spanner.v1.type_pb2 import INT64 -from google.cloud.proto.spanner.v1.type_pb2 import STRING -from google.cloud.proto.spanner.v1.type_pb2 import TIMESTAMP -from google.cloud.proto.spanner.v1.type_pb2 import Type +from google.cloud.spanner_v1.proto.type_pb2 import ARRAY +from google.cloud.spanner_v1.proto.type_pb2 import BOOL +from google.cloud.spanner_v1.proto.type_pb2 import BYTES +from google.cloud.spanner_v1.proto.type_pb2 import DATE +from google.cloud.spanner_v1.proto.type_pb2 import FLOAT64 +from google.cloud.spanner_v1.proto.type_pb2 import INT64 +from google.cloud.spanner_v1.proto.type_pb2 import STRING +from google.cloud.spanner_v1.proto.type_pb2 import TIMESTAMP +from google.cloud.spanner_v1.proto.type_pb2 import Type from google.cloud._helpers import UTC from google.cloud.exceptions import GrpcRendezvous diff --git a/spanner/tests/unit/gapic/v1/test_spanner_client_v1.py b/spanner/tests/unit/gapic/v1/test_spanner_client_v1.py new file mode 100644 index 000000000000..fac97a7fe8e5 --- /dev/null +++ b/spanner/tests/unit/gapic/v1/test_spanner_client_v1.py @@ -0,0 +1,553 @@ +# Copyright 2017, Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Unit tests.""" + +import mock +import unittest + +from google.gax import errors + +from google.cloud import spanner_v1 +from google.cloud.spanner_v1.proto import keys_pb2 +from google.cloud.spanner_v1.proto import result_set_pb2 +from google.cloud.spanner_v1.proto import spanner_pb2 +from google.cloud.spanner_v1.proto import transaction_pb2 +from google.protobuf import empty_pb2 + + +class CustomException(Exception): + pass + + +class TestSpannerClient(unittest.TestCase): + @mock.patch('google.gax.config.create_stub', spec=True) + def test_create_session(self, mock_create_stub): + # Mock gRPC layer + grpc_stub = mock.Mock() + mock_create_stub.return_value = grpc_stub + + client = spanner_v1.SpannerClient() + + # Mock request + database = client.database_path('[PROJECT]', '[INSTANCE]', + '[DATABASE]') + + # Mock response + name = 'name3373707' + expected_response = {'name': name} + expected_response = spanner_pb2.Session(**expected_response) + grpc_stub.CreateSession.return_value = expected_response + + response = client.create_session(database) + self.assertEqual(expected_response, response) + + grpc_stub.CreateSession.assert_called_once() + args, kwargs = grpc_stub.CreateSession.call_args + self.assertEqual(len(args), 2) + self.assertEqual(len(kwargs), 1) + self.assertIn('metadata', kwargs) + actual_request = args[0] + + expected_request = spanner_pb2.CreateSessionRequest(database=database) + self.assertEqual(expected_request, actual_request) + + @mock.patch('google.gax.config.API_ERRORS', (CustomException, )) + @mock.patch('google.gax.config.create_stub', spec=True) + def test_create_session_exception(self, mock_create_stub): + # Mock gRPC layer + grpc_stub = mock.Mock() + mock_create_stub.return_value = grpc_stub + + client = spanner_v1.SpannerClient() + + # Mock request + database = client.database_path('[PROJECT]', '[INSTANCE]', + '[DATABASE]') + + # Mock exception response + grpc_stub.CreateSession.side_effect = CustomException() + + self.assertRaises(errors.GaxError, client.create_session, database) + + @mock.patch('google.gax.config.create_stub', spec=True) + def test_get_session(self, mock_create_stub): + # Mock gRPC layer + grpc_stub = mock.Mock() + mock_create_stub.return_value = grpc_stub + + client = spanner_v1.SpannerClient() + + # Mock request + name = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', + '[SESSION]') + + # Mock response + name_2 = 'name2-1052831874' + expected_response = {'name': name_2} + expected_response = spanner_pb2.Session(**expected_response) + grpc_stub.GetSession.return_value = expected_response + + response = client.get_session(name) + self.assertEqual(expected_response, response) + + grpc_stub.GetSession.assert_called_once() + args, kwargs = grpc_stub.GetSession.call_args + self.assertEqual(len(args), 2) + self.assertEqual(len(kwargs), 1) + self.assertIn('metadata', kwargs) + actual_request = args[0] + + expected_request = spanner_pb2.GetSessionRequest(name=name) + self.assertEqual(expected_request, actual_request) + + @mock.patch('google.gax.config.API_ERRORS', (CustomException, )) + @mock.patch('google.gax.config.create_stub', spec=True) + def test_get_session_exception(self, mock_create_stub): + # Mock gRPC layer + grpc_stub = mock.Mock() + mock_create_stub.return_value = grpc_stub + + client = spanner_v1.SpannerClient() + + # Mock request + name = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', + '[SESSION]') + + # Mock exception response + grpc_stub.GetSession.side_effect = CustomException() + + self.assertRaises(errors.GaxError, client.get_session, name) + + @mock.patch('google.gax.config.create_stub', spec=True) + def test_delete_session(self, mock_create_stub): + # Mock gRPC layer + grpc_stub = mock.Mock() + mock_create_stub.return_value = grpc_stub + + client = spanner_v1.SpannerClient() + + # Mock request + name = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', + '[SESSION]') + + client.delete_session(name) + + grpc_stub.DeleteSession.assert_called_once() + args, kwargs = grpc_stub.DeleteSession.call_args + self.assertEqual(len(args), 2) + self.assertEqual(len(kwargs), 1) + self.assertIn('metadata', kwargs) + actual_request = args[0] + + expected_request = spanner_pb2.DeleteSessionRequest(name=name) + self.assertEqual(expected_request, actual_request) + + @mock.patch('google.gax.config.API_ERRORS', (CustomException, )) + @mock.patch('google.gax.config.create_stub', spec=True) + def test_delete_session_exception(self, mock_create_stub): + # Mock gRPC layer + grpc_stub = mock.Mock() + mock_create_stub.return_value = grpc_stub + + client = spanner_v1.SpannerClient() + + # Mock request + name = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', + '[SESSION]') + + # Mock exception response + grpc_stub.DeleteSession.side_effect = CustomException() + + self.assertRaises(errors.GaxError, client.delete_session, name) + + @mock.patch('google.gax.config.create_stub', spec=True) + def test_execute_sql(self, mock_create_stub): + # Mock gRPC layer + grpc_stub = mock.Mock() + mock_create_stub.return_value = grpc_stub + + client = spanner_v1.SpannerClient() + + # Mock request + session = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', + '[SESSION]') + sql = 'sql114126' + + # Mock response + expected_response = {} + expected_response = result_set_pb2.ResultSet(**expected_response) + grpc_stub.ExecuteSql.return_value = expected_response + + response = client.execute_sql(session, sql) + self.assertEqual(expected_response, response) + + grpc_stub.ExecuteSql.assert_called_once() + args, kwargs = grpc_stub.ExecuteSql.call_args + self.assertEqual(len(args), 2) + self.assertEqual(len(kwargs), 1) + self.assertIn('metadata', kwargs) + actual_request = args[0] + + expected_request = spanner_pb2.ExecuteSqlRequest( + session=session, sql=sql) + self.assertEqual(expected_request, actual_request) + + @mock.patch('google.gax.config.API_ERRORS', (CustomException, )) + @mock.patch('google.gax.config.create_stub', spec=True) + def test_execute_sql_exception(self, mock_create_stub): + # Mock gRPC layer + grpc_stub = mock.Mock() + mock_create_stub.return_value = grpc_stub + + client = spanner_v1.SpannerClient() + + # Mock request + session = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', + '[SESSION]') + sql = 'sql114126' + + # Mock exception response + grpc_stub.ExecuteSql.side_effect = CustomException() + + self.assertRaises(errors.GaxError, client.execute_sql, session, sql) + + @mock.patch('google.gax.config.create_stub', spec=True) + def test_execute_streaming_sql(self, mock_create_stub): + # Mock gRPC layer + grpc_stub = mock.Mock() + mock_create_stub.return_value = grpc_stub + + client = spanner_v1.SpannerClient() + + # Mock request + session = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', + '[SESSION]') + sql = 'sql114126' + + # Mock response + chunked_value = True + resume_token = b'103' + expected_response = { + 'chunked_value': chunked_value, + 'resume_token': resume_token + } + expected_response = result_set_pb2.PartialResultSet( + **expected_response) + grpc_stub.ExecuteStreamingSql.return_value = iter([expected_response]) + + response = client.execute_streaming_sql(session, sql) + resources = list(response) + self.assertEqual(1, len(resources)) + self.assertEqual(expected_response, resources[0]) + + grpc_stub.ExecuteStreamingSql.assert_called_once() + args, kwargs = grpc_stub.ExecuteStreamingSql.call_args + self.assertEqual(len(args), 2) + self.assertEqual(len(kwargs), 1) + self.assertIn('metadata', kwargs) + actual_request = args[0] + + expected_request = spanner_pb2.ExecuteSqlRequest( + session=session, sql=sql) + self.assertEqual(expected_request, actual_request) + + @mock.patch('google.gax.config.API_ERRORS', (CustomException, )) + @mock.patch('google.gax.config.create_stub', spec=True) + def test_execute_streaming_sql_exception(self, mock_create_stub): + # Mock gRPC layer + grpc_stub = mock.Mock() + mock_create_stub.return_value = grpc_stub + + client = spanner_v1.SpannerClient() + + # Mock request + session = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', + '[SESSION]') + sql = 'sql114126' + + # Mock exception response + grpc_stub.ExecuteStreamingSql.side_effect = CustomException() + + self.assertRaises(errors.GaxError, client.execute_streaming_sql, + session, sql) + + @mock.patch('google.gax.config.create_stub', spec=True) + def test_read(self, mock_create_stub): + # Mock gRPC layer + grpc_stub = mock.Mock() + mock_create_stub.return_value = grpc_stub + + client = spanner_v1.SpannerClient() + + # Mock request + session = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', + '[SESSION]') + table = 'table110115790' + columns = [] + key_set = {} + + # Mock response + expected_response = {} + expected_response = result_set_pb2.ResultSet(**expected_response) + grpc_stub.Read.return_value = expected_response + + response = client.read(session, table, columns, key_set) + self.assertEqual(expected_response, response) + + grpc_stub.Read.assert_called_once() + args, kwargs = grpc_stub.Read.call_args + self.assertEqual(len(args), 2) + self.assertEqual(len(kwargs), 1) + self.assertIn('metadata', kwargs) + actual_request = args[0] + + expected_request = spanner_pb2.ReadRequest( + session=session, table=table, columns=columns, key_set=key_set) + self.assertEqual(expected_request, actual_request) + + @mock.patch('google.gax.config.API_ERRORS', (CustomException, )) + @mock.patch('google.gax.config.create_stub', spec=True) + def test_read_exception(self, mock_create_stub): + # Mock gRPC layer + grpc_stub = mock.Mock() + mock_create_stub.return_value = grpc_stub + + client = spanner_v1.SpannerClient() + + # Mock request + session = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', + '[SESSION]') + table = 'table110115790' + columns = [] + key_set = {} + + # Mock exception response + grpc_stub.Read.side_effect = CustomException() + + self.assertRaises(errors.GaxError, client.read, session, table, + columns, key_set) + + @mock.patch('google.gax.config.create_stub', spec=True) + def test_streaming_read(self, mock_create_stub): + # Mock gRPC layer + grpc_stub = mock.Mock() + mock_create_stub.return_value = grpc_stub + + client = spanner_v1.SpannerClient() + + # Mock request + session = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', + '[SESSION]') + table = 'table110115790' + columns = [] + key_set = {} + + # Mock response + chunked_value = True + resume_token = b'103' + expected_response = { + 'chunked_value': chunked_value, + 'resume_token': resume_token + } + expected_response = result_set_pb2.PartialResultSet( + **expected_response) + grpc_stub.StreamingRead.return_value = iter([expected_response]) + + response = client.streaming_read(session, table, columns, key_set) + resources = list(response) + self.assertEqual(1, len(resources)) + self.assertEqual(expected_response, resources[0]) + + grpc_stub.StreamingRead.assert_called_once() + args, kwargs = grpc_stub.StreamingRead.call_args + self.assertEqual(len(args), 2) + self.assertEqual(len(kwargs), 1) + self.assertIn('metadata', kwargs) + actual_request = args[0] + + expected_request = spanner_pb2.ReadRequest( + session=session, table=table, columns=columns, key_set=key_set) + self.assertEqual(expected_request, actual_request) + + @mock.patch('google.gax.config.API_ERRORS', (CustomException, )) + @mock.patch('google.gax.config.create_stub', spec=True) + def test_streaming_read_exception(self, mock_create_stub): + # Mock gRPC layer + grpc_stub = mock.Mock() + mock_create_stub.return_value = grpc_stub + + client = spanner_v1.SpannerClient() + + # Mock request + session = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', + '[SESSION]') + table = 'table110115790' + columns = [] + key_set = {} + + # Mock exception response + grpc_stub.StreamingRead.side_effect = CustomException() + + self.assertRaises(errors.GaxError, client.streaming_read, session, + table, columns, key_set) + + @mock.patch('google.gax.config.create_stub', spec=True) + def test_begin_transaction(self, mock_create_stub): + # Mock gRPC layer + grpc_stub = mock.Mock() + mock_create_stub.return_value = grpc_stub + + client = spanner_v1.SpannerClient() + + # Mock request + session = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', + '[SESSION]') + options_ = {} + + # Mock response + id_ = b'27' + expected_response = {'id': id_} + expected_response = transaction_pb2.Transaction(**expected_response) + grpc_stub.BeginTransaction.return_value = expected_response + + response = client.begin_transaction(session, options_) + self.assertEqual(expected_response, response) + + grpc_stub.BeginTransaction.assert_called_once() + args, kwargs = grpc_stub.BeginTransaction.call_args + self.assertEqual(len(args), 2) + self.assertEqual(len(kwargs), 1) + self.assertIn('metadata', kwargs) + actual_request = args[0] + + expected_request = spanner_pb2.BeginTransactionRequest( + session=session, options=options_) + self.assertEqual(expected_request, actual_request) + + @mock.patch('google.gax.config.API_ERRORS', (CustomException, )) + @mock.patch('google.gax.config.create_stub', spec=True) + def test_begin_transaction_exception(self, mock_create_stub): + # Mock gRPC layer + grpc_stub = mock.Mock() + mock_create_stub.return_value = grpc_stub + + client = spanner_v1.SpannerClient() + + # Mock request + session = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', + '[SESSION]') + options_ = {} + + # Mock exception response + grpc_stub.BeginTransaction.side_effect = CustomException() + + self.assertRaises(errors.GaxError, client.begin_transaction, session, + options_) + + @mock.patch('google.gax.config.create_stub', spec=True) + def test_commit(self, mock_create_stub): + # Mock gRPC layer + grpc_stub = mock.Mock() + mock_create_stub.return_value = grpc_stub + + client = spanner_v1.SpannerClient() + + # Mock request + session = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', + '[SESSION]') + mutations = [] + + # Mock response + expected_response = {} + expected_response = spanner_pb2.CommitResponse(**expected_response) + grpc_stub.Commit.return_value = expected_response + + response = client.commit(session, mutations) + self.assertEqual(expected_response, response) + + grpc_stub.Commit.assert_called_once() + args, kwargs = grpc_stub.Commit.call_args + self.assertEqual(len(args), 2) + self.assertEqual(len(kwargs), 1) + self.assertIn('metadata', kwargs) + actual_request = args[0] + + expected_request = spanner_pb2.CommitRequest( + session=session, mutations=mutations) + self.assertEqual(expected_request, actual_request) + + @mock.patch('google.gax.config.API_ERRORS', (CustomException, )) + @mock.patch('google.gax.config.create_stub', spec=True) + def test_commit_exception(self, mock_create_stub): + # Mock gRPC layer + grpc_stub = mock.Mock() + mock_create_stub.return_value = grpc_stub + + client = spanner_v1.SpannerClient() + + # Mock request + session = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', + '[SESSION]') + mutations = [] + + # Mock exception response + grpc_stub.Commit.side_effect = CustomException() + + self.assertRaises(errors.GaxError, client.commit, session, mutations) + + @mock.patch('google.gax.config.create_stub', spec=True) + def test_rollback(self, mock_create_stub): + # Mock gRPC layer + grpc_stub = mock.Mock() + mock_create_stub.return_value = grpc_stub + + client = spanner_v1.SpannerClient() + + # Mock request + session = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', + '[SESSION]') + transaction_id = b'28' + + client.rollback(session, transaction_id) + + grpc_stub.Rollback.assert_called_once() + args, kwargs = grpc_stub.Rollback.call_args + self.assertEqual(len(args), 2) + self.assertEqual(len(kwargs), 1) + self.assertIn('metadata', kwargs) + actual_request = args[0] + + expected_request = spanner_pb2.RollbackRequest( + session=session, transaction_id=transaction_id) + self.assertEqual(expected_request, actual_request) + + @mock.patch('google.gax.config.API_ERRORS', (CustomException, )) + @mock.patch('google.gax.config.create_stub', spec=True) + def test_rollback_exception(self, mock_create_stub): + # Mock gRPC layer + grpc_stub = mock.Mock() + mock_create_stub.return_value = grpc_stub + + client = spanner_v1.SpannerClient() + + # Mock request + session = client.session_path('[PROJECT]', '[INSTANCE]', '[DATABASE]', + '[SESSION]') + transaction_id = b'28' + + # Mock exception response + grpc_stub.Rollback.side_effect = CustomException() + + self.assertRaises(errors.GaxError, client.rollback, session, + transaction_id) diff --git a/spanner/tests/unit/test__helpers.py b/spanner/tests/unit/test__helpers.py index beb5ed7b6bac..78e710d9697d 100644 --- a/spanner/tests/unit/test__helpers.py +++ b/spanner/tests/unit/test__helpers.py @@ -313,7 +313,7 @@ def _callFUT(self, *args, **kw): def test_w_null(self): from google.protobuf.struct_pb2 import Value, NULL_VALUE - from google.cloud.proto.spanner.v1.type_pb2 import Type, STRING + from google.cloud.spanner_v1.proto.type_pb2 import Type, STRING field_type = Type(code=STRING) value_pb = Value(null_value=NULL_VALUE) @@ -322,7 +322,7 @@ def test_w_null(self): def test_w_string(self): from google.protobuf.struct_pb2 import Value - from google.cloud.proto.spanner.v1.type_pb2 import Type, STRING + from google.cloud.spanner_v1.proto.type_pb2 import Type, STRING VALUE = u'Value' field_type = Type(code=STRING) @@ -332,7 +332,7 @@ def test_w_string(self): def test_w_bytes(self): from google.protobuf.struct_pb2 import Value - from google.cloud.proto.spanner.v1.type_pb2 import Type, BYTES + from google.cloud.spanner_v1.proto.type_pb2 import Type, BYTES VALUE = b'Value' field_type = Type(code=BYTES) @@ -342,7 +342,7 @@ def test_w_bytes(self): def test_w_bool(self): from google.protobuf.struct_pb2 import Value - from google.cloud.proto.spanner.v1.type_pb2 import Type, BOOL + from google.cloud.spanner_v1.proto.type_pb2 import Type, BOOL VALUE = True field_type = Type(code=BOOL) @@ -352,7 +352,7 @@ def test_w_bool(self): def test_w_int(self): from google.protobuf.struct_pb2 import Value - from google.cloud.proto.spanner.v1.type_pb2 import Type, INT64 + from google.cloud.spanner_v1.proto.type_pb2 import Type, INT64 VALUE = 12345 field_type = Type(code=INT64) @@ -362,7 +362,7 @@ def test_w_int(self): def test_w_float(self): from google.protobuf.struct_pb2 import Value - from google.cloud.proto.spanner.v1.type_pb2 import Type, FLOAT64 + from google.cloud.spanner_v1.proto.type_pb2 import Type, FLOAT64 VALUE = 3.14159 field_type = Type(code=FLOAT64) @@ -373,7 +373,7 @@ def test_w_float(self): def test_w_date(self): import datetime from google.protobuf.struct_pb2 import Value - from google.cloud.proto.spanner.v1.type_pb2 import Type, DATE + from google.cloud.spanner_v1.proto.type_pb2 import Type, DATE VALUE = datetime.date.today() field_type = Type(code=DATE) @@ -383,7 +383,7 @@ def test_w_date(self): def test_w_timestamp_wo_nanos(self): from google.protobuf.struct_pb2 import Value - from google.cloud.proto.spanner.v1.type_pb2 import Type, TIMESTAMP + from google.cloud.spanner_v1.proto.type_pb2 import Type, TIMESTAMP from google.cloud._helpers import UTC, _datetime_to_rfc3339 from google.cloud.spanner._helpers import TimestampWithNanoseconds @@ -398,7 +398,7 @@ def test_w_timestamp_wo_nanos(self): def test_w_timestamp_w_nanos(self): from google.protobuf.struct_pb2 import Value - from google.cloud.proto.spanner.v1.type_pb2 import Type, TIMESTAMP + from google.cloud.spanner_v1.proto.type_pb2 import Type, TIMESTAMP from google.cloud._helpers import UTC, _datetime_to_rfc3339 from google.cloud.spanner._helpers import TimestampWithNanoseconds @@ -413,7 +413,7 @@ def test_w_timestamp_w_nanos(self): def test_w_array_empty(self): from google.protobuf.struct_pb2 import Value - from google.cloud.proto.spanner.v1.type_pb2 import Type, ARRAY, INT64 + from google.cloud.spanner_v1.proto.type_pb2 import Type, ARRAY, INT64 field_type = Type(code=ARRAY, array_element_type=Type(code=INT64)) value_pb = Value() @@ -422,7 +422,7 @@ def test_w_array_empty(self): def test_w_array_non_empty(self): from google.protobuf.struct_pb2 import Value, ListValue - from google.cloud.proto.spanner.v1.type_pb2 import Type, ARRAY, INT64 + from google.cloud.spanner_v1.proto.type_pb2 import Type, ARRAY, INT64 field_type = Type(code=ARRAY, array_element_type=Type(code=INT64)) VALUES = [32, 19, 5] @@ -434,8 +434,8 @@ def test_w_array_non_empty(self): def test_w_struct(self): from google.protobuf.struct_pb2 import Value - from google.cloud.proto.spanner.v1.type_pb2 import Type, StructType - from google.cloud.proto.spanner.v1.type_pb2 import ( + from google.cloud.spanner_v1.proto.type_pb2 import Type, StructType + from google.cloud.spanner_v1.proto.type_pb2 import ( STRUCT, STRING, INT64) from google.cloud.spanner._helpers import _make_list_value_pb @@ -451,8 +451,8 @@ def test_w_struct(self): def test_w_unknown_type(self): from google.protobuf.struct_pb2 import Value - from google.cloud.proto.spanner.v1.type_pb2 import Type - from google.cloud.proto.spanner.v1.type_pb2 import ( + from google.cloud.spanner_v1.proto.type_pb2 import Type + from google.cloud.spanner_v1.proto.type_pb2 import ( TYPE_CODE_UNSPECIFIED) field_type = Type(code=TYPE_CODE_UNSPECIFIED) @@ -470,8 +470,8 @@ def _callFUT(self, *args, **kw): return _parse_list_value_pbs(*args, **kw) def test_empty(self): - from google.cloud.proto.spanner.v1.type_pb2 import Type, StructType - from google.cloud.proto.spanner.v1.type_pb2 import STRING, INT64 + from google.cloud.spanner_v1.proto.type_pb2 import Type, StructType + from google.cloud.spanner_v1.proto.type_pb2 import STRING, INT64 struct_type_pb = StructType(fields=[ StructType.Field(name='name', type=Type(code=STRING)), @@ -481,8 +481,8 @@ def test_empty(self): self.assertEqual(self._callFUT(rows=[], row_type=struct_type_pb), []) def test_non_empty(self): - from google.cloud.proto.spanner.v1.type_pb2 import Type, StructType - from google.cloud.proto.spanner.v1.type_pb2 import STRING, INT64 + from google.cloud.spanner_v1.proto.type_pb2 import Type, StructType + from google.cloud.spanner_v1.proto.type_pb2 import STRING, INT64 from google.cloud.spanner._helpers import _make_list_value_pbs VALUES = [ diff --git a/spanner/tests/unit/test_batch.py b/spanner/tests/unit/test_batch.py index cf65fdd7e4f5..0d8257bc5b8b 100644 --- a/spanner/tests/unit/test_batch.py +++ b/spanner/tests/unit/test_batch.py @@ -75,7 +75,7 @@ def test__check_state_virtual(self): base._check_state() def test_insert(self): - from google.cloud.proto.spanner.v1.mutation_pb2 import Mutation + from google.cloud.spanner_v1.proto.mutation_pb2 import Mutation session = _Session() base = self._make_one(session) @@ -92,7 +92,7 @@ def test_insert(self): self._compare_values(write.values, VALUES) def test_update(self): - from google.cloud.proto.spanner.v1.mutation_pb2 import Mutation + from google.cloud.spanner_v1.proto.mutation_pb2 import Mutation session = _Session() base = self._make_one(session) @@ -109,7 +109,7 @@ def test_update(self): self._compare_values(write.values, VALUES) def test_insert_or_update(self): - from google.cloud.proto.spanner.v1.mutation_pb2 import Mutation + from google.cloud.spanner_v1.proto.mutation_pb2 import Mutation session = _Session() base = self._make_one(session) @@ -126,7 +126,7 @@ def test_insert_or_update(self): self._compare_values(write.values, VALUES) def test_replace(self): - from google.cloud.proto.spanner.v1.mutation_pb2 import Mutation + from google.cloud.spanner_v1.proto.mutation_pb2 import Mutation session = _Session() base = self._make_one(session) @@ -143,7 +143,7 @@ def test_replace(self): self._compare_values(write.values, VALUES) def test_delete(self): - from google.cloud.proto.spanner.v1.mutation_pb2 import Mutation + from google.cloud.spanner_v1.proto.mutation_pb2 import Mutation from google.cloud.spanner.keyset import KeySet keys = [[0], [1], [2]] @@ -195,9 +195,9 @@ def test_commit_already_committed(self): def test_commit_grpc_error(self): from google.gax.errors import GaxError - from google.cloud.proto.spanner.v1.transaction_pb2 import ( + from google.cloud.spanner_v1.proto.transaction_pb2 import ( TransactionOptions) - from google.cloud.proto.spanner.v1.mutation_pb2 import ( + from google.cloud.spanner_v1.proto.mutation_pb2 import ( Mutation as MutationPB) from google.cloud.spanner.keyset import KeySet @@ -234,8 +234,8 @@ def test_commit_grpc_error(self): def test_commit_ok(self): import datetime - from google.cloud.proto.spanner.v1.spanner_pb2 import CommitResponse - from google.cloud.proto.spanner.v1.transaction_pb2 import ( + from google.cloud.spanner_v1.proto.spanner_pb2 import CommitResponse + from google.cloud.spanner_v1.proto.transaction_pb2 import ( TransactionOptions) from google.cloud._helpers import UTC from google.cloud._helpers import _datetime_to_pb_timestamp @@ -282,8 +282,8 @@ def test_context_mgr_already_committed(self): def test_context_mgr_success(self): import datetime - from google.cloud.proto.spanner.v1.spanner_pb2 import CommitResponse - from google.cloud.proto.spanner.v1.transaction_pb2 import ( + from google.cloud.spanner_v1.proto.spanner_pb2 import CommitResponse + from google.cloud.spanner_v1.proto.transaction_pb2 import ( TransactionOptions) from google.cloud._helpers import UTC from google.cloud._helpers import _datetime_to_pb_timestamp @@ -312,7 +312,7 @@ def test_context_mgr_success(self): def test_context_mgr_failure(self): import datetime - from google.cloud.proto.spanner.v1.spanner_pb2 import CommitResponse + from google.cloud.spanner_v1.proto.spanner_pb2 import CommitResponse from google.cloud._helpers import UTC from google.cloud._helpers import _datetime_to_pb_timestamp diff --git a/spanner/tests/unit/test_database.py b/spanner/tests/unit/test_database.py index 0b154fd0f264..f520ba85da98 100644 --- a/spanner/tests/unit/test_database.py +++ b/spanner/tests/unit/test_database.py @@ -750,8 +750,8 @@ def test_ctor(self): def test_context_mgr_success(self): import datetime - from google.cloud.proto.spanner.v1.spanner_pb2 import CommitResponse - from google.cloud.proto.spanner.v1.transaction_pb2 import ( + from google.cloud.spanner_v1.proto.spanner_pb2 import CommitResponse + from google.cloud.spanner_v1.proto.transaction_pb2 import ( TransactionOptions) from google.cloud._helpers import UTC from google.cloud._helpers import _datetime_to_pb_timestamp diff --git a/spanner/tests/unit/test_keyset.py b/spanner/tests/unit/test_keyset.py index 6ee0670c5828..80ae245c774b 100644 --- a/spanner/tests/unit/test_keyset.py +++ b/spanner/tests/unit/test_keyset.py @@ -93,7 +93,7 @@ def test_ctor_w_start_closed_and_end_open(self): self.assertEqual(krange.end_closed, None) def test_to_pb_w_start_closed_and_end_open(self): - from google.cloud.proto.spanner.v1.keys_pb2 import KeyRange + from google.cloud.spanner_v1.proto.keys_pb2 import KeyRange KEY_1 = [u'key_1'] KEY_2 = [u'key_2'] @@ -107,7 +107,7 @@ def test_to_pb_w_start_closed_and_end_open(self): self.assertEqual(krange_pb.end_open.values[0].string_value, KEY_2[0]) def test_to_pb_w_start_open_and_end_closed(self): - from google.cloud.proto.spanner.v1.keys_pb2 import KeyRange + from google.cloud.spanner_v1.proto.keys_pb2 import KeyRange KEY_1 = [u'key_1'] KEY_2 = [u'key_2'] @@ -173,7 +173,7 @@ def test_ctor_w_all_and_ranges(self): self._make_one(all_=True, ranges=[range_1, range_2]) def test_to_pb_w_all(self): - from google.cloud.proto.spanner.v1.keys_pb2 import KeySet + from google.cloud.spanner_v1.proto.keys_pb2 import KeySet keyset = self._make_one(all_=True) @@ -185,7 +185,7 @@ def test_to_pb_w_all(self): self.assertEqual(len(result.ranges), 0) def test_to_pb_w_only_keys(self): - from google.cloud.proto.spanner.v1.keys_pb2 import KeySet + from google.cloud.spanner_v1.proto.keys_pb2 import KeySet KEYS = [[u'key1'], [u'key2']] keyset = self._make_one(keys=KEYS) @@ -203,7 +203,7 @@ def test_to_pb_w_only_keys(self): self.assertEqual(len(result.ranges), 0) def test_to_pb_w_only_ranges(self): - from google.cloud.proto.spanner.v1.keys_pb2 import KeySet + from google.cloud.spanner_v1.proto.keys_pb2 import KeySet from google.cloud.spanner.keyset import KeyRange KEY_1 = u'KEY_1' diff --git a/spanner/tests/unit/test_session.py b/spanner/tests/unit/test_session.py index 826369079d29..f10ea3b26518 100644 --- a/spanner/tests/unit/test_session.py +++ b/spanner/tests/unit/test_session.py @@ -437,7 +437,7 @@ def unit_of_work(txn, *args, **kw): self.assertEqual(kw, {}) def test_run_in_transaction_callback_raises_abort(self): - from google.cloud.proto.spanner.v1.transaction_pb2 import ( + from google.cloud.spanner_v1.proto.transaction_pb2 import ( Transaction as TransactionPB) from google.cloud.spanner.transaction import Transaction @@ -481,8 +481,8 @@ def unit_of_work(txn, *args, **kw): def test_run_in_transaction_w_args_w_kwargs_wo_abort(self): import datetime - from google.cloud.proto.spanner.v1.spanner_pb2 import CommitResponse - from google.cloud.proto.spanner.v1.transaction_pb2 import ( + from google.cloud.spanner_v1.proto.spanner_pb2 import CommitResponse + from google.cloud.spanner_v1.proto.transaction_pb2 import ( Transaction as TransactionPB) from google.cloud._helpers import UTC from google.cloud._helpers import _datetime_to_pb_timestamp @@ -528,8 +528,8 @@ def unit_of_work(txn, *args, **kw): def test_run_in_transaction_w_abort_no_retry_metadata(self): import datetime - from google.cloud.proto.spanner.v1.spanner_pb2 import CommitResponse - from google.cloud.proto.spanner.v1.transaction_pb2 import ( + from google.cloud.spanner_v1.proto.spanner_pb2 import CommitResponse + from google.cloud.spanner_v1.proto.transaction_pb2 import ( Transaction as TransactionPB) from google.cloud._helpers import UTC from google.cloud._helpers import _datetime_to_pb_timestamp @@ -575,8 +575,8 @@ def unit_of_work(txn, *args, **kw): def test_run_in_transaction_w_abort_w_retry_metadata(self): import datetime - from google.cloud.proto.spanner.v1.spanner_pb2 import CommitResponse - from google.cloud.proto.spanner.v1.transaction_pb2 import ( + from google.cloud.spanner_v1.proto.spanner_pb2 import CommitResponse + from google.cloud.spanner_v1.proto.transaction_pb2 import ( Transaction as TransactionPB) from google.cloud._helpers import UTC from google.cloud._helpers import _datetime_to_pb_timestamp @@ -636,8 +636,8 @@ def test_run_in_transaction_w_callback_raises_abort_wo_metadata(self): import datetime from google.gax.errors import GaxError from grpc import StatusCode - from google.cloud.proto.spanner.v1.spanner_pb2 import CommitResponse - from google.cloud.proto.spanner.v1.transaction_pb2 import ( + from google.cloud.spanner_v1.proto.spanner_pb2 import CommitResponse + from google.cloud.spanner_v1.proto.transaction_pb2 import ( Transaction as TransactionPB) from google.cloud._helpers import UTC from google.cloud._helpers import _datetime_to_pb_timestamp @@ -702,8 +702,8 @@ def test_run_in_transaction_w_abort_w_retry_metadata_deadline(self): from google.gax.errors import GaxError from google.gax.grpc import exc_to_code from grpc import StatusCode - from google.cloud.proto.spanner.v1.spanner_pb2 import CommitResponse - from google.cloud.proto.spanner.v1.transaction_pb2 import ( + from google.cloud.spanner_v1.proto.spanner_pb2 import CommitResponse + from google.cloud.spanner_v1.proto.transaction_pb2 import ( Transaction as TransactionPB) from google.cloud._helpers import UTC from google.cloud._helpers import _datetime_to_pb_timestamp @@ -763,7 +763,7 @@ def test_run_in_transaction_w_timeout(self): from google.cloud._testing import _Monkey from google.gax.errors import GaxError from google.gax.grpc import exc_to_code - from google.cloud.proto.spanner.v1.transaction_pb2 import ( + from google.cloud.spanner_v1.proto.transaction_pb2 import ( Transaction as TransactionPB) from grpc import StatusCode from google.cloud.spanner.transaction import Transaction diff --git a/spanner/tests/unit/test_snapshot.py b/spanner/tests/unit/test_snapshot.py index 4717a14c2f24..f851050173f6 100644 --- a/spanner/tests/unit/test_snapshot.py +++ b/spanner/tests/unit/test_snapshot.py @@ -57,7 +57,7 @@ class _Derived(self._getTargetClass()): _multi_use = False def _make_txn_selector(self): - from google.cloud.proto.spanner.v1.transaction_pb2 import ( + from google.cloud.spanner_v1.proto.transaction_pb2 import ( TransactionOptions, TransactionSelector) if self._transaction_id: @@ -82,7 +82,7 @@ def test__make_txn_selector_virtual(self): base._make_txn_selector() def test_read_grpc_error(self): - from google.cloud.proto.spanner.v1.transaction_pb2 import ( + from google.cloud.spanner_v1.proto.transaction_pb2 import ( TransactionSelector) from google.gax.errors import GaxError from google.cloud.spanner.keyset import KeySet @@ -114,12 +114,12 @@ def test_read_grpc_error(self): def _read_helper(self, multi_use, first=True, count=0): from google.protobuf.struct_pb2 import Struct - from google.cloud.proto.spanner.v1.result_set_pb2 import ( + from google.cloud.spanner_v1.proto.result_set_pb2 import ( PartialResultSet, ResultSetMetadata, ResultSetStats) - from google.cloud.proto.spanner.v1.transaction_pb2 import ( + from google.cloud.spanner_v1.proto.transaction_pb2 import ( TransactionSelector) - from google.cloud.proto.spanner.v1.type_pb2 import Type, StructType - from google.cloud.proto.spanner.v1.type_pb2 import STRING, INT64 + from google.cloud.spanner_v1.proto.type_pb2 import Type, StructType + from google.cloud.spanner_v1.proto.type_pb2 import STRING, INT64 from google.cloud.spanner.keyset import KeySet from google.cloud.spanner._helpers import _make_value_pb @@ -218,7 +218,7 @@ def test_read_w_multi_use_w_first_w_count_gt_0(self): self._read_helper(multi_use=True, first=True, count=1) def test_execute_sql_grpc_error(self): - from google.cloud.proto.spanner.v1.transaction_pb2 import ( + from google.cloud.spanner_v1.proto.transaction_pb2 import ( TransactionSelector) from google.gax.errors import GaxError @@ -255,12 +255,12 @@ def test_execute_sql_w_params_wo_param_types(self): def _execute_sql_helper(self, multi_use, first=True, count=0): from google.protobuf.struct_pb2 import Struct - from google.cloud.proto.spanner.v1.result_set_pb2 import ( + from google.cloud.spanner_v1.proto.result_set_pb2 import ( PartialResultSet, ResultSetMetadata, ResultSetStats) - from google.cloud.proto.spanner.v1.transaction_pb2 import ( + from google.cloud.spanner_v1.proto.transaction_pb2 import ( TransactionSelector) - from google.cloud.proto.spanner.v1.type_pb2 import Type, StructType - from google.cloud.proto.spanner.v1.type_pb2 import STRING, INT64 + from google.cloud.spanner_v1.proto.type_pb2 import Type, StructType + from google.cloud.spanner_v1.proto.type_pb2 import STRING, INT64 from google.cloud.spanner._helpers import _make_value_pb TXN_ID = b'DEADBEEF' @@ -651,7 +651,7 @@ def test_begin_w_gax_error(self): [('google-cloud-resource-prefix', database.name)]) def test_begin_ok_exact_staleness(self): - from google.cloud.proto.spanner.v1.transaction_pb2 import ( + from google.cloud.spanner_v1.proto.transaction_pb2 import ( Transaction as TransactionPB) transaction_pb = TransactionPB(id=self.TRANSACTION_ID) @@ -677,7 +677,7 @@ def test_begin_ok_exact_staleness(self): [('google-cloud-resource-prefix', database.name)]) def test_begin_ok_exact_strong(self): - from google.cloud.proto.spanner.v1.transaction_pb2 import ( + from google.cloud.spanner_v1.proto.transaction_pb2 import ( Transaction as TransactionPB) transaction_pb = TransactionPB(id=self.TRANSACTION_ID) diff --git a/spanner/tests/unit/test_streamed.py b/spanner/tests/unit/test_streamed.py index 0e0bcb7aff6b..e505cb231650 100644 --- a/spanner/tests/unit/test_streamed.py +++ b/spanner/tests/unit/test_streamed.py @@ -57,15 +57,15 @@ def test_fields_unset(self): @staticmethod def _make_scalar_field(name, type_): - from google.cloud.proto.spanner.v1.type_pb2 import StructType - from google.cloud.proto.spanner.v1.type_pb2 import Type + from google.cloud.spanner_v1.proto.type_pb2 import StructType + from google.cloud.spanner_v1.proto.type_pb2 import Type return StructType.Field(name=name, type=Type(code=type_)) @staticmethod def _make_array_field(name, element_type_code=None, element_type=None): - from google.cloud.proto.spanner.v1.type_pb2 import StructType - from google.cloud.proto.spanner.v1.type_pb2 import Type + from google.cloud.spanner_v1.proto.type_pb2 import StructType + from google.cloud.spanner_v1.proto.type_pb2 import Type if element_type is None: element_type = Type(code=element_type_code) @@ -75,8 +75,8 @@ def _make_array_field(name, element_type_code=None, element_type=None): @staticmethod def _make_struct_type(struct_type_fields): - from google.cloud.proto.spanner.v1.type_pb2 import StructType - from google.cloud.proto.spanner.v1.type_pb2 import Type + from google.cloud.spanner_v1.proto.type_pb2 import StructType + from google.cloud.spanner_v1.proto.type_pb2 import Type fields = [ StructType.Field(name=key, type=Type(code=value)) @@ -103,7 +103,7 @@ def _make_list_value(values=(), value_pbs=None): @staticmethod def _make_result_set_metadata(fields=(), transaction_id=None): - from google.cloud.proto.spanner.v1.result_set_pb2 import ( + from google.cloud.spanner_v1.proto.result_set_pb2 import ( ResultSetMetadata) metadata = ResultSetMetadata() for field in fields: @@ -114,7 +114,7 @@ def _make_result_set_metadata(fields=(), transaction_id=None): @staticmethod def _make_result_set_stats(query_plan=None, **kw): - from google.cloud.proto.spanner.v1.result_set_pb2 import ( + from google.cloud.spanner_v1.proto.result_set_pb2 import ( ResultSetStats) from google.protobuf.struct_pb2 import Struct from google.cloud.spanner._helpers import _make_value_pb @@ -129,7 +129,7 @@ def _make_result_set_stats(query_plan=None, **kw): @staticmethod def _make_partial_result_set( values, metadata=None, stats=None, chunked_value=False): - from google.cloud.proto.spanner.v1.result_set_pb2 import ( + from google.cloud.spanner_v1.proto.result_set_pb2 import ( PartialResultSet) return PartialResultSet( values=values, @@ -349,8 +349,8 @@ def test__merge_chunk_array_of_string_with_null(self): self.assertIsNone(streamed._pending_chunk) def test__merge_chunk_array_of_array_of_int(self): - from google.cloud.proto.spanner.v1.type_pb2 import StructType - from google.cloud.proto.spanner.v1.type_pb2 import Type + from google.cloud.spanner_v1.proto.type_pb2 import StructType + from google.cloud.spanner_v1.proto.type_pb2 import Type subarray_type = Type( code='ARRAY', array_element_type=Type(code='INT64')) @@ -381,8 +381,8 @@ def test__merge_chunk_array_of_array_of_int(self): self.assertIsNone(streamed._pending_chunk) def test__merge_chunk_array_of_array_of_string(self): - from google.cloud.proto.spanner.v1.type_pb2 import StructType - from google.cloud.proto.spanner.v1.type_pb2 import Type + from google.cloud.spanner_v1.proto.type_pb2 import StructType + from google.cloud.spanner_v1.proto.type_pb2 import Type subarray_type = Type( code='ARRAY', array_element_type=Type(code='STRING')) @@ -1022,7 +1022,7 @@ def test_multiple_row_chunks_non_chunks_interleaved(self): def _generate_partial_result_sets(prs_text_pbs): from google.protobuf.json_format import Parse - from google.cloud.proto.spanner.v1.result_set_pb2 import PartialResultSet + from google.cloud.spanner_v1.proto.result_set_pb2 import PartialResultSet partial_result_sets = [] @@ -1055,7 +1055,7 @@ def _normalize_float(cell): def _normalize_results(rows_data, fields): """Helper for _parse_streaming_read_acceptance_tests""" - from google.cloud.proto.spanner.v1 import type_pb2 + from google.cloud.spanner_v1.proto import type_pb2 normalized = [] for row_data in rows_data: diff --git a/spanner/tests/unit/test_transaction.py b/spanner/tests/unit/test_transaction.py index 98b25186ff1e..db37324c4e5f 100644 --- a/spanner/tests/unit/test_transaction.py +++ b/spanner/tests/unit/test_transaction.py @@ -137,7 +137,7 @@ def test_begin_w_gax_error(self): [('google-cloud-resource-prefix', database.name)]) def test_begin_ok(self): - from google.cloud.proto.spanner.v1.transaction_pb2 import ( + from google.cloud.spanner_v1.proto.transaction_pb2 import ( Transaction as TransactionPB) transaction_pb = TransactionPB(id=self.TRANSACTION_ID) @@ -279,7 +279,7 @@ def test_commit_w_gax_error(self): def test_commit_ok(self): import datetime - from google.cloud.proto.spanner.v1.spanner_pb2 import CommitResponse + from google.cloud.spanner_v1.proto.spanner_pb2 import CommitResponse from google.cloud.spanner.keyset import KeySet from google.cloud._helpers import UTC from google.cloud._helpers import _datetime_to_pb_timestamp @@ -311,8 +311,8 @@ def test_commit_ok(self): def test_context_mgr_success(self): import datetime - from google.cloud.proto.spanner.v1.spanner_pb2 import CommitResponse - from google.cloud.proto.spanner.v1.transaction_pb2 import ( + from google.cloud.spanner_v1.proto.spanner_pb2 import CommitResponse + from google.cloud.spanner_v1.proto.transaction_pb2 import ( Transaction as TransactionPB) from google.cloud._helpers import UTC from google.cloud._helpers import _datetime_to_pb_timestamp @@ -344,7 +344,7 @@ def test_context_mgr_success(self): def test_context_mgr_failure(self): from google.protobuf.empty_pb2 import Empty empty_pb = Empty() - from google.cloud.proto.spanner.v1.transaction_pb2 import ( + from google.cloud.spanner_v1.proto.transaction_pb2 import ( Transaction as TransactionPB) transaction_pb = TransactionPB(id=self.TRANSACTION_ID) diff --git a/spanner/tests/unit/test_types.py b/spanner/tests/unit/test_types.py index 4f30779c757f..e6566441d4f6 100644 --- a/spanner/tests/unit/test_types.py +++ b/spanner/tests/unit/test_types.py @@ -19,7 +19,7 @@ class Test_ArrayParamType(unittest.TestCase): def test_it(self): - from google.cloud.proto.spanner.v1 import type_pb2 + from google.cloud.spanner_v1.proto import type_pb2 from google.cloud.spanner.types import ArrayParamType from google.cloud.spanner.types import INT64_PARAM_TYPE @@ -35,7 +35,7 @@ def test_it(self): class Test_Struct(unittest.TestCase): def test_it(self): - from google.cloud.proto.spanner.v1 import type_pb2 + from google.cloud.spanner_v1.proto import type_pb2 from google.cloud.spanner.types import INT64_PARAM_TYPE from google.cloud.spanner.types import STRING_PARAM_TYPE from google.cloud.spanner.types import StructParamType