class Google::Cloud::Spanner::V1::Spanner::Client
Client
for the Spanner
service.
The Cloud
Spanner
API can be used to manage sessions and execute transactions on data stored in Cloud
Spanner
databases.
Attributes
@private
Public Class Methods
Configure the Spanner
Client
class.
See {::Google::Cloud::Spanner::V1::Spanner::Client::Configuration} for a description of the configuration fields.
@example
# Modify the configuration for all Spanner clients ::Google::Cloud::Spanner::V1::Spanner::Client.configure do |config| config.timeout = 10.0 end
@yield [config] Configure the Client
client. @yieldparam config [Client::Configuration]
@return [Client::Configuration]
# File lib/google/cloud/spanner/v1/spanner/client.rb, line 59 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] } 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] } 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] } 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] } 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] } 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] } 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] } 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] } 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] } 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] } 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] } 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] } 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] } default_config end yield @configure if block_given? @configure end
Create a new Spanner
client object.
@example
# 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
@yield [config] Configure the Spanner
client. @yieldparam config [Client::Configuration]
# File lib/google/cloud/spanner/v1/spanner/client.rb, line 181 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 == Client.configure.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, channel_args: @config.channel_args, interceptors: @config.interceptors ) end
Public Instance Methods
Creates multiple new sessions.
This API can be used to initialize a session cache on the clients. See goo.gl/TgSFN2 for best practices on session cache management.
@overload batch_create_sessions
(request, options = nil)
Pass arguments to `batch_create_sessions` via a request object, either of type {::Google::Cloud::Spanner::V1::BatchCreateSessionsRequest} or an equivalent Hash. @param 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. @param options [::Gapic::CallOptions, ::Hash] Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
@overload batch_create_sessions
(database: nil, session_template: nil, session_count: nil)
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). @param database [::String] Required. The database in which the new sessions are created. @param session_template [::Google::Cloud::Spanner::V1::Session, ::Hash] Parameters to be applied to each created session. @param session_count [::Integer] 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 {::Google::Cloud::Spanner::V1::BatchCreateSessionsRequest#session_count session_count} as necessary).
@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Cloud::Spanner::V1::BatchCreateSessionsResponse] @yieldparam operation [::GRPC::ActiveCall::Operation]
@return [::Google::Cloud::Spanner::V1::BatchCreateSessionsResponse]
@raise [::Google::Cloud::Error] if the RPC is aborted.
# File lib/google/cloud/spanner/v1/spanner/client.rb, line 347 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 metadata = @config.rpcs.batch_create_sessions.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"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 metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = { "database" => request.database } request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.batch_create_sessions.timeout, metadata: metadata, retry_policy: @config.rpcs.batch_create_sessions.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, 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
Begins a new transaction. This step can often be skipped: {::Google::Cloud::Spanner::V1::Spanner::Client#read Read}, {::Google::Cloud::Spanner::V1::Spanner::Client#execute_sql ExecuteSql} and {::Google::Cloud::Spanner::V1::Spanner::Client#commit Commit} can begin a new transaction as a side-effect.
@overload begin_transaction
(request, options = nil)
Pass arguments to `begin_transaction` via a request object, either of type {::Google::Cloud::Spanner::V1::BeginTransactionRequest} or an equivalent Hash. @param 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. @param options [::Gapic::CallOptions, ::Hash] Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
@overload begin_transaction
(session: nil, options: nil, request_options: nil)
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). @param session [::String] Required. The session in which the transaction runs. @param options [::Google::Cloud::Spanner::V1::TransactionOptions, ::Hash] Required. Options for the new transaction. @param request_options [::Google::Cloud::Spanner::V1::RequestOptions, ::Hash] 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.
@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Cloud::Spanner::V1::Transaction] @yieldparam operation [::GRPC::ActiveCall::Operation]
@return [::Google::Cloud::Spanner::V1::Transaction]
@raise [::Google::Cloud::Error] if the RPC is aborted.
# File lib/google/cloud/spanner/v1/spanner/client.rb, line 1277 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 metadata = @config.rpcs.begin_transaction.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"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 metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = { "session" => request.session } request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.begin_transaction.timeout, metadata: metadata, retry_policy: @config.rpcs.begin_transaction.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, 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
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.
@overload commit(request, options = nil)
Pass arguments to `commit` via a request object, either of type {::Google::Cloud::Spanner::V1::CommitRequest} or an equivalent Hash. @param 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. @param options [::Gapic::CallOptions, ::Hash] Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
@overload commit(session: nil, transaction_id: nil, single_use_transaction: nil, mutations: nil, return_commit_stats: nil, request_options: nil)
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). @param session [::String] Required. The session in which the transaction to be committed is running. @param transaction_id [::String] Commit a previously-started transaction. @param single_use_transaction [::Google::Cloud::Spanner::V1::TransactionOptions, ::Hash] 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 {::Google::Cloud::Spanner::V1::Spanner::Client#begin_transaction BeginTransaction} and {::Google::Cloud::Spanner::V1::Spanner::Client#commit Commit} instead. @param mutations [::Array<::Google::Cloud::Spanner::V1::Mutation, ::Hash>] The mutations to be executed when this transaction commits. All mutations are applied atomically, in the order they appear in this list. @param return_commit_stats [::Boolean] If `true`, then statistics related to the transaction will be included in the {::Google::Cloud::Spanner::V1::CommitResponse#commit_stats CommitResponse}. Default value is `false`. @param request_options [::Google::Cloud::Spanner::V1::RequestOptions, ::Hash] Common options for this request.
@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Cloud::Spanner::V1::CommitResponse] @yieldparam operation [::GRPC::ActiveCall::Operation]
@return [::Google::Cloud::Spanner::V1::CommitResponse]
@raise [::Google::Cloud::Error] if the RPC is aborted.
# File lib/google/cloud/spanner/v1/spanner/client.rb, line 1380 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 metadata = @config.rpcs.commit.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"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 metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = { "session" => request.session } request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.commit.timeout, metadata: metadata, retry_policy: @config.rpcs.commit.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, 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 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 {Client.configure}.
See {::Google::Cloud::Spanner::V1::Spanner::Client::Configuration} for a description of the configuration fields.
@yield [config] Configure the Client
client. @yieldparam config [Client::Configuration]
@return [Client::Configuration]
# File lib/google/cloud/spanner/v1/spanner/client.rb, line 160 def configure yield @config if block_given? @config end
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”`.
@overload create_session
(request, options = nil)
Pass arguments to `create_session` via a request object, either of type {::Google::Cloud::Spanner::V1::CreateSessionRequest} or an equivalent Hash. @param 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. @param options [::Gapic::CallOptions, ::Hash] Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
@overload create_session
(database: nil, session: nil)
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). @param database [::String] Required. The database in which the new session is created. @param session [::Google::Cloud::Spanner::V1::Session, ::Hash] The session to create.
@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Cloud::Spanner::V1::Session] @yieldparam operation [::GRPC::ActiveCall::Operation]
@return [::Google::Cloud::Spanner::V1::Session]
@raise [::Google::Cloud::Error] if the RPC is aborted.
# File lib/google/cloud/spanner/v1/spanner/client.rb, line 268 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 metadata = @config.rpcs.create_session.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"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 metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = { "database" => request.database } request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.create_session.timeout, metadata: metadata, retry_policy: @config.rpcs.create_session.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, 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
Ends a session, releasing server resources associated with it. This will asynchronously trigger cancellation of any operations that are running with this session.
@overload delete_session
(request, options = nil)
Pass arguments to `delete_session` via a request object, either of type {::Google::Cloud::Spanner::V1::DeleteSessionRequest} or an equivalent Hash. @param 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. @param options [::Gapic::CallOptions, ::Hash] Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
@overload delete_session
(name: nil)
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). @param name [::String] Required. The name of the session to delete.
@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Protobuf::Empty] @yieldparam operation [::GRPC::ActiveCall::Operation]
@return [::Google::Protobuf::Empty]
@raise [::Google::Cloud::Error] if the RPC is aborted.
# File lib/google/cloud/spanner/v1/spanner/client.rb, line 574 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 metadata = @config.rpcs.delete_session.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"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 metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = { "name" => request.name } request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_session.timeout, metadata: metadata, retry_policy: @config.rpcs.delete_session.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, 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
Executes a batch of SQL DML statements. This method allows many statements to be run with lower latency than submitting them sequentially with {::Google::Cloud::Spanner::V1::Spanner::Client#execute_sql ExecuteSql}.
Statements are executed in sequential order. A request can succeed even if a statement fails. The {::Google::Cloud::Spanner::V1::ExecuteBatchDmlResponse#status 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.
@overload execute_batch_dml
(request, options = nil)
Pass arguments to `execute_batch_dml` via a request object, either of type {::Google::Cloud::Spanner::V1::ExecuteBatchDmlRequest} or an equivalent Hash. @param 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. @param options [::Gapic::CallOptions, ::Hash] Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
@overload execute_batch_dml
(session: nil, transaction: nil, statements: nil, seqno: nil, request_options: nil)
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). @param session [::String] Required. The session in which the DML statements should be performed. @param transaction [::Google::Cloud::Spanner::V1::TransactionSelector, ::Hash] 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. @param statements [::Array<::Google::Cloud::Spanner::V1::ExecuteBatchDmlRequest::Statement, ::Hash>] 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. @param seqno [::Integer] 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. @param request_options [::Google::Cloud::Spanner::V1::RequestOptions, ::Hash] Common options for this request.
@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Cloud::Spanner::V1::ExecuteBatchDmlResponse] @yieldparam operation [::GRPC::ActiveCall::Operation]
@return [::Google::Cloud::Spanner::V1::ExecuteBatchDmlResponse]
@raise [::Google::Cloud::Error] if the RPC is aborted.
# File lib/google/cloud/spanner/v1/spanner/client.rb, line 960 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 metadata = @config.rpcs.execute_batch_dml.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"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 metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = { "session" => request.session } request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.execute_batch_dml.timeout, metadata: metadata, retry_policy: @config.rpcs.execute_batch_dml.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, 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
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 {::Google::Cloud::Spanner::V1::Transaction Transaction} for more details.
Larger result sets can be fetched in streaming fashion by calling {::Google::Cloud::Spanner::V1::Spanner::Client#execute_streaming_sql ExecuteStreamingSql} instead.
@overload execute_sql
(request, options = nil)
Pass arguments to `execute_sql` via a request object, either of type {::Google::Cloud::Spanner::V1::ExecuteSqlRequest} or an equivalent Hash. @param 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. @param options [::Gapic::CallOptions, ::Hash] Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
@overload 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)
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). @param session [::String] Required. The session in which the SQL query should be performed. @param transaction [::Google::Cloud::Spanner::V1::TransactionSelector, ::Hash] 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. @param sql [::String] Required. The SQL string. @param params [::Google::Protobuf::Struct, ::Hash] 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 param_types [::Hash{::String => ::Google::Cloud::Spanner::V1::Type, ::Hash}] 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 {::Google::Cloud::Spanner::V1::ExecuteSqlRequest#params 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 {::Google::Cloud::Spanner::V1::Type Type} for more information about SQL types. @param resume_token [::String] If this request is resuming a previously interrupted SQL statement execution, `resume_token` should be copied from the last {::Google::Cloud::Spanner::V1::PartialResultSet 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. @param query_mode [::Google::Cloud::Spanner::V1::ExecuteSqlRequest::QueryMode] Used to control the amount of debugging information returned in {::Google::Cloud::Spanner::V1::ResultSetStats ResultSetStats}. If {::Google::Cloud::Spanner::V1::ExecuteSqlRequest#partition_token partition_token} is set, {::Google::Cloud::Spanner::V1::ExecuteSqlRequest#query_mode query_mode} can only be set to {::Google::Cloud::Spanner::V1::ExecuteSqlRequest::QueryMode::NORMAL QueryMode.NORMAL}. @param partition_token [::String] 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. @param seqno [::Integer] 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. @param query_options [::Google::Cloud::Spanner::V1::ExecuteSqlRequest::QueryOptions, ::Hash] Query optimizer configuration to use for the given query. @param request_options [::Google::Cloud::Spanner::V1::RequestOptions, ::Hash] Common options for this request.
@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Cloud::Spanner::V1::ResultSet] @yieldparam operation [::GRPC::ActiveCall::Operation]
@return [::Google::Cloud::Spanner::V1::ResultSet]
@raise [::Google::Cloud::Error] if the RPC is aborted.
# File lib/google/cloud/spanner/v1/spanner/client.rb, line 719 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 metadata = @config.rpcs.execute_sql.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"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 metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = { "session" => request.session } request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.execute_sql.timeout, metadata: metadata, retry_policy: @config.rpcs.execute_sql.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, 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
Like {::Google::Cloud::Spanner::V1::Spanner::Client#execute_sql ExecuteSql}, except returns the result set as a stream. Unlike {::Google::Cloud::Spanner::V1::Spanner::Client#execute_sql 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.
@overload execute_streaming_sql
(request, options = nil)
Pass arguments to `execute_streaming_sql` via a request object, either of type {::Google::Cloud::Spanner::V1::ExecuteSqlRequest} or an equivalent Hash. @param 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. @param options [::Gapic::CallOptions, ::Hash] Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
@overload 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)
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). @param session [::String] Required. The session in which the SQL query should be performed. @param transaction [::Google::Cloud::Spanner::V1::TransactionSelector, ::Hash] 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. @param sql [::String] Required. The SQL string. @param params [::Google::Protobuf::Struct, ::Hash] 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 param_types [::Hash{::String => ::Google::Cloud::Spanner::V1::Type, ::Hash}] 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 {::Google::Cloud::Spanner::V1::ExecuteSqlRequest#params 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 {::Google::Cloud::Spanner::V1::Type Type} for more information about SQL types. @param resume_token [::String] If this request is resuming a previously interrupted SQL statement execution, `resume_token` should be copied from the last {::Google::Cloud::Spanner::V1::PartialResultSet 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. @param query_mode [::Google::Cloud::Spanner::V1::ExecuteSqlRequest::QueryMode] Used to control the amount of debugging information returned in {::Google::Cloud::Spanner::V1::ResultSetStats ResultSetStats}. If {::Google::Cloud::Spanner::V1::ExecuteSqlRequest#partition_token partition_token} is set, {::Google::Cloud::Spanner::V1::ExecuteSqlRequest#query_mode query_mode} can only be set to {::Google::Cloud::Spanner::V1::ExecuteSqlRequest::QueryMode::NORMAL QueryMode.NORMAL}. @param partition_token [::String] 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. @param seqno [::Integer] 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. @param query_options [::Google::Cloud::Spanner::V1::ExecuteSqlRequest::QueryOptions, ::Hash] Query optimizer configuration to use for the given query. @param request_options [::Google::Cloud::Spanner::V1::RequestOptions, ::Hash] Common options for this request.
@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet>] @yieldparam operation [::GRPC::ActiveCall::Operation]
@return [::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet>]
@raise [::Google::Cloud::Error] if the RPC is aborted.
# File lib/google/cloud/spanner/v1/spanner/client.rb, line 858 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 metadata = @config.rpcs.execute_streaming_sql.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"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 metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = { "session" => request.session } request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.execute_streaming_sql.timeout, metadata: metadata, retry_policy: @config.rpcs.execute_streaming_sql.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, 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
Gets a session. Returns `NOT_FOUND` if the session does not exist. This is mainly useful for determining whether a session is still alive.
@overload get_session
(request, options = nil)
Pass arguments to `get_session` via a request object, either of type {::Google::Cloud::Spanner::V1::GetSessionRequest} or an equivalent Hash. @param 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. @param options [::Gapic::CallOptions, ::Hash] Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
@overload get_session
(name: nil)
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). @param name [::String] Required. The name of the session to retrieve.
@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Cloud::Spanner::V1::Session] @yieldparam operation [::GRPC::ActiveCall::Operation]
@return [::Google::Cloud::Spanner::V1::Session]
@raise [::Google::Cloud::Error] if the RPC is aborted.
# File lib/google/cloud/spanner/v1/spanner/client.rb, line 417 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 metadata = @config.rpcs.get_session.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"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 metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = { "name" => request.name } request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_session.timeout, metadata: metadata, retry_policy: @config.rpcs.get_session.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, 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
Lists all sessions in a given database.
@overload list_sessions
(request, options = nil)
Pass arguments to `list_sessions` via a request object, either of type {::Google::Cloud::Spanner::V1::ListSessionsRequest} or an equivalent Hash. @param 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. @param options [::Gapic::CallOptions, ::Hash] Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
@overload list_sessions
(database: nil, page_size: nil, page_token: nil, filter: nil)
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). @param database [::String] Required. The database in which to list sessions. @param page_size [::Integer] Number of sessions to be returned in the response. If 0 or less, defaults to the server's maximum allowed page size. @param page_token [::String] If non-empty, `page_token` should contain a {::Google::Cloud::Spanner::V1::ListSessionsResponse#next_page_token next_page_token} from a previous {::Google::Cloud::Spanner::V1::ListSessionsResponse ListSessionsResponse}. @param filter [::String] 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".
@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Gapic::PagedEnumerable<::Google::Cloud::Spanner::V1::Session>] @yieldparam operation [::GRPC::ActiveCall::Operation]
@return [::Gapic::PagedEnumerable<::Google::Cloud::Spanner::V1::Session>]
@raise [::Google::Cloud::Error] if the RPC is aborted.
# File lib/google/cloud/spanner/v1/spanner/client.rb, line 503 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 metadata = @config.rpcs.list_sessions.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"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 metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = { "database" => request.database } request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_sessions.timeout, metadata: metadata, retry_policy: @config.rpcs.list_sessions.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, 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
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 {::Google::Cloud::Spanner::V1::Spanner::Client#execute_streaming_sql 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.
@overload partition_query
(request, options = nil)
Pass arguments to `partition_query` via a request object, either of type {::Google::Cloud::Spanner::V1::PartitionQueryRequest} or an equivalent Hash. @param 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. @param options [::Gapic::CallOptions, ::Hash] Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
@overload partition_query
(session: nil, transaction: nil, sql: nil, params: nil, param_types: nil, partition_options: nil)
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). @param session [::String] Required. The session used to create the partitions. @param transaction [::Google::Cloud::Spanner::V1::TransactionSelector, ::Hash] Read only snapshot transactions are supported, read/write and single use transactions are not. @param sql [::String] Required. The query request to generate partitions for. The request will fail if the query is not root partitionable. The query plan of a root partitionable query has a single distributed union operator. A distributed union operator conceptually divides one or more tables into multiple splits, remotely evaluates a subquery independently on each split, and then unions all results. This must not contain DML commands, such as INSERT, UPDATE, or DELETE. Use {::Google::Cloud::Spanner::V1::Spanner::Client#execute_streaming_sql ExecuteStreamingSql} with a PartitionedDml transaction for large, partition-friendly DML operations. @param params [::Google::Protobuf::Struct, ::Hash] 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 param_types [::Hash{::String => ::Google::Cloud::Spanner::V1::Type, ::Hash}] 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 {::Google::Cloud::Spanner::V1::PartitionQueryRequest#params 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 {::Google::Cloud::Spanner::V1::Type Type} for more information about SQL types. @param partition_options [::Google::Cloud::Spanner::V1::PartitionOptions, ::Hash] Additional options that affect how many partitions are created.
@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Cloud::Spanner::V1::PartitionResponse] @yieldparam operation [::GRPC::ActiveCall::Operation]
@return [::Google::Cloud::Spanner::V1::PartitionResponse]
@raise [::Google::Cloud::Error] if the RPC is aborted.
# File lib/google/cloud/spanner/v1/spanner/client.rb, line 1573 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 metadata = @config.rpcs.partition_query.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"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 metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = { "session" => request.session } request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.partition_query.timeout, metadata: metadata, retry_policy: @config.rpcs.partition_query.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, 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
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 {::Google::Cloud::Spanner::V1::Spanner::Client#streaming_read 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.
@overload partition_read
(request, options = nil)
Pass arguments to `partition_read` via a request object, either of type {::Google::Cloud::Spanner::V1::PartitionReadRequest} or an equivalent Hash. @param 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. @param options [::Gapic::CallOptions, ::Hash] Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
@overload partition_read
(session: nil, transaction: nil, table: nil, index: nil, columns: nil, key_set: nil, partition_options: nil)
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). @param session [::String] Required. The session used to create the partitions. @param transaction [::Google::Cloud::Spanner::V1::TransactionSelector, ::Hash] Read only snapshot transactions are supported, read/write and single use transactions are not. @param table [::String] Required. The name of the table in the database to be read. @param index [::String] If non-empty, the name of an index on {::Google::Cloud::Spanner::V1::PartitionReadRequest#table table}. This index is used instead of the table primary key when interpreting {::Google::Cloud::Spanner::V1::PartitionReadRequest#key_set key_set} and sorting result rows. See {::Google::Cloud::Spanner::V1::PartitionReadRequest#key_set key_set} for further information. @param columns [::Array<::String>] The columns of {::Google::Cloud::Spanner::V1::PartitionReadRequest#table table} to be returned for each row matching this request. @param key_set [::Google::Cloud::Spanner::V1::KeySet, ::Hash] Required. `key_set` identifies the rows to be yielded. `key_set` names the primary keys of the rows in {::Google::Cloud::Spanner::V1::PartitionReadRequest#table table} to be yielded, unless {::Google::Cloud::Spanner::V1::PartitionReadRequest#index index} is present. If {::Google::Cloud::Spanner::V1::PartitionReadRequest#index index} is present, then {::Google::Cloud::Spanner::V1::PartitionReadRequest#key_set key_set} instead names index keys in {::Google::Cloud::Spanner::V1::PartitionReadRequest#index 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. @param partition_options [::Google::Cloud::Spanner::V1::PartitionOptions, ::Hash] Additional options that affect how many partitions are created.
@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Cloud::Spanner::V1::PartitionResponse] @yieldparam operation [::GRPC::ActiveCall::Operation]
@return [::Google::Cloud::Spanner::V1::PartitionResponse]
@raise [::Google::Cloud::Error] if the RPC is aborted.
# File lib/google/cloud/spanner/v1/spanner/client.rb, line 1675 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 metadata = @config.rpcs.partition_read.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"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 metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = { "session" => request.session } request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.partition_read.timeout, metadata: metadata, retry_policy: @config.rpcs.partition_read.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, 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
Reads rows from the database using key lookups and scans, as a simple key/value style alternative to {::Google::Cloud::Spanner::V1::Spanner::Client#execute_sql 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 {::Google::Cloud::Spanner::V1::Transaction Transaction} for more details.
Larger result sets can be yielded in streaming fashion by calling {::Google::Cloud::Spanner::V1::Spanner::Client#streaming_read StreamingRead} instead.
@overload read(request, options = nil)
Pass arguments to `read` via a request object, either of type {::Google::Cloud::Spanner::V1::ReadRequest} or an equivalent Hash. @param 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. @param options [::Gapic::CallOptions, ::Hash] Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
@overload 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)
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). @param session [::String] Required. The session in which the read should be performed. @param transaction [::Google::Cloud::Spanner::V1::TransactionSelector, ::Hash] The transaction to use. If none is provided, the default is a temporary read-only transaction with strong concurrency. @param table [::String] Required. The name of the table in the database to be read. @param index [::String] If non-empty, the name of an index on {::Google::Cloud::Spanner::V1::ReadRequest#table table}. This index is used instead of the table primary key when interpreting {::Google::Cloud::Spanner::V1::ReadRequest#key_set key_set} and sorting result rows. See {::Google::Cloud::Spanner::V1::ReadRequest#key_set key_set} for further information. @param columns [::Array<::String>] Required. The columns of {::Google::Cloud::Spanner::V1::ReadRequest#table table} to be returned for each row matching this request. @param key_set [::Google::Cloud::Spanner::V1::KeySet, ::Hash] Required. `key_set` identifies the rows to be yielded. `key_set` names the primary keys of the rows in {::Google::Cloud::Spanner::V1::ReadRequest#table table} to be yielded, unless {::Google::Cloud::Spanner::V1::ReadRequest#index index} is present. If {::Google::Cloud::Spanner::V1::ReadRequest#index index} is present, then {::Google::Cloud::Spanner::V1::ReadRequest#key_set key_set} instead names index keys in {::Google::Cloud::Spanner::V1::ReadRequest#index index}. If the {::Google::Cloud::Spanner::V1::ReadRequest#partition_token partition_token} field is empty, rows are yielded in table primary key order (if {::Google::Cloud::Spanner::V1::ReadRequest#index index} is empty) or index key order (if {::Google::Cloud::Spanner::V1::ReadRequest#index index} is non-empty). If the {::Google::Cloud::Spanner::V1::ReadRequest#partition_token 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. @param limit [::Integer] 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. @param resume_token [::String] If this request is resuming a previously interrupted read, `resume_token` should be copied from the last {::Google::Cloud::Spanner::V1::PartialResultSet 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. @param partition_token [::String] 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. @param request_options [::Google::Cloud::Spanner::V1::RequestOptions, ::Hash] Common options for this request.
@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Cloud::Spanner::V1::ResultSet] @yieldparam operation [::GRPC::ActiveCall::Operation]
@return [::Google::Cloud::Spanner::V1::ResultSet]
@raise [::Google::Cloud::Error] if the RPC is aborted.
# File lib/google/cloud/spanner/v1/spanner/client.rb, line 1083 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 metadata = @config.rpcs.read.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"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 metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = { "session" => request.session } request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.read.timeout, metadata: metadata, retry_policy: @config.rpcs.read.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, 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
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 {::Google::Cloud::Spanner::V1::Spanner::Client#read Read} or {::Google::Cloud::Spanner::V1::Spanner::Client#execute_sql 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`.
@overload rollback(request, options = nil)
Pass arguments to `rollback` via a request object, either of type {::Google::Cloud::Spanner::V1::RollbackRequest} or an equivalent Hash. @param 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. @param options [::Gapic::CallOptions, ::Hash] Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
@overload rollback(session: nil, transaction_id: nil)
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). @param session [::String] Required. The session in which the transaction to roll back is running. @param transaction_id [::String] Required. The transaction to roll back.
@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Google::Protobuf::Empty] @yieldparam operation [::GRPC::ActiveCall::Operation]
@return [::Google::Protobuf::Empty]
@raise [::Google::Cloud::Error] if the RPC is aborted.
# File lib/google/cloud/spanner/v1/spanner/client.rb, line 1457 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 metadata = @config.rpcs.rollback.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"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 metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = { "session" => request.session } request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.rollback.timeout, metadata: metadata, retry_policy: @config.rpcs.rollback.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, 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
Like {::Google::Cloud::Spanner::V1::Spanner::Client#read Read}, except returns the result set as a stream. Unlike {::Google::Cloud::Spanner::V1::Spanner::Client#read 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.
@overload streaming_read
(request, options = nil)
Pass arguments to `streaming_read` via a request object, either of type {::Google::Cloud::Spanner::V1::ReadRequest} or an equivalent Hash. @param 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. @param options [::Gapic::CallOptions, ::Hash] Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
@overload 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)
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). @param session [::String] Required. The session in which the read should be performed. @param transaction [::Google::Cloud::Spanner::V1::TransactionSelector, ::Hash] The transaction to use. If none is provided, the default is a temporary read-only transaction with strong concurrency. @param table [::String] Required. The name of the table in the database to be read. @param index [::String] If non-empty, the name of an index on {::Google::Cloud::Spanner::V1::ReadRequest#table table}. This index is used instead of the table primary key when interpreting {::Google::Cloud::Spanner::V1::ReadRequest#key_set key_set} and sorting result rows. See {::Google::Cloud::Spanner::V1::ReadRequest#key_set key_set} for further information. @param columns [::Array<::String>] Required. The columns of {::Google::Cloud::Spanner::V1::ReadRequest#table table} to be returned for each row matching this request. @param key_set [::Google::Cloud::Spanner::V1::KeySet, ::Hash] Required. `key_set` identifies the rows to be yielded. `key_set` names the primary keys of the rows in {::Google::Cloud::Spanner::V1::ReadRequest#table table} to be yielded, unless {::Google::Cloud::Spanner::V1::ReadRequest#index index} is present. If {::Google::Cloud::Spanner::V1::ReadRequest#index index} is present, then {::Google::Cloud::Spanner::V1::ReadRequest#key_set key_set} instead names index keys in {::Google::Cloud::Spanner::V1::ReadRequest#index index}. If the {::Google::Cloud::Spanner::V1::ReadRequest#partition_token partition_token} field is empty, rows are yielded in table primary key order (if {::Google::Cloud::Spanner::V1::ReadRequest#index index} is empty) or index key order (if {::Google::Cloud::Spanner::V1::ReadRequest#index index} is non-empty). If the {::Google::Cloud::Spanner::V1::ReadRequest#partition_token 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. @param limit [::Integer] 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. @param resume_token [::String] If this request is resuming a previously interrupted read, `resume_token` should be copied from the last {::Google::Cloud::Spanner::V1::PartialResultSet 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. @param partition_token [::String] 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. @param request_options [::Google::Cloud::Spanner::V1::RequestOptions, ::Hash] Common options for this request.
@yield [response, operation] Access the result along with the RPC operation @yieldparam response [::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet>] @yieldparam operation [::GRPC::ActiveCall::Operation]
@return [::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet>]
@raise [::Google::Cloud::Error] if the RPC is aborted.
# File lib/google/cloud/spanner/v1/spanner/client.rb, line 1198 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 metadata = @config.rpcs.streaming_read.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"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 metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = { "session" => request.session } request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.streaming_read.timeout, metadata: metadata, retry_policy: @config.rpcs.streaming_read.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, 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