{-# 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.LakeFormation.GetWorkUnitResults
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Returns the work units resulting from the query. Work units can be
-- executed in any order and in parallel.
module Amazonka.LakeFormation.GetWorkUnitResults
  ( -- * Creating a Request
    GetWorkUnitResults (..),
    newGetWorkUnitResults,

    -- * Request Lenses
    getWorkUnitResults_queryId,
    getWorkUnitResults_workUnitId,
    getWorkUnitResults_workUnitToken,

    -- * Destructuring the Response
    GetWorkUnitResultsResponse (..),
    newGetWorkUnitResultsResponse,

    -- * Response Lenses
    getWorkUnitResultsResponse_httpStatus,
    getWorkUnitResultsResponse_resultStream,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.LakeFormation.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newGetWorkUnitResults' smart constructor.
data GetWorkUnitResults = GetWorkUnitResults'
  { -- | The ID of the plan query operation for which to get results.
    GetWorkUnitResults -> Text
queryId :: Prelude.Text,
    -- | The work unit ID for which to get results. Value generated by
    -- enumerating @WorkUnitIdMin@ to @WorkUnitIdMax@ (inclusive) from the
    -- @WorkUnitRange@ in the output of @GetWorkUnits@.
    GetWorkUnitResults -> Natural
workUnitId :: Prelude.Natural,
    -- | A work token used to query the execution service. Token output from
    -- @GetWorkUnits@.
    GetWorkUnitResults -> Sensitive Text
workUnitToken :: Data.Sensitive Prelude.Text
  }
  deriving (GetWorkUnitResults -> GetWorkUnitResults -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetWorkUnitResults -> GetWorkUnitResults -> Bool
$c/= :: GetWorkUnitResults -> GetWorkUnitResults -> Bool
== :: GetWorkUnitResults -> GetWorkUnitResults -> Bool
$c== :: GetWorkUnitResults -> GetWorkUnitResults -> Bool
Prelude.Eq, Int -> GetWorkUnitResults -> ShowS
[GetWorkUnitResults] -> ShowS
GetWorkUnitResults -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetWorkUnitResults] -> ShowS
$cshowList :: [GetWorkUnitResults] -> ShowS
show :: GetWorkUnitResults -> String
$cshow :: GetWorkUnitResults -> String
showsPrec :: Int -> GetWorkUnitResults -> ShowS
$cshowsPrec :: Int -> GetWorkUnitResults -> ShowS
Prelude.Show, forall x. Rep GetWorkUnitResults x -> GetWorkUnitResults
forall x. GetWorkUnitResults -> Rep GetWorkUnitResults x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetWorkUnitResults x -> GetWorkUnitResults
$cfrom :: forall x. GetWorkUnitResults -> Rep GetWorkUnitResults x
Prelude.Generic)

-- |
-- Create a value of 'GetWorkUnitResults' 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:
--
-- 'queryId', 'getWorkUnitResults_queryId' - The ID of the plan query operation for which to get results.
--
-- 'workUnitId', 'getWorkUnitResults_workUnitId' - The work unit ID for which to get results. Value generated by
-- enumerating @WorkUnitIdMin@ to @WorkUnitIdMax@ (inclusive) from the
-- @WorkUnitRange@ in the output of @GetWorkUnits@.
--
-- 'workUnitToken', 'getWorkUnitResults_workUnitToken' - A work token used to query the execution service. Token output from
-- @GetWorkUnits@.
newGetWorkUnitResults ::
  -- | 'queryId'
  Prelude.Text ->
  -- | 'workUnitId'
  Prelude.Natural ->
  -- | 'workUnitToken'
  Prelude.Text ->
  GetWorkUnitResults
newGetWorkUnitResults :: Text -> Natural -> Text -> GetWorkUnitResults
newGetWorkUnitResults
  Text
pQueryId_
  Natural
pWorkUnitId_
  Text
pWorkUnitToken_ =
    GetWorkUnitResults'
      { $sel:queryId:GetWorkUnitResults' :: Text
queryId = Text
pQueryId_,
        $sel:workUnitId:GetWorkUnitResults' :: Natural
workUnitId = Natural
pWorkUnitId_,
        $sel:workUnitToken:GetWorkUnitResults' :: Sensitive Text
workUnitToken =
          forall a. Iso' (Sensitive a) a
Data._Sensitive forall t b. AReview t b -> b -> t
Lens.# Text
pWorkUnitToken_
      }

-- | The ID of the plan query operation for which to get results.
getWorkUnitResults_queryId :: Lens.Lens' GetWorkUnitResults Prelude.Text
getWorkUnitResults_queryId :: Lens' GetWorkUnitResults Text
getWorkUnitResults_queryId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetWorkUnitResults' {Text
queryId :: Text
$sel:queryId:GetWorkUnitResults' :: GetWorkUnitResults -> Text
queryId} -> Text
queryId) (\s :: GetWorkUnitResults
s@GetWorkUnitResults' {} Text
a -> GetWorkUnitResults
s {$sel:queryId:GetWorkUnitResults' :: Text
queryId = Text
a} :: GetWorkUnitResults)

