{-# 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.TimeStreamQuery.Query
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- @Query@ is a synchronous operation that enables you to run a query
-- against your Amazon Timestream data. @Query@ will time out after 60
-- seconds. You must update the default timeout in the SDK to support a
-- timeout of 60 seconds. See the
-- <https://docs.aws.amazon.com/timestream/latest/developerguide/code-samples.run-query.html code sample>
-- for details.
--
-- Your query request will fail in the following cases:
--
-- -   If you submit a @Query@ request with the same client token outside
--     of the 5-minute idempotency window.
--
-- -   If you submit a @Query@ request with the same client token, but
--     change other parameters, within the 5-minute idempotency window.
--
-- -   If the size of the row (including the query metadata) exceeds 1 MB,
--     then the query will fail with the following error message:
--
--     @Query aborted as max page response size has been exceeded by the output result row@
--
-- -   If the IAM principal of the query initiator and the result reader
--     are not the same and\/or the query initiator and the result reader
--     do not have the same query string in the query requests, the query
--     will fail with an @Invalid pagination token@ error.
--
-- This operation returns paginated results.
module Amazonka.TimeStreamQuery.Query
  ( -- * Creating a Request
    Query (..),
    newQuery,

    -- * Request Lenses
    query_clientToken,
    query_maxRows,
    query_nextToken,
    query_queryString,

    -- * Destructuring the Response
    QueryResponse (..),
    newQueryResponse,

    -- * Response Lenses
    queryResponse_nextToken,
    queryResponse_queryStatus,
    queryResponse_httpStatus,
    queryResponse_queryId,
    queryResponse_rows,
    queryResponse_columnInfo,
  )
where

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

-- | /See:/ 'newQuery' smart constructor.
data Query = Query'
  { -- | Unique, case-sensitive string of up to 64 ASCII characters specified
    -- when a @Query@ request is made. Providing a @ClientToken@ makes the call
    -- to @Query@ /idempotent/. This means that running the same query
    -- repeatedly will produce the same result. In other words, making multiple
    -- identical @Query@ requests has the same effect as making a single
    -- request. When using @ClientToken@ in a query, note the following:
    --
    -- -   If the Query API is instantiated without a @ClientToken@, the Query
    --     SDK generates a @ClientToken@ on your behalf.
    --
    -- -   If the @Query@ invocation only contains the @ClientToken@ but does
    --     not include a @NextToken@, that invocation of @Query@ is assumed to
    --     be a new query run.
    --
    -- -   If the invocation contains @NextToken@, that particular invocation
    --     is assumed to be a subsequent invocation of a prior call to the
    --     Query API, and a result set is returned.
    --
    -- -   After 4 hours, any request with the same @ClientToken@ is treated as
    --     a new request.
    Query -> Maybe (Sensitive Text)
clientToken :: Prelude.Maybe (Data.Sensitive Prelude.Text),
    -- | The total number of rows to be returned in the @Query@ output. The
    -- initial run of @Query@ with a @MaxRows@ value specified will return the
    -- result set of the query in two cases:
    --
    -- -   The size of the result is less than @1MB@.
    --
    -- -   The number of rows in the result set is less than the value of
    --     @maxRows@.
    --
    -- Otherwise, the initial invocation of @Query@ only returns a @NextToken@,
    -- which can then be used in subsequent calls to fetch the result set. To
    -- resume pagination, provide the @NextToken@ value in the subsequent
    -- command.
    --
    -- If the row size is large (e.g. a row has many columns), Timestream may
    -- return fewer rows to keep the response size from exceeding the 1 MB
    -- limit. If @MaxRows@ is not provided, Timestream will send the necessary
    -- number of rows to meet the 1 MB limit.
    Query -> Maybe Natural
maxRows :: Prelude.Maybe Prelude.Natural,
    -- | A pagination token used to return a set of results. When the @Query@ API
    -- is invoked using @NextToken@, that particular invocation is assumed to
    -- be a subsequent invocation of a prior call to @Query@, and a result set
    -- is returned. However, if the @Query@ invocation only contains the
    -- @ClientToken@, that invocation of @Query@ is assumed to be a new query
    -- run.
    --
    -- Note the following when using NextToken in a query:
    --
    -- -   A pagination token can be used for up to five @Query@ invocations,
    --     OR for a duration of up to 1 hour – whichever comes first.
    --
    -- -   Using the same @NextToken@ will return the same set of records. To
    --     keep paginating through the result set, you must to use the most
    --     recent @nextToken@.
    --
    -- -   Suppose a @Query@ invocation returns two @NextToken@ values,
    --     @TokenA@ and @TokenB@. If @TokenB@ is used in a subsequent @Query@
    --     invocation, then @TokenA@ is invalidated and cannot be reused.
    --
    -- -   To request a previous result set from a query after pagination has
    --     begun, you must re-invoke the Query API.
    --
    -- -   The latest @NextToken@ should be used to paginate until @null@ is
    --     returned, at which point a new @NextToken@ should be used.
    --
    -- -   If the IAM principal of the query initiator and the result reader
    --     are not the same and\/or the query initiator and the result reader
    --     do not have the same query string in the query requests, the query
    --     will fail with an @Invalid pagination token@ error.
    Query -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The query to be run by Timestream.
    Query -> Sensitive Text
queryString :: Data.Sensitive Prelude.Text
  }
  deriving (Query -> Query -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Query -> Query -> Bool
$c/= :: Query -> Query -> Bool
== :: Query -> Query -> Bool
$c== :: Query -> Query -> Bool
Prelude.Eq, Int -> Query -> ShowS
[Query] -> ShowS
Query -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Query] -> ShowS
$cshowList :: [Query] -> ShowS
show :: Query -> String
$cshow :: Query -> String
showsPrec :: Int -> Query -> ShowS
$cshowsPrec :: Int -> Query -> ShowS
Prelude.Show, forall x. Rep Query x -> Query
forall x. Query -> Rep Query x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Query x -> Query
$cfrom :: forall x. Query -> Rep Query x
Prelude.Generic)

