{-# 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.CreatePartitionIndex
-- 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)
--
-- Creates a specified partition index in an existing table.
module Amazonka.Glue.CreatePartitionIndex
  ( -- * Creating a Request
    CreatePartitionIndex (..),
    newCreatePartitionIndex,

    -- * Request Lenses
    createPartitionIndex_catalogId,
    createPartitionIndex_databaseName,
    createPartitionIndex_tableName,
    createPartitionIndex_partitionIndex,

    -- * Destructuring the Response
    CreatePartitionIndexResponse (..),
    newCreatePartitionIndexResponse,

    -- * Response Lenses
    createPartitionIndexResponse_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:/ 'newCreatePartitionIndex' smart constructor.
data CreatePartitionIndex = CreatePartitionIndex'
  { -- | The catalog ID where the table resides.
    CreatePartitionIndex -> Maybe Text
catalogId :: Prelude.Maybe Prelude.Text,
    -- | Specifies the name of a database in which you want to create a partition
    -- index.
    CreatePartitionIndex -> Text
databaseName :: Prelude.Text,
    -- | Specifies the name of a table in which you want to create a partition
    -- index.
    CreatePartitionIndex -> Text
tableName :: Prelude.Text,
    -- | Specifies a @PartitionIndex@ structure to create a partition index in an
    -- existing table.
    CreatePartitionIndex -> PartitionIndex
partitionIndex :: PartitionIndex
  }
  deriving (CreatePartitionIndex -> CreatePartitionIndex -> Bool
(CreatePartitionIndex -> CreatePartitionIndex -> Bool)
-> (CreatePartitionIndex -> CreatePartitionIndex -> Bool)
-> Eq CreatePartitionIndex
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreatePartitionIndex -> CreatePartitionIndex -> Bool
$c/= :: CreatePartitionIndex -> CreatePartitionIndex -> Bool
== :: CreatePartitionIndex -> CreatePartitionIndex -> Bool
$c== :: CreatePartitionIndex -> CreatePartitionIndex -> Bool
Prelude.Eq, ReadPrec [CreatePartitionIndex]
ReadPrec CreatePartitionIndex
Int -> ReadS CreatePartitionIndex
ReadS [CreatePartitionIndex]
(Int -> ReadS CreatePartitionIndex)
-> ReadS [CreatePartitionIndex]
-> ReadPrec CreatePartitionIndex
-> ReadPrec [CreatePartitionIndex]
-> Read CreatePartitionIndex
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreatePartitionIndex]
$creadListPrec :: ReadPrec [CreatePartitionIndex]
readPrec :: ReadPrec CreatePartitionIndex
$creadPrec :: ReadPrec CreatePartitionIndex
readList :: ReadS [CreatePartitionIndex]
$creadList :: ReadS [CreatePartitionIndex]
readsPrec :: Int -> ReadS CreatePartitionIndex
$creadsPrec :: Int -> ReadS CreatePartitionIndex
Prelude.Read, Int -> CreatePartitionIndex -> ShowS
[CreatePartitionIndex] -> ShowS
CreatePartitionIndex -> String
(Int -> CreatePartitionIndex -> ShowS)
-> (CreatePartitionIndex -> String)
-> ([CreatePartitionIndex] -> ShowS)
-> Show CreatePartitionIndex
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreatePartitionIndex] -> ShowS
$cshowList :: [CreatePartitionIndex] -> ShowS
show :: CreatePartitionIndex -> String
$cshow :: CreatePartitionIndex -> String
showsPrec :: Int -> CreatePartitionIndex -> ShowS
$cshowsPrec :: Int -> CreatePartitionIndex -> ShowS
Prelude.Show, (forall x. CreatePartitionIndex -> Rep CreatePartitionIndex x)
-> (forall x. Rep CreatePartitionIndex x -> CreatePartitionIndex)
-> Generic CreatePartitionIndex
forall x. Rep CreatePartitionIndex x -> CreatePartitionIndex
forall x. CreatePartitionIndex -> Rep CreatePartitionIndex x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreatePartitionIndex x -> CreatePartitionIndex
$cfrom :: forall x. CreatePartitionIndex -> Rep CreatePartitionIndex x
Prelude.Generic)

-- |
-- Create a value of 'CreatePartitionIndex' 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', 'createPartitionIndex_catalogId' - The catalog ID where the table resides.
--
-- 'databaseName', 'createPartitionIndex_databaseName' - Specifies the name of a database in which you want to create a partition
-- index.
--
-- 'tableName', 'createPartitionIndex_tableName' - Specifies the name of a table in which you want to create a partition
-- index.
--
-- 'partitionIndex', 'createPartitionIndex_partitionIndex' - Specifies a @PartitionIndex@ structure to create a partition index in an
-- existing table.
newCreatePartitionIndex ::
  -- | 'databaseName'
  Prelude.Text ->
  -- | 'tableName'
  Prelude.Text ->
  -- | 'partitionIndex'
  PartitionIndex ->
  CreatePartitionIndex
newCreatePartitionIndex :: Text -> Text -> PartitionIndex -> CreatePartitionIndex
newCreatePartitionIndex
  Text
pDatabaseName_
  Text
pTableName_
  PartitionIndex
pPartitionIndex_ =
    CreatePartitionIndex' :: Maybe Text
-> Text -> Text -> PartitionIndex -> CreatePartitionIndex
CreatePartitionIndex'
      { $sel:catalogId:CreatePartitionIndex' :: Maybe Text
catalogId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:databaseName:CreatePartitionIndex' :: Text
databaseName = Text
pDatabaseName_,
        $sel:tableName:CreatePartitionIndex' :: Text
tableName = Text
pTableName_,
        $sel:partitionIndex:CreatePartitionIndex' :: PartitionIndex
partitionIndex = PartitionIndex
pPartitionIndex_
      }

-- | The catalog ID where the table resides.
createPartitionIndex_catalogId :: Lens.Lens' CreatePartitionIndex (Prelude.Maybe Prelude.Text)
createPartitionIndex_catalogId :: (Maybe Text -> f (Maybe Text))
-> CreatePartitionIndex -> f CreatePartitionIndex
createPartitionIndex_catalogId = (CreatePartitionIndex -> Maybe Text)
-> (CreatePartitionIndex -> Maybe Text -> CreatePartitionIndex)
-> Lens
     CreatePartitionIndex CreatePartitionIndex (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePartitionIndex' {Maybe Text
catalogId :: Maybe Text
$sel:catalogId:CreatePartitionIndex' :: CreatePartitionIndex -> Maybe Text
catalogId} -> Maybe Text
catalogId) (\s :: CreatePartitionIndex
s@CreatePartitionIndex' {} Maybe Text
a -> CreatePartitionIndex
s {$sel:catalogId:CreatePartitionIndex' :: Maybe Text
catalogId = Maybe Text
a} :: CreatePartitionIndex)

-- | Specifies the name of a database in which you want to create a partition
-- index.
createPartitionIndex_databaseName :: Lens.Lens' CreatePartitionIndex Prelude.Text
createPartitionIndex_databaseName :: (Text -> f Text) -> CreatePartitionIndex -> f CreatePartitionIndex
createPartitionIndex_databaseName = (CreatePartitionIndex -> Text)
-> (CreatePartitionIndex -> Text -> CreatePartitionIndex)
-> Lens CreatePartitionIndex CreatePartitionIndex Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePartitionIndex' {Text
databaseName :: Text
$sel:databaseName:CreatePartitionIndex' :: CreatePartitionIndex -> Text
databaseName} -> Text
databaseName) (\s :: CreatePartitionIndex
s@CreatePartitionIndex' {} Text
a -> CreatePartitionIndex
s {$sel:databaseName:CreatePartitionIndex' :: Text
databaseName = Text
a} :: CreatePartitionIndex)

-- | Specifies the name of a table in which you want to create a partition
-- index.
createPartitionIndex_tableName :: Lens.Lens' CreatePartitionIndex Prelude.Text
createPartitionIndex_tableName :: (Text -> f Text) -> CreatePartitionIndex -> f CreatePartitionIndex
createPartitionIndex_tableName = (CreatePartitionIndex -> Text)
-> (CreatePartitionIndex -> Text -> CreatePartitionIndex)
-> Lens CreatePartitionIndex CreatePartitionIndex Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePartitionIndex' {Text
tableName :: Text
$sel:tableName:CreatePartitionIndex' :: CreatePartitionIndex -> Text
tableName} -> Text
tableName) (\s :: CreatePartitionIndex
s@CreatePartitionIndex' {} Text
a -> CreatePartitionIndex
s {$sel:tableName:CreatePartitionIndex' :: Text
tableName = Text
a} :: CreatePartitionIndex)

-- | Specifies a @PartitionIndex@ structure to create a partition index in an
-- existing table.
createPartitionIndex_partitionIndex :: Lens.Lens' CreatePartitionIndex PartitionIndex
createPartitionIndex_partitionIndex :: (PartitionIndex -> f PartitionIndex)
-> CreatePartitionIndex -> f CreatePartitionIndex
createPartitionIndex_partitionIndex = (CreatePartitionIndex -> PartitionIndex)
-> (CreatePartitionIndex -> PartitionIndex -> CreatePartitionIndex)
-> Lens
     CreatePartitionIndex
     CreatePartitionIndex
     PartitionIndex
     PartitionIndex
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePartitionIndex' {PartitionIndex
partitionIndex :: PartitionIndex
$sel:partitionIndex:CreatePartitionIndex' :: CreatePartitionIndex -> PartitionIndex
partitionIndex} -> PartitionIndex
partitionIndex) (\s :: CreatePartitionIndex
s@CreatePartitionIndex' {} PartitionIndex
a -> CreatePartitionIndex
s {$sel:partitionIndex:CreatePartitionIndex' :: PartitionIndex
partitionIndex = PartitionIndex
a} :: CreatePartitionIndex)

instance Core.AWSRequest CreatePartitionIndex where
  type
    AWSResponse CreatePartitionIndex =
      CreatePartitionIndexResponse
  request :: CreatePartitionIndex -> Request CreatePartitionIndex
request = Service -> CreatePartitionIndex -> Request CreatePartitionIndex
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreatePartitionIndex
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreatePartitionIndex)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse CreatePartitionIndex))
-> Logger
-> Service
-> Proxy CreatePartitionIndex
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreatePartitionIndex)))
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 -> CreatePartitionIndexResponse
CreatePartitionIndexResponse'
            (Int -> CreatePartitionIndexResponse)
-> Either String Int -> Either String CreatePartitionIndexResponse
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 CreatePartitionIndex

instance Prelude.NFData CreatePartitionIndex

instance Core.ToHeaders CreatePartitionIndex where
  toHeaders :: CreatePartitionIndex -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreatePartitionIndex -> 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.CreatePartitionIndex" ::
                          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 CreatePartitionIndex where
  toJSON :: CreatePartitionIndex -> Value
toJSON CreatePartitionIndex' {Maybe Text
Text
PartitionIndex
partitionIndex :: PartitionIndex
tableName :: Text
databaseName :: Text
catalogId :: Maybe Text
$sel:partitionIndex:CreatePartitionIndex' :: CreatePartitionIndex -> PartitionIndex
$sel:tableName:CreatePartitionIndex' :: CreatePartitionIndex -> Text
$sel:databaseName:CreatePartitionIndex' :: CreatePartitionIndex -> Text
$sel:catalogId:CreatePartitionIndex' :: CreatePartitionIndex -> 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
"PartitionIndex" Text -> PartitionIndex -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= PartitionIndex
partitionIndex)
          ]
      )

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

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

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

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

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

instance Prelude.NFData CreatePartitionIndexResponse