antiope-athena 1.0.0 → 3.1.0
raw patch · 3 files changed
+106/−40 lines, 3 filesdep +unliftio-corePVP ok
version bump matches the API change (PVP)
Dependencies added: unliftio-core
API changes (from Hackage documentation)
+ Antiope.Athena.Classy: query :: MonadAWS m => ResultConfiguration -> QueryExecutionContext -> Text -> Text -> m [Row]
+ Antiope.Athena.Classy: queryExecutionSucceed :: MonadAWS m => Text -> m Bool
- Antiope.Athena: query :: (MonadResource m, MonadAWS m) => ResultConfiguration -> QueryExecutionContext -> Text -> Text -> m [Row]
+ Antiope.Athena: query :: (HasEnv e, MonadUnliftIO m) => e -> ResultConfiguration -> QueryExecutionContext -> Text -> Text -> m [Row]
- Antiope.Athena: queryExecutionSucceed :: (MonadResource m, MonadAWS m) => Text -> m Bool
+ Antiope.Athena: queryExecutionSucceed :: (MonadUnliftIO m, HasEnv e) => e -> Text -> m Bool
Files
- antiope-athena.cabal +7/−5
- src/Antiope/Athena.hs +36/−35
- src/Antiope/Athena/Classy.hs +63/−0
antiope-athena.cabal view
@@ -1,23 +1,22 @@--- This file has been generated from package.yaml by hpack version 0.20.0.+-- This file has been generated from package.yaml by hpack version 0.28.2. -- -- see: https://github.com/sol/hpack ----- hash: 1f2e25e53eece55bff870faefa1ede3bdaa0f8637db39b08513199c3a928573c+-- hash: 588dd34471160f3891b4a4702d5ed76a07d0c8b8cd4a23ced576a9c88e11f5f6 name: antiope-athena-version: 1.0.0+version: 3.1.0 description: Please see the README on Github at <https://github.com/arbor/antiope#readme> category: Services homepage: https://github.com/arbor/antiope#readme bug-reports: https://github.com/arbor/antiope/issues-author: Tyler Durden+author: Arbor Networks maintainer: mayhem@arbor.net copyright: Arbor Networks license: MIT license-file: LICENSE build-type: Simple cabal-version: >= 1.10- extra-source-files: ChangeLog.md README.md@@ -39,8 +38,10 @@ , lens , resourcet , text+ , unliftio-core exposed-modules: Antiope.Athena+ Antiope.Athena.Classy other-modules: Paths_antiope_athena default-language: Haskell2010@@ -61,6 +62,7 @@ , lens , resourcet , text+ , unliftio-core other-modules: Paths_antiope_athena default-language: Haskell2010
src/Antiope/Athena.hs view
@@ -2,40 +2,41 @@ ( query , queryExecutionSucceed , module Network.AWS.Athena- )where+ ) where import Control.Lens-import Control.Monad.Trans.AWS hiding (await, send)-import Control.Monad.Trans.Resource-import Data.Text (Text)-import Network.AWS (MonadAWS, await, send)+import Control.Monad.IO.Unlift (MonadUnliftIO)+import Data.Text (Text)+import Network.AWS (HasEnv, Rs) import Network.AWS.Athena-import Network.AWS.Waiter hiding (accept)+import Network.AWS.Waiter hiding (accept) -query :: (MonadResource m, MonadAWS m)- => ResultConfiguration- -> QueryExecutionContext- -> Text- -> Text- -> m [Row]-query config context qstring clientRequestToken = do- resp <- send $ startQueryExecution qstring config- & sqeQueryExecutionContext ?~ context- & sqeClientRequestToken ?~ clientRequestToken+import qualified Network.AWS as AWS++query :: (HasEnv e, MonadUnliftIO m)+ => e+ -> ResultConfiguration+ -> QueryExecutionContext+ -> Text+ -> Text+ -> m [Row]+query e config context qstring clientRequestToken = AWS.runResourceT $ AWS.runAWS e $ do+ resp <- AWS.send $ startQueryExecution qstring config+ & sqeQueryExecutionContext ?~ context+ & sqeClientRequestToken ?~ clientRequestToken case resp ^. sqersQueryExecutionId of Just qeid -> go qeid Nothing -> return []- where- go qeid = do- accept <- await queryExecutionFinished (getQueryExecution qeid)- case accept of- AcceptSuccess -> do- results <- send $ getQueryResults qeid- case view gqrrsResultSet results of- Just rs -> return $ view rsRows rs- Nothing -> return []- AcceptRetry -> go qeid- _ -> return []+ where go qeid = do+ accept <- AWS.await queryExecutionFinished (getQueryExecution qeid)+ case accept of+ AcceptSuccess -> do+ results <- AWS.send $ getQueryResults qeid+ case view gqrrsResultSet results of+ Just rs -> return $ view rsRows rs+ Nothing -> return []+ AcceptRetry -> go qeid+ _ -> return [] queryExecutionFinished :: Wait GetQueryExecution queryExecutionFinished = Wait@@ -50,15 +51,15 @@ , matchAll Running AcceptRetry status ] }- where- status :: Fold (Rs GetQueryExecution) QueryExecutionState- status = gqersQueryExecution . _Just . qeStatus . _Just . qesState . _Just+ where status :: Fold (Rs GetQueryExecution) QueryExecutionState+ status = gqersQueryExecution . _Just . qeStatus . _Just . qesState . _Just -queryExecutionSucceed :: (MonadResource m, MonadAWS m)- => Text- -> m Bool-queryExecutionSucceed qeid = do- eq <- view gqersQueryExecution <$> send (getQueryExecution qeid)+queryExecutionSucceed :: (MonadUnliftIO m, HasEnv e)+ => e+ -> Text+ -> m Bool+queryExecutionSucceed e qeid = AWS.runResourceT $ AWS.runAWS e $ do+ eq <- view gqersQueryExecution <$> AWS.send (getQueryExecution qeid) case view qesState =<< (view qeStatus =<< eq) of Just Succeeded -> return True Just _ -> return False
+ src/Antiope/Athena/Classy.hs view
@@ -0,0 +1,63 @@+module Antiope.Athena.Classy+ ( query+ , queryExecutionSucceed+ , module Network.AWS.Athena+ ) where++import Control.Lens+import Data.Text (Text)+import Network.AWS (MonadAWS, Rs)+import Network.AWS.Athena+import Network.AWS.Waiter hiding (accept)++import qualified Network.AWS as AWS++query :: MonadAWS m+ => ResultConfiguration+ -> QueryExecutionContext+ -> Text+ -> Text+ -> m [Row]+query config context qstring clientRequestToken = do+ resp <- AWS.send $ startQueryExecution qstring config+ & sqeQueryExecutionContext ?~ context+ & sqeClientRequestToken ?~ clientRequestToken+ case resp ^. sqersQueryExecutionId of+ Just qeid -> go qeid+ Nothing -> return []+ where go qeid = do+ accept <- AWS.await queryExecutionFinished (getQueryExecution qeid)+ case accept of+ AcceptSuccess -> do+ results <- AWS.send $ getQueryResults qeid+ case view gqrrsResultSet results of+ Just rs -> return $ view rsRows rs+ Nothing -> return []+ AcceptRetry -> go qeid+ _ -> return []++queryExecutionFinished :: Wait GetQueryExecution+queryExecutionFinished = Wait+ { _waitName = "QueryFinished"+ , _waitAttempts = 100+ , _waitDelay = 1+ , _waitAcceptors =+ [ matchAll Succeeded AcceptSuccess status+ , matchAll Failed AcceptFailure status+ , matchAll Cancelled AcceptFailure status+ , matchAll Queued AcceptRetry status+ , matchAll Running AcceptRetry status+ ]+ }+ where status :: Fold (Rs GetQueryExecution) QueryExecutionState+ status = gqersQueryExecution . _Just . qeStatus . _Just . qesState . _Just++queryExecutionSucceed :: MonadAWS m+ => Text+ -> m Bool+queryExecutionSucceed qeid = do+ eq <- view gqersQueryExecution <$> AWS.send (getQueryExecution qeid)+ case view qesState =<< (view qeStatus =<< eq) of+ Just Succeeded -> return True+ Just _ -> return False+ Nothing -> return False