-- |
-- Create a value of 'Query' 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:
--
-- 'clientToken', 'query_clientToken' - Unique, case-sensitive string of up to 64 ASCII characters specified
-- when a @Query@ request is made. Providing a @ClientToken@ makes the call
-- to @Query@ /idempotent/. This means that running the same query
-- repeatedly will produce the same result. In other words, making multiple
-- identical @Query@ requests has the same effect as making a single
-- request. When using @ClientToken@ in a query, note the following:
--
-- -   If the Query API is instantiated without a @ClientToken@, the Query
--     SDK generates a @ClientToken@ on your behalf.
--
-- -   If the @Query@ invocation only contains the @ClientToken@ but does
--     not include a @NextToken@, that invocation of @Query@ is assumed to
--     be a new query run.
--
-- -   If the invocation contains @NextToken@, that particular invocation
--     is assumed to be a subsequent invocation of a prior call to the
--     Query API, and a result set is returned.
--
-- -   After 4 hours, any request with the same @ClientToken@ is treated as
--     a new request.
--
-- 'maxRows', 'query_maxRows' - The total number of rows to be returned in the @Query@ output. The
-- initial run of @Query@ with a @MaxRows@ value specified will return the
-- result set of the query in two cases:
--
-- -   The size of the result is less than @1MB@.
--
-- -   The number of rows in the result set is less than the value of
--     @maxRows@.
--
-- Otherwise, the initial invocation of @Query@ only returns a @NextToken@,
-- which can then be used in subsequent calls to fetch the result set. To
-- resume pagination, provide the @NextToken@ value in the subsequent
-- command.
--
-- If the row size is large (e.g. a row has many columns), Timestream may
-- return fewer rows to keep the response size from exceeding the 1 MB
-- limit. If @MaxRows@ is not provided, Timestream will send the necessary
-- number of rows to meet the 1 MB limit.
--
-- 'nextToken', 'query_nextToken' - A pagination token used to return a set of results. When the @Query@ API
-- is invoked using @NextToken@, that particular invocation is assumed to
-- be a subsequent invocation of a prior call to @Query@, and a result set
-- is returned. However, if the @Query@ invocation only contains the
-- @ClientToken@, that invocation of @Query@ is assumed to be a new query
-- run.
--
-- Note the following when using NextToken in a query:
--
-- -   A pagination token can be used for up to five @Query@ invocations,
--     OR for a duration of up to 1 hour – whichever comes first.
--
-- -   Using the same @NextToken@ will return the same set of records. To
--     keep paginating through the result set, you must to use the most
--     recent @nextToken@.
--
-- -   Suppose a @Query@ invocation returns two @NextToken@ values,
--     @TokenA@ and @TokenB@. If @TokenB@ is used in a subsequent @Query@
--     invocation, then @TokenA@ is invalidated and cannot be reused.
--
-- -   To request a previous result set from a query after pagination has
--     begun, you must re-invoke the Query API.
--
-- -   The latest @NextToken@ should be used to paginate until @null@ is
--     returned, at which point a new @NextToken@ should be used.
--
-- -   If the IAM principal of the query initiator and the result reader
--     are not the same and\/or the query initiator and the result reader
--     do not have the same query string in the query requests, the query
--     will fail with an @Invalid pagination token@ error.
--
-- 'queryString', 'query_queryString' - The query to be run by Timestream.
newQuery ::
  -- | 'queryString'
  Prelude.Text ->
  Query
