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.
Instance Attribute Summary collapse
-
#execute ⇒ Object
readonly
@ private.
-
#read ⇒ Object
readonly
@ private.
Class Method Summary collapse
-
.from_execute_grpc(grpc) ⇒ Object
object.
- .from_read_grpc(grpc) ⇒ Object
-
.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.
-
#empty? ⇒ Boolean
Whether the partition does not have an execute or read operation.
-
#execute? ⇒ Boolean
Whether the partition was created for an execute/query operation.
-
#initialize ⇒ Partition
constructor
A new instance of Partition.
- #inspect ⇒ Object
-
#read? ⇒ Boolean
Whether the partition was created for a read operation.
-
#to_h ⇒ Hash
Converts the the batch partition object to a Hash ready for serialization.
Constructor Details
#initialize ⇒ Partition
Returns a new instance of Partition.
52 |
# File 'lib/google/cloud/spanner/partition.rb', line 52 def initialize; end |
Instance Attribute Details
#execute ⇒ Object (readonly)
@ private
48 49 50 |
# File 'lib/google/cloud/spanner/partition.rb', line 48 def execute @execute end |
#read ⇒ Object (readonly)
@ private
48 49 50 |
# File 'lib/google/cloud/spanner/partition.rb', line 48 def read @read end |
Class Method Details
.from_execute_grpc(grpc) ⇒ Object
object.
192 193 194 195 196 |
# File 'lib/google/cloud/spanner/partition.rb', line 192 def self.from_execute_grpc grpc new.tap do |p| p.instance_variable_set :@execute, grpc end end |
.from_read_grpc(grpc) ⇒ Object
200 201 202 203 204 |
# File 'lib/google/cloud/spanner/partition.rb', line 200 def self.from_read_grpc grpc new.tap do |p| p.instance_variable_set :@read, grpc end end |
.load(data) ⇒ Google::Cloud::Spanner::Partition
Returns a Google::Cloud::Spanner::Partition from a serialized representation.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/google/cloud/spanner/partition.rb', line 163 def self.load data data = JSON.parse data, symbolize_names: true unless data.is_a? Hash # TODO: raise if hash[:execute].nil? && hash[:read].nil? new.tap do |p| if data[:execute] execute_grpc = Google::Spanner::V1::ExecuteSqlRequest.decode \ Base64.decode64(data[:execute]) p.instance_variable_set :@execute, execute_grpc end if data[:read] read_grpc = Google::Spanner::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.
124 125 126 |
# File 'lib/google/cloud/spanner/partition.rb', line 124 def dump JSON.dump to_h end |
#empty? ⇒ Boolean
Whether the partition does not have an execute or read operation.
72 73 74 |
# File 'lib/google/cloud/spanner/partition.rb', line 72 def empty? @execute.nil? && @read.nil? end |
#execute? ⇒ Boolean
Whether the partition was created for an execute/query operation.
57 58 59 |
# File 'lib/google/cloud/spanner/partition.rb', line 57 def execute? !@execute.nil? end |
#inspect ⇒ Object
182 183 184 185 186 187 |
# File 'lib/google/cloud/spanner/partition.rb', line 182 def inspect status = "empty" status = "execute" if execute? status = "read" if read? "#<#{self.class.name} #{status}>" end |
#read? ⇒ Boolean
Whether the partition was created for a read operation.
64 65 66 |
# File 'lib/google/cloud/spanner/partition.rb', line 64 def read? !@read.nil? end |
#to_h ⇒ Hash
Converts the the batch partition object to a Hash ready for serialization.
84 85 86 87 88 89 |
# File 'lib/google/cloud/spanner/partition.rb', line 84 def to_h {}.tap do |h| h[:execute] = Base64.strict_encode64(@execute.to_proto) if @execute h[:read] = Base64.strict_encode64(@read.to_proto) if @read end end |