{-# 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.Glue.BatchCreatePartition
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates one or more partitions in a batch operation.
module Amazonka.Glue.BatchCreatePartition
  ( -- * Creating a Request
    BatchCreatePartition (..),
    newBatchCreatePartition,

    -- * Request Lenses
    batchCreatePartition_catalogId,
    batchCreatePartition_databaseName,
    batchCreatePartition_tableName,
    batchCreatePartition_partitionInputList,

    -- * Destructuring the Response
    BatchCreatePartitionResponse (..),
    newBatchCreatePartitionResponse,

    -- * Response Lenses
    batchCreatePartitionResponse_errors,
    batchCreatePartitionResponse_httpStatus,
  )
where

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

-- | /See:/ 'newBatchCreatePartition' smart constructor.
data BatchCreatePartition = BatchCreatePartition'
  { -- | The ID of the catalog in which the partition is to be created.
    -- Currently, this should be the Amazon Web Services account ID.
    BatchCreatePartition -> Maybe Text
catalogId :: Prelude.Maybe Prelude.Text,
    -- | The name of the metadata database in which the partition is to be
    -- created.
    BatchCreatePartition -> Text
databaseName :: Prelude.Text,
    -- | The name of the metadata table in which the partition is to be created.
    BatchCreatePartition -> Text
tableName :: Prelude.Text,
    -- | A list of @PartitionInput@ structures that define the partitions to be
    -- created.
    BatchCreatePartition -> [PartitionInput]
partitionInputList :: [PartitionInput]
  }
  deriving (BatchCreatePartition -> BatchCreatePartition -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchCreatePartition -> BatchCreatePartition -> Bool
$c/= :: BatchCreatePartition -> BatchCreatePartition -> Bool
== :: BatchCreatePartition -> BatchCreatePartition -> Bool
$c== :: BatchCreatePartition -> BatchCreatePartition -> Bool
Prelude.Eq, ReadPrec [BatchCreatePartition]
ReadPrec BatchCreatePartition
Int -> ReadS BatchCreatePartition
ReadS [BatchCreatePartition]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchCreatePartition]
$creadListPrec :: ReadPrec [BatchCreatePartition]
readPrec :: ReadPrec BatchCreatePartition
$creadPrec :: ReadPrec BatchCreatePartition
readList :: ReadS [BatchCreatePartition]
$creadList :: ReadS [BatchCreatePartition]
readsPrec :: Int -> ReadS BatchCreatePartition
$creadsPrec :: Int -> ReadS BatchCreatePartition
Prelude.Read, Int -> BatchCreatePartition -> ShowS
[BatchCreatePartition] -> ShowS
BatchCreatePartition -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchCreatePartition] -> ShowS
$cshowList :: [BatchCreatePartition] -> ShowS
show :: BatchCreatePartition -> String
$cshow :: BatchCreatePartition -> String
showsPrec :: Int -> BatchCreatePartition -> ShowS
$cshowsPrec :: Int -> BatchCreatePartition -> ShowS
Prelude.Show, forall x. Rep BatchCreatePartition x -> BatchCreatePartition
forall x. BatchCreatePartition -> Rep BatchCreatePartition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BatchCreatePartition x -> BatchCreatePartition
$cfrom :: forall x. BatchCreatePartition -> Rep BatchCreatePartition x
Prelude.Generic)

-- |
-- Create a value of 'BatchCreatePartition' 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:
--
-- 'catalogId', 'batchCreatePartition_catalogId' - The ID of the catalog in which the partition is to be created.
-- Currently, this should be the Amazon Web Services account ID.
--
-- 'databaseName', 'batchCreatePartition_databaseName' - The name of the metadata database in which the partition is to be
-- created.
--
-- 'tableName', 'batchCreatePartition_tableName' - The name of the metadata table in which the partition is to be created.
--
-- 'partitionInputList', 'batchCreatePartition_partitionInputList' - A list of @PartitionInput@ structures that define the partitions to be
-- created.
newBatchCreatePartition ::
  -- | 'databaseName'
  Prelude.Text ->
  -- | 'tableName'
  Prelude.Text ->
  BatchCreatePartition