newQuery :: Text -> Query
newQuery Text
pQueryString_ =
  Query'
    { $sel:clientToken:Query' :: Maybe (Sensitive Text)
clientToken = forall a. Maybe a
Prelude.Nothing,
      $sel:maxRows:Query' :: Maybe Natural
maxRows = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:Query' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:queryString:Query' :: Sensitive Text
queryString = forall a. Iso' (Sensitive a) a
Data._Sensitive forall t b. AReview t b -> b -> t
Lens.# Text
pQueryString_
    }

-- | Unique, case-sensitive string of up to 64 ASCII characters specified
-- when a @Query@ request is made. Providing a @ClientToken@ makes the call
-- to @Query@ /idempotent/. This means that running the same query
-- repeatedly will produce the same result. In other words, making multiple
-- identical @Query@ requests has the same effect as making a single
-- request. When using @ClientToken@ in a query, note the following:
--
-- -   If the Query API is instantiated without a @ClientToken@, the Query
--     SDK generates a @ClientToken@ on your behalf.
--
-- -   If the @Query@ invocation only contains the @ClientToken@ but does
--     not include a @NextToken@, that invocation of @Query@ is assumed to
--     be a new query run.
--
-- -   If the invocation contains @NextToken@, that particular invocation
--     is assumed to be a subsequent invocation of a prior call to the
--     Query API, and a result set is returned.
--
-- -   After 4 hours, any request with the same @ClientToken@ is treated as
--     a new request.
query_clientToken :: Lens.Lens' Query (Prelude.Maybe Prelude.Text)
query_clientToken :: Lens' Query (Maybe Text)
query_clientToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Query' {Maybe (Sensitive Text)
clientToken :: Maybe (Sensitive Text)
$sel:clientToken:Query' :: Query -> Maybe (Sensitive Text)
clientToken} -> Maybe (Sensitive Text)
clientToken) (\s :: Query
s@Query' {} Maybe (Sensitive Text)
a -> Query
s {$sel:clientToken:Query' :: Maybe (Sensitive Text)
clientToken = Maybe (Sensitive Text)
a} :: Query) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall a. Iso' (Sensitive a) a
Data._Sensitive

-- | The total number of rows to be returned in the @Query@ output. The
-- initial run of @Query@ with a @MaxRows@ value specified will return the
-- result set of the query in two cases:
--
-- -   The size of the result is less than @1MB@.
--
-- -   The number of rows in the result set is less than the value of
--     @maxRows@.
--
-- Otherwise, the initial invocation of @Query@ only returns a @NextToken@,
-- which can then be used in subsequent calls to fetch the result set. To
-- resume pagination, provide the @NextToken@ value in the subsequent
-- command.
--
-- If the row size is large (e.g. a row has many columns), Timestream may
-- return fewer rows to keep the response size from exceeding the 1 MB
-- limit. If @MaxRows@ is not provided, Timestream will send the necessary
-- number of rows to meet the 1 MB limit.
query_maxRows :: Lens.Lens' Query (Prelude.Maybe Prelude.Natural)
query_maxRows :: Lens' Query (Maybe Natural)
query_maxRows = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Query' {Maybe Natural
maxRows :: Maybe Natural
$sel:maxRows:Query' :: Query -> Maybe Natural
maxRows} -> Maybe Natural
maxRows) (\s :: Query
s@Query' {} Maybe Natural
a -> Query
s {$sel:maxRows:Query' :: Maybe Natural
maxRows = Maybe Natural
a} :: Query)

