presto-hdbc 0.1.0.0 → 0.1.0.1
raw patch · 2 files changed
+135/−2 lines, 2 files
Files
- presto-hdbc.cabal +2/−2
- src/Database/HDBC/PrestoData.hs +133/−0
presto-hdbc.cabal view
@@ -11,7 +11,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 0.1.0.0+version: 0.1.0.1 -- A short (one-line) description of the package. synopsis: An HDBC connector for Presto@@ -55,7 +55,7 @@ exposed-modules: Database.HDBC.Presto -- Modules included in this library but not exported.- -- other-modules:+ other-modules: Database.HDBC.PrestoData -- LANGUAGE extensions used by modules in this package. -- other-extensions:
+ src/Database/HDBC/PrestoData.hs view
@@ -0,0 +1,133 @@+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE TemplateHaskell #-}+module Database.HDBC.PrestoData where++import Control.Monad+import Data.Aeson+import Data.Aeson.TH+import Data.Scientific+import Data.Text as T+import Database.HDBC (SqlValue)+import GHC.Generics+import Util.JSONConventions++data PrestoStats = PrestoStats { state :: String+ , scheduled :: Bool+ , nodes :: Integer+ , totalSplits :: Integer+ , queuedSplits :: Integer+ , runningSplits :: Integer+ , completedSplits :: Integer+ , userTimeMillis :: Integer+ , cpuTimeMillis :: Integer+ , wallTimeMillis :: Integer+ , processedRows :: Integer+ , processedBytes :: Integer+ } deriving (Show, Generic)+++data AnyValue = NumValue Scientific+ | TextValue T.Text+ | BoolValue Bool+ | NullValue++instance Show AnyValue where+ show (NumValue n) = show n+ show (TextValue t) = show t+ show (BoolValue b) = show b++instance FromJSON AnyValue where+ parseJSON (Number n) = return $ NumValue n+ parseJSON (String t) = return $ TextValue t+ parseJSON (Bool b) = return $ BoolValue b+ parseJSON (Array a) = error $ "Don't know how to parse array: " ++ show a+ parseJSON (Object o) = error $ "Don't know how to parse object: " ++ show o+ parseJSON Null = return $ NullValue++instance ToJSON AnyValue where+ toJSON (NumValue n) = Number n+ toJSON (TextValue t) = String t+ toJSON (BoolValue b) = Bool b+++type PrestoRow = [SqlValue]+data PrestoColumn = PrestoColumn {+ prestoColumn_name :: String,+ prestoColumn_type :: String+ } deriving (Show, Generic)++data PrestoResponse = PrestoResponse { response_id :: String+ , infoUri :: String+ , nextUri :: Maybe String+ , stats :: PrestoStats++ , columns :: Maybe [PrestoColumn]+ , _data :: Maybe [[AnyValue]]++ } deriving (Show, Generic)++data PrestoInfo = PrestoInfo { pi_queryId :: String+ , pi_session :: PrestoSession+ , pi_state :: String+ , pi_self :: String+ , pi_fieldNames :: [String]+ , pi_query :: String+ , pi_queryStats :: PrestoQueryStats+ , pi_failureInfo :: Maybe PrestoFailureInfo+ , pi_errorCode :: Maybe PrestoErrorCode+ , pi_inputs :: [String]+ } deriving (Show, Generic)+++data PrestoSession = PrestoSession { ps_user :: String+ , ps_catalog :: String+ , ps_schema :: String+ , ps_timeZoneKey :: Int+ , ps_locale :: String+ , ps_remoteUserAddress :: String+ , ps_startTime :: Int+ } deriving (Show, Generic)++data PrestoQueryStats = PrestoQueryStats { pqs_createTime :: String+ , pqs_lastHeartbeat :: String+ , pqs_endTime :: String+ , pqs_elapsedTime :: String+ , pqs_queuedTime :: String+ , pqs_totalTasks :: Int+ , pqs_runningTasks :: Int+ , pqs_completedTasks :: Int+ , pqs_totalDrivers :: Int+ , pqs_queuedDrivers :: Int+ , pqs_runningDrivers :: Int+ , pqs_completedDrivers :: Int+ , pqs_totalMemoryReservation :: String+ , pqs_totalScheduledTime :: String+ , pqs_totalCpuTime :: String+ , pqs_totalUserTime :: String+ , pqs_totalBlockedTime :: String+ , pqs_rawInputDataSize :: String+ , pqs_rawInputPositions :: Int+ , pqs_processedInputDataSize :: String+ , pqs_processedInputPositions :: Int+ , pqs_outputDataSize :: String+ , pqs_outputPositions :: Int+ } deriving (Show, Generic)++data PrestoFailureInfo = PrestoFailureInfo { pfi_type :: String+ , pfi_message :: String+ , pfi_suppressed :: [String]+ , pfi_stack :: [String]+ } deriving (Show, Generic)++data PrestoErrorCode = PrestoErrorCode { pec_code :: Int+ , pec_name :: String+ } deriving (Show, Generic)++$(deriveJSON jsonOptions ''PrestoStats)+$(deriveJSON jsonOptions ''PrestoResponse)+$(deriveJSON jsonOptions ''PrestoColumn)+$(deriveJSON jsonOptions ''PrestoQueryStats)+$(deriveJSON jsonOptions ''PrestoSession)+$(deriveJSON jsonOptions ''PrestoFailureInfo)+$(deriveJSON jsonOptions ''PrestoErrorCode)+$(deriveJSON jsonOptions ''PrestoInfo)