newBatchCreatePartition :: Text -> Text -> BatchCreatePartition
newBatchCreatePartition Text
pDatabaseName_ Text
pTableName_ =
  BatchCreatePartition'
    { $sel:catalogId:BatchCreatePartition' :: Maybe Text
catalogId = forall a. Maybe a
Prelude.Nothing,
      $sel:databaseName:BatchCreatePartition' :: Text
databaseName = Text
pDatabaseName_,
      $sel:tableName:BatchCreatePartition' :: Text
tableName = Text
pTableName_,
      $sel:partitionInputList:BatchCreatePartition' :: [PartitionInput]
partitionInputList = forall a. Monoid a => a
Prelude.mempty
    }

-- | The ID of the catalog in which the partition is to be created.
-- Currently, this should be the Amazon Web Services account ID.
batchCreatePartition_catalogId :: Lens.Lens' BatchCreatePartition (Prelude.Maybe Prelude.Text)
batchCreatePartition_catalogId :: Lens' BatchCreatePartition (Maybe Text)
batchCreatePartition_catalogId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchCreatePartition' {Maybe Text
catalogId :: Maybe Text
$sel:catalogId:BatchCreatePartition' :: BatchCreatePartition -> Maybe Text
catalogId} -> Maybe Text
catalogId) (\s :: BatchCreatePartition
s@BatchCreatePartition' {} Maybe Text
a -> BatchCreatePartition
s {$sel:catalogId:BatchCreatePartition' :: Maybe Text
catalogId = Maybe Text
a} :: BatchCreatePartition)

-- | The name of the metadata database in which the partition is to be
-- created.
batchCreatePartition_databaseName :: Lens.Lens' BatchCreatePartition Prelude.Text
batchCreatePartition_databaseName :: Lens' BatchCreatePartition Text
batchCreatePartition_databaseName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchCreatePartition' {Text
databaseName :: Text
$sel:databaseName:BatchCreatePartition' :: BatchCreatePartition -> Text
databaseName} -> Text
databaseName) (\s :: BatchCreatePartition
s@BatchCreatePartition' {} Text
a -> BatchCreatePartition
s {$sel:databaseName:BatchCreatePartition' :: Text
databaseName = Text
a} :: BatchCreatePartition)

-- | The name of the metadata table in which the partition is to be created.
batchCreatePartition_tableName :: Lens.Lens' BatchCreatePartition Prelude.Text
batchCreatePartition_tableName :: Lens' BatchCreatePartition Text
batchCreatePartition_tableName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchCreatePartition' {Text
tableName :: Text
$sel:tableName:BatchCreatePartition' :: BatchCreatePartition -> Text
tableName} -> Text
tableName) (\s :: BatchCreatePartition
s@BatchCreatePartition' {} Text
a -> BatchCreatePartition
s {$sel:tableName:BatchCreatePartition' :: Text
tableName = Text
a} :: BatchCreatePartition)

-- | A list of @PartitionInput@ structures that define the partitions to be
-- created.
batchCreatePartition_partitionInputList :: Lens.Lens' BatchCreatePartition [PartitionInput]
batchCreatePartition_partitionInputList :: Lens' BatchCreatePartition [PartitionInput]
batchCreatePartition_partitionInputList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchCreatePartition' {[PartitionInput]
partitionInputList :: [PartitionInput]
$sel:partitionInputList:BatchCreatePartition' :: BatchCreatePartition -> [PartitionInput]
partitionInputList} -> [PartitionInput]
partitionInputList) (\s :: BatchCreatePartition
s@BatchCreatePartition' {} [PartitionInput]
a -> BatchCreatePartition
s {$sel:partitionInputList:BatchCreatePartition' :: [PartitionInput]
partitionInputList = [PartitionInput]
a} :: BatchCreatePartition) 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 BatchCreatePartition where
  type
    AWSResponse BatchCreatePartition =
      BatchCreatePartitionResponse
  request :: (Service -> Service)
-> BatchCreatePartition -> Request BatchCreatePartition
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 BatchCreatePartition
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse BatchCreatePartition)))
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 [PartitionError] -> Int -> BatchCreatePartitionResponse
BatchCreatePartitionResponse'
            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
"Errors" 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))
      )

instance Prelude.Hashable BatchCreatePartition where
  hashWithSalt :: Int -> BatchCreatePartition -> Int
hashWithSalt Int
_salt BatchCreatePartition' {[PartitionInput]
Maybe Text
Text
partitionInputList :: [PartitionInput]
tableName :: Text
databaseName :: Text
catalogId :: Maybe Text
$sel:partitionInputList:BatchCreatePartition' :: BatchCreatePartition -> [PartitionInput]
$sel:tableName:BatchCreatePartition' :: BatchCreatePartition -> Text
$sel:databaseName:BatchCreatePartition' :: BatchCreatePartition -> Text
$sel:catalogId:BatchCreatePartition' :: BatchCreatePartition -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
catalogId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
databaseName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
tableName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [PartitionInput]
partitionInputList

instance Prelude.NFData BatchCreatePartition where
  rnf :: BatchCreatePartition -> ()
rnf BatchCreatePartition' {[PartitionInput]
Maybe Text
Text
partitionInputList :: [PartitionInput]
tableName :: Text
databaseName :: Text
catalogId :: Maybe Text
$sel:partitionInputList:BatchCreatePartition' :: BatchCreatePartition -> [PartitionInput]
$sel:tableName:BatchCreatePartition' :: BatchCreatePartition -> Text
$sel:databaseName:BatchCreatePartition' :: BatchCreatePartition -> Text
$sel:catalogId:BatchCreatePartition' :: BatchCreatePartition -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
catalogId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
databaseName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
tableName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [PartitionInput]
partitionInputList

instance Data.ToHeaders BatchCreatePartition where
  toHeaders :: BatchCreatePartition -> 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
"AWSGlue.BatchCreatePartition" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON BatchCreatePartition where
  toJSON :: BatchCreatePartition -> Value
toJSON BatchCreatePartition' {[PartitionInput]
Maybe Text
Text
partitionInputList :: [PartitionInput]
tableName :: Text
databaseName :: Text
catalogId :: Maybe Text
$sel:partitionInputList:BatchCreatePartition' :: BatchCreatePartition -> [PartitionInput]
$sel:tableName:BatchCreatePartition' :: BatchCreatePartition -> Text
$sel:databaseName:BatchCreatePartition' :: BatchCreatePartition -> Text
$sel:catalogId:BatchCreatePartition' :: BatchCreatePartition -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"CatalogId" 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 Text
catalogId,
            forall a. a -> Maybe a
Prelude.Just (Key
"DatabaseName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
databaseName),
            forall a. a -> Maybe a
Prelude.Just (Key
"TableName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
tableName),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"PartitionInputList" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [PartitionInput]
partitionInputList)
          ]
      )

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

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

-- | /See:/ 'newBatchCreatePartitionResponse' smart constructor.
data BatchCreatePartitionResponse = BatchCreatePartitionResponse'
  { -- | The errors encountered when trying to create the requested partitions.
    BatchCreatePartitionResponse -> Maybe [PartitionError]
errors :: Prelude.Maybe [PartitionError],
    -- | The response's http status code.
    BatchCreatePartitionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (BatchCreatePartitionResponse
-> BatchCreatePartitionResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchCreatePartitionResponse
-> BatchCreatePartitionResponse -> Bool
$c/= :: BatchCreatePartitionResponse
-> BatchCreatePartitionResponse -> Bool
== :: BatchCreatePartitionResponse
-> BatchCreatePartitionResponse -> Bool
$c== :: BatchCreatePartitionResponse
-> BatchCreatePartitionResponse -> Bool
Prelude.Eq, ReadPrec [BatchCreatePartitionResponse]
ReadPrec BatchCreatePartitionResponse
Int -> ReadS BatchCreatePartitionResponse
ReadS [BatchCreatePartitionResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchCreatePartitionResponse]
$creadListPrec :: ReadPrec [BatchCreatePartitionResponse]
readPrec :: ReadPrec BatchCreatePartitionResponse
$creadPrec :: ReadPrec BatchCreatePartitionResponse
readList :: ReadS [BatchCreatePartitionResponse]
$creadList :: ReadS [BatchCreatePartitionResponse]
readsPrec :: Int -> ReadS BatchCreatePartitionResponse
$creadsPrec :: Int -> ReadS BatchCreatePartitionResponse
Prelude.Read, Int -> BatchCreatePartitionResponse -> ShowS
[BatchCreatePartitionResponse] -> ShowS
BatchCreatePartitionResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchCreatePartitionResponse] -> ShowS
$cshowList :: [BatchCreatePartitionResponse] -> ShowS
show :: BatchCreatePartitionResponse -> String
$cshow :: BatchCreatePartitionResponse -> String
showsPrec :: Int -> BatchCreatePartitionResponse -> ShowS
$cshowsPrec :: Int -> BatchCreatePartitionResponse -> ShowS
Prelude.Show, forall x.
Rep BatchCreatePartitionResponse x -> BatchCreatePartitionResponse
forall x.
BatchCreatePartitionResponse -> Rep BatchCreatePartitionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep BatchCreatePartitionResponse x -> BatchCreatePartitionResponse
$cfrom :: forall x.
BatchCreatePartitionResponse -> Rep BatchCreatePartitionResponse x
Prelude.Generic)