-- | A pagination token used to return a set of results. When the @Query@ API
-- is invoked using @NextToken@, that particular invocation is assumed to
-- be a subsequent invocation of a prior call to @Query@, and a result set
-- is returned. However, if the @Query@ invocation only contains the
-- @ClientToken@, that invocation of @Query@ is assumed to be a new query
-- run.
--
-- Note the following when using NextToken in a query:
--
-- -   A pagination token can be used for up to five @Query@ invocations,
--     OR for a duration of up to 1 hour – whichever comes first.
--
-- -   Using the same @NextToken@ will return the same set of records. To
--     keep paginating through the result set, you must to use the most
--     recent @nextToken@.
--
-- -   Suppose a @Query@ invocation returns two @NextToken@ values,
--     @TokenA@ and @TokenB@. If @TokenB@ is used in a subsequent @Query@
--     invocation, then @TokenA@ is invalidated and cannot be reused.
--
-- -   To request a previous result set from a query after pagination has
--     begun, you must re-invoke the Query API.
--
-- -   The latest @NextToken@ should be used to paginate until @null@ is
--     returned, at which point a new @NextToken@ should be used.
--
-- -   If the IAM principal of the query initiator and the result reader
--     are not the same and\/or the query initiator and the result reader
--     do not have the same query string in the query requests, the query
--     will fail with an @Invalid pagination token@ error.
query_nextToken :: Lens.Lens' Query (Prelude.Maybe Prelude.Text)
query_nextToken :: Lens' Query (Maybe Text)
query_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Query' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:Query' :: Query -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: Query
s@Query' {} Maybe Text
a -> Query
s {$sel:nextToken:Query' :: Maybe Text
nextToken = Maybe Text
a} :: Query)

-- | The query to be run by Timestream.
query_queryString :: Lens.Lens' Query Prelude.Text
query_queryString :: Lens' Query Text
query_queryString = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Query' {Sensitive Text
queryString :: Sensitive Text
$sel:queryString:Query' :: Query -> Sensitive Text
queryString} -> Sensitive Text
queryString) (\s :: Query
s@Query' {} Sensitive Text
a -> Query
s {$sel:queryString:Query' :: Sensitive Text
queryString = Sensitive Text
a} :: Query) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. Iso' (Sensitive a) a
Data._Sensitive

instance Core.AWSPager Query where
  page :: Query -> AWSResponse Query -> Maybe Query
page Query
rq AWSResponse Query
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse Query
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' QueryResponse (Maybe Text)
queryResponse_nextToken
            forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
        forall a. Maybe a
Prelude.Nothing
    | forall a. AWSTruncated a => a -> Bool
Core.stop (AWSResponse Query
rs forall s a. s -> Getting a s a -> a
Lens.^. Lens' QueryResponse [Row]
queryResponse_rows) =
        forall a. Maybe a
Prelude.Nothing
    | Bool
Prelude.otherwise =
        forall a. a -> Maybe a
Prelude.Just
          forall a b. (a -> b) -> a -> b
Prelude.$ Query
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' Query (Maybe Text)
query_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse Query
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' QueryResponse (Maybe Text)
queryResponse_nextToken
          forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just

instance Core.AWSRequest Query where
  type AWSResponse Query = QueryResponse
  request :: (Service -> Service) -> Query -> Request Query
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 Query
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse Query)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text
-> Maybe QueryStatus
-> Int
-> Text
-> [Row]
-> [ColumnInfo]
-> QueryResponse
QueryResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"NextToken")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"QueryStatus")
            forall (f :: * -> *) a b. Applicative f => 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.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String a
Data..:> Key
"QueryId")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"Rows" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"ColumnInfo" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable Query where
  hashWithSalt :: Int -> Query -> Int
hashWithSalt Int
_salt Query' {Maybe Natural
Maybe Text
Maybe (Sensitive Text)
Sensitive Text
queryString :: Sensitive Text
nextToken :: Maybe Text
maxRows :: Maybe Natural
clientToken :: Maybe (Sensitive Text)
$sel:queryString:Query' :: Query -> Sensitive Text
$sel:nextToken:Query' :: Query -> Maybe Text
$sel:maxRows:Query' :: Query -> Maybe Natural
$sel:clientToken:Query' :: Query -> Maybe (Sensitive Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (Sensitive Text)
clientToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
maxRows
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
nextToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Sensitive Text
queryString

instance Prelude.NFData Query where
  rnf :: Query -> ()
rnf Query' {Maybe Natural
Maybe Text
Maybe (Sensitive Text)
Sensitive Text
queryString :: Sensitive Text
nextToken :: Maybe Text
maxRows :: Maybe Natural
clientToken :: Maybe (Sensitive Text)
$sel:queryString:Query' :: Query -> Sensitive Text
$sel:nextToken:Query' :: Query -> Maybe Text
$sel:maxRows:Query' :: Query -> Maybe Natural
$sel:clientToken:Query' :: Query -> Maybe (Sensitive Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (Sensitive Text)
clientToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
maxRows
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Sensitive Text
queryString

