AzureTableStor/man/table_batch.Rd

107 строки
4.7 KiB
Plaintext
Исходник Постоянная ссылка Обычный вид История

2020-10-21 16:58:47 +03:00
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/table_batch_request.R
2020-10-22 03:31:14 +03:00
\name{create_table_operation}
\alias{create_table_operation}
\alias{create_batch_transaction}
2020-10-21 16:58:47 +03:00
\alias{do_batch_transaction}
2020-10-22 03:31:14 +03:00
\alias{do_batch_transaction.batch_transaction}
2020-10-21 16:58:47 +03:00
\title{Batch transactions for table storage}
\usage{
2020-10-22 03:31:14 +03:00
create_table_operation(
2020-10-21 16:58:47 +03:00
endpoint,
path,
options = list(),
headers = list(),
body = NULL,
metadata = c("none", "minimal", "full"),
http_verb = c("GET", "PUT", "POST", "PATCH", "DELETE", "HEAD")
)
2020-10-22 03:31:14 +03:00
create_batch_transaction(endpoint, operations)
do_batch_transaction(transaction, ...)
\method{do_batch_transaction}{batch_transaction}(
transaction,
batch_status_handler = c("warn", "stop", "message", "pass"),
num_retries = 10,
2020-10-22 03:31:14 +03:00
...
2020-10-21 16:58:47 +03:00
)
}
\arguments{
\item{endpoint}{A table storage endpoint, of class \code{table_endpoint}.}
\item{path}{The path component of the operation.}
\item{options}{A named list giving the query parameters for the operation.}
\item{headers}{A named list giving any additional HTTP headers to send to the host. AzureCosmosR will handle authentication details, so you don't have to specify these here.}
\item{body}{The request body for a PUT/POST/PATCH operation.}
\item{metadata}{The level of ODATA metadata to include in the response.}
\item{http_verb}{The HTTP verb (method) for the operation.}
2020-10-22 03:31:14 +03:00
\item{operations}{A list of individual table operation objects, each of class \code{table_operation}.}
\item{transaction}{For \code{do_batch_transaction}, an object of class \code{batch_transaction}.}
\item{...}{Arguments passed to lower-level functions.}
2020-10-21 16:58:47 +03:00
\item{batch_status_handler}{For \code{do_batch_transaction}, what to do if one or more of the batch operations fails. The default is to signal a warning and return a list of response objects, from which the details of the failure(s) can be determined. Set this to "pass" to ignore the failure.}
\item{num_retries}{The number of times to retry the call, if the response is a HTTP error 429 (too many requests). The Cosmos DB endpoint tends to be aggressive at rate-limiting requests, to maintain the desired level of latency. This will generally not affect calls to an endpoint provided by a storage account.}
2020-10-21 16:58:47 +03:00
}
\value{
2020-10-22 03:31:14 +03:00
\code{create_table_operation} returns an object of class \code{table_operation}.
2020-10-21 16:58:47 +03:00
Assuming the batch transaction did not fail due to rate-limiting, \code{do_batch_transaction} returns a list of objects of class \code{table_operation_response}, representing the results of each individual operation. Each object contains elements named \code{status}, \code{headers} and \code{body} containing the respective parts of the response. Note that the number of returned objects may be smaller than the number of operations in the batch, if the transaction failed.
2020-10-21 16:58:47 +03:00
}
\description{
Batch transactions for table storage
}
\details{
Table storage supports batch transactions on entities that are in the same table and belong to the same partition group. Batch transactions are also known as \emph{entity group transactions}.
2020-10-22 03:31:14 +03:00
You can use \code{create_table_operation} to produce an object corresponding to a single table storage operation, such as inserting, deleting or updating an entity. Multiple such objects can then be passed to \code{create_batch_transaction}, which bundles them into a single atomic transaction. Call \code{do_batch_transaction} to send the transaction to the endpoint.
2020-10-21 16:58:47 +03:00
Note that batch transactions are subject to some limitations imposed by the REST API:
\itemize{
\item All entities subject to operations as part of the transaction must have the same \code{PartitionKey} value.
\item An entity can appear only once in the transaction, and only one operation may be performed against it.
\item The transaction can include at most 100 entities, and its total payload may be no more than 4 MB in size.
2020-10-22 02:06:03 +03:00
}
}
\examples{
\dontrun{
endp <- table_endpoint("https://mycosmosdb.table.cosmos.azure.com:443", key="mykey")
2020-10-22 16:04:00 +03:00
tab <- create_storage_table(endp, "mytable")
2020-10-22 02:06:03 +03:00
## a simple batch insert
ir <- subset(iris, Species == "setosa")
# property names must be valid C# variable names
names(ir) <- sub("\\\\.", "_", names(ir))
# create the PartitionKey and RowKey properties
ir$PartitionKey <- ir$Species
ir$RowKey <- sprintf("\%03d", seq_len(nrow(ir)))
# generate the array of insert operations: 1 per row
ops <- lapply(seq_len(nrow(ir)), function(i)
2020-10-22 03:31:14 +03:00
create_table_operation(endp, "mytable", body=ir[i, ], http_verb="POST")))
2020-10-22 02:06:03 +03:00
2020-10-22 03:31:14 +03:00
# create a batch transaction and send it to the endpoint
bat <- create_batch_transaction(endp, ops)
do_batch_transaction(bat)
2020-10-22 02:06:03 +03:00
2020-10-21 16:58:47 +03:00
}
}
\seealso{
\link{import_table_entities}, which uses (multiple) batch transactions under the hood
\href{https://docs.microsoft.com/en-us/rest/api/storageservices/performing-entity-group-transactions}{Performing entity group transactions}
}