pub struct Partition { /* private fields */ }Expand description
Defines the segments of data to be read in a partitioned read or query.
§Example
// Coordinator serializes partition to send to a worker:
let serialized = serde_json::to_string(&partitions[0])?;
// Worker deserializes the partition and executes it:
let partition: Partition = serde_json::from_str(&serialized)?;
let mut result_set = partition.execute(&db_client).await?;Partitions can be serialized and processed across several different worker machines
or processes using any serde-compatible format (such as JSON or binary).
Serialization is wrapped in a versioned wire envelope to guarantee backward and forward compatibility across client versions.
Implementations§
Source§impl Partition
impl Partition
Sourcepub fn set_data_boost(self, enabled: bool) -> Self
pub fn set_data_boost(self, enabled: bool) -> Self
Sets whether Data Boost is enabled for this partition.
§Example
// On a worker receiving a partition, execute it with Data Boost:
let mut result_set = partitions[0].clone()
.set_data_boost(true)
.execute(&db_client)
.await?;Sourcepub fn with_attempt_timeout(self, timeout: Duration) -> Self
pub fn with_attempt_timeout(self, timeout: Duration) -> Self
Sets the per-attempt timeout for this partition execution.
Note: This field is not serialized. Each host that executes a partition must set its own attempt timeout.
Sourcepub fn with_retry_policy(self, policy: impl Into<RetryPolicyArg>) -> Self
pub fn with_retry_policy(self, policy: impl Into<RetryPolicyArg>) -> Self
Sets the retry policy for this partition execution.
Note: This field is not serialized. Each host that executes a partition must set its own retry policy.
Sourcepub fn with_backoff_policy(self, policy: impl Into<BackoffPolicyArg>) -> Self
pub fn with_backoff_policy(self, policy: impl Into<BackoffPolicyArg>) -> Self
Sets the backoff policy for this partition execution.
Note: This field is not serialized. Each host that executes a partition must set its own backoff policy.
Sourcepub async fn execute(&self, client: &DatabaseClient) -> Result<ResultSet>
pub async fn execute(&self, client: &DatabaseClient) -> Result<ResultSet>
Executes this partition and returns a ResultSet that contains the rows that belong to this partition.
§Example: executing a query partition
let db_client = spanner.database_client("projects/p/instances/i/databases/d").build().await?;
let transaction = db_client.batch_read_only_transaction().build().await?;
let partitions = transaction.partition_query(
Statement::builder("SELECT * FROM Users").build(),
PartitionOptions::default()
).await?;
// ... send partitions to other workers ...
// On a worker receiving a partition, execute it:
let mut result_set = partitions[0].execute(&db_client).await?;
while let Some(row) = result_set.next().await.transpose()? {
// process row
}§Example: executing a read partition
let db_client = spanner.database_client("projects/p/instances/i/databases/d").build().await?;
let transaction = db_client.batch_read_only_transaction().build().await?;
let request = ReadRequest::builder("Users", vec!["Id", "Name"]).with_keys(KeySet::all()).build();
let partitions = transaction.partition_read(request, PartitionOptions::default()).await?;
// ... send partitions to other workers ...
// On a worker receiving a partition, execute it:
let mut result_set = partitions[0].execute(&db_client).await?;
while let Some(row) = result_set.next().await.transpose()? {
// process row
}§Example: executing a partition with a custom timeout
let db_client = spanner.database_client("projects/p/instances/i/databases/d").build().await?;
// Configure a custom attempt timeout before executing the partition:
let mut result_set = partition
.with_attempt_timeout(Duration::from_secs(60))
.execute(&db_client)
.await?;
while let Some(row) = result_set.next().await.transpose()? {
// process row
}A partition can be executed by any DatabaseClient that is connected to
the database that the partitions belong to.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Partition
impl<'de> Deserialize<'de> for Partition
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl !Freeze for Partition
impl !RefUnwindSafe for Partition
impl !UnwindSafe for Partition
impl Forget for Partition
impl Move for Partition
impl Send for Partition
impl Sync for Partition
impl Unpin for Partition
impl UnsafeUnpin for Partition
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request