instance Data.ToHeaders Query where
  toHeaders :: Query -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# (ByteString
"Timestream_20181101.Query" :: Prelude.ByteString),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.0" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON Query where
  toJSON :: Query -> Value
toJSON Query' {Maybe Natural
Maybe Text
Maybe (Sensitive Text)
Sensitive Text
queryString :: Sensitive Text
nextToken :: Maybe Text
maxRows :: Maybe Natural
clientToken :: Maybe (Sensitive Text)
$sel:queryString:Query' :: Query -> Sensitive Text
$sel:nextToken:Query' :: Query -> Maybe Text
$sel:maxRows:Query' :: Query -> Maybe Natural
$sel:clientToken:Query' :: Query -> Maybe (Sensitive Text)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"ClientToken" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (Sensitive Text)
clientToken,
            (Key
"MaxRows" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
maxRows,
            (Key
"NextToken" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
nextToken,
            forall a. a -> Maybe a
Prelude.Just (Key
"QueryString" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Sensitive Text
queryString)
          ]
      )

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

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

-- | /See:/ 'newQueryResponse' smart constructor.
data QueryResponse = QueryResponse'
  { -- | A pagination token that can be used again on a @Query@ call to get the
    -- next set of results.
    QueryResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | Information about the status of the query, including progress and bytes
    -- scanned.
    QueryResponse -> Maybe QueryStatus
queryStatus :: Prelude.Maybe QueryStatus,
    -- | The response's http status code.
    QueryResponse -> Int
httpStatus :: Prelude.Int,
    -- | A unique ID for the given query.
    QueryResponse -> Text
queryId :: Prelude.Text,
    -- | The result set rows returned by the query.
    QueryResponse -> [Row]
rows :: [Row],
    -- | The column data types of the returned result set.
    QueryResponse -> [ColumnInfo]
columnInfo :: [ColumnInfo]
  }
  deriving (QueryResponse -> QueryResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: QueryResponse -> QueryResponse -> Bool
$c/= :: QueryResponse -> QueryResponse -> Bool
== :: QueryResponse -> QueryResponse -> Bool
$c== :: QueryResponse -> QueryResponse -> Bool
Prelude.Eq, ReadPrec [QueryResponse]
ReadPrec QueryResponse
Int -> ReadS QueryResponse
ReadS [QueryResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [QueryResponse]
$creadListPrec :: ReadPrec [QueryResponse]
readPrec :: ReadPrec QueryResponse
$creadPrec :: ReadPrec QueryResponse
readList :: ReadS [QueryResponse]
$creadList :: ReadS [QueryResponse]
readsPrec :: Int -> ReadS QueryResponse
$creadsPrec :: Int -> ReadS QueryResponse
Prelude.Read, Int -> QueryResponse -> ShowS
[QueryResponse] -> ShowS
QueryResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [QueryResponse] -> ShowS
$cshowList :: [QueryResponse] -> ShowS
show :: QueryResponse -> String
$cshow :: QueryResponse -> String
showsPrec :: Int -> QueryResponse -> ShowS
$cshowsPrec :: Int -> QueryResponse -> ShowS
Prelude.Show, forall x. Rep QueryResponse x -> QueryResponse
forall x. QueryResponse -> Rep QueryResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep QueryResponse x -> QueryResponse
$cfrom :: forall x. QueryResponse -> Rep QueryResponse x
Prelude.Generic)

-- |
-- Create a value of 'QueryResponse' 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:
--
-- 'nextToken', 'queryResponse_nextToken' - A pagination token that can be used again on a @Query@ call to get the
-- next set of results.
--
-- 'queryStatus', 'queryResponse_queryStatus' - Information about the status of the query, including progress and bytes
-- scanned.
--
-- 'httpStatus', 'queryResponse_httpStatus' - The response's http status code.
--
-- 'queryId', 'queryResponse_queryId' - A unique ID for the given query.
--
-- 'rows', 'queryResponse_rows' - The result set rows returned by the query.
--
-- 'columnInfo', 'queryResponse_columnInfo' - The column data types of the returned result set.
newQueryResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'queryId'
  Prelude.Text ->
  QueryResponse
newQueryResponse :: Int -> Text -> QueryResponse
newQueryResponse Int
pHttpStatus_ Text
pQueryId_ =
  QueryResponse'
    { $sel:nextToken:QueryResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:queryStatus:QueryResponse' :: Maybe QueryStatus
queryStatus = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:QueryResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:queryId:QueryResponse' :: Text
queryId = Text
pQueryId_,
      $sel:rows:QueryResponse' :: [Row]
rows = forall a. Monoid a => a
Prelude.mempty,
      $sel:columnInfo:QueryResponse' :: [ColumnInfo]
columnInfo = forall a. Monoid a => a
Prelude.mempty
    }

-- | A pagination token that can be used again on a @Query@ call to get the
-- next set of results.
queryResponse_nextToken :: Lens.Lens' QueryResponse (Prelude.Maybe Prelude.Text)
queryResponse_nextToken :: Lens' QueryResponse (Maybe Text)
queryResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QueryResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:QueryResponse' :: QueryResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: QueryResponse
s@QueryResponse' {} Maybe Text
a -> QueryResponse
s {$sel:nextToken:QueryResponse' :: Maybe Text
nextToken = Maybe Text
a} :: QueryResponse)

