Class: Google::Cloud::Spanner::V1::Spanner::Client

Inherits:
Object
  • Object
show all
Includes:
Paths
Defined in:
lib/google/cloud/spanner/v1/spanner/client.rb

Overview

Client for the Spanner service.

Cloud Spanner API

The Cloud Spanner API can be used to manage sessions and execute transactions on data stored in Cloud Spanner databases.

Defined Under Namespace

Classes: Configuration

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Paths

#database_path, #session_path

Constructor Details

#initialize {|config| ... } ⇒ Client

Create a new Spanner client object.

Examples:


# Create a client using the default configuration
client = ::Google::Cloud::Spanner::V1::Spanner::Client.new

# Create a client using a custom configuration
client = ::Google::Cloud::Spanner::V1::Spanner::Client.new do |config|
  config.timeout = 10.0
end

Yields:

  • (config)

    Configure the Spanner client.

Yield Parameters:



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 195

def initialize
  # These require statements are intentionally placed here to initialize
  # the gRPC module only when it's required.
  # See https://github.com/googleapis/toolkit/issues/446
  require "gapic/grpc"
  require "google/spanner/v1/spanner_services_pb"

  # Create the configuration object
  @config = Configuration.new Client.configure

  # Yield the configuration if needed
  yield @config if block_given?

  # Create credentials
  credentials = @config.credentials
  # Use self-signed JWT if the endpoint is unchanged from default,
  # but only if the default endpoint does not have a region prefix.
  enable_self_signed_jwt = @config.endpoint.nil? ||
                           (@config.endpoint == Configuration::DEFAULT_ENDPOINT &&
                           !@config.endpoint.split(".").first.include?("-"))
  credentials ||= Credentials.default scope: @config.scope,
                                      enable_self_signed_jwt: enable_self_signed_jwt
  if credentials.is_a?(::String) || credentials.is_a?(::Hash)
    credentials = Credentials.new credentials, scope: @config.scope
  end
  @quota_project_id = @config.quota_project
  @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id

  @spanner_stub = ::Gapic::ServiceStub.new(
    ::Google::Cloud::Spanner::V1::Spanner::Stub,
    credentials: credentials,
    endpoint: @config.endpoint,
    endpoint_template: DEFAULT_ENDPOINT_TEMPLATE,
    universe_domain: @config.universe_domain,
    channel_args: @config.channel_args,
    interceptors: @config.interceptors,
    channel_pool_config: @config.channel_pool
  )
end

Class Method Details

.configure {|config| ... } ⇒ Client::Configuration

Configure the Spanner Client class.

See Configuration for a description of the configuration fields.

Examples:


# Modify the configuration for all Spanner clients
::Google::Cloud::Spanner::V1::Spanner::Client.configure do |config|
  config.timeout = 10.0
end

Yields:

  • (config)

    Configure the Client client.

Yield Parameters:

Returns:



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 62

def self.configure
  @configure ||= begin
    namespace = ["Google", "Cloud", "Spanner", "V1"]
    parent_config = while namespace.any?
                      parent_name = namespace.join "::"
                      parent_const = const_get parent_name
                      break parent_const.configure if parent_const.respond_to? :configure
                      namespace.pop
                    end
    default_config = Client::Configuration.new parent_config

    default_config.rpcs.create_session.timeout = 30.0
    default_config.rpcs.create_session.retry_policy = {
      initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14, 8]
    }

    default_config.rpcs.batch_create_sessions.timeout = 60.0
    default_config.rpcs.batch_create_sessions.retry_policy = {
      initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14, 8]
    }

    default_config.rpcs.get_session.timeout = 30.0
    default_config.rpcs.get_session.retry_policy = {
      initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14, 8]
    }

    default_config.rpcs.list_sessions.timeout = 3600.0
    default_config.rpcs.list_sessions.retry_policy = {
      initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14, 8]
    }

    default_config.rpcs.delete_session.timeout = 30.0
    default_config.rpcs.delete_session.retry_policy = {
      initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14, 8]
    }

    default_config.rpcs.execute_sql.timeout = 30.0
    default_config.rpcs.execute_sql.retry_policy = {
      initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14, 8]
    }

    default_config.rpcs.execute_streaming_sql.timeout = 3600.0

    default_config.rpcs.execute_batch_dml.timeout = 30.0
    default_config.rpcs.execute_batch_dml.retry_policy = {
      initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14, 8]
    }

    default_config.rpcs.read.timeout = 30.0
    default_config.rpcs.read.retry_policy = {
      initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14, 8]
    }

    default_config.rpcs.streaming_read.timeout = 3600.0

    default_config.rpcs.begin_transaction.timeout = 30.0
    default_config.rpcs.begin_transaction.retry_policy = {
      initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14, 8]
    }

    default_config.rpcs.commit.timeout = 3600.0
    default_config.rpcs.commit.retry_policy = {
      initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14, 8]
    }

    default_config.rpcs.rollback.timeout = 30.0
    default_config.rpcs.rollback.retry_policy = {
      initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14, 8]
    }

    default_config.rpcs.partition_query.timeout = 30.0
    default_config.rpcs.partition_query.retry_policy = {
      initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14, 8]
    }

    default_config.rpcs.partition_read.timeout = 30.0
    default_config.rpcs.partition_read.retry_policy = {
      initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14, 8]
    }

    default_config.rpcs.batch_write.timeout = 3600.0

    default_config
  end
  yield @configure if block_given?
  @configure
end

Instance Method Details

#batch_create_sessions(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::BatchCreateSessionsResponse #batch_create_sessions(database: nil, session_template: nil, session_count: nil) ⇒ ::Google::Cloud::Spanner::V1::BatchCreateSessionsResponse

Creates multiple new sessions.

This API can be used to initialize a session cache on the clients. See https://goo.gl/TgSFN2 for best practices on session cache management.

