{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.DynamoDB.BatchWriteItem
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- The @BatchWriteItem@ operation puts or deletes multiple items in one or
-- more tables. A single call to @BatchWriteItem@ can transmit up to 16MB
-- of data over the network, consisting of up to 25 item put or delete
-- operations. While individual items can be up to 400 KB once stored,
-- it\'s important to note that an item\'s representation might be greater
-- than 400KB while being sent in DynamoDB\'s JSON format for the API call.
-- For more details on this distinction, see
-- <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html Naming Rules and Data Types>.
--
-- @BatchWriteItem@ cannot update items. If you perform a @BatchWriteItem@
-- operation on an existing item, that item\'s values will be overwritten
-- by the operation and it will appear like it was updated. To update
-- items, we recommend you use the @UpdateItem@ action.
--
-- The individual @PutItem@ and @DeleteItem@ operations specified in
-- @BatchWriteItem@ are atomic; however @BatchWriteItem@ as a whole is not.
-- If any requested operations fail because the table\'s provisioned
-- throughput is exceeded or an internal processing failure occurs, the
-- failed operations are returned in the @UnprocessedItems@ response
-- parameter. You can investigate and optionally resend the requests.
-- Typically, you would call @BatchWriteItem@ in a loop. Each iteration
-- would check for unprocessed items and submit a new @BatchWriteItem@
-- request with those unprocessed items until all items have been
-- processed.
--
-- If /none/ of the items can be processed due to insufficient provisioned
-- throughput on all of the tables in the request, then @BatchWriteItem@
-- returns a @ProvisionedThroughputExceededException@.
--
-- If DynamoDB returns any unprocessed items, you should retry the batch
-- operation on those items. However, /we strongly recommend that you use
-- an exponential backoff algorithm/. If you retry the batch operation
-- immediately, the underlying read or write requests can still fail due to
-- throttling on the individual tables. If you delay the batch operation
-- using exponential backoff, the individual requests in the batch are much
-- more likely to succeed.
--
-- For more information, see
-- <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ErrorHandling.html#Programming.Errors.BatchOperations Batch Operations and Error Handling>
-- in the /Amazon DynamoDB Developer Guide/.
--
-- With @BatchWriteItem@, you can efficiently write or delete large amounts
-- of data, such as from Amazon EMR, or copy data from another database
-- into DynamoDB. In order to improve performance with these large-scale
-- operations, @BatchWriteItem@ does not behave in the same way as
-- individual @PutItem@ and @DeleteItem@ calls would. For example, you
-- cannot specify conditions on individual put and delete requests, and
-- @BatchWriteItem@ does not return deleted items in the response.
--
-- If you use a programming language that supports concurrency, you can use
-- threads to write items in parallel. Your application must include the
-- necessary logic to manage the threads. With languages that don\'t
-- support threading, you must update or delete the specified items one at
-- a time. In both situations, @BatchWriteItem@ performs the specified put
-- and delete operations in parallel, giving you the power of the thread
-- pool approach without having to introduce complexity into your
-- application.
--
-- Parallel processing reduces latency, but each specified put and delete
-- request consumes the same number of write capacity units whether it is
-- processed in parallel or not. Delete operations on nonexistent items
-- consume one write capacity unit.
--
-- If one or more of the following is true, DynamoDB rejects the entire
-- batch write operation:
--
-- -   One or more tables specified in the @BatchWriteItem@ request does
--     not exist.
--
-- -   Primary key attributes specified on an item in the request do not
--     match those in the corresponding table\'s primary key schema.
--
-- -   You try to perform multiple operations on the same item in the same
--     @BatchWriteItem@ request. For example, you cannot put and delete the
--     same item in the same @BatchWriteItem@ request.
--
-- -   Your request contains at least two items with identical hash and
--     range keys (which essentially is two put operations).
--
-- -   There are more than 25 requests in the batch.
--
-- -   Any individual item in a batch exceeds 400 KB.
--
-- -   The total request size exceeds 16 MB.
module Amazonka.DynamoDB.BatchWriteItem
  ( -- * Creating a Request
    BatchWriteItem (..),
    newBatchWriteItem,

    -- * Request Lenses
    batchWriteItem_returnConsumedCapacity,
    batchWriteItem_returnItemCollectionMetrics,
    batchWriteItem_requestItems,

    -- * Destructuring the Response
    BatchWriteItemResponse (..),
    newBatchWriteItemResponse,

    -- * Response Lenses
    batchWriteItemResponse_consumedCapacity,
    batchWriteItemResponse_itemCollectionMetrics,
    batchWriteItemResponse_httpStatus,
    batchWriteItemResponse_unprocessedItems,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.DynamoDB.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | Represents the input of a @BatchWriteItem@ operation.
--
-- /See:/ 'newBatchWriteItem' smart constructor.
data BatchWriteItem = BatchWriteItem'
  { BatchWriteItem -> Maybe ReturnConsumedCapacity
returnConsumedCapacity :: Prelude.Maybe ReturnConsumedCapacity,
    -- | Determines whether item collection metrics are returned. If set to
    -- @SIZE@, the response includes statistics about item collections, if any,
    -- that were modified during the operation are returned in the response. If
    -- set to @NONE@ (the default), no statistics are returned.
    BatchWriteItem -> Maybe ReturnItemCollectionMetrics
returnItemCollectionMetrics :: Prelude.Maybe ReturnItemCollectionMetrics,
    -- | A map of one or more table names and, for each table, a list of
    -- operations to be performed (@DeleteRequest@ or @PutRequest@). Each
    -- element in the map consists of the following:
    --
    -- -   @DeleteRequest@ - Perform a @DeleteItem@ operation on the specified
    --     item. The item to be deleted is identified by a @Key@ subelement:
    --
    --     -   @Key@ - A map of primary key attribute values that uniquely
    --         identify the item. Each entry in this map consists of an
    --         attribute name and an attribute value. For each primary key, you
    --         must provide /all/ of the key attributes. For example, with a
    --         simple primary key, you only need to provide a value for the
    --         partition key. For a composite primary key, you must provide
    --         values for /both/ the partition key and the sort key.
    --
    -- -   @PutRequest@ - Perform a @PutItem@ operation on the specified item.
    --     The item to be put is identified by an @Item@ subelement:
    --
    --     -   @Item@ - A map of attributes and their values. Each entry in
    --         this map consists of an attribute name and an attribute value.
    --         Attribute values must not be null; string and binary type
    --         attributes must have lengths greater than zero; and set type
    --         attributes must not be empty. Requests that contain empty values
    --         are rejected with a @ValidationException@ exception.
    --
    --         If you specify any attributes that are part of an index key,
    --         then the data types for those attributes must match those of the
    --         schema in the table\'s attribute definition.
    BatchWriteItem -> HashMap Text (NonEmpty WriteRequest)
requestItems :: Prelude.HashMap Prelude.Text (Prelude.NonEmpty WriteRequest)
  }
  deriving (BatchWriteItem -> BatchWriteItem -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchWriteItem -> BatchWriteItem -> Bool
$c/= :: BatchWriteItem -> BatchWriteItem -> Bool
== :: BatchWriteItem -> BatchWriteItem -> Bool
$c== :: BatchWriteItem -> BatchWriteItem -> Bool
Prelude.Eq, ReadPrec [BatchWriteItem]
ReadPrec BatchWriteItem
Int -> ReadS BatchWriteItem
ReadS [BatchWriteItem]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchWriteItem]
$creadListPrec :: ReadPrec [BatchWriteItem]
readPrec :: ReadPrec BatchWriteItem
$creadPrec :: ReadPrec BatchWriteItem
readList :: ReadS [BatchWriteItem]
$creadList :: ReadS [BatchWriteItem]
readsPrec :: Int -> ReadS BatchWriteItem
$creadsPrec :: Int -> ReadS BatchWriteItem
Prelude.Read, Int -> BatchWriteItem -> ShowS
[BatchWriteItem] -> ShowS
BatchWriteItem -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchWriteItem] -> ShowS
$cshowList :: [BatchWriteItem] -> ShowS
show :: BatchWriteItem -> String
$cshow :: BatchWriteItem -> String
showsPrec :: Int -> BatchWriteItem -> ShowS
$cshowsPrec :: Int -> BatchWriteItem -> ShowS
Prelude.Show, forall x. Rep BatchWriteItem x -> BatchWriteItem
forall x. BatchWriteItem -> Rep BatchWriteItem x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BatchWriteItem x -> BatchWriteItem
$cfrom :: forall x. BatchWriteItem -> Rep BatchWriteItem x
Prelude.Generic)