-- | Information about the status of the query, including progress and bytes
-- scanned.
queryResponse_queryStatus :: Lens.Lens' QueryResponse (Prelude.Maybe QueryStatus)
queryResponse_queryStatus :: Lens' QueryResponse (Maybe QueryStatus)
queryResponse_queryStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QueryResponse' {Maybe QueryStatus
queryStatus :: Maybe QueryStatus
$sel:queryStatus:QueryResponse' :: QueryResponse -> Maybe QueryStatus
queryStatus} -> Maybe QueryStatus
queryStatus) (\s :: QueryResponse
s@QueryResponse' {} Maybe QueryStatus
a -> QueryResponse
s {$sel:queryStatus:QueryResponse' :: Maybe QueryStatus
queryStatus = Maybe QueryStatus
a} :: QueryResponse)

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

-- | A unique ID for the given query.
queryResponse_queryId :: Lens.Lens' QueryResponse Prelude.Text
queryResponse_queryId :: Lens' QueryResponse Text
queryResponse_queryId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QueryResponse' {Text
queryId :: Text
$sel:queryId:QueryResponse' :: QueryResponse -> Text
queryId} -> Text
queryId) (\s :: QueryResponse
s@QueryResponse' {} Text
a -> QueryResponse
s {$sel:queryId:QueryResponse' :: Text
queryId = Text
a} :: QueryResponse)

-- | The result set rows returned by the query.
queryResponse_rows :: Lens.Lens' QueryResponse [Row]
queryResponse_rows :: Lens' QueryResponse [Row]
queryResponse_rows = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QueryResponse' {[Row]
rows :: [Row]
$sel:rows:QueryResponse' :: QueryResponse -> [Row]
rows} -> [Row]
rows) (\s :: QueryResponse
s@QueryResponse' {} [Row]
a -> QueryResponse
s {$sel:rows:QueryResponse' :: [Row]
rows = [Row]
a} :: QueryResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The column data types of the returned result set.
queryResponse_columnInfo :: Lens.Lens' QueryResponse [ColumnInfo]
queryResponse_columnInfo :: Lens' QueryResponse [ColumnInfo]
queryResponse_columnInfo = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QueryResponse' {[ColumnInfo]
columnInfo :: [ColumnInfo]
$sel:columnInfo:QueryResponse' :: QueryResponse -> [ColumnInfo]
columnInfo} -> [ColumnInfo]
columnInfo) (\s :: QueryResponse
s@QueryResponse' {} [ColumnInfo]
a -> QueryResponse
s {$sel:columnInfo:QueryResponse' :: [ColumnInfo]
columnInfo = [ColumnInfo]
a} :: QueryResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Prelude.NFData QueryResponse where
  rnf :: QueryResponse -> ()
rnf QueryResponse' {Int
[ColumnInfo]
[Row]
Maybe Text
Maybe QueryStatus
Text
columnInfo :: [ColumnInfo]
rows :: [Row]
queryId :: Text
httpStatus :: Int
queryStatus :: Maybe QueryStatus
nextToken :: Maybe Text
$sel:columnInfo:QueryResponse' :: QueryResponse -> [ColumnInfo]
$sel:rows:QueryResponse' :: QueryResponse -> [Row]
$sel:queryId:QueryResponse' :: QueryResponse -> Text
$sel:httpStatus:QueryResponse' :: QueryResponse -> Int
$sel:queryStatus:QueryResponse' :: QueryResponse -> Maybe QueryStatus
$sel:nextToken:QueryResponse' :: QueryResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe QueryStatus
queryStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` 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 [Row]
rows
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [ColumnInfo]
columnInfo