Examples:

Basic example

require "google/cloud/spanner/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Spanner::V1::Spanner::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Spanner::V1::BatchCreateSessionsRequest.new

# Call the batch_create_sessions method.
result = client.batch_create_sessions request

# The returned object is of type Google::Cloud::Spanner::V1::BatchCreateSessionsResponse.
p result

Overloads:

  • #batch_create_sessions(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::BatchCreateSessionsResponse

    Pass arguments to batch_create_sessions via a request object, either of type BatchCreateSessionsRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Spanner::V1::BatchCreateSessionsRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #batch_create_sessions(database: nil, session_template: nil, session_count: nil) ⇒ ::Google::Cloud::Spanner::V1::BatchCreateSessionsResponse

    Pass arguments to batch_create_sessions via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • database (::String) (defaults to: nil)

      Required. The database in which the new sessions are created.

    • session_template (::Google::Cloud::Spanner::V1::Session, ::Hash) (defaults to: nil)

      Parameters to be applied to each created session.

    • session_count (::Integer) (defaults to: nil)

      Required. The number of sessions to be created in this batch call. The API may return fewer than the requested number of sessions. If a specific number of sessions are desired, the client can make additional calls to BatchCreateSessions (adjusting session_count as necessary).

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 398

def batch_create_sessions request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::BatchCreateSessionsRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.batch_create_sessions..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Spanner::V1::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.database
    header_params["database"] = request.database
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.batch_create_sessions.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.batch_create_sessions.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @spanner_stub.call_rpc :batch_create_sessions, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#batch_write(request, options = nil) ⇒ ::Enumerable<::Google::Cloud::Spanner::V1::BatchWriteResponse> #batch_write(session: nil, request_options: nil, mutation_groups: nil, exclude_txn_from_change_streams: nil) ⇒ ::Enumerable<::Google::Cloud::Spanner::V1::BatchWriteResponse>

Batches the supplied mutation groups in a collection of efficient transactions. All mutations in a group are committed atomically. However, mutations across groups can be committed non-atomically in an unspecified order and thus, they must be independent of each other. Partial failure is possible, i.e., some groups may have been committed successfully, while some may have failed. The results of individual batches are streamed into the response as the batches are applied.

BatchWrite requests are not replay protected, meaning that each mutation group may be applied more than once. Replays of non-idempotent mutations may have undesirable effects. For example, replays of an insert mutation may produce an already exists error or if you use generated or commit timestamp-based keys, it may result in additional rows being added to the mutation's table. We recommend structuring your mutation groups to be idempotent to avoid this issue.

Examples:

Basic example

require "google/cloud/spanner/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Spanner::V1::Spanner::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Spanner::V1::BatchWriteRequest.new

# Call the batch_write method to start streaming.
output = client.batch_write request

# The returned object is a streamed enumerable yielding elements of type
# ::Google::Cloud::Spanner::V1::BatchWriteResponse
output.each do |current_response|
  p current_response
end

Overloads:

  • #batch_write(request, options = nil) ⇒ ::Enumerable<::Google::Cloud::Spanner::V1::BatchWriteResponse>

    Pass arguments to batch_write via a request object, either of type BatchWriteRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Spanner::V1::BatchWriteRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #batch_write(session: nil, request_options: nil, mutation_groups: nil, exclude_txn_from_change_streams: nil) ⇒ ::Enumerable<::Google::Cloud::Spanner::V1::BatchWriteResponse>

    Pass arguments to batch_write via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • session (::String) (defaults to: nil)

      Required. The session in which the batch request is to be run.

    • request_options (::Google::Cloud::Spanner::V1::RequestOptions, ::Hash) (defaults to: nil)

      Common options for this request.

    • mutation_groups (::Array<::Google::Cloud::Spanner::V1::BatchWriteRequest::MutationGroup, ::Hash>) (defaults to: nil)

      Required. The groups of mutations to be applied.

    • exclude_txn_from_change_streams (::Boolean) (defaults to: nil)

      Optional. When exclude_txn_from_change_streams is set to true:

      • Mutations from all transactions in this batch write operation will not be recorded in change streams with DDL option allow_txn_exclusion=true that are tracking columns modified by these transactions.
      • Mutations from all transactions in this batch write operation will be recorded in change streams with DDL option allow_txn_exclusion=false or not set that are tracking columns modified by these transactions.

      When exclude_txn_from_change_streams is set to false or not set, mutations from all transactions in this batch write operation will be recorded in all change streams that are tracking columns modified by these transactions.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 2154

def batch_write request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::BatchWriteRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.batch_write..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Spanner::V1::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.session
    header_params["session"] = request.session
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.batch_write.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.batch_write.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @spanner_stub.call_rpc :batch_write, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#begin_transaction(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::Transaction #begin_transaction(session: nil, options: nil, request_options: nil) ⇒ ::Google::Cloud::Spanner::V1::Transaction

Begins a new transaction. This step can often be skipped: Read, ExecuteSql and Commit can begin a new transaction as a side-effect.

Examples:

Basic example

require "google/cloud/spanner/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Spanner::V1::Spanner::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Spanner::V1::BeginTransactionRequest.new

# Call the begin_transaction method.
result = client.begin_transaction request

# The returned object is of type Google::Cloud::Spanner::V1::Transaction.
p result

Overloads:

  • #begin_transaction(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::Transaction

    Pass arguments to begin_transaction via a request object, either of type BeginTransactionRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Spanner::V1::BeginTransactionRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #begin_transaction(session: nil, options: nil, request_options: nil) ⇒ ::Google::Cloud::Spanner::V1::Transaction

    Pass arguments to begin_transaction via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • session (::String) (defaults to: nil)

      Required. The session in which the transaction runs.

    • options (::Google::Cloud::Spanner::V1::TransactionOptions, ::Hash) (defaults to: nil)

      Required. Options for the new transaction.

    • request_options (::Google::Cloud::Spanner::V1::RequestOptions, ::Hash) (defaults to: nil)

      Common options for this request. Priority is ignored for this request. Setting the priority in this request_options struct will not do anything. To set the priority for a transaction, set it on the reads and writes that are part of this transaction instead.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 1551

