{-# 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.UpdatePartition
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Updates a partition.
module Amazonka.Glue.UpdatePartition
  ( -- * Creating a Request
    UpdatePartition (..),
    newUpdatePartition,

    -- * Request Lenses
    updatePartition_catalogId,
    updatePartition_databaseName,
    updatePartition_tableName,
    updatePartition_partitionValueList,
    updatePartition_partitionInput,

    -- * Destructuring the Response
    UpdatePartitionResponse (..),
    newUpdatePartitionResponse,

    -- * Response Lenses
    updatePartitionResponse_httpStatus,
  )
where

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

-- | /See:/ 'newUpdatePartition' smart constructor.
data UpdatePartition = UpdatePartition'
  { -- | The ID of the Data Catalog where the partition to be updated resides. If
    -- none is provided, the Amazon Web Services account ID is used by default.
    UpdatePartition -> Maybe Text
catalogId :: Prelude.Maybe Prelude.Text,
    -- | The name of the catalog database in which the table in question resides.
    UpdatePartition -> Text
databaseName :: Prelude.Text,
    -- | The name of the table in which the partition to be updated is located.
    UpdatePartition -> Text
tableName :: Prelude.Text,
    -- | List of partition key values that define the partition to update.
    UpdatePartition -> [Text]
partitionValueList :: [Prelude.Text],
    -- | The new partition object to update the partition to.
    --
    -- The @Values@ property can\'t be changed. If you want to change the
    -- partition key values for a partition, delete and recreate the partition.
    UpdatePartition -> PartitionInput
partitionInput :: PartitionInput
  }
  deriving (UpdatePartition -> UpdatePartition -> Bool
(UpdatePartition -> UpdatePartition -> Bool)
-> (UpdatePartition -> UpdatePartition -> Bool)
-> Eq UpdatePartition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdatePartition -> UpdatePartition -> Bool
$c/= :: UpdatePartition -> UpdatePartition -> Bool
== :: UpdatePartition -> UpdatePartition -> Bool
$c== :: UpdatePartition -> UpdatePartition -> Bool
Prelude.Eq, ReadPrec [UpdatePartition]
ReadPrec UpdatePartition
Int -> ReadS UpdatePartition
ReadS [UpdatePartition]
(Int -> ReadS UpdatePartition)
-> ReadS [UpdatePartition]
-> ReadPrec UpdatePartition
-> ReadPrec [UpdatePartition]
-> Read UpdatePartition
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdatePartition]
$creadListPrec :: ReadPrec [UpdatePartition]
readPrec :: ReadPrec UpdatePartition
$creadPrec :: ReadPrec UpdatePartition
readList :: ReadS [UpdatePartition]
$creadList :: ReadS [UpdatePartition]
readsPrec :: Int -> ReadS UpdatePartition
$creadsPrec :: Int -> ReadS UpdatePartition
Prelude.Read, Int -> UpdatePartition -> ShowS
[UpdatePartition] -> ShowS
UpdatePartition -> String
(Int -> UpdatePartition -> ShowS)
-> (UpdatePartition -> String)
-> ([UpdatePartition] -> ShowS)
-> Show UpdatePartition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdatePartition] -> ShowS
$cshowList :: [UpdatePartition] -> ShowS
show :: UpdatePartition -> String
$cshow :: UpdatePartition -> String
showsPrec :: Int -> UpdatePartition -> ShowS
$cshowsPrec :: Int -> UpdatePartition -> ShowS
Prelude.Show, (forall x. UpdatePartition -> Rep UpdatePartition x)
-> (forall x. Rep UpdatePartition x -> UpdatePartition)
-> Generic UpdatePartition
forall x. Rep UpdatePartition x -> UpdatePartition
forall x. UpdatePartition -> Rep UpdatePartition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdatePartition x -> UpdatePartition
$cfrom :: forall x. UpdatePartition -> Rep UpdatePartition x
Prelude.Generic)