-- |
-- Create a value of 'BatchWriteItem' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'returnConsumedCapacity', 'batchWriteItem_returnConsumedCapacity' - Undocumented member.
--
-- 'returnItemCollectionMetrics', 'batchWriteItem_returnItemCollectionMetrics' - Determines whether item collection metrics are returned. If set to
-- @SIZE@, the response includes statistics about item collections, if any,
-- that were modified during the operation are returned in the response. If
-- set to @NONE@ (the default), no statistics are returned.
--
-- 'requestItems', 'batchWriteItem_requestItems' - A map of one or more table names and, for each table, a list of
-- operations to be performed (@DeleteRequest@ or @PutRequest@). Each
-- element in the map consists of the following:
--
-- -   @DeleteRequest@ - Perform a @DeleteItem@ operation on the specified
--     item. The item to be deleted is identified by a @Key@ subelement:
--
--     -   @Key@ - A map of primary key attribute values that uniquely
--         identify the item. Each entry in this map consists of an
--         attribute name and an attribute value. For each primary key, you
--         must provide /all/ of the key attributes. For example, with a
--         simple primary key, you only need to provide a value for the
--         partition key. For a composite primary key, you must provide
--         values for /both/ the partition key and the sort key.
--
-- -   @PutRequest@ - Perform a @PutItem@ operation on the specified item.
--     The item to be put is identified by an @Item@ subelement:
--
--     -   @Item@ - A map of attributes and their values. Each entry in
--         this map consists of an attribute name and an attribute value.
--         Attribute values must not be null; string and binary type
--         attributes must have lengths greater than zero; and set type
--         attributes must not be empty. Requests that contain empty values
--         are rejected with a @ValidationException@ exception.
--
--         If you specify any attributes that are part of an index key,
--         then the data types for those attributes must match those of the
--         schema in the table\'s attribute definition.
newBatchWriteItem ::
  BatchWriteItem