def begin_transaction request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::BeginTransactionRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.begin_transaction..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Spanner::V1::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.session
    header_params["session"] = request.session
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.begin_transaction.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.begin_transaction.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @spanner_stub.call_rpc :begin_transaction, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#commit(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::CommitResponse #commit(session: nil, transaction_id: nil, single_use_transaction: nil, mutations: nil, return_commit_stats: nil, max_commit_delay: nil, request_options: nil) ⇒ ::Google::Cloud::Spanner::V1::CommitResponse

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.

On very rare occasions, Commit might return UNKNOWN. This can happen, for example, if the client job experiences a 1+ hour networking failure. At that point, Cloud Spanner has lost track of the transaction outcome and we recommend that you perform another read from the database to see the state of things as they are now.

Examples:

Basic example

require "google/cloud/spanner/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Spanner::V1::Spanner::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Spanner::V1::CommitRequest.new

# Call the commit method.
result = client.commit request

# The returned object is of type Google::Cloud::Spanner::V1::CommitResponse.
p result

Overloads:

  • #commit(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::CommitResponse

    Pass arguments to commit via a request object, either of type CommitRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Spanner::V1::CommitRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #commit(session: nil, transaction_id: nil, single_use_transaction: nil, mutations: nil, return_commit_stats: nil, max_commit_delay: nil, request_options: nil) ⇒ ::Google::Cloud::Spanner::V1::CommitResponse

    Pass arguments to commit via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • session (::String) (defaults to: nil)

      Required. The session in which the transaction to be committed is running.

    • transaction_id (::String) (defaults to: nil)

      Commit a previously-started transaction.

    • single_use_transaction (::Google::Cloud::Spanner::V1::TransactionOptions, ::Hash) (defaults to: nil)

      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.

    • mutations (::Array<::Google::Cloud::Spanner::V1::Mutation, ::Hash>) (defaults to: nil)

      The mutations to be executed when this transaction commits. All mutations are applied atomically, in the order they appear in this list.

    • return_commit_stats (::Boolean) (defaults to: nil)

      If true, then statistics related to the transaction will be included in the CommitResponse. Default value is false.

    • max_commit_delay (::Google::Protobuf::Duration, ::Hash) (defaults to: nil)

      Optional. The amount of latency this request is willing to incur in order to improve throughput. If this field is not set, Spanner assumes requests are relatively latency sensitive and automatically determines an appropriate delay time. You can specify a batching delay value between 0 and 500 ms.

    • request_options (::Google::Cloud::Spanner::V1::RequestOptions, ::Hash) (defaults to: nil)

      Common options for this request.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 1677

def commit request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::CommitRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.commit..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Spanner::V1::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.session
    header_params["session"] = request.session
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.commit.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.commit.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @spanner_stub.call_rpc :commit, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#configure {|config| ... } ⇒ Client::Configuration

Configure the Spanner Client instance.

The configuration is set to the derived mode, meaning that values can be changed, but structural changes (adding new fields, etc.) are not allowed. Structural changes should be made on configure.

See Configuration for a description of the configuration fields.

Yields:

  • (config)

    Configure the Client client.

Yield Parameters:

Returns:



165
166
167
168
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 165

def configure
  yield @config if block_given?
  @config
end

#create_session(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::Session #create_session(database: nil, session: nil) ⇒ ::Google::Cloud::Spanner::V1::Session

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.

Active sessions use additional server resources, so it is a good idea to delete idle and unneeded sessions. Aside from explicit deletes, Cloud Spanner may 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".

Examples:

Basic example

require "google/cloud/spanner/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Spanner::V1::Spanner::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Spanner::V1::CreateSessionRequest.new

# Call the create_session method.
result = client.create_session request

# The returned object is of type Google::Cloud::Spanner::V1::Session.
p result

Overloads:

  • #create_session(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::Session

    Pass arguments to create_session via a request object, either of type CreateSessionRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Spanner::V1::CreateSessionRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #create_session(database: nil, session: nil) ⇒ ::Google::Cloud::Spanner::V1::Session

    Pass arguments to create_session via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • database (::String) (defaults to: nil)

      Required. The database in which the new session is created.

    • session (::Google::Cloud::Spanner::V1::Session, ::Hash) (defaults to: nil)

      Required. The session to create.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 301

def create_session request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::CreateSessionRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.create_session..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Spanner::V1::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.database
    header_params["database"] = request.database
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.create_session.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.create_session.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @spanner_stub.call_rpc :create_session, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#delete_session(request, options = nil) ⇒ ::Google::Protobuf::Empty #delete_session(name: nil) ⇒ ::Google::Protobuf::Empty

Ends a session, releasing server resources associated with it. This will asynchronously trigger cancellation of any operations that are running with this session.

Examples:

Basic example

require "google/cloud/spanner/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Spanner::V1::Spanner::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Spanner::V1::DeleteSessionRequest.new

# Call the delete_session method.
result = client.delete_session request

# The returned object is of type Google::Protobuf::Empty.
p result

Overloads:

  • #delete_session(request, options = nil) ⇒ ::Google::Protobuf::Empty

    Pass arguments to delete_session via a request object, either of type DeleteSessionRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Spanner::V1::DeleteSessionRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #delete_session(name: nil) ⇒ ::Google::Protobuf::Empty

    Pass arguments to delete_session via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • name (::String) (defaults to: nil)

      Required. The name of the session to delete.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 681