-- | The work unit ID for which to get results. Value generated by
-- enumerating @WorkUnitIdMin@ to @WorkUnitIdMax@ (inclusive) from the
-- @WorkUnitRange@ in the output of @GetWorkUnits@.
getWorkUnitResults_workUnitId :: Lens.Lens' GetWorkUnitResults Prelude.Natural
getWorkUnitResults_workUnitId :: Lens' GetWorkUnitResults Natural
getWorkUnitResults_workUnitId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetWorkUnitResults' {Natural
workUnitId :: Natural
$sel:workUnitId:GetWorkUnitResults' :: GetWorkUnitResults -> Natural
workUnitId} -> Natural
workUnitId) (\s :: GetWorkUnitResults
s@GetWorkUnitResults' {} Natural
a -> GetWorkUnitResults
s {$sel:workUnitId:GetWorkUnitResults' :: Natural
workUnitId = Natural
a} :: GetWorkUnitResults)

-- | A work token used to query the execution service. Token output from
-- @GetWorkUnits@.
getWorkUnitResults_workUnitToken :: Lens.Lens' GetWorkUnitResults Prelude.Text
getWorkUnitResults_workUnitToken :: Lens' GetWorkUnitResults Text
getWorkUnitResults_workUnitToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetWorkUnitResults' {Sensitive Text
workUnitToken :: Sensitive Text
$sel:workUnitToken:GetWorkUnitResults' :: GetWorkUnitResults -> Sensitive Text
workUnitToken} -> Sensitive Text
workUnitToken) (\s :: GetWorkUnitResults
s@GetWorkUnitResults' {} Sensitive Text
a -> GetWorkUnitResults
s {$sel:workUnitToken:GetWorkUnitResults' :: Sensitive Text
workUnitToken = Sensitive Text
a} :: GetWorkUnitResults) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. Iso' (Sensitive a) a
Data._Sensitive

instance Core.AWSRequest GetWorkUnitResults where
  type
    AWSResponse GetWorkUnitResults =
      GetWorkUnitResultsResponse
  request :: (Service -> Service)
-> GetWorkUnitResults -> Request GetWorkUnitResults
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 GetWorkUnitResults
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetWorkUnitResults)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int
 -> ResponseHeaders
 -> ResponseBody
 -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveBody
      ( \Int
s ResponseHeaders
h ResponseBody
x ->
          Int -> ResponseBody -> GetWorkUnitResultsResponse
GetWorkUnitResultsResponse'
            forall (f :: * -> *) a b. Functor 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))
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure ResponseBody
x)
      )

instance Prelude.Hashable GetWorkUnitResults where
  hashWithSalt :: Int -> GetWorkUnitResults -> Int
hashWithSalt Int
_salt GetWorkUnitResults' {Natural
Text
Sensitive Text
workUnitToken :: Sensitive Text
workUnitId :: Natural
queryId :: Text
$sel:workUnitToken:GetWorkUnitResults' :: GetWorkUnitResults -> Sensitive Text
$sel:workUnitId:GetWorkUnitResults' :: GetWorkUnitResults -> Natural
$sel:queryId:GetWorkUnitResults' :: GetWorkUnitResults -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
queryId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
workUnitId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Sensitive Text
workUnitToken

instance Prelude.NFData GetWorkUnitResults where
  rnf :: GetWorkUnitResults -> ()
rnf GetWorkUnitResults' {Natural
Text
Sensitive Text
workUnitToken :: Sensitive Text
workUnitId :: Natural
queryId :: Text
$sel:workUnitToken:GetWorkUnitResults' :: GetWorkUnitResults -> Sensitive Text
$sel:workUnitId:GetWorkUnitResults' :: GetWorkUnitResults -> Natural
$sel:queryId:GetWorkUnitResults' :: GetWorkUnitResults -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
queryId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
workUnitId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Sensitive Text
workUnitToken