newBatchWriteItem :: BatchWriteItem
newBatchWriteItem =
  BatchWriteItem'
    { $sel:returnConsumedCapacity:BatchWriteItem' :: Maybe ReturnConsumedCapacity
returnConsumedCapacity =
        forall a. Maybe a
Prelude.Nothing,
      $sel:returnItemCollectionMetrics:BatchWriteItem' :: Maybe ReturnItemCollectionMetrics
returnItemCollectionMetrics = forall a. Maybe a
Prelude.Nothing,
      $sel:requestItems:BatchWriteItem' :: HashMap Text (NonEmpty WriteRequest)
requestItems = forall a. Monoid a => a
Prelude.mempty
    }

-- | Undocumented member.
batchWriteItem_returnConsumedCapacity :: Lens.Lens' BatchWriteItem (Prelude.Maybe ReturnConsumedCapacity)
batchWriteItem_returnConsumedCapacity :: Lens' BatchWriteItem (Maybe ReturnConsumedCapacity)
batchWriteItem_returnConsumedCapacity = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchWriteItem' {Maybe ReturnConsumedCapacity
returnConsumedCapacity :: Maybe ReturnConsumedCapacity
$sel:returnConsumedCapacity:BatchWriteItem' :: BatchWriteItem -> Maybe ReturnConsumedCapacity
returnConsumedCapacity} -> Maybe ReturnConsumedCapacity
returnConsumedCapacity) (\s :: BatchWriteItem
s@BatchWriteItem' {} Maybe ReturnConsumedCapacity
a -> BatchWriteItem
s {$sel:returnConsumedCapacity:BatchWriteItem' :: Maybe ReturnConsumedCapacity
returnConsumedCapacity = Maybe ReturnConsumedCapacity
a} :: BatchWriteItem)

-- | Determines whether item collection metrics are returned. If set to
-- @SIZE@, the response includes statistics about item collections, if any,
-- that were modified during the operation are returned in the response. If
-- set to @NONE@ (the default), no statistics are returned.
batchWriteItem_returnItemCollectionMetrics :: Lens.Lens' BatchWriteItem (Prelude.Maybe ReturnItemCollectionMetrics)
batchWriteItem_returnItemCollectionMetrics :: Lens' BatchWriteItem (Maybe ReturnItemCollectionMetrics)
batchWriteItem_returnItemCollectionMetrics = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchWriteItem' {Maybe ReturnItemCollectionMetrics
returnItemCollectionMetrics :: Maybe ReturnItemCollectionMetrics
$sel:returnItemCollectionMetrics:BatchWriteItem' :: BatchWriteItem -> Maybe ReturnItemCollectionMetrics
returnItemCollectionMetrics} -> Maybe ReturnItemCollectionMetrics
returnItemCollectionMetrics) (\s :: BatchWriteItem
s@BatchWriteItem' {} Maybe ReturnItemCollectionMetrics
a -> BatchWriteItem
s {$sel:returnItemCollectionMetrics:BatchWriteItem' :: Maybe ReturnItemCollectionMetrics
returnItemCollectionMetrics = Maybe ReturnItemCollectionMetrics
a} :: BatchWriteItem)

