{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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 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:/ '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
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]
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
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. 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'
    { $sel:catalogId:GetPartition' :: Maybe Text
catalogId = 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 = 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 :: Lens' GetPartition (Maybe Text)
getPartition_catalogId = 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 :: Lens' GetPartition Text
getPartition_databaseName = 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 :: Lens' GetPartition Text
getPartition_tableName = 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 :: Lens' GetPartition [Text]
getPartition_partitionValues = 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) 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 GetPartition where
  type AWSResponse GetPartition = GetPartitionResponse
  request :: (Service -> Service) -> GetPartition -> Request GetPartition
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 GetPartition
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetPartition)))
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 Partition -> Int -> GetPartitionResponse
GetPartitionResponse'
            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
"Partition")
            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 GetPartition where
  hashWithSalt :: Int -> GetPartition -> Int
hashWithSalt Int
_salt 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
..} =
    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` [Text]
partitionValues

instance Prelude.NFData GetPartition where
  rnf :: GetPartition -> ()
rnf 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
..} =
    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 [Text]
partitionValues

instance Data.ToHeaders GetPartition where
  toHeaders :: GetPartition -> 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.GetPartition" :: 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 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
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
"PartitionValues" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [Text]
partitionValues)
          ]
      )

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

instance Data.ToQuery GetPartition where
  toQuery :: GetPartition -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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. 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'
    { $sel:partition:GetPartitionResponse' :: Maybe Partition
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 :: Lens' GetPartitionResponse (Maybe Partition)
getPartitionResponse_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 :: Lens' GetPartitionResponse Int
getPartitionResponse_httpStatus = 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 where
  rnf :: GetPartitionResponse -> ()
rnf GetPartitionResponse' {Int
Maybe Partition
httpStatus :: Int
partition :: Maybe Partition
$sel:httpStatus:GetPartitionResponse' :: GetPartitionResponse -> Int
$sel:partition:GetPartitionResponse' :: GetPartitionResponse -> Maybe Partition
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Partition
partition
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus