{-# 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.DeleteTable
-- 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)
--
-- Removes a table definition from the Data Catalog.
--
-- After completing this operation, you no longer have access to the table
-- versions and partitions that belong to the deleted table. Glue deletes
-- these \"orphaned\" resources asynchronously in a timely manner, at the
-- discretion of the service.
--
-- To ensure the immediate deletion of all related resources, before
-- calling @DeleteTable@, use @DeleteTableVersion@ or
-- @BatchDeleteTableVersion@, and @DeletePartition@ or
-- @BatchDeletePartition@, to delete any resources that belong to the
-- table.
module Amazonka.Glue.DeleteTable
  ( -- * Creating a Request
    DeleteTable (..),
    newDeleteTable,

    -- * Request Lenses
    deleteTable_catalogId,
    deleteTable_databaseName,
    deleteTable_name,

    -- * Destructuring the Response
    DeleteTableResponse (..),
    newDeleteTableResponse,

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

-- |
-- Create a value of 'DeleteTable' 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', 'deleteTable_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', 'deleteTable_databaseName' - The name of the catalog database in which the table resides. For Hive
-- compatibility, this name is entirely lowercase.
--
-- 'name', 'deleteTable_name' - The name of the table to be deleted. For Hive compatibility, this name
-- is entirely lowercase.
newDeleteTable ::
  -- | 'databaseName'
  Prelude.Text ->
  -- | 'name'
  Prelude.Text ->
  DeleteTable
newDeleteTable :: Text -> Text -> DeleteTable
newDeleteTable Text
pDatabaseName_ Text
pName_ =
  DeleteTable' :: Maybe Text -> Text -> Text -> DeleteTable
DeleteTable'
    { $sel:catalogId:DeleteTable' :: Maybe Text
catalogId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:databaseName:DeleteTable' :: Text
databaseName = Text
pDatabaseName_,
      $sel:name:DeleteTable' :: 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.
deleteTable_catalogId :: Lens.Lens' DeleteTable (Prelude.Maybe Prelude.Text)
deleteTable_catalogId :: (Maybe Text -> f (Maybe Text)) -> DeleteTable -> f DeleteTable
deleteTable_catalogId = (DeleteTable -> Maybe Text)
-> (DeleteTable -> Maybe Text -> DeleteTable)
-> Lens DeleteTable DeleteTable (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteTable' {Maybe Text
catalogId :: Maybe Text
$sel:catalogId:DeleteTable' :: DeleteTable -> Maybe Text
catalogId} -> Maybe Text
catalogId) (\s :: DeleteTable
s@DeleteTable' {} Maybe Text
a -> DeleteTable
s {$sel:catalogId:DeleteTable' :: Maybe Text
catalogId = Maybe Text
a} :: DeleteTable)

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

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

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

instance Prelude.NFData DeleteTable

instance Core.ToHeaders DeleteTable where
  toHeaders :: DeleteTable -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DeleteTable -> 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.DeleteTable" :: 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 DeleteTable where
  toJSON :: DeleteTable -> Value
toJSON DeleteTable' {Maybe Text
Text
name :: Text
databaseName :: Text
catalogId :: Maybe Text
$sel:name:DeleteTable' :: DeleteTable -> Text
$sel:databaseName:DeleteTable' :: DeleteTable -> Text
$sel:catalogId:DeleteTable' :: DeleteTable -> 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 DeleteTable where
  toPath :: DeleteTable -> ByteString
toPath = ByteString -> DeleteTable -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

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

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

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

instance Prelude.NFData DeleteTableResponse