-- | A map of one or more table names and, for each table, a list of
-- operations to be performed (@DeleteRequest@ or @PutRequest@). Each
-- element in the map consists of the following:
--
-- -   @DeleteRequest@ - Perform a @DeleteItem@ operation on the specified
--     item. The item to be deleted is identified by a @Key@ subelement:
--
--     -   @Key@ - A map of primary key attribute values that uniquely
--         identify the item. Each entry in this map consists of an
--         attribute name and an attribute value. For each primary key, you
--         must provide /all/ of the key attributes. For example, with a
--         simple primary key, you only need to provide a value for the
--         partition key. For a composite primary key, you must provide
--         values for /both/ the partition key and the sort key.
--
-- -   @PutRequest@ - Perform a @PutItem@ operation on the specified item.
--     The item to be put is identified by an @Item@ subelement:
--
--     -   @Item@ - A map of attributes and their values. Each entry in
--         this map consists of an attribute name and an attribute value.
--         Attribute values must not be null; string and binary type
--         attributes must have lengths greater than zero; and set type
--         attributes must not be empty. Requests that contain empty values
--         are rejected with a @ValidationException@ exception.
--
--         If you specify any attributes that are part of an index key,
--         then the data types for those attributes must match those of the
--         schema in the table\'s attribute definition.
batchWriteItem_requestItems :: Lens.Lens' BatchWriteItem (Prelude.HashMap Prelude.Text (Prelude.NonEmpty WriteRequest))
batchWriteItem_requestItems :: Lens' BatchWriteItem (HashMap Text (NonEmpty WriteRequest))
batchWriteItem_requestItems = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchWriteItem' {HashMap Text (NonEmpty WriteRequest)
requestItems :: HashMap Text (NonEmpty WriteRequest)
$sel:requestItems:BatchWriteItem' :: BatchWriteItem -> HashMap Text (NonEmpty WriteRequest)
requestItems} -> HashMap Text (NonEmpty WriteRequest)
requestItems) (\s :: BatchWriteItem
s@BatchWriteItem' {} HashMap Text (NonEmpty WriteRequest)
a -> BatchWriteItem
s {$sel:requestItems:BatchWriteItem' :: HashMap Text (NonEmpty WriteRequest)
requestItems = HashMap Text (NonEmpty WriteRequest)
a} :: BatchWriteItem) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest BatchWriteItem where
  type
    AWSResponse BatchWriteItem =
      BatchWriteItemResponse
  request :: (Service -> Service) -> BatchWriteItem -> Request BatchWriteItem
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy BatchWriteItem
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse BatchWriteItem)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe [ConsumedCapacity]
-> Maybe (HashMap Text [ItemCollectionMetrics])
-> Int
-> HashMap Text (NonEmpty WriteRequest)
-> BatchWriteItemResponse
BatchWriteItemResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x
                            forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"ConsumedCapacity"
                            forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                        )
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x
                            forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"ItemCollectionMetrics"
                            forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                        )
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x
                            forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"UnprocessedItems"
                            forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable BatchWriteItem where
  hashWithSalt :: Int -> BatchWriteItem -> Int
hashWithSalt Int
_salt BatchWriteItem' {Maybe ReturnItemCollectionMetrics
Maybe ReturnConsumedCapacity
HashMap Text (NonEmpty WriteRequest)
requestItems :: HashMap Text (NonEmpty WriteRequest)
returnItemCollectionMetrics :: Maybe ReturnItemCollectionMetrics
returnConsumedCapacity :: Maybe ReturnConsumedCapacity
$sel:requestItems:BatchWriteItem' :: BatchWriteItem -> HashMap Text (NonEmpty WriteRequest)
$sel:returnItemCollectionMetrics:BatchWriteItem' :: BatchWriteItem -> Maybe ReturnItemCollectionMetrics
$sel:returnConsumedCapacity:BatchWriteItem' :: BatchWriteItem -> Maybe ReturnConsumedCapacity
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ReturnConsumedCapacity
returnConsumedCapacity
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ReturnItemCollectionMetrics
returnItemCollectionMetrics
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` HashMap Text (NonEmpty WriteRequest)
requestItems

instance Prelude.NFData BatchWriteItem where
  rnf :: BatchWriteItem -> ()
rnf BatchWriteItem' {Maybe ReturnItemCollectionMetrics
Maybe ReturnConsumedCapacity
HashMap Text (NonEmpty WriteRequest)
requestItems :: HashMap Text (NonEmpty WriteRequest)
returnItemCollectionMetrics :: Maybe ReturnItemCollectionMetrics
returnConsumedCapacity :: Maybe ReturnConsumedCapacity
$sel:requestItems:BatchWriteItem' :: BatchWriteItem -> HashMap Text (NonEmpty WriteRequest)
$sel:returnItemCollectionMetrics:BatchWriteItem' :: BatchWriteItem -> Maybe ReturnItemCollectionMetrics
$sel:returnConsumedCapacity:BatchWriteItem' :: BatchWriteItem -> Maybe ReturnConsumedCapacity
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ReturnConsumedCapacity
returnConsumedCapacity
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ReturnItemCollectionMetrics
returnItemCollectionMetrics
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf HashMap Text (NonEmpty WriteRequest)
requestItems

instance Data.ToHeaders BatchWriteItem where
  toHeaders :: BatchWriteItem -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"DynamoDB_20120810.BatchWriteItem" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.0" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON BatchWriteItem where
  toJSON :: BatchWriteItem -> Value
toJSON BatchWriteItem' {Maybe ReturnItemCollectionMetrics
Maybe ReturnConsumedCapacity
HashMap Text (NonEmpty WriteRequest)
requestItems :: HashMap Text (NonEmpty WriteRequest)
returnItemCollectionMetrics :: Maybe ReturnItemCollectionMetrics
returnConsumedCapacity :: Maybe ReturnConsumedCapacity
$sel:requestItems:BatchWriteItem' :: BatchWriteItem -> HashMap Text (NonEmpty WriteRequest)
$sel:returnItemCollectionMetrics:BatchWriteItem' :: BatchWriteItem -> Maybe ReturnItemCollectionMetrics
$sel:returnConsumedCapacity:BatchWriteItem' :: BatchWriteItem -> Maybe ReturnConsumedCapacity
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"ReturnConsumedCapacity" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ReturnConsumedCapacity
returnConsumedCapacity,
            (Key
"ReturnItemCollectionMetrics" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ReturnItemCollectionMetrics
returnItemCollectionMetrics,
            forall a. a -> Maybe a
Prelude.Just (Key
"RequestItems" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= HashMap Text (NonEmpty WriteRequest)
requestItems)
          ]
      )

instance Data.ToPath BatchWriteItem where
  toPath :: BatchWriteItem -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Data.ToQuery BatchWriteItem where
  toQuery :: BatchWriteItem -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

-- | Represents the output of a @BatchWriteItem@ operation.
--
-- /See:/ 'newBatchWriteItemResponse' smart constructor.
data BatchWriteItemResponse = BatchWriteItemResponse'
  { -- | The capacity units consumed by the entire @BatchWriteItem@ operation.
    --
    -- Each element consists of:
    --
    -- -   @TableName@ - The table that consumed the provisioned throughput.
    --
    -- -   @CapacityUnits@ - The total number of capacity units consumed.
    BatchWriteItemResponse -> Maybe [ConsumedCapacity]
consumedCapacity :: Prelude.Maybe [ConsumedCapacity],
    -- | A list of tables that were processed by @BatchWriteItem@ and, for each
    -- table, information about any item collections that were affected by
    -- individual @DeleteItem@ or @PutItem@ operations.
    --
    -- Each entry consists of the following subelements:
    --
    -- -   @ItemCollectionKey@ - The partition key value of the item
    --     collection. This is the same as the partition key value of the item.
    --
    -- -   @SizeEstimateRangeGB@ - An estimate of item collection size,
    --     expressed in GB. This is a two-element array containing a lower
    --     bound and an upper bound for the estimate. The estimate includes the
    --     size of all the items in the table, plus the size of all attributes
    --     projected into all of the local secondary indexes on the table. Use
    --     this estimate to measure whether a local secondary index is
    --     approaching its size limit.
    --
    --     The estimate is subject to change over time; therefore, do not rely
    --     on the precision or accuracy of the estimate.
    BatchWriteItemResponse
-> Maybe (HashMap Text [ItemCollectionMetrics])
itemCollectionMetrics :: Prelude.Maybe (Prelude.HashMap Prelude.Text [ItemCollectionMetrics]),
    -- | The response's http status code.
    BatchWriteItemResponse -> Int
httpStatus :: Prelude.Int,
    -- | A map of tables and requests against those tables that were not
    -- processed. The @UnprocessedItems@ value is in the same form as
    -- @RequestItems@, so you can provide this value directly to a subsequent
    -- @BatchWriteItem@ operation. For more information, see @RequestItems@ in
    -- the Request Parameters section.
    --
    -- Each @UnprocessedItems@ entry consists of a table name and, for that
    -- table, a list of operations to perform (@DeleteRequest@ or
    -- @PutRequest@).
    --
    -- -   @DeleteRequest@ - Perform a @DeleteItem@ operation on the specified
    --     item. The item to be deleted is identified by a @Key@ subelement:
    --
    --     -   @Key@ - A map of primary key attribute values that uniquely
    --         identify the item. Each entry in this map consists of an
    --         attribute name and an attribute value.
    --
    -- -   @PutRequest@ - Perform a @PutItem@ operation on the specified item.
    --     The item to be put is identified by an @Item@ subelement:
    --
    --     -   @Item@ - A map of attributes and their values. Each entry in
    --         this map consists of an attribute name and an attribute value.
    --         Attribute values must not be null; string and binary type
    --         attributes must have lengths greater than zero; and set type
    --         attributes must not be empty. Requests that contain empty values
    --         will be rejected with a @ValidationException@ exception.
    --
    --         If you specify any attributes that are part of an index key,
    --         then the data types for those attributes must match those of the
    --         schema in the table\'s attribute definition.
    --
    -- If there are no unprocessed items remaining, the response contains an
    -- empty @UnprocessedItems@ map.
    BatchWriteItemResponse -> HashMap Text (NonEmpty WriteRequest)
unprocessedItems :: Prelude.HashMap Prelude.Text (Prelude.NonEmpty WriteRequest)
  }
  deriving (BatchWriteItemResponse -> BatchWriteItemResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchWriteItemResponse -> BatchWriteItemResponse -> Bool
$c/= :: BatchWriteItemResponse -> BatchWriteItemResponse -> Bool
== :: BatchWriteItemResponse -> BatchWriteItemResponse -> Bool
$c== :: BatchWriteItemResponse -> BatchWriteItemResponse -> Bool
Prelude.Eq, ReadPrec [BatchWriteItemResponse]
ReadPrec BatchWriteItemResponse
Int -> ReadS BatchWriteItemResponse
ReadS [BatchWriteItemResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchWriteItemResponse]
$creadListPrec :: ReadPrec [BatchWriteItemResponse]
readPrec :: ReadPrec BatchWriteItemResponse
$creadPrec :: ReadPrec BatchWriteItemResponse
readList :: ReadS [BatchWriteItemResponse]
$creadList :: ReadS [BatchWriteItemResponse]
readsPrec :: Int -> ReadS BatchWriteItemResponse
$creadsPrec :: Int -> ReadS BatchWriteItemResponse
Prelude.Read, Int -> BatchWriteItemResponse -> ShowS
[BatchWriteItemResponse] -> ShowS
BatchWriteItemResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchWriteItemResponse] -> ShowS
$cshowList :: [BatchWriteItemResponse] -> ShowS
show :: BatchWriteItemResponse -> String
$cshow :: BatchWriteItemResponse -> String
showsPrec :: Int -> BatchWriteItemResponse -> ShowS
$cshowsPrec :: Int -> BatchWriteItemResponse -> ShowS
Prelude.Show, forall x. Rep BatchWriteItemResponse x -> BatchWriteItemResponse
forall x. BatchWriteItemResponse -> Rep BatchWriteItemResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BatchWriteItemResponse x -> BatchWriteItemResponse
$cfrom :: forall x. BatchWriteItemResponse -> Rep BatchWriteItemResponse x
Prelude.Generic)

-- |
-- Create a value of 'BatchWriteItemResponse' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'consumedCapacity', 'batchWriteItemResponse_consumedCapacity' - The capacity units consumed by the entire @BatchWriteItem@ operation.
--
-- Each element consists of:
--
-- -   @TableName@ - The table that consumed the provisioned throughput.
--
-- -   @CapacityUnits@ - The total number of capacity units consumed.
--
-- 'itemCollectionMetrics', 'batchWriteItemResponse_itemCollectionMetrics' - A list of tables that were processed by @BatchWriteItem@ and, for each
-- table, information about any item collections that were affected by
-- individual @DeleteItem@ or @PutItem@ operations.
--
-- Each entry consists of the following subelements:
--
-- -   @ItemCollectionKey@ - The partition key value of the item
--     collection. This is the same as the partition key value of the item.
--
-- -   @SizeEstimateRangeGB@ - An estimate of item collection size,
--     expressed in GB. This is a two-element array containing a lower
--     bound and an upper bound for the estimate. The estimate includes the
--     size of all the items in the table, plus the size of all attributes
--     projected into all of the local secondary indexes on the table. Use
--     this estimate to measure whether a local secondary index is
--     approaching its size limit.
--
--     The estimate is subject to change over time; therefore, do not rely
--     on the precision or accuracy of the estimate.
--
-- 'httpStatus', 'batchWriteItemResponse_httpStatus' - The response's http status code.
--
-- 'unprocessedItems', 'batchWriteItemResponse_unprocessedItems' - A map of tables and requests against those tables that were not
-- processed. The @UnprocessedItems@ value is in the same form as
-- @RequestItems@, so you can provide this value directly to a subsequent
-- @BatchWriteItem@ operation. For more information, see @RequestItems@ in
-- the Request Parameters section.
--
-- Each @UnprocessedItems@ entry consists of a table name and, for that
-- table, a list of operations to perform (@DeleteRequest@ or
-- @PutRequest@).
--
-- -   @DeleteRequest@ - Perform a @DeleteItem@ operation on the specified
--     item. The item to be deleted is identified by a @Key@ subelement:
--
--     -   @Key@ - A map of primary key attribute values that uniquely
--         identify the item. Each entry in this map consists of an
--         attribute name and an attribute value.
--
-- -   @PutRequest@ - Perform a @PutItem@ operation on the specified item.
--     The item to be put is identified by an @Item@ subelement:
--
--     -   @Item@ - A map of attributes and their values. Each entry in
--         this map consists of an attribute name and an attribute value.
--         Attribute values must not be null; string and binary type
--         attributes must have lengths greater than zero; and set type
--         attributes must not be empty. Requests that contain empty values
--         will be rejected with a @ValidationException@ exception.
--
--         If you specify any attributes that are part of an index key,
--         then the data types for those attributes must match those of the
--         schema in the table\'s attribute definition.
--
-- If there are no unprocessed items remaining, the response contains an
-- empty @UnprocessedItems@ map.
newBatchWriteItemResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  BatchWriteItemResponse
newBatchWriteItemResponse :: Int -> BatchWriteItemResponse
newBatchWriteItemResponse Int
pHttpStatus_ =
  BatchWriteItemResponse'
    { $sel:consumedCapacity:BatchWriteItemResponse' :: Maybe [ConsumedCapacity]
consumedCapacity =
        forall a. Maybe a
Prelude.Nothing,
      $sel:itemCollectionMetrics:BatchWriteItemResponse' :: Maybe (HashMap Text [ItemCollectionMetrics])
itemCollectionMetrics = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:BatchWriteItemResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:unprocessedItems:BatchWriteItemResponse' :: HashMap Text (NonEmpty WriteRequest)
unprocessedItems = forall a. Monoid a => a
Prelude.mempty
    }

-- | The capacity units consumed by the entire @BatchWriteItem@ operation.
--
-- Each element consists of:
--
-- -   @TableName@ - The table that consumed the provisioned throughput.
--
-- -   @CapacityUnits@ - The total number of capacity units consumed.
batchWriteItemResponse_consumedCapacity :: Lens.Lens' BatchWriteItemResponse (Prelude.Maybe [ConsumedCapacity])
batchWriteItemResponse_consumedCapacity :: Lens' BatchWriteItemResponse (Maybe [ConsumedCapacity])
batchWriteItemResponse_consumedCapacity = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchWriteItemResponse' {Maybe [ConsumedCapacity]
consumedCapacity :: Maybe [ConsumedCapacity]
$sel:consumedCapacity:BatchWriteItemResponse' :: BatchWriteItemResponse -> Maybe [ConsumedCapacity]
consumedCapacity} -> Maybe [ConsumedCapacity]
consumedCapacity) (\s :: BatchWriteItemResponse
s@BatchWriteItemResponse' {} Maybe [ConsumedCapacity]
a -> BatchWriteItemResponse
s {$sel:consumedCapacity:BatchWriteItemResponse' :: Maybe [ConsumedCapacity]
consumedCapacity = Maybe [ConsumedCapacity]
a} :: BatchWriteItemResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A list of tables that were processed by @BatchWriteItem@ and, for each
-- table, information about any item collections that were affected by
-- individual @DeleteItem@ or @PutItem@ operations.
--
-- Each entry consists of the following subelements:
--
-- -   @ItemCollectionKey@ - The partition key value of the item
--     collection. This is the same as the partition key value of the item.
--
-- -   @SizeEstimateRangeGB@ - An estimate of item collection size,
--     expressed in GB. This is a two-element array containing a lower
--     bound and an upper bound for the estimate. The estimate includes the
--     size of all the items in the table, plus the size of all attributes
--     projected into all of the local secondary indexes on the table. Use
--     this estimate to measure whether a local secondary index is
--     approaching its size limit.
--
--     The estimate is subject to change over time; therefore, do not rely
--     on the precision or accuracy of the estimate.
batchWriteItemResponse_itemCollectionMetrics :: Lens.Lens' BatchWriteItemResponse (Prelude.Maybe (Prelude.HashMap Prelude.Text [ItemCollectionMetrics]))
batchWriteItemResponse_itemCollectionMetrics :: Lens'
  BatchWriteItemResponse
  (Maybe (HashMap Text [ItemCollectionMetrics]))
batchWriteItemResponse_itemCollectionMetrics = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchWriteItemResponse' {Maybe (HashMap Text [ItemCollectionMetrics])
itemCollectionMetrics :: Maybe (HashMap Text [ItemCollectionMetrics])
$sel:itemCollectionMetrics:BatchWriteItemResponse' :: BatchWriteItemResponse
-> Maybe (HashMap Text [ItemCollectionMetrics])
itemCollectionMetrics} -> Maybe (HashMap Text [ItemCollectionMetrics])
itemCollectionMetrics) (\s :: BatchWriteItemResponse
s@BatchWriteItemResponse' {} Maybe (HashMap Text [ItemCollectionMetrics])
a -> BatchWriteItemResponse
s {$sel:itemCollectionMetrics:BatchWriteItemResponse' :: Maybe (HashMap Text [ItemCollectionMetrics])
itemCollectionMetrics = Maybe (HashMap Text [ItemCollectionMetrics])
a} :: BatchWriteItemResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The response's http status code.
batchWriteItemResponse_httpStatus :: Lens.Lens' BatchWriteItemResponse Prelude.Int
batchWriteItemResponse_httpStatus :: Lens' BatchWriteItemResponse Int
batchWriteItemResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchWriteItemResponse' {Int
httpStatus :: Int
$sel:httpStatus:BatchWriteItemResponse' :: BatchWriteItemResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: BatchWriteItemResponse
s@BatchWriteItemResponse' {} Int
a -> BatchWriteItemResponse
s {$sel:httpStatus:BatchWriteItemResponse' :: Int
httpStatus = Int
a} :: BatchWriteItemResponse)

-- | A map of tables and requests against those tables that were not
-- processed. The @UnprocessedItems@ value is in the same form as
-- @RequestItems@, so you can provide this value directly to a subsequent
-- @BatchWriteItem@ operation. For more information, see @RequestItems@ in
-- the Request Parameters section.
--
-- Each @UnprocessedItems@ entry consists of a table name and, for that
-- table, a list of operations to perform (@DeleteRequest@ or
-- @PutRequest@).
--
-- -   @DeleteRequest@ - Perform a @DeleteItem@ operation on the specified
--     item. The item to be deleted is identified by a @Key@ subelement:
--
--     -   @Key@ - A map of primary key attribute values that uniquely
--         identify the item. Each entry in this map consists of an
--         attribute name and an attribute value.
--
-- -   @PutRequest@ - Perform a @PutItem@ operation on the specified item.
--     The item to be put is identified by an @Item@ subelement:
--
--     -   @Item@ - A map of attributes and their values. Each entry in
--         this map consists of an attribute name and an attribute value.
--         Attribute values must not be null; string and binary type
--         attributes must have lengths greater than zero; and set type
--         attributes must not be empty. Requests that contain empty values
--         will be rejected with a @ValidationException@ exception.
--
--         If you specify any attributes that are part of an index key,
--         then the data types for those attributes must match those of the
--         schema in the table\'s attribute definition.
--
-- If there are no unprocessed items remaining, the response contains an
-- empty @UnprocessedItems@ map.
batchWriteItemResponse_unprocessedItems :: Lens.Lens' BatchWriteItemResponse (Prelude.HashMap Prelude.Text (Prelude.NonEmpty WriteRequest))
batchWriteItemResponse_unprocessedItems :: Lens' BatchWriteItemResponse (HashMap Text (NonEmpty WriteRequest))
batchWriteItemResponse_unprocessedItems = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchWriteItemResponse' {HashMap Text (NonEmpty WriteRequest)
unprocessedItems :: HashMap Text (NonEmpty WriteRequest)
$sel:unprocessedItems:BatchWriteItemResponse' :: BatchWriteItemResponse -> HashMap Text (NonEmpty WriteRequest)
unprocessedItems} -> HashMap Text (NonEmpty WriteRequest)
unprocessedItems) (\s :: BatchWriteItemResponse
s@BatchWriteItemResponse' {} HashMap Text (NonEmpty WriteRequest)
a -> BatchWriteItemResponse
s {$sel:unprocessedItems:BatchWriteItemResponse' :: HashMap Text (NonEmpty WriteRequest)
unprocessedItems = HashMap Text (NonEmpty WriteRequest)
a} :: BatchWriteItemResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Prelude.NFData BatchWriteItemResponse where
  rnf :: BatchWriteItemResponse -> ()
rnf BatchWriteItemResponse' {Int
Maybe [ConsumedCapacity]
Maybe (HashMap Text [ItemCollectionMetrics])
HashMap Text (NonEmpty WriteRequest)
unprocessedItems :: HashMap Text (NonEmpty WriteRequest)
httpStatus :: Int
itemCollectionMetrics :: Maybe (HashMap Text [ItemCollectionMetrics])
consumedCapacity :: Maybe [ConsumedCapacity]
$sel:unprocessedItems:BatchWriteItemResponse' :: BatchWriteItemResponse -> HashMap Text (NonEmpty WriteRequest)
$sel:httpStatus:BatchWriteItemResponse' :: BatchWriteItemResponse -> Int
$sel:itemCollectionMetrics:BatchWriteItemResponse' :: BatchWriteItemResponse
-> Maybe (HashMap Text [ItemCollectionMetrics])
$sel:consumedCapacity:BatchWriteItemResponse' :: BatchWriteItemResponse -> Maybe [ConsumedCapacity]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [ConsumedCapacity]
consumedCapacity
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text [ItemCollectionMetrics])
itemCollectionMetrics
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf HashMap Text (NonEmpty WriteRequest)
unprocessedItems