instance Data.ToHeaders GetWorkUnitResults where
  toHeaders :: GetWorkUnitResults -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON GetWorkUnitResults where
  toJSON :: GetWorkUnitResults -> Value
toJSON GetWorkUnitResults' {Natural
Text
Sensitive Text
workUnitToken :: Sensitive Text
workUnitId :: Natural
queryId :: Text
$sel:workUnitToken:GetWorkUnitResults' :: GetWorkUnitResults -> Sensitive Text
$sel:workUnitId:GetWorkUnitResults' :: GetWorkUnitResults -> Natural
$sel:queryId:GetWorkUnitResults' :: GetWorkUnitResults -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"QueryId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
queryId),
            forall a. a -> Maybe a
Prelude.Just (Key
"WorkUnitId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
workUnitId),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"WorkUnitToken" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Sensitive Text
workUnitToken)
          ]
      )

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

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

-- | A structure for the output.
--
-- /See:/ 'newGetWorkUnitResultsResponse' smart constructor.
data GetWorkUnitResultsResponse = GetWorkUnitResultsResponse'
  { -- | The response's http status code.
    GetWorkUnitResultsResponse -> Int
httpStatus :: Prelude.Int,
    -- | Rows returned from the @GetWorkUnitResults@ operation as a stream of
    -- Apache Arrow v1.0 messages.
    GetWorkUnitResultsResponse -> ResponseBody
resultStream :: Data.ResponseBody
  }
  deriving (Int -> GetWorkUnitResultsResponse -> ShowS
[GetWorkUnitResultsResponse] -> ShowS
GetWorkUnitResultsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetWorkUnitResultsResponse] -> ShowS
$cshowList :: [GetWorkUnitResultsResponse] -> ShowS
show :: GetWorkUnitResultsResponse -> String
$cshow :: GetWorkUnitResultsResponse -> String
showsPrec :: Int -> GetWorkUnitResultsResponse -> ShowS
$cshowsPrec :: Int -> GetWorkUnitResultsResponse -> ShowS
Prelude.Show, forall x.
Rep GetWorkUnitResultsResponse x -> GetWorkUnitResultsResponse
forall x.
GetWorkUnitResultsResponse -> Rep GetWorkUnitResultsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetWorkUnitResultsResponse x -> GetWorkUnitResultsResponse
$cfrom :: forall x.
GetWorkUnitResultsResponse -> Rep GetWorkUnitResultsResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetWorkUnitResultsResponse' 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', 'getWorkUnitResultsResponse_httpStatus' - The response's http status code.
--
-- 'resultStream', 'getWorkUnitResultsResponse_resultStream' - Rows returned from the @GetWorkUnitResults@ operation as a stream of
-- Apache Arrow v1.0 messages.
newGetWorkUnitResultsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'resultStream'
  Data.ResponseBody ->
  GetWorkUnitResultsResponse
newGetWorkUnitResultsResponse :: Int -> ResponseBody -> GetWorkUnitResultsResponse
newGetWorkUnitResultsResponse
  Int
pHttpStatus_
  ResponseBody
pResultStream_ =
    GetWorkUnitResultsResponse'
      { $sel:httpStatus:GetWorkUnitResultsResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:resultStream:GetWorkUnitResultsResponse' :: ResponseBody
resultStream = ResponseBody
pResultStream_
      }

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

-- | Rows returned from the @GetWorkUnitResults@ operation as a stream of
-- Apache Arrow v1.0 messages.
getWorkUnitResultsResponse_resultStream :: Lens.Lens' GetWorkUnitResultsResponse Data.ResponseBody
getWorkUnitResultsResponse_resultStream :: Lens' GetWorkUnitResultsResponse ResponseBody
getWorkUnitResultsResponse_resultStream = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetWorkUnitResultsResponse' {ResponseBody
resultStream :: ResponseBody
$sel:resultStream:GetWorkUnitResultsResponse' :: GetWorkUnitResultsResponse -> ResponseBody
resultStream} -> ResponseBody
resultStream) (\s :: GetWorkUnitResultsResponse
s@GetWorkUnitResultsResponse' {} ResponseBody
a -> GetWorkUnitResultsResponse
s {$sel:resultStream:GetWorkUnitResultsResponse' :: ResponseBody
resultStream = ResponseBody
a} :: GetWorkUnitResultsResponse)