# Cloud Spanner API - Class Google::Cloud::Spanner::Partition (v2.36.0)

2.36.0 (latest) 2.35.0 2.34.0 2.33.0 2.32.0 2.31.0 2.30.0 2.29.0 2.28.0 2.27.0 2.26.0 2.25.0 2.24.0 2.23.0 2.22.0 2.21.0 2.20.0 2.19.1 2.18.1 2.17.0 2.16.1 2.15.0 2.14.0 2.13.0 2.12.1 2.11.0 Reference documentation and code samples for the Cloud Spanner API class Google::Cloud::Spanner::Partition.

## 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](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-BatchSnapshot#Google__Cloud__Spanner__BatchSnapshot_partition_read_instance_ "Google::Cloud::Spanner::BatchSnapshot#partition_read (method)"), [BatchSnapshot#partition_query](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-BatchSnapshot#Google__Cloud__Spanner__BatchSnapshot_partition_query_instance_ "Google::Cloud::Spanner::BatchSnapshot#partition_query (method)"), and
[BatchSnapshot#execute_partition](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-BatchSnapshot#Google__Cloud__Spanner__BatchSnapshot_execute_partition_instance_ "Google::Cloud::Spanner::BatchSnapshot#execute_partition (method)").

## Inherits

- Object

## Example

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new

batch_client = spanner.batch_client "my-instance", "my-database"

batch_snapshot = batch_client.batch_snapshot
partitions = batch_snapshot.partition_read "users", [:id, :name]

partition = partitions.first

results = batch_snapshot.execute_partition partition
```

## Methods

### .load

    def self.load(data) -> Google::Cloud::Spanner::Partition

Returns a [Partition](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Partition "Google::Cloud::Spanner::Partition (class)") from a serialized representation.
**Parameter**

- **data** (String) --- The serialized representation of an existing batch partition. See [#dump](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Partition#Google__Cloud__Spanner__Partition_dump_instance_ "Google::Cloud::Spanner::Partition#dump (method)").
**Returns**

- ([Google::Cloud::Spanner::Partition](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Partition))
**Example**

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new

batch_client = spanner.batch_client "my-instance", "my-database"

batch_snapshot = batch_client.batch_snapshot

partitions = batch_snapshot.partition_read "users", [:id, :name]

partition = partitions.first

serialized_snapshot = batch_snapshot.dump
serialized_partition = partition.dump

# In a separate process
new_batch_snapshot = batch_client.load_batch_snapshot \
  serialized_snapshot

new_partition = Google::Cloud::Spanner::Partition.load \
  serialized_partition

results = new_batch_snapshot.execute_partition \
  new_partition
```

### #dump

    def dump() -> String

**Aliases**

- [#serialize](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Partition#Google__Cloud__Spanner__Partition_serialize_instance_)
Serializes the batch partition object so it can be recreated on
another process. See [Partition.load](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Partition#Google__Cloud__Spanner__Partition_load_class_ "Google::Cloud::Spanner::Partition.load (method)") and
[BatchClient#load_partition](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-BatchClient#Google__Cloud__Spanner__BatchClient_load_partition_instance_ "Google::Cloud::Spanner::BatchClient#load_partition (method)").
**Returns**

- (String) --- The serialized representation of the batch partition.
**Example**

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new

batch_client = spanner.batch_client "my-instance", "my-database"

batch_snapshot = batch_client.batch_snapshot

partitions = batch_snapshot.partition_read "users", [:id, :name]

partition = partitions.first

serialized_snapshot = batch_snapshot.dump
serialized_partition = partition.dump

# In a separate process
new_batch_snapshot = batch_client.load_batch_snapshot \
  serialized_snapshot

new_partition = batch_client.load_partition \
  serialized_partition

results = new_batch_snapshot.execute_partition \
  new_partition
```

### #execute?

    def execute?() -> Boolean

**Alias Of** : [#execute_query?](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Partition#Google__Cloud__Spanner__Partition_execute_query?_instance_) Whether the partition was created for an execute_query/query
operation.
**Returns**

- (Boolean)

### #execute_query?

    def execute_query?() -> Boolean

**Aliases**

- [#execute?](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Partition#Google__Cloud__Spanner__Partition_execute?_instance_)
- [#execute_sql?](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Partition#Google__Cloud__Spanner__Partition_execute_sql?_instance_)
- [#query?](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Partition#Google__Cloud__Spanner__Partition_query?_instance_)
Whether the partition was created for an execute_query/query
operation.
**Returns**

- (Boolean)

### #execute_sql?

    def execute_sql?() -> Boolean

**Alias Of** : [#execute_query?](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Partition#Google__Cloud__Spanner__Partition_execute_query?_instance_) Whether the partition was created for an execute_query/query
operation.
**Returns**

- (Boolean)

### #query?

    def query?() -> Boolean

**Alias Of** : [#execute_query?](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Partition#Google__Cloud__Spanner__Partition_execute_query?_instance_) Whether the partition was created for an execute_query/query
operation.
**Returns**

- (Boolean)

### #read?

    def read?() -> Boolean

Whether the partition was created for a read operation.
**Returns**

- (Boolean)

### #serialize

    def serialize() -> String

**Alias Of** : [#dump](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Partition#Google__Cloud__Spanner__Partition_dump_instance_) Serializes the batch partition object so it can be recreated on
another process. See [Partition.load](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Partition#Google__Cloud__Spanner__Partition_load_class_ "Google::Cloud::Spanner::Partition.load (method)") and
[BatchClient#load_partition](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-BatchClient#Google__Cloud__Spanner__BatchClient_load_partition_instance_ "Google::Cloud::Spanner::BatchClient#load_partition (method)").
**Returns**

- (String) --- The serialized representation of the batch partition.
**Example**

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new

batch_client = spanner.batch_client "my-instance", "my-database"

batch_snapshot = batch_client.batch_snapshot

partitions = batch_snapshot.partition_read "users", [:id, :name]

partition = partitions.first

serialized_snapshot = batch_snapshot.dump
serialized_partition = partition.dump

# In a separate process
new_batch_snapshot = batch_client.load_batch_snapshot \
  serialized_snapshot

new_partition = batch_client.load_partition \
  serialized_partition

results = new_batch_snapshot.execute_partition \
  new_partition
```