{-# 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.Athena.GetQueryExecution
-- 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)
--
-- Returns information about a single execution of a query if you have
-- access to the workgroup in which the query ran. Each time a query
-- executes, information about the query execution is saved with a unique
-- ID.
module Amazonka.Athena.GetQueryExecution
  ( -- * Creating a Request
    GetQueryExecution (..),
    newGetQueryExecution,

    -- * Request Lenses
    getQueryExecution_queryExecutionId,

    -- * Destructuring the Response
    GetQueryExecutionResponse (..),
    newGetQueryExecutionResponse,

    -- * Response Lenses
    getQueryExecutionResponse_queryExecution,
    getQueryExecutionResponse_httpStatus,
  )
where

import Amazonka.Athena.Types
import qualified Amazonka.Core as Core
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:/ 'newGetQueryExecution' smart constructor.
data GetQueryExecution = GetQueryExecution'
  { -- | The unique ID of the query execution.
    GetQueryExecution -> Text
queryExecutionId :: Prelude.Text
  }
  deriving (GetQueryExecution -> GetQueryExecution -> Bool
(GetQueryExecution -> GetQueryExecution -> Bool)
-> (GetQueryExecution -> GetQueryExecution -> Bool)
-> Eq GetQueryExecution
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetQueryExecution -> GetQueryExecution -> Bool
$c/= :: GetQueryExecution -> GetQueryExecution -> Bool
== :: GetQueryExecution -> GetQueryExecution -> Bool
$c== :: GetQueryExecution -> GetQueryExecution -> Bool
Prelude.Eq, ReadPrec [GetQueryExecution]
ReadPrec GetQueryExecution
Int -> ReadS GetQueryExecution
ReadS [GetQueryExecution]
(Int -> ReadS GetQueryExecution)
-> ReadS [GetQueryExecution]
-> ReadPrec GetQueryExecution
-> ReadPrec [GetQueryExecution]
-> Read GetQueryExecution
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetQueryExecution]
$creadListPrec :: ReadPrec [GetQueryExecution]
readPrec :: ReadPrec GetQueryExecution
$creadPrec :: ReadPrec GetQueryExecution
readList :: ReadS [GetQueryExecution]
$creadList :: ReadS [GetQueryExecution]
readsPrec :: Int -> ReadS GetQueryExecution
$creadsPrec :: Int -> ReadS GetQueryExecution
Prelude.Read, Int -> GetQueryExecution -> ShowS
[GetQueryExecution] -> ShowS
GetQueryExecution -> String
(Int -> GetQueryExecution -> ShowS)
-> (GetQueryExecution -> String)
-> ([GetQueryExecution] -> ShowS)
-> Show GetQueryExecution
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetQueryExecution] -> ShowS
$cshowList :: [GetQueryExecution] -> ShowS
show :: GetQueryExecution -> String
$cshow :: GetQueryExecution -> String
showsPrec :: Int -> GetQueryExecution -> ShowS
$cshowsPrec :: Int -> GetQueryExecution -> ShowS
Prelude.Show, (forall x. GetQueryExecution -> Rep GetQueryExecution x)
-> (forall x. Rep GetQueryExecution x -> GetQueryExecution)
-> Generic GetQueryExecution
forall x. Rep GetQueryExecution x -> GetQueryExecution
forall x. GetQueryExecution -> Rep GetQueryExecution x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetQueryExecution x -> GetQueryExecution
$cfrom :: forall x. GetQueryExecution -> Rep GetQueryExecution x
Prelude.Generic)

-- |
-- Create a value of 'GetQueryExecution' 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:
--
-- 'queryExecutionId', 'getQueryExecution_queryExecutionId' - The unique ID of the query execution.
newGetQueryExecution ::
  -- | 'queryExecutionId'
  Prelude.Text ->
  GetQueryExecution
newGetQueryExecution :: Text -> GetQueryExecution
newGetQueryExecution Text
pQueryExecutionId_ =
  GetQueryExecution' :: Text -> GetQueryExecution
