Class: Google::Cloud::Spanner::BatchClient
- Inherits:
-
Object
- Object
- Google::Cloud::Spanner::BatchClient
- Defined in:
- lib/google/cloud/spanner/batch_client.rb
Overview
BatchClient
Provides a batch client that can be used to read data from a Cloud Spanner database. An instance of this class is tied to a specific database.
BatchClient is useful when one wants to read or query a large amount of data from Cloud Spanner across multiple processes, even across different machines. It allows to create partitions of Cloud Spanner database and then read or query over each partition independently yet at the same snapshot.
See Project#batch_client.
Instance Method Summary collapse
-
#batch_snapshot(strong: nil, timestamp: nil, read_timestamp: nil, staleness: nil, exact_staleness: nil) {|snapshot| ... } ⇒ Google::Cloud::Spanner::BatchSnapshot
Returns a BatchSnapshot context in which multiple reads and/or queries can be performed.
-
#database ⇒ Database
The Spanner database connected to.
-
#database_id ⇒ String
The unique identifier for the database.
-
#fields(types) ⇒ Fields
Creates a configuration object (Fields) that may be provided to queries or used to create STRUCT objects.
-
#instance ⇒ Instance
The Spanner instance connected to.
-
#instance_id ⇒ String
The unique identifier for the instance.
-
#load_batch_snapshot(serialized_snapshot) ⇒ Google::Cloud::Spanner::BatchSnapshot
Returns a BatchSnapshot context in which multiple reads and/or queries can be performed.
-
#load_partition(serialized_partition) ⇒ Google::Cloud::Spanner::Partition
Returns a Partition from a serialized representation.
-
#project ⇒ Project
The Spanner project connected to.
-
#project_id ⇒ String
The unique identifier for the project.
-
#range(beginning, ending, exclude_begin: false, exclude_end: false) ⇒ Google::Cloud::Spanner::Range
Creates a Spanner Range.
Instance Method Details
#batch_snapshot(strong: nil, timestamp: nil, read_timestamp: nil, staleness: nil, exact_staleness: nil) {|snapshot| ... } ⇒ Google::Cloud::Spanner::BatchSnapshot
Returns a Google::Cloud::Spanner::BatchSnapshot context in which multiple reads and/or queries can be performed. All reads/queries will use the same timestamp, and the timestamp can be inspected after this transaction is created successfully. This is a blocking method since it waits to finish the RPCs.
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/google/cloud/spanner/batch_client.rb', line 178 def batch_snapshot strong: nil, timestamp: nil, read_timestamp: nil, staleness: nil, exact_staleness: nil validate_snapshot_args! strong: strong, timestamp: , read_timestamp: , staleness: staleness, exact_staleness: exact_staleness ensure_service! snp_session = session snp_grpc = @project.service.create_snapshot \ snp_session.path, strong: strong, timestamp: ( || ), staleness: (staleness || exact_staleness) BatchSnapshot.from_grpc snp_grpc, snp_session end |
#database ⇒ Database
The Spanner database connected to.
107 108 109 |
# File 'lib/google/cloud/spanner/batch_client.rb', line 107 def database @project.database instance_id, database_id end |
#database_id ⇒ String
The unique identifier for the database.
89 90 91 |
# File 'lib/google/cloud/spanner/batch_client.rb', line 89 def database_id @database_id end |
#fields(types) ⇒ Fields
Creates a configuration object (Fields) that may be provided to queries or used to create STRUCT objects. (The STRUCT will be represented by the Data class.) See Client#execute and/or Fields#struct.
For more information, see Data Types - Constructing a STRUCT.
346 347 348 |
# File 'lib/google/cloud/spanner/batch_client.rb', line 346 def fields types Fields.new types end |
#instance ⇒ Instance
The Spanner instance connected to.
101 102 103 |
# File 'lib/google/cloud/spanner/batch_client.rb', line 101 def instance @project.instance instance_id end |
#instance_id ⇒ String
The unique identifier for the instance.
83 84 85 |
# File 'lib/google/cloud/spanner/batch_client.rb', line 83 def instance_id @instance_id end |
#load_batch_snapshot(serialized_snapshot) ⇒ Google::Cloud::Spanner::BatchSnapshot
Returns a Google::Cloud::Spanner::BatchSnapshot context in which multiple reads and/or queries can be performed. All reads/queries will use the same timestamp, and the timestamp can be inspected after this transaction is created successfully. This method does not perform an RPC.
231 232 233 234 235 |
# File 'lib/google/cloud/spanner/batch_client.rb', line 231 def load_batch_snapshot serialized_snapshot ensure_service! BatchSnapshot.load serialized_snapshot, service: @project.service end |
#load_partition(serialized_partition) ⇒ Google::Cloud::Spanner::Partition
Returns a Partition from a serialized representation. See Partition.load.
272 273 274 |
# File 'lib/google/cloud/spanner/batch_client.rb', line 272 def load_partition serialized_partition Partition.load serialized_partition end |
#project ⇒ Project
The Spanner project connected to.
95 96 97 |
# File 'lib/google/cloud/spanner/batch_client.rb', line 95 def project @project end |
#project_id ⇒ String
The unique identifier for the project.
77 78 79 |
# File 'lib/google/cloud/spanner/batch_client.rb', line 77 def project_id @project.service.project end |
#range(beginning, ending, exclude_begin: false, exclude_end: false) ⇒ Google::Cloud::Spanner::Range
Creates a Spanner Range. This can be used in place of a Ruby Range when needing to exclude the beginning value.
377 378 379 380 381 |
# File 'lib/google/cloud/spanner/batch_client.rb', line 377 def range beginning, ending, exclude_begin: false, exclude_end: false Range.new beginning, ending, exclude_begin: exclude_begin, exclude_end: exclude_end end |