{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}
module Network.AWS.Athena.GetQueryResults
(
getQueryResults
, GetQueryResults
, gqrNextToken
, gqrMaxResults
, gqrQueryExecutionId
, getQueryResultsResponse
, GetQueryResultsResponse
, gqrrsNextToken
, gqrrsResultSet
, gqrrsResponseStatus
) where
import Network.AWS.Athena.Types
import Network.AWS.Athena.Types.Product
import Network.AWS.Lens
import Network.AWS.Pager
import Network.AWS.Prelude
import Network.AWS.Request
import Network.AWS.Response
data GetQueryResults = GetQueryResults'
{ _gqrNextToken :: !(Maybe Text)
, _gqrMaxResults :: !(Maybe Nat)
, _gqrQueryExecutionId :: !Text
} deriving (Eq, Read, Show, Data, Typeable, Generic)
getQueryResults
:: Text
-> GetQueryResults
getQueryResults pQueryExecutionId_ =
GetQueryResults'
{ _gqrNextToken = Nothing
, _gqrMaxResults = Nothing
, _gqrQueryExecutionId = pQueryExecutionId_
}
gqrNextToken :: Lens' GetQueryResults (Maybe Text)
gqrNextToken = lens _gqrNextToken (\ s a -> s{_gqrNextToken = a})
gqrMaxResults :: Lens' GetQueryResults (Maybe Natural)
gqrMaxResults = lens _gqrMaxResults (\ s a -> s{_gqrMaxResults = a}) . mapping _Nat
gqrQueryExecutionId :: Lens' GetQueryResults Text
gqrQueryExecutionId = lens _gqrQueryExecutionId (\ s a -> s{_gqrQueryExecutionId = a})
instance AWSPager GetQueryResults where
page rq rs
| stop (rs ^. gqrrsNextToken) = Nothing
| stop (rs ^? gqrrsResultSet . _Just . rsRows) =
Nothing
| otherwise =
Just $ rq & gqrNextToken .~ rs ^. gqrrsNextToken
instance AWSRequest GetQueryResults where
type Rs GetQueryResults = GetQueryResultsResponse
request = postJSON athena
response
= receiveJSON
(\ s h x ->
GetQueryResultsResponse' <$>
(x .?> "NextToken") <*> (x .?> "ResultSet") <*>
(pure (fromEnum s)))
instance Hashable GetQueryResults where
instance NFData GetQueryResults where
instance ToHeaders GetQueryResults where
toHeaders
= const
(mconcat
["X-Amz-Target" =#
("AmazonAthena.GetQueryResults" :: ByteString),
"Content-Type" =#
("application/x-amz-json-1.1" :: ByteString)])
instance ToJSON GetQueryResults where
toJSON GetQueryResults'{..}
= object
(catMaybes
[("NextToken" .=) <$> _gqrNextToken,
("MaxResults" .=) <$> _gqrMaxResults,
Just ("QueryExecutionId" .= _gqrQueryExecutionId)])
instance ToPath GetQueryResults where
toPath = const "/"
instance ToQuery GetQueryResults where
toQuery = const mempty
data GetQueryResultsResponse = GetQueryResultsResponse'
{ _gqrrsNextToken :: !(Maybe Text)
, _gqrrsResultSet :: !(Maybe ResultSet)
, _gqrrsResponseStatus :: !Int
} deriving (Eq, Read, Show, Data, Typeable, Generic)
getQueryResultsResponse
:: Int
-> GetQueryResultsResponse
getQueryResultsResponse pResponseStatus_ =
GetQueryResultsResponse'
{ _gqrrsNextToken = Nothing
, _gqrrsResultSet = Nothing
, _gqrrsResponseStatus = pResponseStatus_
}
gqrrsNextToken :: Lens' GetQueryResultsResponse (Maybe Text)
gqrrsNextToken = lens _gqrrsNextToken (\ s a -> s{_gqrrsNextToken = a})
gqrrsResultSet :: Lens' GetQueryResultsResponse (Maybe ResultSet)
gqrrsResultSet = lens _gqrrsResultSet (\ s a -> s{_gqrrsResultSet = a})
gqrrsResponseStatus :: Lens' GetQueryResultsResponse Int
gqrrsResponseStatus = lens _gqrrsResponseStatus (\ s a -> s{_gqrrsResponseStatus = a})
instance NFData GetQueryResultsResponse where