{-# 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.GetTableVersion
-- 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 a specified version of a table.
module Amazonka.Glue.GetTableVersion
  ( -- * Creating a Request
    GetTableVersion (..),
    newGetTableVersion,

    -- * Request Lenses
    getTableVersion_versionId,
    getTableVersion_catalogId,
    getTableVersion_databaseName,
    getTableVersion_tableName,

    -- * Destructuring the Response
    GetTableVersionResponse (..),
    newGetTableVersionResponse,

    -- * Response Lenses
    getTableVersionResponse_tableVersion,
    getTableVersionResponse_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:/ 'newGetTableVersion' smart constructor.
data GetTableVersion = GetTableVersion'
  { -- | The ID value of the table version to be retrieved. A @VersionID@ is a
    -- string representation of an integer. Each version is incremented by 1.
    GetTableVersion -> Maybe Text
versionId :: Prelude.Maybe Prelude.Text,
    -- | The ID of the Data Catalog where the tables reside. If none is provided,
    -- the Amazon Web Services account ID is used by default.
    GetTableVersion -> Maybe Text
catalogId :: Prelude.Maybe Prelude.Text,
    -- | The database in the catalog in which the table resides. For Hive
    -- compatibility, this name is entirely lowercase.
    GetTableVersion -> Text
databaseName :: Prelude.Text,
    -- | The name of the table. For Hive compatibility, this name is entirely
    -- lowercase.
    GetTableVersion -> Text
tableName :: Prelude.Text
  }
  deriving (GetTableVersion -> GetTableVersion -> Bool
(GetTableVersion -> GetTableVersion -> Bool)
-> (GetTableVersion -> GetTableVersion -> Bool)
-> Eq GetTableVersion
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetTableVersion -> GetTableVersion -> Bool
$c/= :: GetTableVersion -> GetTableVersion -> Bool
== :: GetTableVersion -> GetTableVersion -> Bool
$c== :: GetTableVersion -> GetTableVersion -> Bool
Prelude.Eq, ReadPrec [GetTableVersion]
ReadPrec GetTableVersion
Int -> ReadS GetTableVersion
ReadS [GetTableVersion]
(Int -> ReadS GetTableVersion)
-> ReadS [GetTableVersion]
-> ReadPrec GetTableVersion
-> ReadPrec [GetTableVersion]
-> Read GetTableVersion
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetTableVersion]
$creadListPrec :: ReadPrec [GetTableVersion]
readPrec :: ReadPrec GetTableVersion
$creadPrec :: ReadPrec GetTableVersion
readList :: ReadS [GetTableVersion]
$creadList :: ReadS [GetTableVersion]
readsPrec :: Int -> ReadS GetTableVersion
$creadsPrec :: Int -> ReadS GetTableVersion
Prelude.Read, Int -> GetTableVersion -> ShowS
[GetTableVersion] -> ShowS
GetTableVersion -> String
(Int -> GetTableVersion -> ShowS)
-> (GetTableVersion -> String)
-> ([GetTableVersion] -> ShowS)
-> Show GetTableVersion
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetTableVersion] -> ShowS
$cshowList :: [GetTableVersion] -> ShowS
show :: GetTableVersion -> String
$cshow :: GetTableVersion -> String
showsPrec :: Int -> GetTableVersion -> ShowS
$cshowsPrec :: Int -> GetTableVersion -> ShowS
Prelude.Show, (forall x. GetTableVersion -> Rep GetTableVersion x)
-> (forall x. Rep GetTableVersion x -> GetTableVersion)
-> Generic GetTableVersion
forall x. Rep GetTableVersion x -> GetTableVersion
forall x. GetTableVersion -> Rep GetTableVersion x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetTableVersion x -> GetTableVersion
$cfrom :: forall x. GetTableVersion -> Rep GetTableVersion x
Prelude.Generic)

-- |
-- Create a value of 'GetTableVersion' 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:
--
-- 'versionId', 'getTableVersion_versionId' - The ID value of the table version to be retrieved. A @VersionID@ is a
-- string representation of an integer. Each version is incremented by 1.
--
-- 'catalogId', 'getTableVersion_catalogId' - The ID of the Data Catalog where the tables reside. If none is provided,
-- the Amazon Web Services account ID is used by default.
--
-- 'databaseName', 'getTableVersion_databaseName' - The database in the catalog in which the table resides. For Hive
-- compatibility, this name is entirely lowercase.
--
-- 'tableName', 'getTableVersion_tableName' - The name of the table. For Hive compatibility, this name is entirely
-- lowercase.
newGetTableVersion ::
  -- | 'databaseName'
  Prelude.Text ->
  -- | 'tableName'
  Prelude.Text ->
  GetTableVersion
newGetTableVersion :: Text -> Text -> GetTableVersion
newGetTableVersion Text
pDatabaseName_ Text
pTableName_ =
  GetTableVersion' :: Maybe Text -> Maybe Text -> Text -> Text -> GetTableVersion
GetTableVersion'
    { $sel:versionId:GetTableVersion' :: Maybe Text
versionId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:catalogId:GetTableVersion' :: Maybe Text
catalogId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:databaseName:GetTableVersion' :: Text
databaseName = Text
pDatabaseName_,
      $sel:tableName:GetTableVersion' :: Text
tableName = Text
pTableName_
    }

