- 2.0.1-RC1 (latest)
 - 2.0.0-RC1
 - 1.106.0
 - 1.105.1
 - 1.104.1
 - 1.103.0
 - 1.102.0
 - 1.101.0
 - 1.100.0
 - 1.98.0
 - 1.97.0
 - 1.96.0
 - 1.95.0
 - 1.94.0
 - 1.93.1
 - 1.92.1
 - 1.91.0
 - 1.90.0
 - 1.89.0
 - 1.88.0
 - 1.87.0
 - 1.86.0
 - 1.85.0
 - 1.84.0
 - 1.83.0
 - 1.82.0
 - 1.81.0
 - 1.80.0
 - 1.79.0
 - 1.78.0
 - 1.77.0
 - 1.76.1
 - 1.68.0
 - 1.67.0
 - 1.66.0
 - 1.65.0
 - 1.64.0
 - 1.63.2
 - 1.62.1
 - 1.61.0
 - 1.60.0
 - 1.59.0
 - 1.58.4
 - 1.57.0
 - 1.56.0
 - 1.55.0
 - 1.54.2
 
Reference documentation and code samples for the Cloud Spanner Client class BatchClient.
Provides Batch APIs used to read data from a Cloud Spanner database.
Batch Clients are useful when one wants to read or query a large amount of data from Cloud Spanner across multiple processes, even across multiple machines. It allows creation of partitions of a Cloud Spanner database in order to facilitate reading or querying of each partition independently at the same snapshot.
Example:
use Google\Cloud\Spanner\SpannerClient;
$spanner = new SpannerClient();
$batch = $spanner->batch('instance-id', 'database-id');
// Using Cloud Pub/Sub to share partitions with workers
use Google\Cloud\PubSub\PubSubClient;
$pubsub = new PubSubClient();
$topic = $pubsub->topic('partition-queries');
$snapshot = $batch->snapshot();
// Executing a partition query will return a list of Partitions.
$partitions = $snapshot->partitionQuery('SELECT * FROM Users WHERE firstName = %s AND location = %s', [
    'parameters' => [
        'firstName' => 'John',
        'location' => 'USA'
    ]
]);
// Each partition is published to Cloud Pub/Sub, where it can be executed by
// a worker.
foreach ($partitions as $partition) {
    $topic->publish([
        'attributes' => [
            'snapshot' => $snapshot->serialize(),
            'partition' => $partition->serialize()
        ]
    ]);
}
// Once all workers have finished, we will close the snapshot.
// The logic to determine whether the snapshot is no longer needed will vary
// and is not implemented here.
do {
    $finished = areWorkersDone();
    if ($finished) {
        $snapshot->close();
    }
} while(!$finished);
// Using Cloud Pub/Sub to consume a partition and return a result.
use Google\Cloud\PubSub\PubSubClient;
$pubsub = new PubSubClient();
$subscription = $pubsub->subscription('partition-query-consumer');
$messages = $subscription->pull([
    'returnImmediately' => true,
    'maxMessages' => 1
]);
if ($messages) {
    $message = $messages[0];
    $snapshot = $batch->snapshotFromString($message->attribute('snapshot'));
    $partition = $batch->partitionFromString($message->attribute('partition'));
    // Do something with the query result.
    processResult($snapshot->executePartition($partition));
}
Namespace
Google \ Cloud \ Spanner \ BatchMethods
__construct
| Parameters | |
|---|---|
| Name | Description | 
operation | 
        
          Google\Cloud\Spanner\Operation
          A Cloud Spanner Operations wrapper.  | 
      
databaseName | 
        
          string
          The database name to which the batch client instance is scoped.  | 
      
options | 
        
          array
          Configuration options.  | 
      
↳ databaseRole | 
        
          string
          The user created database role which creates the session.  | 
      
snapshot
Create a batch snapshot.
Example:
$snapshot = $batch->snapshot();
| Parameters | |
|---|---|
| Name | Description | 
options | 
        
          array
          Configuration Options  | 
      
↳ transactionOptions | 
        
          bool
          .strong Read at a timestamp where all previously committed transactions are visible.  | 
      
↳ transactionOptions | 
        
          Timestamp
          .readTimestamp Executes all reads at the given timestamp.  | 
      
↳ transactionOptions | 
        
          Duration
          .exactStaleness Represents a number of seconds. Executes all reads at a timestamp that is $exactStaleness old.  | 
      
↳ sessionOptions | 
        
          array
          Configuration options for session creation.  | 
      
| Returns | |
|---|---|
| Type | Description | 
BatchSnapshot | 
        |
snapshotFromString
Create a BatchSnapshot from a snapshot identifier.
This method can be used to deserialize a snapshot which is shared across multiple servers or processes.
Example:
$snapshot = $batch->snapshotFromString($snapshotString);
| Parameter | |
|---|---|
| Name | Description | 
identifier | 
        
          string
          A stringified representation of BatchSnapshot.  | 
      
| Returns | |
|---|---|
| Type | Description | 
BatchSnapshot | 
        |
partitionFromString
Create a PartitionInterface instance.
This method can be used to deserialize a partition which is shared across multiple servers or processes.
Example:
$partition = $batch->partitionFromString($partitionString);
| Parameter | |
|---|---|
| Name | Description | 
partition | 
        
          string
          Partition data  | 
      
| Returns | |
|---|---|
| Type | Description | 
PartitionInterface | 
        |
Constants
PARTITION_TYPE_KEY
Value: '__partitionTypeName'