Class: Google::Cloud::Spanner::Partition
- Inherits:
-
Object
- Object
- Google::Cloud::Spanner::Partition
- Defined in:
- lib/google/cloud/spanner/partition.rb
Overview
Partition
Defines the segments of data to be read in a batch read/query context. A Partition instance can be serialized and used across several different machines or processes.
See BatchSnapshot#partition_read, BatchSnapshot#partition_query, and BatchSnapshot#execute_partition.
Class Method Summary collapse
-
.load(data) ⇒ Google::Cloud::Spanner::Partition
Returns a Partition from a serialized representation.
Instance Method Summary collapse
-
#dump ⇒ String
(also: #serialize)
Serializes the batch partition object so it can be recreated on another process.
-
#execute_query? ⇒ Boolean
(also: #execute?, #execute_sql?, #query?)
Whether the partition was created for an execute_query/query operation.
-
#read? ⇒ Boolean
Whether the partition was created for a read operation.
Class Method Details
.load(data) ⇒ Google::Cloud::Spanner::Partition
Returns a Google::Cloud::Spanner::Partition from a serialized representation.
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/google/cloud/spanner/partition.rb', line 176 def self.load data data = JSON.parse data, symbolize_names: true unless data.is_a? Hash # TODO: raise if hash[:execute_query].nil? && hash[:read].nil? new.tap do |p| if data[:execute] execute_sql_grpc = V1::ExecuteSqlRequest.decode( Base64.decode64(data[:execute]) ) p.instance_variable_set :@execute, execute_sql_grpc end if data[:read] read_grpc = V1::ReadRequest.decode \ Base64.decode64(data[:read]) p.instance_variable_set :@read, read_grpc end end end |
Instance Method Details
#dump ⇒ String Also known as: serialize
Serializes the batch partition object so it can be recreated on another process. See load and BatchClient#load_partition.
137 138 139 |
# File 'lib/google/cloud/spanner/partition.rb', line 137 def dump JSON.dump to_h end |
#execute_query? ⇒ Boolean Also known as: execute?, execute_sql?, query?
Whether the partition was created for an execute_query/query operation.
66 67 68 |
# File 'lib/google/cloud/spanner/partition.rb', line 66 def execute_query? !@execute.nil? end |
#read? ⇒ Boolean
Whether the partition was created for a read operation.
76 77 78 |
# File 'lib/google/cloud/spanner/partition.rb', line 76 def read? !@read.nil? end |