-- |
-- Create a value of 'UpdatePartition' 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', 'updatePartition_catalogId' - The ID of the Data Catalog where the partition to be updated resides. If
-- none is provided, the Amazon Web Services account ID is used by default.
--
-- 'databaseName', 'updatePartition_databaseName' - The name of the catalog database in which the table in question resides.
--
-- 'tableName', 'updatePartition_tableName' - The name of the table in which the partition to be updated is located.
--
-- 'partitionValueList', 'updatePartition_partitionValueList' - List of partition key values that define the partition to update.
--
-- 'partitionInput', 'updatePartition_partitionInput' - The new partition object to update the partition to.
--
-- The @Values@ property can\'t be changed. If you want to change the
-- partition key values for a partition, delete and recreate the partition.
newUpdatePartition ::
  -- | 'databaseName'
  Prelude.Text ->
  -- | 'tableName'
  Prelude.Text ->
  -- | 'partitionInput'
  PartitionInput ->
  UpdatePartition
newUpdatePartition :: Text -> Text -> PartitionInput -> UpdatePartition
newUpdatePartition
  Text
pDatabaseName_
  Text
pTableName_
  PartitionInput
pPartitionInput_ =
    UpdatePartition' :: Maybe Text
-> Text -> Text -> [Text] -> PartitionInput -> UpdatePartition
UpdatePartition'
      { $sel:catalogId:UpdatePartition' :: Maybe Text
catalogId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:databaseName:UpdatePartition' :: Text
databaseName = Text
pDatabaseName_,
        $sel:tableName:UpdatePartition' :: Text
tableName = Text
pTableName_,
        $sel:partitionValueList:UpdatePartition' :: [Text]
partitionValueList = [Text]
forall a. Monoid a => a
Prelude.mempty,
        $sel:partitionInput:UpdatePartition' :: PartitionInput
partitionInput = PartitionInput
pPartitionInput_
      }

-- | The ID of the Data Catalog where the partition to be updated resides. If
-- none is provided, the Amazon Web Services account ID is used by default.
updatePartition_catalogId :: Lens.Lens' UpdatePartition (Prelude.Maybe Prelude.Text)
updatePartition_catalogId :: (Maybe Text -> f (Maybe Text))
-> UpdatePartition -> f UpdatePartition
updatePartition_catalogId = (UpdatePartition -> Maybe Text)
-> (UpdatePartition -> Maybe Text -> UpdatePartition)
-> Lens UpdatePartition UpdatePartition (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdatePartition' {Maybe Text
catalogId :: Maybe Text
$sel:catalogId:UpdatePartition' :: UpdatePartition -> Maybe Text
catalogId} -> Maybe Text
catalogId) (\s :: UpdatePartition
s@UpdatePartition' {} Maybe Text
a -> UpdatePartition
s {$sel:catalogId:UpdatePartition' :: Maybe Text
catalogId = Maybe Text
a} :: UpdatePartition)

-- | The name of the catalog database in which the table in question resides.
updatePartition_databaseName :: Lens.Lens' UpdatePartition Prelude.Text
updatePartition_databaseName :: (Text -> f Text) -> UpdatePartition -> f UpdatePartition
updatePartition_databaseName = (UpdatePartition -> Text)
-> (UpdatePartition -> Text -> UpdatePartition)
-> Lens UpdatePartition UpdatePartition Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdatePartition' {Text
databaseName :: Text
$sel:databaseName:UpdatePartition' :: UpdatePartition -> Text
databaseName} -> Text
databaseName) (\s :: UpdatePartition
s@UpdatePartition' {} Text
a -> UpdatePartition
s {$sel:databaseName:UpdatePartition' :: Text
databaseName = Text
a} :: UpdatePartition)

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