def delete_session request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::DeleteSessionRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.delete_session..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Spanner::V1::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.name
    header_params["name"] = request.name
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.delete_session.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.delete_session.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @spanner_stub.call_rpc :delete_session, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#execute_batch_dml(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::ExecuteBatchDmlResponse #execute_batch_dml(session: nil, transaction: nil, statements: nil, seqno: nil, request_options: nil) ⇒ ::Google::Cloud::Spanner::V1::ExecuteBatchDmlResponse

Executes a batch of SQL DML statements. This method allows many statements to be run with lower latency than submitting them sequentially with ExecuteSql.

Statements are executed in sequential order. A request can succeed even if a statement fails. The ExecuteBatchDmlResponse.status field in the response provides information about the statement that failed. Clients must inspect this field to determine whether an error occurred.

Execution stops after the first failed statement; the remaining statements are not executed.

Examples:

Basic example

require "google/cloud/spanner/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Spanner::V1::Spanner::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Spanner::V1::ExecuteBatchDmlRequest.new

# Call the execute_batch_dml method.
result = client.execute_batch_dml request

# The returned object is of type Google::Cloud::Spanner::V1::ExecuteBatchDmlResponse.
p result

Overloads:

  • #execute_batch_dml(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::ExecuteBatchDmlResponse

    Pass arguments to execute_batch_dml via a request object, either of type ExecuteBatchDmlRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Spanner::V1::ExecuteBatchDmlRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #execute_batch_dml(session: nil, transaction: nil, statements: nil, seqno: nil, request_options: nil) ⇒ ::Google::Cloud::Spanner::V1::ExecuteBatchDmlResponse

    Pass arguments to execute_batch_dml via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • session (::String) (defaults to: nil)

      Required. The session in which the DML statements should be performed.

    • transaction (::Google::Cloud::Spanner::V1::TransactionSelector, ::Hash) (defaults to: nil)

      Required. The transaction to use. Must be a read-write transaction.

      To protect against replays, single-use transactions are not supported. The caller must either supply an existing transaction ID or begin a new transaction.

    • statements (::Array<::Google::Cloud::Spanner::V1::ExecuteBatchDmlRequest::Statement, ::Hash>) (defaults to: nil)

      Required. The list of statements to execute in this batch. Statements are executed serially, such that the effects of statement i are visible to statement i+1. Each statement must be a DML statement. Execution stops at the first failed statement; the remaining statements are not executed.

      Callers must provide at least one statement.

    • seqno (::Integer) (defaults to: nil)

      Required. A per-transaction sequence number used to identify this request. This field makes each request idempotent such that if the request is received multiple times, at most one will succeed.

      The sequence number must be monotonically increasing within the transaction. If a request arrives for the first time with an out-of-order sequence number, the transaction may be aborted. Replays of previously handled requests will yield the same response as the first execution.

    • request_options (::Google::Cloud::Spanner::V1::RequestOptions, ::Hash) (defaults to: nil)

      Common options for this request.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 1148

def execute_batch_dml request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::ExecuteBatchDmlRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.execute_batch_dml..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Spanner::V1::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.session
    header_params["session"] = request.session
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.execute_batch_dml.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.execute_batch_dml.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @spanner_stub.call_rpc :execute_batch_dml, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#execute_sql(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::ResultSet #execute_sql(session: nil, transaction: nil, sql: nil, params: nil, param_types: nil, resume_token: nil, query_mode: nil, partition_token: nil, seqno: nil, query_options: nil, request_options: nil, directed_read_options: nil, data_boost_enabled: nil) ⇒ ::Google::Cloud::Spanner::V1::ResultSet

Executes an SQL statement, returning all results 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.

Operations 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.

Examples:

Basic example

require "google/cloud/spanner/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Spanner::V1::Spanner::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Spanner::V1::ExecuteSqlRequest.new

# Call the execute_sql method.
result = client.execute_sql request

# The returned object is of type Google::Cloud::Spanner::V1::ResultSet.
p result

Overloads:

  • #execute_sql(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::ResultSet

    Pass arguments to execute_sql via a request object, either of type ExecuteSqlRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Spanner::V1::ExecuteSqlRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #execute_sql(session: nil, transaction: nil, sql: nil, params: nil, param_types: nil, resume_token: nil, query_mode: nil, partition_token: nil, seqno: nil, query_options: nil, request_options: nil, directed_read_options: nil, data_boost_enabled: nil) ⇒ ::Google::Cloud::Spanner::V1::ResultSet

    Pass arguments to execute_sql via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • session (::String) (defaults to: nil)

      Required. The session in which the SQL query should be performed.

    • transaction (::Google::Cloud::Spanner::V1::TransactionSelector, ::Hash) (defaults to: nil)

      The transaction to use.

      For queries, if none is provided, the default is a temporary read-only transaction with strong concurrency.

      Standard DML statements require a read-write transaction. To protect against replays, single-use transactions are not supported. The caller must either supply an existing transaction ID or begin a new transaction.

      Partitioned DML requires an existing Partitioned DML transaction ID.

    • sql (::String) (defaults to: nil)

      Required. The SQL string.

    • params (::Google::Protobuf::Struct, ::Hash) (defaults to: nil)

      Parameter names and values that bind to placeholders in the SQL string.

      A parameter placeholder consists of the @ character followed by the parameter name (for example, @firstName). Parameter names must conform to the naming requirements of identifiers as specified at https://cloud.google.com/spanner/docs/lexical#identifiers.

      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 a SQL statement with unbound parameters.

    • param_types (::Hash{::String => ::Google::Cloud::Spanner::V1::Type, ::Hash}) (defaults to: nil)

      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 statement parameters. See the definition of Type for more information about SQL types.

    • resume_token (::String) (defaults to: nil)

      If this request is resuming a previously interrupted SQL statement execution, resume_token should be copied from the last PartialResultSet yielded before the interruption. Doing this enables the new SQL statement 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::ExecuteSqlRequest::QueryMode) (defaults to: nil)

      Used to control the amount of debugging information returned in ResultSetStats. If partition_token is set, query_mode can only be set to QueryMode.NORMAL.

    • partition_token (::String) (defaults to: nil)

      If present, results will be restricted to the specified partition previously created using PartitionQuery(). There must be an exact match for the values of fields common to this message and the PartitionQueryRequest message used to create this partition_token.

    • seqno (::Integer) (defaults to: nil)

      A per-transaction sequence number used to identify this request. This field makes each request idempotent such that if the request is received multiple times, at most one will succeed.

      The sequence number must be monotonically increasing within the transaction. If a request arrives for the first time with an out-of-order sequence number, the transaction may be aborted. Replays of previously handled requests will yield the same response as the first execution.

      Required for DML statements. Ignored for queries.

    • query_options (::Google::Cloud::Spanner::V1::ExecuteSqlRequest::QueryOptions, ::Hash) (defaults to: nil)

      Query optimizer configuration to use for the given query.

    • request_options (::Google::Cloud::Spanner::V1::RequestOptions, ::Hash) (defaults to: nil)

      Common options for this request.

    • directed_read_options (::Google::Cloud::Spanner::V1::DirectedReadOptions, ::Hash) (defaults to: nil)

      Directed read options for this request.

    • data_boost_enabled (::Boolean) (defaults to: nil)

      If this is for a partitioned query and this field is set to true, the request is executed with Spanner Data Boost independent compute resources.

      If the field is set to true but the request does not set partition_token, the API returns an INVALID_ARGUMENT error.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 857