-- | The ID value of the table version to be retrieved. A @VersionID@ is a
-- string representation of an integer. Each version is incremented by 1.
getTableVersion_versionId :: Lens.Lens' GetTableVersion (Prelude.Maybe Prelude.Text)
getTableVersion_versionId :: (Maybe Text -> f (Maybe Text))
-> GetTableVersion -> f GetTableVersion
getTableVersion_versionId = (GetTableVersion -> Maybe Text)
-> (GetTableVersion -> Maybe Text -> GetTableVersion)
-> Lens GetTableVersion GetTableVersion (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetTableVersion' {Maybe Text
versionId :: Maybe Text
$sel:versionId:GetTableVersion' :: GetTableVersion -> Maybe Text
versionId} -> Maybe Text
versionId) (\s :: GetTableVersion
s@GetTableVersion' {} Maybe Text
a -> GetTableVersion
s {$sel:versionId:GetTableVersion' :: Maybe Text
versionId = Maybe Text
a} :: GetTableVersion)

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

-- | The database in the catalog in which the table resides. For Hive
-- compatibility, this name is entirely lowercase.
getTableVersion_databaseName :: Lens.Lens' GetTableVersion Prelude.Text
getTableVersion_databaseName :: (Text -> f Text) -> GetTableVersion -> f GetTableVersion
getTableVersion_databaseName = (GetTableVersion -> Text)
-> (GetTableVersion -> Text -> GetTableVersion)
-> Lens GetTableVersion GetTableVersion Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetTableVersion' {Text
databaseName :: Text
$sel:databaseName:GetTableVersion' :: GetTableVersion -> Text
databaseName} -> Text
databaseName) (\s :: GetTableVersion
s@GetTableVersion' {} Text
a -> GetTableVersion
s {$sel:databaseName:GetTableVersion' :: Text
databaseName = Text
a} :: GetTableVersion)

-- | The name of the table. For Hive compatibility, this name is entirely
-- lowercase.
getTableVersion_tableName :: Lens.Lens' GetTableVersion Prelude.Text
getTableVersion_tableName :: (Text -> f Text) -> GetTableVersion -> f GetTableVersion
getTableVersion_tableName = (GetTableVersion -> Text)
-> (GetTableVersion -> Text -> GetTableVersion)
-> Lens GetTableVersion GetTableVersion Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetTableVersion' {Text
tableName :: Text
$sel:tableName:GetTableVersion' :: GetTableVersion -> Text
tableName} -> Text
tableName) (\s :: GetTableVersion
s@GetTableVersion' {} Text
a -> GetTableVersion
s {$sel:tableName:GetTableVersion' :: Text
tableName = Text
a} :: GetTableVersion)

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

instance Prelude.NFData GetTableVersion

instance Core.ToHeaders GetTableVersion where
  toHeaders :: GetTableVersion -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetTableVersion -> 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.GetTableVersion" :: 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 GetTableVersion where
  toJSON :: GetTableVersion -> Value
toJSON GetTableVersion' {Maybe Text
Text
tableName :: Text
databaseName :: Text
catalogId :: Maybe Text
versionId :: Maybe Text
$sel:tableName:GetTableVersion' :: GetTableVersion -> Text
$sel:databaseName:GetTableVersion' :: GetTableVersion -> Text
$sel:catalogId:GetTableVersion' :: GetTableVersion -> Maybe Text
$sel:versionId:GetTableVersion' :: GetTableVersion -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"VersionId" 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
versionId,
            (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)
          ]
      )

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

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

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

-- |
-- Create a value of 'GetTableVersionResponse' 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:
--
-- 'tableVersion', 'getTableVersionResponse_tableVersion' - The requested table version.
--
-- 'httpStatus', 'getTableVersionResponse_httpStatus' - The response's http status code.
newGetTableVersionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetTableVersionResponse
newGetTableVersionResponse :: Int -> GetTableVersionResponse
newGetTableVersionResponse Int
pHttpStatus_ =
  GetTableVersionResponse' :: Maybe TableVersion -> Int -> GetTableVersionResponse
GetTableVersionResponse'
    { $sel:tableVersion:GetTableVersionResponse' :: Maybe TableVersion
tableVersion =
        Maybe TableVersion
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetTableVersionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The requested table version.
getTableVersionResponse_tableVersion :: Lens.Lens' GetTableVersionResponse (Prelude.Maybe TableVersion)
getTableVersionResponse_tableVersion :: (Maybe TableVersion -> f (Maybe TableVersion))
-> GetTableVersionResponse -> f GetTableVersionResponse
getTableVersionResponse_tableVersion = (GetTableVersionResponse -> Maybe TableVersion)
-> (GetTableVersionResponse
    -> Maybe TableVersion -> GetTableVersionResponse)
-> Lens
     GetTableVersionResponse
     GetTableVersionResponse
     (Maybe TableVersion)
     (Maybe TableVersion)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetTableVersionResponse' {Maybe TableVersion
tableVersion :: Maybe TableVersion
$sel:tableVersion:GetTableVersionResponse' :: GetTableVersionResponse -> Maybe TableVersion
tableVersion} -> Maybe TableVersion
tableVersion) (\s :: GetTableVersionResponse
s@GetTableVersionResponse' {} Maybe TableVersion
a -> GetTableVersionResponse
s {$sel:tableVersion:GetTableVersionResponse' :: Maybe TableVersion
tableVersion = Maybe TableVersion
a} :: GetTableVersionResponse)

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

instance Prelude.NFData GetTableVersionResponse