GetQueryExecution'
    { $sel:queryExecutionId:GetQueryExecution' :: Text
queryExecutionId =
        Text
pQueryExecutionId_
    }

-- | The unique ID of the query execution.
getQueryExecution_queryExecutionId :: Lens.Lens' GetQueryExecution Prelude.Text
getQueryExecution_queryExecutionId :: (Text -> f Text) -> GetQueryExecution -> f GetQueryExecution
getQueryExecution_queryExecutionId = (GetQueryExecution -> Text)
-> (GetQueryExecution -> Text -> GetQueryExecution)
-> Lens GetQueryExecution GetQueryExecution Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetQueryExecution' {Text
queryExecutionId :: Text
$sel:queryExecutionId:GetQueryExecution' :: GetQueryExecution -> Text
queryExecutionId} -> Text
queryExecutionId) (\s :: GetQueryExecution
s@GetQueryExecution' {} Text
a -> GetQueryExecution
s {$sel:queryExecutionId:GetQueryExecution' :: Text
queryExecutionId = Text
a} :: GetQueryExecution)

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

instance Prelude.NFData GetQueryExecution

instance Core.ToHeaders GetQueryExecution where
  toHeaders :: GetQueryExecution -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetQueryExecution -> 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
"AmazonAthena.GetQueryExecution" ::
                          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 GetQueryExecution where
  toJSON :: GetQueryExecution -> Value
toJSON GetQueryExecution' {Text
queryExecutionId :: Text
$sel:queryExecutionId:GetQueryExecution' :: GetQueryExecution -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"QueryExecutionId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
queryExecutionId)
          ]
      )

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

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

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

-- |
-- Create a value of 'GetQueryExecutionResponse' 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:
--
-- 'queryExecution', 'getQueryExecutionResponse_queryExecution' - Information about the query execution.
--
-- 'httpStatus', 'getQueryExecutionResponse_httpStatus' - The response's http status code.
newGetQueryExecutionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetQueryExecutionResponse
newGetQueryExecutionResponse :: Int -> GetQueryExecutionResponse
newGetQueryExecutionResponse Int
pHttpStatus_ =
  GetQueryExecutionResponse' :: Maybe QueryExecution -> Int -> GetQueryExecutionResponse
GetQueryExecutionResponse'
    { $sel:queryExecution:GetQueryExecutionResponse' :: Maybe QueryExecution
queryExecution =
        Maybe QueryExecution
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetQueryExecutionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Information about the query execution.
getQueryExecutionResponse_queryExecution :: Lens.Lens' GetQueryExecutionResponse (Prelude.Maybe QueryExecution)
getQueryExecutionResponse_queryExecution :: (Maybe QueryExecution -> f (Maybe QueryExecution))
-> GetQueryExecutionResponse -> f GetQueryExecutionResponse
getQueryExecutionResponse_queryExecution = (GetQueryExecutionResponse -> Maybe QueryExecution)
-> (GetQueryExecutionResponse
    -> Maybe QueryExecution -> GetQueryExecutionResponse)
-> Lens
     GetQueryExecutionResponse
     GetQueryExecutionResponse
     (Maybe QueryExecution)
     (Maybe QueryExecution)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetQueryExecutionResponse' {Maybe QueryExecution
queryExecution :: Maybe QueryExecution
$sel:queryExecution:GetQueryExecutionResponse' :: GetQueryExecutionResponse -> Maybe QueryExecution
queryExecution} -> Maybe QueryExecution
queryExecution) (\s :: GetQueryExecutionResponse
s@GetQueryExecutionResponse' {} Maybe QueryExecution
a -> GetQueryExecutionResponse
s {$sel:queryExecution:GetQueryExecutionResponse' :: Maybe QueryExecution
queryExecution = Maybe QueryExecution
a} :: GetQueryExecutionResponse)

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

instance Prelude.NFData GetQueryExecutionResponse