-- | List of partition key values that define the partition to update.
updatePartition_partitionValueList :: Lens.Lens' UpdatePartition [Prelude.Text]
updatePartition_partitionValueList :: ([Text] -> f [Text]) -> UpdatePartition -> f UpdatePartition
updatePartition_partitionValueList = (UpdatePartition -> [Text])
-> (UpdatePartition -> [Text] -> UpdatePartition)
-> Lens UpdatePartition UpdatePartition [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdatePartition' {[Text]
partitionValueList :: [Text]
$sel:partitionValueList:UpdatePartition' :: UpdatePartition -> [Text]
partitionValueList} -> [Text]
partitionValueList) (\s :: UpdatePartition
s@UpdatePartition' {} [Text]
a -> UpdatePartition
s {$sel:partitionValueList:UpdatePartition' :: [Text]
partitionValueList = [Text]
a} :: UpdatePartition) (([Text] -> f [Text]) -> UpdatePartition -> f UpdatePartition)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> UpdatePartition
-> f UpdatePartition
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The new partition object to update the partition to.
--
-- The @Values@ property can\'t be changed. If you want to change the
-- partition key values for a partition, delete and recreate the partition.
updatePartition_partitionInput :: Lens.Lens' UpdatePartition PartitionInput
updatePartition_partitionInput :: (PartitionInput -> f PartitionInput)
-> UpdatePartition -> f UpdatePartition
updatePartition_partitionInput = (UpdatePartition -> PartitionInput)
-> (UpdatePartition -> PartitionInput -> UpdatePartition)
-> Lens
     UpdatePartition UpdatePartition PartitionInput PartitionInput
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdatePartition' {PartitionInput
partitionInput :: PartitionInput
$sel:partitionInput:UpdatePartition' :: UpdatePartition -> PartitionInput
partitionInput} -> PartitionInput
partitionInput) (\s :: UpdatePartition
s@UpdatePartition' {} PartitionInput
a -> UpdatePartition
s {$sel:partitionInput:UpdatePartition' :: PartitionInput
partitionInput = PartitionInput
a} :: UpdatePartition)

instance Core.AWSRequest UpdatePartition where
  type
    AWSResponse UpdatePartition =
      UpdatePartitionResponse
  request :: UpdatePartition -> Request UpdatePartition
request = Service -> UpdatePartition -> Request UpdatePartition
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy UpdatePartition
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdatePartition)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse UpdatePartition))
-> Logger
-> Service
-> Proxy UpdatePartition
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdatePartition)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> UpdatePartitionResponse
UpdatePartitionResponse'
            (Int -> UpdatePartitionResponse)
-> Either String Int -> Either String UpdatePartitionResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable UpdatePartition

instance Prelude.NFData UpdatePartition

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

instance Core.ToJSON UpdatePartition where
  toJSON :: UpdatePartition -> Value
toJSON UpdatePartition' {[Text]
Maybe Text
Text
PartitionInput
partitionInput :: PartitionInput
partitionValueList :: [Text]
tableName :: Text
databaseName :: Text
catalogId :: Maybe Text
$sel:partitionInput:UpdatePartition' :: UpdatePartition -> PartitionInput
$sel:partitionValueList:UpdatePartition' :: UpdatePartition -> [Text]
$sel:tableName:UpdatePartition' :: UpdatePartition -> Text
$sel:databaseName:UpdatePartition' :: UpdatePartition -> Text
$sel:catalogId:UpdatePartition' :: UpdatePartition -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"CatalogId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
catalogId,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"DatabaseName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
databaseName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"TableName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
tableName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"PartitionValueList" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Text]
partitionValueList),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"PartitionInput" Text -> PartitionInput -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= PartitionInput
partitionInput)
          ]
      )

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

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

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

-- |
-- Create a value of 'UpdatePartitionResponse' 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:
--
-- 'httpStatus', 'updatePartitionResponse_httpStatus' - The response's http status code.
newUpdatePartitionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  UpdatePartitionResponse
newUpdatePartitionResponse :: Int -> UpdatePartitionResponse
newUpdatePartitionResponse Int
pHttpStatus_ =
  UpdatePartitionResponse' :: Int -> UpdatePartitionResponse
UpdatePartitionResponse' {$sel:httpStatus:UpdatePartitionResponse' :: Int
httpStatus = Int
pHttpStatus_}

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

instance Prelude.NFData UpdatePartitionResponse