-- |
-- Create a value of 'BatchCreatePartitionResponse' 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:
--
-- 'errors', 'batchCreatePartitionResponse_errors' - The errors encountered when trying to create the requested partitions.
--
-- 'httpStatus', 'batchCreatePartitionResponse_httpStatus' - The response's http status code.
newBatchCreatePartitionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  BatchCreatePartitionResponse
newBatchCreatePartitionResponse :: Int -> BatchCreatePartitionResponse
newBatchCreatePartitionResponse Int
pHttpStatus_ =
  BatchCreatePartitionResponse'
    { $sel:errors:BatchCreatePartitionResponse' :: Maybe [PartitionError]
errors =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:BatchCreatePartitionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The errors encountered when trying to create the requested partitions.
batchCreatePartitionResponse_errors :: Lens.Lens' BatchCreatePartitionResponse (Prelude.Maybe [PartitionError])
batchCreatePartitionResponse_errors :: Lens' BatchCreatePartitionResponse (Maybe [PartitionError])
batchCreatePartitionResponse_errors = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchCreatePartitionResponse' {Maybe [PartitionError]
errors :: Maybe [PartitionError]
$sel:errors:BatchCreatePartitionResponse' :: BatchCreatePartitionResponse -> Maybe [PartitionError]
errors} -> Maybe [PartitionError]
errors) (\s :: BatchCreatePartitionResponse
s@BatchCreatePartitionResponse' {} Maybe [PartitionError]
a -> BatchCreatePartitionResponse
s {$sel:errors:BatchCreatePartitionResponse' :: Maybe [PartitionError]
errors = Maybe [PartitionError]
a} :: BatchCreatePartitionResponse) 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.
batchCreatePartitionResponse_httpStatus :: Lens.Lens' BatchCreatePartitionResponse Prelude.Int
batchCreatePartitionResponse_httpStatus :: Lens' BatchCreatePartitionResponse Int
batchCreatePartitionResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchCreatePartitionResponse' {Int
httpStatus :: Int
$sel:httpStatus:BatchCreatePartitionResponse' :: BatchCreatePartitionResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: BatchCreatePartitionResponse
s@BatchCreatePartitionResponse' {} Int
a -> BatchCreatePartitionResponse
s {$sel:httpStatus:BatchCreatePartitionResponse' :: Int
httpStatus = Int
a} :: BatchCreatePartitionResponse)

instance Prelude.NFData BatchCreatePartitionResponse where
  rnf :: BatchCreatePartitionResponse -> ()
rnf BatchCreatePartitionResponse' {Int
Maybe [PartitionError]
httpStatus :: Int
errors :: Maybe [PartitionError]
$sel:httpStatus:BatchCreatePartitionResponse' :: BatchCreatePartitionResponse -> Int
$sel:errors:BatchCreatePartitionResponse' :: BatchCreatePartitionResponse -> Maybe [PartitionError]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [PartitionError]
errors
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus