{-# 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.GetPartition
-- 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)
--
-- Retrieves information about a specified partition.
module Amazonka.Glue.GetPartition
  ( -- * Creating a Request
    GetPartition (..),
    newGetPartition,

    -- * Request Lenses
    getPartition_catalogId,
    getPartition_databaseName,
    getPartition_tableName,
    getPartition_partitionValues,

    -- * Destructuring the Response
    GetPartitionResponse (..),
    newGetPartitionResponse,

    -- * Response Lenses
    getPartitionResponse_partition,
    getPartitionResponse_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:/ 'newGetPartition' smart constructor.
data GetPartition = GetPartition'
  { -- | The ID of the Data Catalog where the partition in question resides. If
    -- none is provided, the Amazon Web Services account ID is used by default.
    GetPartition -> Maybe Text
catalogId :: Prelude.Maybe Prelude.Text,
    -- | The name of the catalog database where the partition resides.
    GetPartition -> Text
databaseName :: Prelude.Text,
    -- | The name of the partition\'s table.
    GetPartition -> Text
tableName :: Prelude.Text,
    -- | The values that define the partition.
    GetPartition -> [Text]
partitionValues :: [Prelude.Text]
  }
  deriving (GetPartition -> GetPartition -> Bool
(GetPartition -> GetPartition -> Bool)
-> (GetPartition -> GetPartition -> Bool) -> Eq GetPartition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetPartition -> GetPartition -> Bool
$c/= :: GetPartition -> GetPartition -> Bool
== :: GetPartition -> GetPartition -> Bool
$c== :: GetPartition -> GetPartition -> Bool
Prelude.Eq, ReadPrec [GetPartition]
ReadPrec GetPartition
Int -> ReadS GetPartition
ReadS [GetPartition]
(Int -> ReadS GetPartition)
-> ReadS [GetPartition]
-> ReadPrec GetPartition
-> ReadPrec [GetPartition]
-> Read GetPartition
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetPartition]
$creadListPrec :: ReadPrec [GetPartition]
readPrec :: ReadPrec GetPartition
$creadPrec :: ReadPrec GetPartition
readList :: ReadS [GetPartition]
$creadList :: ReadS [GetPartition]
readsPrec :: Int -> ReadS GetPartition
$creadsPrec :: Int -> ReadS GetPartition
Prelude.Read, Int -> GetPartition -> ShowS
[GetPartition] -> ShowS
GetPartition -> String
(Int -> GetPartition -> ShowS)
-> (GetPartition -> String)
-> ([GetPartition] -> ShowS)
-> Show GetPartition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetPartition] -> ShowS
$cshowList :: [GetPartition] -> ShowS
show :: GetPartition -> String
$cshow :: GetPartition -> String
showsPrec :: Int -> GetPartition -> ShowS
$cshowsPrec :: Int -> GetPartition -> ShowS
Prelude.Show, (forall x. GetPartition -> Rep GetPartition x)
-> (forall x. Rep GetPartition x -> GetPartition)
-> Generic GetPartition
forall x. Rep GetPartition x -> GetPartition
forall x. GetPartition -> Rep GetPartition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetPartition x -> GetPartition
$cfrom :: forall x. GetPartition -> Rep GetPartition x
Prelude.Generic)

-- |
-- Create a value of 'GetPartition' 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', 'getPartition_catalogId' - The ID of the Data Catalog where the partition in question resides. If
-- none is provided, the Amazon Web Services account ID is used by default.
--
-- 'databaseName', 'getPartition_databaseName' - The name of the catalog database where the partition resides.
--
-- 'tableName', 'getPartition_tableName' - The name of the partition\'s table.
--
-- 'partitionValues', 'getPartition_partitionValues' - The values that define the partition.
newGetPartition ::
  -- | 'databaseName'
  Prelude.Text ->
  -- | 'tableName'
  Prelude.Text ->
  GetPartition
newGetPartition :: Text -> Text -> GetPartition
newGetPartition Text
pDatabaseName_ Text
pTableName_ =
  GetPartition' :: Maybe Text -> Text -> Text -> [Text] -> GetPartition
GetPartition'
    { $sel:catalogId:GetPartition' :: Maybe Text
catalogId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:databaseName:GetPartition' :: Text
databaseName = Text
pDatabaseName_,
      $sel:tableName:GetPartition' :: Text
tableName = Text
pTableName_,
      $sel:partitionValues:GetPartition' :: [Text]
partitionValues = [Text]
forall a. Monoid a => a
Prelude.mempty
    }

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

-- | The name of the catalog database where the partition resides.
getPartition_databaseName :: Lens.Lens' GetPartition Prelude.Text
getPartition_databaseName :: (Text -> f Text) -> GetPartition -> f GetPartition
getPartition_databaseName = (GetPartition -> Text)
-> (GetPartition -> Text -> GetPartition)
-> Lens GetPartition GetPartition Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetPartition' {Text
databaseName :: Text
$sel:databaseName:GetPartition' :: GetPartition -> Text
databaseName} -> Text
databaseName) (\s :: GetPartition
s@GetPartition' {} Text
a -> GetPartition
s {$sel:databaseName:GetPartition' :: Text
databaseName = Text
a} :: GetPartition)

-- | The name of the partition\'s table.
getPartition_tableName :: Lens.Lens' GetPartition Prelude.Text
getPartition_tableName :: (Text -> f Text) -> GetPartition -> f GetPartition
getPartition_tableName = (GetPartition -> Text)
-> (GetPartition -> Text -> GetPartition)
-> Lens GetPartition GetPartition Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetPartition' {Text
tableName :: Text
$sel:tableName:GetPartition' :: GetPartition -> Text
tableName} -> Text
tableName) (\s :: GetPartition
s@GetPartition' {} Text
a -> GetPartition
s {$sel:tableName:GetPartition' :: Text
tableName = Text
a} :: GetPartition)

-- | The values that define the partition.
getPartition_partitionValues :: Lens.Lens' GetPartition [Prelude.Text]
getPartition_partitionValues :: ([Text] -> f [Text]) -> GetPartition -> f GetPartition
getPartition_partitionValues = (GetPartition -> [Text])
-> (GetPartition -> [Text] -> GetPartition)
-> Lens GetPartition GetPartition [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetPartition' {[Text]
partitionValues :: [Text]
$sel:partitionValues:GetPartition' :: GetPartition -> [Text]
partitionValues} -> [Text]
partitionValues) (\s :: GetPartition
s@GetPartition' {} [Text]
a -> GetPartition
s {$sel:partitionValues:GetPartition' :: [Text]
partitionValues = [Text]
a} :: GetPartition) (([Text] -> f [Text]) -> GetPartition -> f GetPartition)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> GetPartition
-> f GetPartition
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

instance Core.AWSRequest GetPartition where
  type AWSResponse GetPartition = GetPartitionResponse
  request :: GetPartition -> Request GetPartition
request = Service -> GetPartition -> Request GetPartition
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetPartition
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetPartition)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetPartition))
-> Logger
-> Service
-> Proxy GetPartition
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetPartition)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Partition -> Int -> GetPartitionResponse
GetPartitionResponse'
            (Maybe Partition -> Int -> GetPartitionResponse)
-> Either String (Maybe Partition)
-> Either String (Int -> GetPartitionResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Partition)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Partition")
            Either String (Int -> GetPartitionResponse)
-> Either String Int -> Either String GetPartitionResponse
forall (f :: * -> *) a b. Applicative f => 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 GetPartition

instance Prelude.NFData GetPartition

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

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

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

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

-- |
-- Create a value of 'GetPartitionResponse' 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:
--
-- 'partition', 'getPartitionResponse_partition' - The requested information, in the form of a @Partition@ object.
--
-- 'httpStatus', 'getPartitionResponse_httpStatus' - The response's http status code.
newGetPartitionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetPartitionResponse
newGetPartitionResponse :: Int -> GetPartitionResponse
newGetPartitionResponse Int
pHttpStatus_ =
  GetPartitionResponse' :: Maybe Partition -> Int -> GetPartitionResponse
GetPartitionResponse'
    { $sel:partition:GetPartitionResponse' :: Maybe Partition
partition = Maybe Partition
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetPartitionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The requested information, in the form of a @Partition@ object.
getPartitionResponse_partition :: Lens.Lens' GetPartitionResponse (Prelude.Maybe Partition)
getPartitionResponse_partition :: (Maybe Partition -> f (Maybe Partition))
-> GetPartitionResponse -> f GetPartitionResponse
getPartitionResponse_partition = (GetPartitionResponse -> Maybe Partition)
-> (GetPartitionResponse
    -> Maybe Partition -> GetPartitionResponse)
-> Lens
     GetPartitionResponse
     GetPartitionResponse
     (Maybe Partition)
     (Maybe Partition)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetPartitionResponse' {Maybe Partition
partition :: Maybe Partition
$sel:partition:GetPartitionResponse' :: GetPartitionResponse -> Maybe Partition
partition} -> Maybe Partition
partition) (\s :: GetPartitionResponse
s@GetPartitionResponse' {} Maybe Partition
a -> GetPartitionResponse
s {$sel:partition:GetPartitionResponse' :: Maybe Partition
partition = Maybe Partition
a} :: GetPartitionResponse)

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

instance Prelude.NFData GetPartitionResponse