def execute_sql request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::ExecuteSqlRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.execute_sql..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Spanner::V1::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.session
    header_params["session"] = request.session
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.execute_sql.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.execute_sql.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @spanner_stub.call_rpc :execute_sql, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#execute_streaming_sql(request, options = nil) ⇒ ::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet> #execute_streaming_sql(session: nil, transaction: nil, sql: nil, params: nil, param_types: nil, resume_token: nil, query_mode: nil, partition_token: nil, seqno: nil, query_options: nil, request_options: nil, directed_read_options: nil, data_boost_enabled: nil) ⇒ ::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet>

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.

Examples:

Basic example

require "google/cloud/spanner/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Spanner::V1::Spanner::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Spanner::V1::ExecuteSqlRequest.new

# Call the execute_streaming_sql method to start streaming.
output = client.execute_streaming_sql request

# The returned object is a streamed enumerable yielding elements of type
# ::Google::Cloud::Spanner::V1::PartialResultSet
output.each do |current_response|
  p current_response
end

Overloads:

  • #execute_streaming_sql(request, options = nil) ⇒ ::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet>

    Pass arguments to execute_streaming_sql via a request object, either of type ExecuteSqlRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Spanner::V1::ExecuteSqlRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #execute_streaming_sql(session: nil, transaction: nil, sql: nil, params: nil, param_types: nil, resume_token: nil, query_mode: nil, partition_token: nil, seqno: nil, query_options: nil, request_options: nil, directed_read_options: nil, data_boost_enabled: nil) ⇒ ::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet>

    Pass arguments to execute_streaming_sql via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • session (::String) (defaults to: nil)

      Required. The session in which the SQL query should be performed.

    • transaction (::Google::Cloud::Spanner::V1::TransactionSelector, ::Hash) (defaults to: nil)

      The transaction to use.

      For queries, if none is provided, the default is a temporary read-only transaction with strong concurrency.

      Standard DML statements require a read-write transaction. To protect against replays, single-use transactions are not supported. The caller must either supply an existing transaction ID or begin a new transaction.

      Partitioned DML requires an existing Partitioned DML transaction ID.

    • sql (::String) (defaults to: nil)

      Required. The SQL string.

    • params (::Google::Protobuf::Struct, ::Hash) (defaults to: nil)

      Parameter names and values that bind to placeholders in the SQL string.

      A parameter placeholder consists of the @ character followed by the parameter name (for example, @firstName). Parameter names must conform to the naming requirements of identifiers as specified at https://cloud.google.com/spanner/docs/lexical#identifiers.

      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 a SQL statement with unbound parameters.

    • param_types (::Hash{::String => ::Google::Cloud::Spanner::V1::Type, ::Hash}) (defaults to: nil)

      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 statement parameters. See the definition of Type for more information about SQL types.

    • resume_token (::String) (defaults to: nil)

      If this request is resuming a previously interrupted SQL statement execution, resume_token should be copied from the last PartialResultSet yielded before the interruption. Doing this enables the new SQL statement 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::ExecuteSqlRequest::QueryMode) (defaults to: nil)

      Used to control the amount of debugging information returned in ResultSetStats. If partition_token is set, query_mode can only be set to QueryMode.NORMAL.

    • partition_token (::String) (defaults to: nil)

      If present, results will be restricted to the specified partition previously created using PartitionQuery(). There must be an exact match for the values of fields common to this message and the PartitionQueryRequest message used to create this partition_token.

    • seqno (::Integer) (defaults to: nil)

      A per-transaction sequence number used to identify this request. This field makes each request idempotent such that if the request is received multiple times, at most one will succeed.

      The sequence number must be monotonically increasing within the transaction. If a request arrives for the first time with an out-of-order sequence number, the transaction may be aborted. Replays of previously handled requests will yield the same response as the first execution.

      Required for DML statements. Ignored for queries.

    • query_options (::Google::Cloud::Spanner::V1::ExecuteSqlRequest::QueryOptions, ::Hash) (defaults to: nil)

      Query optimizer configuration to use for the given query.

    • request_options (::Google::Cloud::Spanner::V1::RequestOptions, ::Hash) (defaults to: nil)

      Common options for this request.

    • directed_read_options (::Google::Cloud::Spanner::V1::DirectedReadOptions, ::Hash) (defaults to: nil)

      Directed read options for this request.

    • data_boost_enabled (::Boolean) (defaults to: nil)

      If this is for a partitioned query and this field is set to true, the request is executed with Spanner Data Boost independent compute resources.

      If the field is set to true but the request does not set partition_token, the API returns an INVALID_ARGUMENT error.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 1028

