{-# 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.GetTable
-- 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 the @Table@ definition in a Data Catalog for a specified
-- table.
module Amazonka.Glue.GetTable
  ( -- * Creating a Request
    GetTable (..),
    newGetTable,

    -- * Request Lenses
    getTable_catalogId,
    getTable_databaseName,
    getTable_name,

    -- * Destructuring the Response
    GetTableResponse (..),
    newGetTableResponse,

    -- * Response Lenses
    getTableResponse_table,
    getTableResponse_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:/ 'newGetTable' smart constructor.
data GetTable = GetTable'
  { -- | The ID of the Data Catalog where the table resides. If none is provided,
    -- the Amazon Web Services account ID is used by default.
    GetTable -> Maybe Text
catalogId :: Prelude.Maybe Prelude.Text,
    -- | The name of the database in the catalog in which the table resides. For
    -- Hive compatibility, this name is entirely lowercase.
    GetTable -> Text
databaseName :: Prelude.Text,
    -- | The name of the table for which to retrieve the definition. For Hive
    -- compatibility, this name is entirely lowercase.
    GetTable -> Text
name :: Prelude.Text
  }
  deriving (GetTable -> GetTable -> Bool
(GetTable -> GetTable -> Bool)
-> (GetTable -> GetTable -> Bool) -> Eq GetTable
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetTable -> GetTable -> Bool
$c/= :: GetTable -> GetTable -> Bool
== :: GetTable -> GetTable -> Bool
$c== :: GetTable -> GetTable -> Bool
Prelude.Eq, ReadPrec [GetTable]
ReadPrec GetTable
Int -> ReadS GetTable
ReadS [GetTable]
(Int -> ReadS GetTable)
-> ReadS [GetTable]
-> ReadPrec GetTable
-> ReadPrec [GetTable]
-> Read GetTable
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetTable]
$creadListPrec :: ReadPrec [GetTable]
readPrec :: ReadPrec GetTable
$creadPrec :: ReadPrec GetTable
readList :: ReadS [GetTable]
$creadList :: ReadS [GetTable]
readsPrec :: Int -> ReadS GetTable
$creadsPrec :: Int -> ReadS GetTable
Prelude.Read, Int -> GetTable -> ShowS
[GetTable] -> ShowS
GetTable -> String
(Int -> GetTable -> ShowS)
-> (GetTable -> String) -> ([GetTable] -> ShowS) -> Show GetTable
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetTable] -> ShowS
$cshowList :: [GetTable] -> ShowS
show :: GetTable -> String
$cshow :: GetTable -> String
showsPrec :: Int -> GetTable -> ShowS
$cshowsPrec :: Int -> GetTable -> ShowS
Prelude.Show, (forall x. GetTable -> Rep GetTable x)
-> (forall x. Rep GetTable x -> GetTable) -> Generic GetTable
forall x. Rep GetTable x -> GetTable
forall x. GetTable -> Rep GetTable x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetTable x -> GetTable
$cfrom :: forall x. GetTable -> Rep GetTable x
Prelude.Generic)

-- |
-- Create a value of 'GetTable' 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', 'getTable_catalogId' - The ID of the Data Catalog where the table resides. If none is provided,
-- the Amazon Web Services account ID is used by default.
--
-- 'databaseName', 'getTable_databaseName' - The name of the database in the catalog in which the table resides. For
-- Hive compatibility, this name is entirely lowercase.
--
-- 'name', 'getTable_name' - The name of the table for which to retrieve the definition. For Hive
-- compatibility, this name is entirely lowercase.
newGetTable ::
  -- | 'databaseName'
  Prelude.Text ->
  -- | 'name'
  Prelude.Text ->
  GetTable
newGetTable :: Text -> Text -> GetTable
newGetTable Text
pDatabaseName_ Text
pName_ =
  GetTable' :: Maybe Text -> Text -> Text -> GetTable
GetTable'
    { $sel:catalogId:GetTable' :: Maybe Text
catalogId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:databaseName:GetTable' :: Text
databaseName = Text
pDatabaseName_,
      $sel:name:GetTable' :: Text
name = Text
pName_
    }

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

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

-- | The name of the table for which to retrieve the definition. For Hive
-- compatibility, this name is entirely lowercase.
getTable_name :: Lens.Lens' GetTable Prelude.Text
getTable_name :: (Text -> f Text) -> GetTable -> f GetTable
getTable_name = (GetTable -> Text)
-> (GetTable -> Text -> GetTable)
-> Lens GetTable GetTable Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetTable' {Text
name :: Text
$sel:name:GetTable' :: GetTable -> Text
name} -> Text
name) (\s :: GetTable
s@GetTable' {} Text
a -> GetTable
s {$sel:name:GetTable' :: Text
name = Text
a} :: GetTable)

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

instance Prelude.NFData GetTable

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

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

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

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

-- |
-- Create a value of 'GetTableResponse' 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:
--
-- 'table', 'getTableResponse_table' - The @Table@ object that defines the specified table.
--
-- 'httpStatus', 'getTableResponse_httpStatus' - The response's http status code.
newGetTableResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetTableResponse
newGetTableResponse :: Int -> GetTableResponse
newGetTableResponse Int
pHttpStatus_ =
  GetTableResponse' :: Maybe Table -> Int -> GetTableResponse
GetTableResponse'
    { $sel:table:GetTableResponse' :: Maybe Table
table = Maybe Table
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetTableResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The @Table@ object that defines the specified table.
getTableResponse_table :: Lens.Lens' GetTableResponse (Prelude.Maybe Table)
getTableResponse_table :: (Maybe Table -> f (Maybe Table))
-> GetTableResponse -> f GetTableResponse
getTableResponse_table = (GetTableResponse -> Maybe Table)
-> (GetTableResponse -> Maybe Table -> GetTableResponse)
-> Lens
     GetTableResponse GetTableResponse (Maybe Table) (Maybe Table)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetTableResponse' {Maybe Table
table :: Maybe Table
$sel:table:GetTableResponse' :: GetTableResponse -> Maybe Table
table} -> Maybe Table
table) (\s :: GetTableResponse
s@GetTableResponse' {} Maybe Table
a -> GetTableResponse
s {$sel:table:GetTableResponse' :: Maybe Table
table = Maybe Table
a} :: GetTableResponse)

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

instance Prelude.NFData GetTableResponse