def execute_streaming_sql request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::ExecuteSqlRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.execute_streaming_sql..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Spanner::V1::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.session
    header_params["session"] = request.session
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.execute_streaming_sql.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.execute_streaming_sql.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @spanner_stub.call_rpc :execute_streaming_sql, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#get_session(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::Session #get_session(name: nil) ⇒ ::Google::Cloud::Spanner::V1::Session

Gets a session. Returns NOT_FOUND if the session does not exist. This is mainly useful for determining whether a session is still alive.

Examples:

Basic example

require "google/cloud/spanner/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Spanner::V1::Spanner::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Spanner::V1::GetSessionRequest.new

# Call the get_session method.
result = client.get_session request

# The returned object is of type Google::Cloud::Spanner::V1::Session.
p result

Overloads:

  • #get_session(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::Session

    Pass arguments to get_session via a request object, either of type GetSessionRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Spanner::V1::GetSessionRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #get_session(name: nil) ⇒ ::Google::Cloud::Spanner::V1::Session

    Pass arguments to get_session via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • name (::String) (defaults to: nil)

      Required. The name of the session to retrieve.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 485

def get_session request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::GetSessionRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.get_session..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Spanner::V1::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.name
    header_params["name"] = request.name
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.get_session.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.get_session.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @spanner_stub.call_rpc :get_session, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#list_sessions(request, options = nil) ⇒ ::Gapic::PagedEnumerable<::Google::Cloud::Spanner::V1::Session> #list_sessions(database: nil, page_size: nil, page_token: nil, filter: nil) ⇒ ::Gapic::PagedEnumerable<::Google::Cloud::Spanner::V1::Session>

Lists all sessions in a given database.

Examples:

Basic example

require "google/cloud/spanner/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Spanner::V1::Spanner::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Spanner::V1::ListSessionsRequest.new

# Call the list_sessions method.
result = client.list_sessions request

# The returned object is of type Gapic::PagedEnumerable. You can iterate
# over elements, and API calls will be issued to fetch pages as needed.
result.each do |item|
  # Each element is of type ::Google::Cloud::Spanner::V1::Session.
  p item
end

Overloads:

  • #list_sessions(request, options = nil) ⇒ ::Gapic::PagedEnumerable<::Google::Cloud::Spanner::V1::Session>

    Pass arguments to list_sessions via a request object, either of type ListSessionsRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Spanner::V1::ListSessionsRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #list_sessions(database: nil, page_size: nil, page_token: nil, filter: nil) ⇒ ::Gapic::PagedEnumerable<::Google::Cloud::Spanner::V1::Session>

    Pass arguments to list_sessions via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • database (::String) (defaults to: nil)

      Required. The database in which to list sessions.

    • page_size (::Integer) (defaults to: nil)

      Number of sessions to be returned in the response. If 0 or less, defaults to the server's maximum allowed page size.

    • page_token (::String) (defaults to: nil)

      If non-empty, page_token should contain a next_page_token from a previous ListSessionsResponse.

    • filter (::String) (defaults to: nil)

      An expression for filtering the results of the request. Filter rules are case insensitive. The fields eligible for filtering are:

      • labels.key where key is the name of a label

      Some examples of using filters are:

      • labels.env:* --> The session has the label "env".
      • labels.env:dev --> The session has the label "env" and the value of the label contains the string "dev".

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 593

def list_sessions request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::ListSessionsRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.list_sessions..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Spanner::V1::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.database
    header_params["database"] = request.database
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.list_sessions.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.list_sessions.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @spanner_stub.call_rpc :list_sessions, request, options: options do |response, operation|
    response = ::Gapic::PagedEnumerable.new @spanner_stub, :list_sessions, request, response, operation, options
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#partition_query(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::PartitionResponse #partition_query(session: nil, transaction: nil, sql: nil, params: nil, param_types: nil, partition_options: nil) ⇒ ::Google::Cloud::Spanner::V1::PartitionResponse

Creates a set of partition tokens that can be used to execute a query operation in parallel. Each of the returned partition tokens can be used by ExecuteStreamingSql to specify a subset of the query result to read. The same session and read-only transaction must be used by the PartitionQueryRequest used to create the partition tokens and the ExecuteSqlRequests that use the partition tokens.

Partition tokens become invalid when the session used to create them is deleted, is idle for too long, begins a new transaction, or becomes too old. When any of these happen, it is not possible to resume the query, and the whole operation must be restarted from the beginning.

Examples:

Basic example

require "google/cloud/spanner/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Spanner::V1::Spanner::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Spanner::V1::PartitionQueryRequest.new

# Call the partition_query method.
result = client.partition_query request

# The returned object is of type Google::Cloud::Spanner::V1::PartitionResponse.
p result

Overloads:

  • #partition_query(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::PartitionResponse

    Pass arguments to partition_query via a request object, either of type PartitionQueryRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Spanner::V1::PartitionQueryRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #partition_query(session: nil, transaction: nil, sql: nil, params: nil, param_types: nil, partition_options: nil) ⇒ ::Google::Cloud::Spanner::V1::PartitionResponse

    Pass arguments to partition_query via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • session (::String) (defaults to: nil)

      Required. The session used to create the partitions.

    • transaction (::Google::Cloud::Spanner::V1::TransactionSelector, ::Hash) (defaults to: nil)

      Read only snapshot transactions are supported, read/write and single use transactions are not.

    • sql (::String) (defaults to: nil)

      Required. The query request to generate partitions for. The request will fail if the query is not root partitionable. For a query to be root partitionable, it needs to satisfy a few conditions. For example, if the query execution plan contains a distributed union operator, then it must be the first operator in the plan. For more information about other conditions, see Read data in parallel.

      The query request must not contain DML commands, such as INSERT, UPDATE, or DELETE. Use ExecuteStreamingSql with a PartitionedDml transaction for large, partition-friendly DML operations.

    • params (::Google::Protobuf::Struct, ::Hash) (defaults to: nil)

      Parameter names and values that bind to placeholders in the SQL string.

      A parameter placeholder consists of the @ character followed by the parameter name (for example, @firstName). Parameter names can contain 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 a SQL statement with unbound parameters.

    • param_types (::Hash{::String => ::Google::Cloud::Spanner::V1::Type, ::Hash}) (defaults to: nil)

      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.

    • partition_options (::Google::Cloud::Spanner::V1::PartitionOptions, ::Hash) (defaults to: nil)

      Additional options that affect how many partitions are created.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 1909

def partition_query request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::PartitionQueryRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.partition_query..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Spanner::V1::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.session
    header_params["session"] = request.session
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.partition_query.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.partition_query.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @spanner_stub.call_rpc :partition_query, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#partition_read(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::PartitionResponse #partition_read(session: nil, transaction: nil, table: nil, index: nil, columns: nil, key_set: nil, partition_options: nil) ⇒ ::Google::Cloud::Spanner::V1::PartitionResponse

Creates a set of partition tokens that can be used to execute a read operation in parallel. Each of the returned partition tokens can be used by StreamingRead to specify a subset of the read result to read. The same session and read-only transaction must be used by the PartitionReadRequest used to create the partition tokens and the ReadRequests that use the partition tokens. There are no ordering guarantees on rows returned among the returned partition tokens, or even within each individual StreamingRead call issued with a partition_token.

Partition tokens become invalid when the session used to create them is deleted, is idle for too long, begins a new transaction, or becomes too old. When any of these happen, it is not possible to resume the read, and the whole operation must be restarted from the beginning.

Examples:

Basic example

require "google/cloud/spanner/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Spanner::V1::Spanner::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Spanner::V1::PartitionReadRequest.new

# Call the partition_read method.
result = client.partition_read request

# The returned object is of type Google::Cloud::Spanner::V1::PartitionResponse.
p result

Overloads:

  • #partition_read(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::PartitionResponse

    Pass arguments to partition_read via a request object, either of type PartitionReadRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Spanner::V1::PartitionReadRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #partition_read(session: nil, transaction: nil, table: nil, index: nil, columns: nil, key_set: nil, partition_options: nil) ⇒ ::Google::Cloud::Spanner::V1::PartitionResponse

    Pass arguments to partition_read via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • session (::String) (defaults to: nil)

      Required. The session used to create the partitions.

    • transaction (::Google::Cloud::Spanner::V1::TransactionSelector, ::Hash) (defaults to: nil)

      Read only snapshot transactions are supported, read/write and single use transactions are not.

    • table (::String) (defaults to: nil)

      Required. The name of the table in the database to be read.

    • index (::String) (defaults to: nil)

      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.

    • columns (::Array<::String>) (defaults to: nil)

      The columns of table to be returned for each row matching this request.

    • key_set (::Google::Cloud::Spanner::V1::KeySet, ::Hash) (defaults to: nil)

      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.

      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.

    • partition_options (::Google::Cloud::Spanner::V1::PartitionOptions, ::Hash) (defaults to: nil)

      Additional options that affect how many partitions are created.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 2035

def partition_read request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::PartitionReadRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.partition_read..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Spanner::V1::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.session
    header_params["session"] = request.session
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.partition_read.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.partition_read.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @spanner_stub.call_rpc :partition_read, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#read(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::ResultSet #read(session: nil, transaction: nil, table: nil, index: nil, columns: nil, key_set: nil, limit: nil, resume_token: nil, partition_token: nil, request_options: nil, directed_read_options: nil, data_boost_enabled: nil) ⇒ ::Google::Cloud::Spanner::V1::ResultSet

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.

Examples:

Basic example

require "google/cloud/spanner/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Spanner::V1::Spanner::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Spanner::V1::ReadRequest.new

# Call the read method.
result = client.read request

# The returned object is of type Google::Cloud::Spanner::V1::ResultSet.
p result

Overloads:

  • #read(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::ResultSet

    Pass arguments to read via a request object, either of type ReadRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Spanner::V1::ReadRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #read(session: nil, transaction: nil, table: nil, index: nil, columns: nil, key_set: nil, limit: nil, resume_token: nil, partition_token: nil, request_options: nil, directed_read_options: nil, data_boost_enabled: nil) ⇒ ::Google::Cloud::Spanner::V1::ResultSet

    Pass arguments to read via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • session (::String) (defaults to: nil)

      Required. The session in which the read should be performed.

    • transaction (::Google::Cloud::Spanner::V1::TransactionSelector, ::Hash) (defaults to: nil)

      The transaction to use. If none is provided, the default is a temporary read-only transaction with strong concurrency.

    • table (::String) (defaults to: nil)

      Required. The name of the table in the database to be read.

    • index (::String) (defaults to: nil)

      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.

    • columns (::Array<::String>) (defaults to: nil)

      Required. The columns of table to be returned for each row matching this request.

    • key_set (::Google::Cloud::Spanner::V1::KeySet, ::Hash) (defaults to: nil)

      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.

      If the partition_token field is empty, rows are yielded in table primary key order (if index is empty) or index key order (if index is non-empty). If the partition_token field is not empty, rows will be yielded in an unspecified order.

      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 (::Integer) (defaults to: nil)

      If greater than zero, only the first limit rows are yielded. If limit is zero, the default is no limit. A limit cannot be specified if partition_token is set.

    • resume_token (::String) (defaults to: nil)

      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.

    • partition_token (::String) (defaults to: nil)

      If present, results will be restricted to the specified partition previously created using PartitionRead(). There must be an exact match for the values of fields common to this message and the PartitionReadRequest message used to create this partition_token.

    • request_options (::Google::Cloud::Spanner::V1::RequestOptions, ::Hash) (defaults to: nil)

      Common options for this request.

    • directed_read_options (::Google::Cloud::Spanner::V1::DirectedReadOptions, ::Hash) (defaults to: nil)

      Directed read options for this request.

    • data_boost_enabled (::Boolean) (defaults to: nil)

      If this is for a partitioned read and this field is set to true, the request is executed with Spanner Data Boost independent compute resources.

      If the field is set to true but the request does not set partition_token, the API returns an INVALID_ARGUMENT error.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 1304

def read request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::ReadRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.read..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Spanner::V1::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.session
    header_params["session"] = request.session
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.read.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.read.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @spanner_stub.call_rpc :read, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#rollback(request, options = nil) ⇒ ::Google::Protobuf::Empty #rollback(session: nil, transaction_id: nil) ⇒ ::Google::Protobuf::Empty

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.

Examples:

Basic example

require "google/cloud/spanner/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Spanner::V1::Spanner::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Spanner::V1::RollbackRequest.new

# Call the rollback method.
result = client.rollback request

# The returned object is of type Google::Protobuf::Empty.
p result

Overloads:

  • #rollback(request, options = nil) ⇒ ::Google::Protobuf::Empty

    Pass arguments to rollback via a request object, either of type RollbackRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Spanner::V1::RollbackRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #rollback(session: nil, transaction_id: nil) ⇒ ::Google::Protobuf::Empty

    Pass arguments to rollback via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • session (::String) (defaults to: nil)

      Required. The session in which the transaction to roll back is running.

    • transaction_id (::String) (defaults to: nil)

      Required. The transaction to roll back.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 1772

def rollback request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::RollbackRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.rollback..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Spanner::V1::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.session
    header_params["session"] = request.session
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.rollback.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.rollback.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @spanner_stub.call_rpc :rollback, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#streaming_read(request, options = nil) ⇒ ::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet> #streaming_read(session: nil, transaction: nil, table: nil, index: nil, columns: nil, key_set: nil, limit: nil, resume_token: nil, partition_token: nil, request_options: nil, directed_read_options: nil, data_boost_enabled: nil) ⇒ ::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet>

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.

Examples:

Basic example

require "google/cloud/spanner/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Spanner::V1::Spanner::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Spanner::V1::ReadRequest.new

# Call the streaming_read method to start streaming.
output = client.streaming_read request

# The returned object is a streamed enumerable yielding elements of type
# ::Google::Cloud::Spanner::V1::PartialResultSet
output.each do |current_response|
  p current_response
end

Overloads:

  • #streaming_read(request, options = nil) ⇒ ::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet>

    Pass arguments to streaming_read via a request object, either of type ReadRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Spanner::V1::ReadRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #streaming_read(session: nil, transaction: nil, table: nil, index: nil, columns: nil, key_set: nil, limit: nil, resume_token: nil, partition_token: nil, request_options: nil, directed_read_options: nil, data_boost_enabled: nil) ⇒ ::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet>

    Pass arguments to streaming_read via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • session (::String) (defaults to: nil)

      Required. The session in which the read should be performed.

    • transaction (::Google::Cloud::Spanner::V1::TransactionSelector, ::Hash) (defaults to: nil)

      The transaction to use. If none is provided, the default is a temporary read-only transaction with strong concurrency.

    • table (::String) (defaults to: nil)

      Required. The name of the table in the database to be read.

    • index (::String) (defaults to: nil)

      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.

    • columns (::Array<::String>) (defaults to: nil)

      Required. The columns of table to be returned for each row matching this request.

    • key_set (::Google::Cloud::Spanner::V1::KeySet, ::Hash) (defaults to: nil)

      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.

      If the partition_token field is empty, rows are yielded in table primary key order (if index is empty) or index key order (if index is non-empty). If the partition_token field is not empty, rows will be yielded in an unspecified order.

      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 (::Integer) (defaults to: nil)

      If greater than zero, only the first limit rows are yielded. If limit is zero, the default is no limit. A limit cannot be specified if partition_token is set.

    • resume_token (::String) (defaults to: nil)

      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.

    • partition_token (::String) (defaults to: nil)

      If present, results will be restricted to the specified partition previously created using PartitionRead(). There must be an exact match for the values of fields common to this message and the PartitionReadRequest message used to create this partition_token.

    • request_options (::Google::Cloud::Spanner::V1::RequestOptions, ::Hash) (defaults to: nil)

      Common options for this request.

    • directed_read_options (::Google::Cloud::Spanner::V1::DirectedReadOptions, ::Hash) (defaults to: nil)

      Directed read options for this request.

    • data_boost_enabled (::Boolean) (defaults to: nil)

      If this is for a partitioned read and this field is set to true, the request is executed with Spanner Data Boost independent compute resources.

      If the field is set to true but the request does not set partition_token, the API returns an INVALID_ARGUMENT error.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 1454

def streaming_read request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::ReadRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.streaming_read..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Spanner::V1::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.session
    header_params["session"] = request.session
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.streaming_read.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.streaming_read.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @spanner_stub.call_rpc :streaming_read, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#universe_domainString

The effective universe domain

Returns:

  • (String)


175
176
177
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 175

def universe_domain
  @spanner_stub.universe_domain
end