{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE GeneralizedNewtypeDeriving -- In order to be able to derive from non-standard derivable classes (such as Num)
,BangPatterns
,RecordWildCards
,DeriveGeneric -- Allow automatic deriving of instances for the Generic typeclass (see Text.PrettyPrint.Tabulate.Example)
,DeriveDataTypeable -- Enable automatic deriving of instances for the Data typeclass (see Text.PrettyPrint.Tabulate.Example)
,ExistentialQuantification
,StandaloneDeriving
{--
:set -XDeriveGeneric
:set -XDeriveDataTypeable
--}
-- Allow definition of type class instances for type synonyms. (used for RTuple instance of Tabulate)
--,TypeSynonymInstances
--,FlexibleInstances
#-}
module RTable.Core (
RTable (..)
,RTuple (..)
,RDataType (..)
,RTimestamp (..)
,RTableMData (..)
,RTupleMData (..)
,ColumnInfo (..)
,ColumnOrder
,Name
,ColumnName
,RTableName
,ColumnDType (..)
,Delimiter
,RTabular (..)
,ROperation (..)
,UnaryRTableOperation
,BinaryRTableOperation
,RAggOperation (..)
,AggFunction (..)
,raggGenericAgg
,raggSum
,raggCount
,raggCountDist
,raggCountStar
,raggAvg
,raggMax
,raggMin
,raggStrAgg
,RPredicate
,RGroupPredicate
,RJoinPredicate
,RUpsertPredicate (..)
,runUnaryROperation
,ropU
,runUnaryROperationRes
,ropUres
,runBinaryROperation
,ropB
,runBinaryROperationRes
,ropBres
,RTuplesRet
,RTabResult
,rtabResult
,runRTabResult
,execRTabResult
,rtuplesRet
,getRTuplesRet
, (.)
, (<=<)
,runRfilter
,f
,runInnerJoinO
,iJ
,runLeftJoin
,lJ
,runRightJoin
,rJ
,runFullOuterJoin
,foJ
,sJ
,runSemiJoin
,aJ
,runAntiJoin
,joinRTuples
,runUnion
,runUnionAll
,u
,runIntersect
,i
,runDiff
,d
,runProjection
,runProjectionMissedHits
,p
,runAggregation
,rAgg
,runGroupBy
,rG
,groupNoAggList
,groupNoAgg
,runOrderBy
,rO
,runCombinedROp
,rComb
,IgnoreDefault (..)
,decodeRTable
,decodeColValue
,toRTimestamp
,createRTimestamp
,toUTCTime
,fromUTCTime
,rTimestampToRText
,stdTimestampFormat
,stdDateFormat
,instrRText
,instr
,instrText
,rdtappend
,stripRText
,removeCharAroundRText
,isText
,nvlRTable
,nvlRTuple
,isNullRTuple
,isNull
,isNotNull
,nvl
,nvlColValue
,isRTabEmpty
,headRTup
,limit
,isRTupEmpty
,getRTupColValue
,rtupLookup
,rtupLookupDefault
, (<!>)
, (<!!>)
,rtableToList
,concatRTab
,rtupleToList
,toListRDataType
,toText
,fromText
,rtabMap
,rtabFoldr'
,rtabFoldl'
,rtupleMap
,rtupleMapWithKey
,rdatatypeFoldr'
,rdatatypeFoldl'
,insertAppendRTab
,insertPrependRTab
,insertRTabToRTab
,deleteRTab
,updateRTab
,upsertRTab
,updateRTuple
,upsertRTuple
,emptyRTable
,createSingletonRTable
,rtableFromList
,addColumn
,removeColumn
,emptyRTuple
,createNullRTuple
,createRTuple
,rtupleFromList
,createRDataType
,createRTableMData
,getColumnNamesFromRTab
,getColumnNamesFromRTuple
,getColumnInfoFromRTab
,getColumnInfoFromRTuple
,getTheType
,listOfColInfoRDataType
,toListColumnName
,toListColumnInfo
,rtabsSameStructure
,rtuplesSameStructure
,getUniqueColumnNamesAfterJoin
,ColumnDoesNotExist (..)
,ConflictingRTableStructures (..)
,EmptyInputStringsInToRTimestamp (..)
,UnsupportedTimeStampFormat (..)
,UniquenessViolationInUpsert (..)
,printRTable
,eitherPrintRTable
,printfRTable
,eitherPrintfRTable
,RTupleFormat (..)
,ColFormatMap
,FormatSpecifier (..)
,OrderingSpec (..)
,genRTupleFormat
,genRTupleFormatDefault
,genColFormatMap
,genDefaultColFormatMap
) where
import Debug.Trace
import Data.Serialize (decode, encode)
import qualified Data.Vector as V
import Data.HashMap.Strict as HM
import Data.Text as T
import qualified Data.ByteString as BS
import qualified Data.Typeable as TB
import qualified Data.Dynamic as D
import Data.List (find, filter, last, all, elem, break, span, map, null, zip, zipWith, elemIndex, sortOn, union, intersect, (\\), take, length, repeat, groupBy, sort, sortBy, foldl', foldr, foldr1, foldl',head, findIndex, tails, isPrefixOf)
import Data.Maybe (fromJust, fromMaybe)
import Data.Char (toUpper,digitToInt, isDigit, isAlpha)
import Data.Monoid as M
import Control.Monad ((<=<))
import Control.Monad.Trans.Writer.Strict (Writer, writer, runWriter, execWriter)
import Text.Printf (printf)
import Control.Exception
import GHC.Generics (Generic)
import Control.DeepSeq
import Data.Time.Clock (UTCTime(..), diffTimeToPicoseconds, secondsToDiffTime)
import Data.Time.Calendar (Day, toGregorian, fromGregorian)
myRTableOperation :: RTable -> RTable
myRTableOperation :: RTable -> RTable
myRTableOperation RTable
rtab = do
RTuple
rtup <- RTable
rtab
let new_rtup :: RTuple
new_rtup = RTuple -> RTuple
doStuff RTuple
rtup
RTuple -> RTable
forall (m :: * -> *) a. Monad m => a -> m a
return RTuple
new_rtup
where
doStuff :: RTuple -> RTuple
doStuff :: RTuple -> RTuple
doStuff = RTuple -> RTuple
forall a. HasCallStack => a
undefined
class RTabular a where
toRTable :: RTableMData -> a -> RTable
fromRTable :: RTableMData -> RTable -> a
{-# MINIMAL toRTable, fromRTable #-}
type RTable = V.Vector RTuple
type RTuple = HM.HashMap ColumnName RDataType
rtableToList :: RTable -> [RTuple]
rtableToList :: RTable -> [RTuple]
rtableToList = RTable -> [RTuple]
forall a. Vector a -> [a]
V.toList
rtableFromList :: [RTuple] -> RTable
rtableFromList :: [RTuple] -> RTable
rtableFromList = [RTuple] -> RTable
forall a. [a] -> Vector a
V.fromList
rtupleToList :: RTuple -> [(ColumnName, RDataType)]
rtupleToList :: RTuple -> [(ColumnName, RDataType)]
rtupleToList = RTuple -> [(ColumnName, RDataType)]
forall k v. HashMap k v -> [(k, v)]
HM.toList
rtupleFromList :: [(ColumnName, RDataType)] -> RTuple
rtupleFromList :: [(ColumnName, RDataType)] -> RTuple
rtupleFromList = [(ColumnName, RDataType)] -> RTuple
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HM.fromList
type Name = Text
type ColumnName = Name
type RTableName = Name
data ColumnDType = UknownType | Integer | Varchar | Date Text | Timestamp Text | Double deriving (Int -> ColumnDType -> ShowS
[ColumnDType] -> ShowS
ColumnDType -> String
(Int -> ColumnDType -> ShowS)
-> (ColumnDType -> String)
-> ([ColumnDType] -> ShowS)
-> Show ColumnDType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ColumnDType] -> ShowS
$cshowList :: [ColumnDType] -> ShowS
show :: ColumnDType -> String
$cshow :: ColumnDType -> String
showsPrec :: Int -> ColumnDType -> ShowS
$cshowsPrec :: Int -> ColumnDType -> ShowS
Show, ColumnDType -> ColumnDType -> Bool
(ColumnDType -> ColumnDType -> Bool)
-> (ColumnDType -> ColumnDType -> Bool) -> Eq ColumnDType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ColumnDType -> ColumnDType -> Bool
$c/= :: ColumnDType -> ColumnDType -> Bool
== :: ColumnDType -> ColumnDType -> Bool
$c== :: ColumnDType -> ColumnDType -> Bool
Eq)
data RDataType =
RInt { RDataType -> Integer
rint :: !Integer }
| RText { RDataType -> ColumnName
rtext :: !T.Text }
| RUTCTime { RDataType -> UTCTime
rutct :: !UTCTime}
| RDate {
RDataType -> ColumnName
rdate :: !T.Text
,RDataType -> ColumnName
dtformat :: !Text
}
| RTime { RDataType -> RTimestamp
rtime :: !RTimestamp }
| RDouble { RDataType -> Double
rdouble :: !Double }
| Null
deriving (Int -> RDataType -> ShowS
[RDataType] -> ShowS
RDataType -> String
(Int -> RDataType -> ShowS)
-> (RDataType -> String)
-> ([RDataType] -> ShowS)
-> Show RDataType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RDataType] -> ShowS
$cshowList :: [RDataType] -> ShowS
show :: RDataType -> String
$cshow :: RDataType -> String
showsPrec :: Int -> RDataType -> ShowS
$cshowsPrec :: Int -> RDataType -> ShowS
Show, ReadPrec [RDataType]
ReadPrec RDataType
Int -> ReadS RDataType
ReadS [RDataType]
(Int -> ReadS RDataType)
-> ReadS [RDataType]
-> ReadPrec RDataType
-> ReadPrec [RDataType]
-> Read RDataType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RDataType]
$creadListPrec :: ReadPrec [RDataType]
readPrec :: ReadPrec RDataType
$creadPrec :: ReadPrec RDataType
readList :: ReadS [RDataType]
$creadList :: ReadS [RDataType]
readsPrec :: Int -> ReadS RDataType
$creadsPrec :: Int -> ReadS RDataType
Read, (forall x. RDataType -> Rep RDataType x)
-> (forall x. Rep RDataType x -> RDataType) -> Generic RDataType
forall x. Rep RDataType x -> RDataType
forall x. RDataType -> Rep RDataType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RDataType x -> RDataType
$cfrom :: forall x. RDataType -> Rep RDataType x
Generic, TB.Typeable)
instance NFData RDataType
instance Eq RDataType where
RInt Integer
i1 == :: RDataType -> RDataType -> Bool
== RInt Integer
i2 = Integer
i1 Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
i2
RText ColumnName
t1 == RText ColumnName
t2 = ColumnName
t1 ColumnName -> ColumnName -> Bool
forall a. Eq a => a -> a -> Bool
== ColumnName
t2
RDate ColumnName
t1 ColumnName
s1 == RDate ColumnName
t2 ColumnName
s2 = String -> String -> RTimestamp
toRTimestamp (ColumnName -> String
unpack ColumnName
s1) (ColumnName -> String
unpack ColumnName
t1) RTimestamp -> RTimestamp -> Bool
forall a. Eq a => a -> a -> Bool
== String -> String -> RTimestamp
toRTimestamp (ColumnName -> String
unpack ColumnName
s2) (ColumnName -> String
unpack ColumnName
t2)
RTime RTimestamp
t1 == RTime RTimestamp
t2 = RTimestamp
t1 RTimestamp -> RTimestamp -> Bool
forall a. Eq a => a -> a -> Bool
== RTimestamp
t2
RDouble Double
d1 == RDouble Double
d2 = Double
d1 Double -> Double -> Bool
forall a. Eq a => a -> a -> Bool
== Double
d2
RDataType
Null == RDataType
Null = Bool
False
RDataType
_ == RDataType
Null = Bool
False
RDataType
Null == RDataType
_ = Bool
False
RDataType
_ == RDataType
_ = Bool
False
RDataType
Null /= :: RDataType -> RDataType -> Bool
/= RDataType
Null = Bool
False
RDataType
_ /= RDataType
Null = Bool
False
RDataType
Null /= RDataType
_ = Bool
False
RDataType
x /= RDataType
y = Bool -> Bool
not (RDataType
x RDataType -> RDataType -> Bool
forall a. Eq a => a -> a -> Bool
== RDataType
y)
instance Ord RDataType where
compare :: RDataType -> RDataType -> Ordering
compare RDataType
Null RDataType
_ = Ordering
GT
compare RDataType
_ RDataType
Null = Ordering
GT
compare (RInt Integer
i1) (RInt Integer
i2) = Integer -> Integer -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Integer
i1 Integer
i2
compare (RText ColumnName
t1) (RText ColumnName
t2) = ColumnName -> ColumnName -> Ordering
forall a. Ord a => a -> a -> Ordering
compare ColumnName
t1 ColumnName
t2
compare (RDate ColumnName
t1 ColumnName
s1) (RDate ColumnName
t2 ColumnName
s2) = RTimestamp -> RTimestamp -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (String -> String -> RTimestamp
toRTimestamp (ColumnName -> String
unpack ColumnName
s1) (ColumnName -> String
unpack ColumnName
t1)) (String -> String -> RTimestamp
toRTimestamp (ColumnName -> String
unpack ColumnName
s2) (ColumnName -> String
unpack ColumnName
t2))
compare (RTime RTimestamp
t1) (RTime RTimestamp
t2) = RTimestamp -> RTimestamp -> Ordering
forall a. Ord a => a -> a -> Ordering
compare RTimestamp
t1 RTimestamp
t2
compare (RDouble Double
d1) (RDouble Double
d2) = Double -> Double -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Double
d1 Double
d2
compare RDataType
_ RDataType
_ = Ordering
GT
isNull :: RDataType -> Bool
isNull :: RDataType -> Bool
isNull RDataType
x =
case RDataType
x of
RDataType
Null -> Bool
True
RDataType
_ -> Bool
False
isNotNull :: RDataType -> Bool
isNotNull = Bool -> Bool
not (Bool -> Bool) -> (RDataType -> Bool) -> RDataType -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDataType -> Bool
isNull
instance Num RDataType where
+ :: RDataType -> RDataType -> RDataType
(+) (RInt Integer
i1) (RInt Integer
i2) = Integer -> RDataType
RInt (Integer
i1 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
i2)
(+) (RDouble Double
d1) (RDouble Double
d2) = Double -> RDataType
RDouble (Double
d1 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
d2)
(+) (RDouble Double
d1) (RInt Integer
i2) = Double -> RDataType
RDouble (Double
d1 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Integer -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
i2)
(+) (RInt Integer
i1) (RDouble Double
d2) = Double -> RDataType
RDouble (Integer -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
i1 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
d2)
(+) (RInt Integer
i1) (RDataType
Null) = RDataType
Null
(+) (RDataType
Null) (RInt Integer
i2) = RDataType
Null
(+) (RDouble Double
d1) (RDataType
Null) = RDataType
Null
(+) (RDataType
Null) (RDouble Double
d2) = RDataType
Null
(+) RDataType
_ RDataType
_ = RDataType
Null
* :: RDataType -> RDataType -> RDataType
(*) (RInt Integer
i1) (RInt Integer
i2) = Integer -> RDataType
RInt (Integer
i1 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
i2)
(*) (RDouble Double
d1) (RDouble Double
d2) = Double -> RDataType
RDouble (Double
d1 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
d2)
(*) (RDouble Double
d1) (RInt Integer
i2) = Double -> RDataType
RDouble (Double
d1 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Integer -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
i2)
(*) (RInt Integer
i1) (RDouble Double
d2) = Double -> RDataType
RDouble (Integer -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
i1 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
d2)
(*) (RInt Integer
i1) (RDataType
Null) = RDataType
Null
(*) (RDataType
Null) (RInt Integer
i2) = RDataType
Null
(*) (RDouble Double
d1) (RDataType
Null) = RDataType
Null
(*) (RDataType
Null) (RDouble Double
d2) = RDataType
Null
(*) RDataType
_ RDataType
_ = RDataType
Null
abs :: RDataType -> RDataType
abs (RInt Integer
i) = Integer -> RDataType
RInt (Integer -> Integer
forall a. Num a => a -> a
abs Integer
i)
abs (RDouble Double
i) = Double -> RDataType
RDouble (Double -> Double
forall a. Num a => a -> a
abs Double
i)
abs RDataType
_ = RDataType
Null
signum :: RDataType -> RDataType
signum (RInt Integer
i) = Integer -> RDataType
RInt (Integer -> Integer
forall a. Num a => a -> a
signum Integer
i)
signum (RDouble Double
i) = Double -> RDataType
RDouble (Double -> Double
forall a. Num a => a -> a
signum Double
i)
signum RDataType
_ = RDataType
Null
fromInteger :: Integer -> RDataType
fromInteger Integer
i = Integer -> RDataType
RInt Integer
i
negate :: RDataType -> RDataType
negate (RInt Integer
i) = Integer -> RDataType
RInt (Integer -> Integer
forall a. Num a => a -> a
negate Integer
i)
negate (RDouble Double
i) = Double -> RDataType
RDouble (Double -> Double
forall a. Num a => a -> a
negate Double
i)
negate RDataType
_ = RDataType
Null
instance Fractional RDataType where
/ :: RDataType -> RDataType -> RDataType
(/) (RInt Integer
i1) (RInt Integer
i2) = Double -> RDataType
RDouble (Double -> RDataType) -> Double -> RDataType
forall a b. (a -> b) -> a -> b
$ (Integer -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
i1)Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/(Integer -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
i2)
(/) (RDouble Double
d1) (RInt Integer
i2) = Double -> RDataType
RDouble (Double -> RDataType) -> Double -> RDataType
forall a b. (a -> b) -> a -> b
$ (Double
d1)Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/(Integer -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
i2)
(/) (RInt Integer
i1) (RDouble Double
d2) = Double -> RDataType
RDouble (Double -> RDataType) -> Double -> RDataType
forall a b. (a -> b) -> a -> b
$ (Integer -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
i1)Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/(Double
d2)
(/) (RDouble Double
d1) (RDouble Double
d2) = Double -> RDataType
RDouble (Double -> RDataType) -> Double -> RDataType
forall a b. (a -> b) -> a -> b
$ Double
d1Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/Double
d2
(/) RDataType
_ RDataType
_ = RDataType
Null
fromRational :: Rational -> RDataType
fromRational Rational
r = Double -> RDataType
RDouble (Rational -> Double
forall a. Fractional a => Rational -> a
fromRational Rational
r)
stdDateFormat :: String
stdDateFormat = String
"DD/MM/YYYY"
getColumnNamesFromRTab :: RTable -> [ColumnName]
getColumnNamesFromRTab :: RTable -> [ColumnName]
getColumnNamesFromRTab RTable
rtab = RTuple -> [ColumnName]
getColumnNamesFromRTuple (RTuple -> [ColumnName]) -> RTuple -> [ColumnName]
forall a b. (a -> b) -> a -> b
$ RTable -> RTuple
headRTup RTable
rtab
getColumnNamesFromRTuple :: RTuple -> [ColumnName]
getColumnNamesFromRTuple :: RTuple -> [ColumnName]
getColumnNamesFromRTuple RTuple
t = RTuple -> [ColumnName]
forall k v. HashMap k v -> [k]
HM.keys RTuple
t
getColumnInfoFromRTab :: RTable -> [ColumnInfo]
getColumnInfoFromRTab :: RTable -> [ColumnInfo]
getColumnInfoFromRTab RTable
rtab = RTuple -> [ColumnInfo]
getColumnInfoFromRTuple (RTuple -> [ColumnInfo]) -> RTuple -> [ColumnInfo]
forall a b. (a -> b) -> a -> b
$ RTable -> RTuple
headRTup RTable
rtab
getColumnInfoFromRTuple :: RTuple -> [ColumnInfo]
getColumnInfoFromRTuple :: RTuple -> [ColumnInfo]
getColumnInfoFromRTuple RTuple
t =
HashMap ColumnName ColumnInfo -> [ColumnInfo]
forall k v. HashMap k v -> [v]
HM.elems (HashMap ColumnName ColumnInfo -> [ColumnInfo])
-> HashMap ColumnName ColumnInfo -> [ColumnInfo]
forall a b. (a -> b) -> a -> b
$ (ColumnName -> RDataType -> ColumnInfo)
-> RTuple -> HashMap ColumnName ColumnInfo
forall k v1 v2. (k -> v1 -> v2) -> HashMap k v1 -> HashMap k v2
HM.mapWithKey (\ColumnName
c RDataType
v -> ColumnInfo :: ColumnName -> ColumnDType -> ColumnInfo
ColumnInfo { name :: ColumnName
name = ColumnName
c, dtype :: ColumnDType
dtype = RDataType -> ColumnDType
getTheType RDataType
v}) RTuple
t
getTheType :: RDataType -> ColumnDType
getTheType :: RDataType -> ColumnDType
getTheType RDataType
v =
case RDataType
v of
RInt Integer
_ -> ColumnDType
Integer
RText ColumnName
_ -> ColumnDType
Varchar
RDate {rdate :: RDataType -> ColumnName
rdate = ColumnName
d, dtformat :: RDataType -> ColumnName
dtformat = ColumnName
f} -> ColumnName -> ColumnDType
Date ColumnName
f
RTime RTimestamp
_ -> ColumnName -> ColumnDType
Timestamp (String -> ColumnName
pack String
stdTimestampFormat)
RDouble Double
_ -> ColumnDType
Double
RDataType
Null -> ColumnDType
UknownType
headRTup ::
RTable
-> RTuple
headRTup :: RTable -> RTuple
headRTup = RTable -> RTuple
forall a. Vector a -> a
V.head
rtupLookup ::
ColumnName
-> RTuple
-> Maybe RDataType
rtupLookup :: ColumnName -> RTuple -> Maybe RDataType
rtupLookup = ColumnName -> RTuple -> Maybe RDataType
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HM.lookup
rtupLookupDefault ::
RDataType
-> ColumnName
-> RTuple
-> RDataType
rtupLookupDefault :: RDataType -> ColumnName -> RTuple -> RDataType
rtupLookupDefault = RDataType -> ColumnName -> RTuple -> RDataType
forall k v. (Eq k, Hashable k) => v -> k -> HashMap k v -> v
HM.lookupDefault
getRTupColValue ::
ColumnName
-> RTuple
-> RDataType
getRTupColValue :: ColumnName -> RTuple -> RDataType
getRTupColValue = RDataType -> ColumnName -> RTuple -> RDataType
rtupLookupDefault RDataType
Null
(<!>) ::
RTuple
-> ColumnName
-> RDataType
<!> :: RTuple -> ColumnName -> RDataType
(<!>) RTuple
t ColumnName
c =
case ColumnName -> RTuple -> Maybe RDataType
rtupLookup ColumnName
c RTuple
t of
Just RDataType
v -> RDataType
v
Maybe RDataType
Nothing -> ColumnDoesNotExist -> RDataType
forall a e. Exception e => e -> a
throw (ColumnDoesNotExist -> RDataType)
-> ColumnDoesNotExist -> RDataType
forall a b. (a -> b) -> a -> b
$ ColumnName -> ColumnDoesNotExist
ColumnDoesNotExist ColumnName
c
(<!!>) ::
RTuple
-> ColumnName
-> Maybe RDataType
<!!> :: RTuple -> ColumnName -> Maybe RDataType
(<!!>) RTuple
t ColumnName
c = ColumnName -> RTuple -> Maybe RDataType
rtupLookup ColumnName
c RTuple
t
nvl ::
RDataType
-> RDataType
-> RDataType
nvl :: RDataType -> RDataType -> RDataType
nvl RDataType
v RDataType
defaultVal =
if RDataType -> Bool
isNull RDataType
v
then RDataType
defaultVal
else RDataType
v
nvlColValue ::
ColumnName
-> RDataType
-> RTuple
-> RDataType
nvlColValue :: ColumnName -> RDataType -> RTuple -> RDataType
nvlColValue ColumnName
col RDataType
defaultVal RTuple
tup =
if RTuple -> Bool
isRTupEmpty RTuple
tup
then RDataType
Null
else
case RTuple
tup RTuple -> ColumnName -> RDataType
<!> ColumnName
col of
RDataType
Null -> RDataType
defaultVal
RDataType
val -> RDataType
val
data IgnoreDefault = Ignore | NotIgnore deriving (IgnoreDefault -> IgnoreDefault -> Bool
(IgnoreDefault -> IgnoreDefault -> Bool)
-> (IgnoreDefault -> IgnoreDefault -> Bool) -> Eq IgnoreDefault
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IgnoreDefault -> IgnoreDefault -> Bool
$c/= :: IgnoreDefault -> IgnoreDefault -> Bool
== :: IgnoreDefault -> IgnoreDefault -> Bool
$c== :: IgnoreDefault -> IgnoreDefault -> Bool
Eq, Int -> IgnoreDefault -> ShowS
[IgnoreDefault] -> ShowS
IgnoreDefault -> String
(Int -> IgnoreDefault -> ShowS)
-> (IgnoreDefault -> String)
-> ([IgnoreDefault] -> ShowS)
-> Show IgnoreDefault
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IgnoreDefault] -> ShowS
$cshowList :: [IgnoreDefault] -> ShowS
show :: IgnoreDefault -> String
$cshow :: IgnoreDefault -> String
showsPrec :: Int -> IgnoreDefault -> ShowS
$cshowsPrec :: Int -> IgnoreDefault -> ShowS
Show)
decodeColValue ::
ColumnName
-> RDataType
-> RDataType
-> RDataType
-> IgnoreDefault
-> RTuple
-> RDataType
decodeColValue :: ColumnName
-> RDataType
-> RDataType
-> RDataType
-> IgnoreDefault
-> RTuple
-> RDataType
decodeColValue ColumnName
cname RDataType
searchVal RDataType
returnVal RDataType
defaultVal IgnoreDefault
ignoreInd RTuple
tup =
if RTuple -> Bool
isRTupEmpty RTuple
tup
then RDataType
Null
else
if RTuple
tup RTuple -> ColumnName -> RDataType
<!> ColumnName
cname RDataType -> RDataType -> Bool
forall a. Eq a => a -> a -> Bool
== RDataType
searchVal
then RDataType
returnVal
else
if IgnoreDefault
ignoreInd IgnoreDefault -> IgnoreDefault -> Bool
forall a. Eq a => a -> a -> Bool
== IgnoreDefault
Ignore
then RTuple
tup RTuple -> ColumnName -> RDataType
<!> ColumnName
cname
else RDataType
defaultVal
nvlRTuple ::
ColumnName
-> RDataType
-> RTuple
-> RTuple
nvlRTuple :: ColumnName -> RDataType -> RTuple -> RTuple
nvlRTuple ColumnName
c RDataType
defaultVal RTuple
tup =
if RTuple -> Bool
isRTupEmpty RTuple
tup
then RTuple
emptyRTuple
else (RDataType -> RDataType) -> RTuple -> RTuple
forall v1 v2 k. (v1 -> v2) -> HashMap k v1 -> HashMap k v2
HM.map (\RDataType
v -> RDataType -> RDataType -> RDataType
nvl RDataType
v RDataType
defaultVal) RTuple
tup
nvlRTable ::
ColumnName
-> RDataType
-> RTable
-> RTable
nvlRTable :: ColumnName -> RDataType -> RTable -> RTable
nvlRTable ColumnName
c RDataType
defaultVal RTable
tab =
if RTable -> Bool
isRTabEmpty RTable
tab
then RTable
emptyRTable
else
(RTuple -> RTuple) -> RTable -> RTable
forall a b. (a -> b) -> Vector a -> Vector b
V.map (\RTuple
t -> ColumnName -> RDataType -> RTuple -> RTuple
upsertRTuple ColumnName
c (ColumnName -> RDataType -> RTuple -> RDataType
nvlColValue ColumnName
c RDataType
defaultVal RTuple
t) RTuple
t) RTable
tab
decodeRTable ::
ColumnName
-> RDataType
-> RDataType
-> RDataType
-> IgnoreDefault
-> RTable
-> RTable
decodeRTable :: ColumnName
-> RDataType
-> RDataType
-> RDataType
-> IgnoreDefault
-> RTable
-> RTable
decodeRTable ColumnName
cName RDataType
searchVal RDataType
returnVal RDataType
defaultVal IgnoreDefault
ignoreInd RTable
tab =
if RTable -> Bool
isRTabEmpty RTable
tab
then RTable
emptyRTable
else
(RTuple -> RTuple) -> RTable -> RTable
forall a b. (a -> b) -> Vector a -> Vector b
V.map (\RTuple
t -> ColumnName -> RDataType -> RTuple -> RTuple
upsertRTuple ColumnName
cName (ColumnName
-> RDataType
-> RDataType
-> RDataType
-> IgnoreDefault
-> RTuple
-> RDataType
decodeColValue ColumnName
cName RDataType
searchVal RDataType
returnVal RDataType
defaultVal IgnoreDefault
ignoreInd RTuple
t) RTuple
t) RTable
tab
stripRText ::
RDataType
-> RDataType
stripRText :: RDataType -> RDataType
stripRText (RText ColumnName
t) = ColumnName -> RDataType
RText (ColumnName -> RDataType) -> ColumnName -> RDataType
forall a b. (a -> b) -> a -> b
$ ColumnName -> ColumnName
T.strip ColumnName
t
stripRText RDataType
_ = RDataType
Null
rdtappend ::
RDataType
-> RDataType
-> RDataType
rdtappend :: RDataType -> RDataType -> RDataType
rdtappend (RText ColumnName
t1) (RText ColumnName
t2) = ColumnName -> RDataType
RText (ColumnName
t1 ColumnName -> ColumnName -> ColumnName
`T.append` ColumnName
t2)
rdtappend RDataType
_ RDataType
_ = RDataType
Null
removeCharAroundRText :: Char -> RDataType -> RDataType
removeCharAroundRText :: Char -> RDataType -> RDataType
removeCharAroundRText Char
ch (RText ColumnName
t) = ColumnName -> RDataType
RText (ColumnName -> RDataType) -> ColumnName -> RDataType
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> ColumnName -> ColumnName
T.dropAround (\Char
c -> Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
ch) ColumnName
t
removeCharAroundRText Char
ch RDataType
_ = RDataType
Null
data RTimestamp = RTimestampVal {
RTimestamp -> Int
year :: !Int
,RTimestamp -> Int
month :: !Int
,RTimestamp -> Int
day :: !Int
,RTimestamp -> Int
hours24 :: !Int
,RTimestamp -> Int
minutes :: !Int
,RTimestamp -> Int
seconds :: !Int
} deriving (Int -> RTimestamp -> ShowS
[RTimestamp] -> ShowS
RTimestamp -> String
(Int -> RTimestamp -> ShowS)
-> (RTimestamp -> String)
-> ([RTimestamp] -> ShowS)
-> Show RTimestamp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RTimestamp] -> ShowS
$cshowList :: [RTimestamp] -> ShowS
show :: RTimestamp -> String
$cshow :: RTimestamp -> String
showsPrec :: Int -> RTimestamp -> ShowS
$cshowsPrec :: Int -> RTimestamp -> ShowS
Show, ReadPrec [RTimestamp]
ReadPrec RTimestamp
Int -> ReadS RTimestamp
ReadS [RTimestamp]
(Int -> ReadS RTimestamp)
-> ReadS [RTimestamp]
-> ReadPrec RTimestamp
-> ReadPrec [RTimestamp]
-> Read RTimestamp
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RTimestamp]
$creadListPrec :: ReadPrec [RTimestamp]
readPrec :: ReadPrec RTimestamp
$creadPrec :: ReadPrec RTimestamp
readList :: ReadS [RTimestamp]
$creadList :: ReadS [RTimestamp]
readsPrec :: Int -> ReadS RTimestamp
$creadsPrec :: Int -> ReadS RTimestamp
Read, (forall x. RTimestamp -> Rep RTimestamp x)
-> (forall x. Rep RTimestamp x -> RTimestamp) -> Generic RTimestamp
forall x. Rep RTimestamp x -> RTimestamp
forall x. RTimestamp -> Rep RTimestamp x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RTimestamp x -> RTimestamp
$cfrom :: forall x. RTimestamp -> Rep RTimestamp x
Generic)
instance NFData RTimestamp
instance Eq RTimestamp where
RTimestampVal Int
y1 Int
m1 Int
d1 Int
h1 Int
mi1 Int
s1 == :: RTimestamp -> RTimestamp -> Bool
== RTimestampVal Int
y2 Int
m2 Int
d2 Int
h2 Int
mi2 Int
s2 =
Int
y1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
y2 Bool -> Bool -> Bool
&& Int
m1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
m2 Bool -> Bool -> Bool
&& Int
d1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
d2 Bool -> Bool -> Bool
&& Int
h1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
h2 Bool -> Bool -> Bool
&& Int
mi1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
mi2 Bool -> Bool -> Bool
&& Int
s1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
s2
instance Ord RTimestamp where
compare :: RTimestamp -> RTimestamp -> Ordering
compare (RTimestampVal Int
y1 Int
m1 Int
d1 Int
h1 Int
mi1 Int
s1) (RTimestampVal Int
y2 Int
m2 Int
d2 Int
h2 Int
mi2 Int
s2) =
if Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
y1 Int
y2 Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
/= Ordering
EQ
then Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
y1 Int
y2
else
if Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
m1 Int
m2 Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
/= Ordering
EQ
then Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
m1 Int
m2
else if Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
d1 Int
d2 Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
/= Ordering
EQ
then Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
d1 Int
d2
else if Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
h1 Int
h2 Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
/= Ordering
EQ
then Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
h1 Int
h2
else if Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
mi1 Int
mi2 Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
/= Ordering
EQ
then Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
mi1 Int
mi2
else if Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
s1 Int
s2 Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
/= Ordering
EQ
then Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
s1 Int
s2
else Ordering
EQ
toRTimestamp ::
String
-> String
-> RTimestamp
toRTimestamp :: String -> String -> RTimestamp
toRTimestamp String
fmt String
stime =
if String
fmt String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== [] Bool -> Bool -> Bool
|| String
stime String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== []
then EmptyInputStringsInToRTimestamp -> RTimestamp
forall a e. Exception e => e -> a
throw (EmptyInputStringsInToRTimestamp -> RTimestamp)
-> EmptyInputStringsInToRTimestamp -> RTimestamp
forall a b. (a -> b) -> a -> b
$ String -> String -> EmptyInputStringsInToRTimestamp
EmptyInputStringsInToRTimestamp String
fmt String
stime
else
let
elemMap :: HashMap String String
elemMap = String -> String -> HashMap String String -> HashMap String String
parseFormat2 String
fmt String
stime HashMap String String
forall k v. HashMap k v
HM.empty
y :: Int
y = case String -> HashMap String String -> Maybe String
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HM.lookup String
"YYYY" HashMap String String
elemMap of
Maybe String
Nothing -> Int
1 :: Int
Just String
yyyy -> (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ (Char -> Int
digitToInt (Char -> Int) -> Char -> Int
forall a b. (a -> b) -> a -> b
$ (String
yyyy String -> Int -> Char
forall a. [a] -> Int -> a
!! Int
0)) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
1000)
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ (Char -> Int
digitToInt (Char -> Int) -> Char -> Int
forall a b. (a -> b) -> a -> b
$ (String
yyyy String -> Int -> Char
forall a. [a] -> Int -> a
!! Int
1)) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
100)
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ (Char -> Int
digitToInt (Char -> Int) -> Char -> Int
forall a b. (a -> b) -> a -> b
$ (String
yyyy String -> Int -> Char
forall a. [a] -> Int -> a
!! Int
2)) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
10)
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Char -> Int
digitToInt (Char -> Int) -> Char -> Int
forall a b. (a -> b) -> a -> b
$ (String
yyyy String -> Int -> Char
forall a. [a] -> Int -> a
!! Int
3))
year :: Int
year = case Int
y Int -> Int -> Int
forall a. Integral a => a -> a -> a
`rem` Int
9999 of
Int
0 -> Int
9999
Int
yv -> Int
yv
mo :: Int
mo = case String -> HashMap String String -> Maybe String
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HM.lookup String
"MM" HashMap String String
elemMap of
Maybe String
Nothing -> Int
1 :: Int
Just String
mm ->
if String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length String
mm Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1
then (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ (Char -> Int
digitToInt (Char -> Int) -> Char -> Int
forall a b. (a -> b) -> a -> b
$ (String
mm String -> Int -> Char
forall a. [a] -> Int -> a
!! Int
0)) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
1)
else
(Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ (Char -> Int
digitToInt (Char -> Int) -> Char -> Int
forall a b. (a -> b) -> a -> b
$ (String
mm String -> Int -> Char
forall a. [a] -> Int -> a
!! Int
0)) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
10)
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Char -> Int
digitToInt (Char -> Int) -> Char -> Int
forall a b. (a -> b) -> a -> b
$ (String
mm String -> Int -> Char
forall a. [a] -> Int -> a
!! Int
1))
month :: Int
month = case Int
mo Int -> Int -> Int
forall a. Integral a => a -> a -> a
`rem` Int
12 of
Int
0 -> Int
12
Int
mv -> Int
mv
d :: Int
d = case String -> HashMap String String -> Maybe String
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HM.lookup String
"DD" HashMap String String
elemMap of
Maybe String
Nothing -> Int
1 :: Int
Just String
dd ->
if String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length String
dd Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1
then (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ (Char -> Int
digitToInt (Char -> Int) -> Char -> Int
forall a b. (a -> b) -> a -> b
$ (String
dd String -> Int -> Char
forall a. [a] -> Int -> a
!! Int
0)) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
1)
else
(Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ (Char -> Int
digitToInt (Char -> Int) -> Char -> Int
forall a b. (a -> b) -> a -> b
$ (String
dd String -> Int -> Char
forall a. [a] -> Int -> a
!! Int
0)) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
10)
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Char -> Int
digitToInt (Char -> Int) -> Char -> Int
forall a b. (a -> b) -> a -> b
$ (String
dd String -> Int -> Char
forall a. [a] -> Int -> a
!! Int
1))
day :: Int
day = case Int
d Int -> Int -> Int
forall a. Integral a => a -> a -> a
`rem` Int
31 of
Int
0 -> Int
31
Int
dv -> Int
dv
h :: Int
h = case String -> HashMap String String -> Maybe String
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HM.lookup String
"HH" HashMap String String
elemMap of
Maybe String
Nothing -> Int
0 :: Int
Just String
hh ->
if String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length String
hh Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1
then (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ (Char -> Int
digitToInt (Char -> Int) -> Char -> Int
forall a b. (a -> b) -> a -> b
$ (String
hh String -> Int -> Char
forall a. [a] -> Int -> a
!! Int
0)) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
1)
else
(Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ (Char -> Int
digitToInt (Char -> Int) -> Char -> Int
forall a b. (a -> b) -> a -> b
$ (String
hh String -> Int -> Char
forall a. [a] -> Int -> a
!! Int
0)) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
10)
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Char -> Int
digitToInt (Char -> Int) -> Char -> Int
forall a b. (a -> b) -> a -> b
$ (String
hh String -> Int -> Char
forall a. [a] -> Int -> a
!! Int
1))
hour :: Int
hour = Int
h Int -> Int -> Int
forall a. Integral a => a -> a -> a
`rem` Int
24
m :: Int
m = case String -> HashMap String String -> Maybe String
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HM.lookup String
"MI" HashMap String String
elemMap of
Maybe String
Nothing -> Int
0 :: Int
Just String
mi ->
if String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length String
mi Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1
then (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ (Char -> Int
digitToInt (Char -> Int) -> Char -> Int
forall a b. (a -> b) -> a -> b
$ (String
mi String -> Int -> Char
forall a. [a] -> Int -> a
!! Int
0)) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
1)
else
(Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ (Char -> Int
digitToInt (Char -> Int) -> Char -> Int
forall a b. (a -> b) -> a -> b
$ (String
mi String -> Int -> Char
forall a. [a] -> Int -> a
!! Int
0)) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
10)
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Char -> Int
digitToInt (Char -> Int) -> Char -> Int
forall a b. (a -> b) -> a -> b
$ (String
mi String -> Int -> Char
forall a. [a] -> Int -> a
!! Int
1))
min :: Int
min = Int
m Int -> Int -> Int
forall a. Integral a => a -> a -> a
`rem` Int
60
s :: Int
s = case String -> HashMap String String -> Maybe String
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HM.lookup String
"SS" HashMap String String
elemMap of
Maybe String
Nothing -> Int
0 :: Int
Just String
ss ->
if String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length String
ss Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1
then (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ (Char -> Int
digitToInt (Char -> Int) -> Char -> Int
forall a b. (a -> b) -> a -> b
$ (String
ss String -> Int -> Char
forall a. [a] -> Int -> a
!! Int
0)) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
1)
else
(Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ (Char -> Int
digitToInt (Char -> Int) -> Char -> Int
forall a b. (a -> b) -> a -> b
$ (String
ss String -> Int -> Char
forall a. [a] -> Int -> a
!! Int
0)) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
10)
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (Int -> Int
forall a. Num a => a -> a
abs (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Char -> Int
digitToInt (Char -> Int) -> Char -> Int
forall a b. (a -> b) -> a -> b
$ (String
ss String -> Int -> Char
forall a. [a] -> Int -> a
!! Int
1))
sec :: Int
sec = Int
s Int -> Int -> Int
forall a. Integral a => a -> a -> a
`rem` Int
60
in RTimestampVal :: Int -> Int -> Int -> Int -> Int -> Int -> RTimestamp
RTimestampVal {
year :: Int
year = Int
year
,month :: Int
month = Int
month
,day :: Int
day = Int
day
,hours24 :: Int
hours24 = Int
hour
,minutes :: Int
minutes = Int
min
,seconds :: Int
seconds = Int
sec
}
where
parseFormat2 ::
String
-> String
-> HashMap String String
-> HashMap String String
parseFormat2 :: String -> String -> HashMap String String -> HashMap String String
parseFormat2 [] String
_ HashMap String String
currMap = HashMap String String
currMap
parseFormat2 String
fmt String
tstamp HashMap String String
currMap =
let
keywords :: [String]
keywords = [String
"YYYY",String
"MM", String
"DD", String
"HH", String
"MI", String
"SS"]
positions :: [Maybe Int]
positions = (String -> Maybe Int) -> [String] -> [Maybe Int]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\String
subs -> String -> String -> Maybe Int
forall a. Eq a => [a] -> [a] -> Maybe Int
instr String
subs String
fmt) [String]
keywords
(String
fmtElement, String
restFormat) = (Char -> Bool) -> String -> (String, String)
forall a. (a -> Bool) -> [a] -> ([a], [a])
Data.List.span (\Char
c -> Char -> Bool
isAlpha Char
c) String
fmt
restFormatFinal :: String
restFormatFinal = (String, String) -> String
forall a b. (a, b) -> b
snd ((String, String) -> String) -> (String, String) -> String
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> String -> (String, String)
forall a. (a -> Bool) -> [a] -> ([a], [a])
Data.List.span (\Char
c -> Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Char -> Bool
isAlpha Char
c) String
restFormat
(String
tmElement, String
restTstamp) = (Char -> Bool) -> String -> (String, String)
forall a. (a -> Bool) -> [a] -> ([a], [a])
Data.List.span (\Char
c -> Char -> Bool
isDigit Char
c) String
tstamp
restTstampFinal :: String
restTstampFinal = (String, String) -> String
forall a b. (a, b) -> b
snd ((String, String) -> String) -> (String, String) -> String
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> String -> (String, String)
forall a. (a -> Bool) -> [a] -> ([a], [a])
Data.List.span (\Char
c -> Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Char -> Bool
isDigit Char
c) String
restTstamp
newMap :: HashMap String String
newMap = String -> String -> HashMap String String -> HashMap String String
forall k v.
(Eq k, Hashable k) =>
k -> v -> HashMap k v -> HashMap k v
HM.insert String
fmtElement String
tmElement HashMap String String
currMap
in
if (Maybe Int -> Bool) -> [Maybe Int] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
Data.List.all (\Maybe Int
t -> Maybe Int
t Maybe Int -> Maybe Int -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe Int
forall a. Maybe a
Nothing) ([Maybe Int] -> Bool) -> [Maybe Int] -> Bool
forall a b. (a -> b) -> a -> b
$ [Maybe Int]
positions
then UnsupportedTimeStampFormat -> HashMap String String
forall a e. Exception e => e -> a
throw (UnsupportedTimeStampFormat -> HashMap String String)
-> UnsupportedTimeStampFormat -> HashMap String String
forall a b. (a -> b) -> a -> b
$ String -> UnsupportedTimeStampFormat
UnsupportedTimeStampFormat String
fmt
else String -> String -> HashMap String String -> HashMap String String
parseFormat2 String
restFormatFinal String
restTstampFinal HashMap String String
newMap
toUTCTime :: RTimestamp -> UTCTime
toUTCTime :: RTimestamp -> UTCTime
toUTCTime (RTimestampVal Int
yy Int
mm Int
dd Int
hh24 Int
mins Int
ss) =
let day :: Day
day = Integer -> Int -> Int -> Day
fromGregorian (Int -> Integer
forall a. Integral a => a -> Integer
toInteger (Int -> Integer) -> Int -> Integer
forall a b. (a -> b) -> a -> b
$ Int
yy::Integer) Int
mm Int
dd
secs :: DiffTime
secs = Integer -> DiffTime
secondsToDiffTime (Integer -> DiffTime) -> Integer -> DiffTime
forall a b. (a -> b) -> a -> b
$ (Int -> Integer
forall a. Integral a => a -> Integer
toInteger (Int -> Integer) -> Int -> Integer
forall a b. (a -> b) -> a -> b
$ Int
hh24Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
60Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
60 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
mmInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
60 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
ss :: Integer)
in Day -> DiffTime -> UTCTime
UTCTime Day
day DiffTime
secs
fromUTCTime :: UTCTime -> RTimestamp
fromUTCTime :: UTCTime -> RTimestamp
fromUTCTime UTCTime
utc =
let UTCTime Day
day DiffTime
s = UTCTime
utc
secs :: Int
secs = Double -> Int
forall a b. (RealFrac a, Integral b) => a -> b
round (Double -> Int) -> Double -> Int
forall a b. (a -> b) -> a -> b
$ ((Double
1.0e-12::Double) Double -> Double -> Double
forall a. Num a => a -> a -> a
*) (Double -> Double) -> Double -> Double
forall a b. (a -> b) -> a -> b
$ (Integer -> Double
forall a. Num a => Integer -> a
fromInteger (Integer -> Double) -> Integer -> Double
forall a b. (a -> b) -> a -> b
$ DiffTime -> Integer
diffTimeToPicoseconds DiffTime
s) ::Int
(Integer
yy, Int
mm, Int
dd) = Day -> (Integer, Int, Int)
toGregorian Day
day
hh24 :: Int
hh24 = (Int
secs Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
60) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
60
mins :: Int
mins = (Int
secs Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
60) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`rem` Int
60
ss :: Int
ss = (Int
secs Int -> Int -> Int
forall a. Integral a => a -> a -> a
`rem` (Int
60Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
60)) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`rem` Int
60
in
RTimestampVal :: Int -> Int -> Int -> Int -> Int -> Int -> RTimestamp
RTimestampVal {year :: Int
year = (Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
yy), month :: Int
month = Int
mm, day :: Int
day = Int
dd, hours24 :: Int
hours24 = Int
hh24, minutes :: Int
minutes = Int
mins, seconds :: Int
seconds = Int
ss}
instr :: Eq a =>
[a]
-> [a]
-> Maybe Int
instr :: [a] -> [a] -> Maybe Int
instr [a]
subs [a]
s = ([a] -> Bool) -> [[a]] -> Maybe Int
forall a. (a -> Bool) -> [a] -> Maybe Int
Data.List.findIndex ([a] -> [a] -> Bool
forall a. Eq a => [a] -> [a] -> Bool
Data.List.isPrefixOf [a]
subs) ([[a]] -> Maybe Int) -> [[a]] -> Maybe Int
forall a b. (a -> b) -> a -> b
$ [a] -> [[a]]
forall a. [a] -> [[a]]
Data.List.tails [a]
s
instrText ::
Text
-> Text
-> Maybe Int
instrText :: ColumnName -> ColumnName -> Maybe Int
instrText ColumnName
subs ColumnName
s = String -> String -> Maybe Int
forall a. Eq a => [a] -> [a] -> Maybe Int
instr (ColumnName -> String
T.unpack ColumnName
subs) (String -> Maybe Int) -> String -> Maybe Int
forall a b. (a -> b) -> a -> b
$ ColumnName -> String
T.unpack ColumnName
s
instrRText ::
RDataType
-> RDataType
-> Maybe Int
instrRText :: RDataType -> RDataType -> Maybe Int
instrRText (RText ColumnName
subs) (RText ColumnName
s) = ColumnName -> ColumnName -> Maybe Int
instrText ColumnName
subs ColumnName
s
instrRText RDataType
_ RDataType
_ = Maybe Int
forall a. Maybe a
Nothing
createRTimestamp ::
String
-> String
-> RTimestamp
createRTimestamp :: String -> String -> RTimestamp
createRTimestamp String
fmt String
timeVal = String -> String -> RTimestamp
toRTimestamp String
fmt String
timeVal
toText :: RDataType -> Maybe T.Text
toText :: RDataType -> Maybe ColumnName
toText (RText ColumnName
t) = ColumnName -> Maybe ColumnName
forall a. a -> Maybe a
Just ColumnName
t
toText RDataType
_ = Maybe ColumnName
forall a. Maybe a
Nothing
fromText :: T.Text -> RDataType
fromText :: ColumnName -> RDataType
fromText ColumnName
t = ColumnName -> RDataType
RText ColumnName
t
isText :: RDataType -> Bool
isText :: RDataType -> Bool
isText (RText ColumnName
t) = Bool
True
isText RDataType
_ = Bool
False
stdTimestampFormat :: String
stdTimestampFormat = String
"DD/MM/YYYY HH24:MI:SS" :: String
rTimestampToRText ::
String
-> RTimestamp
-> RDataType
rTimestampToRText :: String -> RTimestamp -> RDataType
rTimestampToRText String
"DD/MM/YYYY HH24:MI:SS" RTimestamp
ts = let
timeString :: String
timeString = Int -> String
forall a. (Ord a, Num a, Show a) => a -> String
expand (RTimestamp -> Int
day RTimestamp
ts) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"/" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. (Ord a, Num a, Show a) => a -> String
expand (RTimestamp -> Int
month RTimestamp
ts) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"/" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. (Ord a, Num a, Show a) => a -> String
expand (RTimestamp -> Int
year RTimestamp
ts) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. (Ord a, Num a, Show a) => a -> String
expand (RTimestamp -> Int
hours24 RTimestamp
ts) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
":" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. (Ord a, Num a, Show a) => a -> String
expand (RTimestamp -> Int
minutes RTimestamp
ts) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
":" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. (Ord a, Num a, Show a) => a -> String
expand (RTimestamp -> Int
seconds RTimestamp
ts)
expand :: a -> String
expand a
i = if a
i a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
10 then String
"0"String -> ShowS
forall a. [a] -> [a] -> [a]
++ (a -> String
forall a. Show a => a -> String
show a
i) else a -> String
forall a. Show a => a -> String
show a
i
in ColumnName -> RDataType
RText (ColumnName -> RDataType) -> ColumnName -> RDataType
forall a b. (a -> b) -> a -> b
$ String -> ColumnName
T.pack String
timeString
rTimestampToRText String
"YYYYMMDD-HH24.MI.SS" RTimestamp
ts = let
timeString :: String
timeString = Int -> String
forall a. (Ord a, Num a, Show a) => a -> String
expand (RTimestamp -> Int
year RTimestamp
ts) String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. (Ord a, Num a, Show a) => a -> String
expand (RTimestamp -> Int
month RTimestamp
ts) String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. (Ord a, Num a, Show a) => a -> String
expand (RTimestamp -> Int
day RTimestamp
ts) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"-" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. (Ord a, Num a, Show a) => a -> String
expand (RTimestamp -> Int
hours24 RTimestamp
ts) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"." String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. (Ord a, Num a, Show a) => a -> String
expand (RTimestamp -> Int
minutes RTimestamp
ts) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"." String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. (Ord a, Num a, Show a) => a -> String
expand (RTimestamp -> Int
seconds RTimestamp
ts)
expand :: a -> String
expand a
i = if a
i a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
10 then String
"0"String -> ShowS
forall a. [a] -> [a] -> [a]
++ (a -> String
forall a. Show a => a -> String
show a
i) else a -> String
forall a. Show a => a -> String
show a
i
in ColumnName -> RDataType
RText (ColumnName -> RDataType) -> ColumnName -> RDataType
forall a b. (a -> b) -> a -> b
$ String -> ColumnName
T.pack String
timeString
rTimestampToRText String
"YYYYMMDD" RTimestamp
ts = let
timeString :: String
timeString = Int -> String
forall a. (Ord a, Num a, Show a) => a -> String
expand (RTimestamp -> Int
year RTimestamp
ts) String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. (Ord a, Num a, Show a) => a -> String
expand (RTimestamp -> Int
month RTimestamp
ts) String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. (Ord a, Num a, Show a) => a -> String
expand (RTimestamp -> Int
day RTimestamp
ts)
expand :: a -> String
expand a
i = if a
i a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
10 then String
"0"String -> ShowS
forall a. [a] -> [a] -> [a]
++ (a -> String
forall a. Show a => a -> String
show a
i) else a -> String
forall a. Show a => a -> String
show a
i
in ColumnName -> RDataType
RText (ColumnName -> RDataType) -> ColumnName -> RDataType
forall a b. (a -> b) -> a -> b
$ String -> ColumnName
T.pack String
timeString
rTimestampToRText String
"YYYYMM" RTimestamp
ts = let
timeString :: String
timeString = Int -> String
forall a. (Ord a, Num a, Show a) => a -> String
expand (RTimestamp -> Int
year RTimestamp
ts) String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. (Ord a, Num a, Show a) => a -> String
expand (RTimestamp -> Int
month RTimestamp
ts)
expand :: a -> String
expand a
i = if a
i a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
10 then String
"0"String -> ShowS
forall a. [a] -> [a] -> [a]
++ (a -> String
forall a. Show a => a -> String
show a
i) else a -> String
forall a. Show a => a -> String
show a
i
in ColumnName -> RDataType
RText (ColumnName -> RDataType) -> ColumnName -> RDataType
forall a b. (a -> b) -> a -> b
$ String -> ColumnName
T.pack String
timeString
rTimestampToRText String
"YYYY" RTimestamp
ts = let
timeString :: String
timeString = Int -> String
forall a. Show a => a -> String
show (Int -> String) -> Int -> String
forall a b. (a -> b) -> a -> b
$ RTimestamp -> Int
year RTimestamp
ts
in ColumnName -> RDataType
RText (ColumnName -> RDataType) -> ColumnName -> RDataType
forall a b. (a -> b) -> a -> b
$ String -> ColumnName
T.pack String
timeString
rTimestampToRText String
_ RTimestamp
ts = let
timeString :: String
timeString = Int -> String
forall a. (Ord a, Num a, Show a) => a -> String
expand (RTimestamp -> Int
day RTimestamp
ts) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"/" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. (Ord a, Num a, Show a) => a -> String
expand (RTimestamp -> Int
month RTimestamp
ts) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"/" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. (Ord a, Num a, Show a) => a -> String
expand (RTimestamp -> Int
year RTimestamp
ts) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. (Ord a, Num a, Show a) => a -> String
expand (RTimestamp -> Int
hours24 RTimestamp
ts) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
":" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. (Ord a, Num a, Show a) => a -> String
expand (RTimestamp -> Int
minutes RTimestamp
ts) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
":" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. (Ord a, Num a, Show a) => a -> String
expand (RTimestamp -> Int
seconds RTimestamp
ts)
expand :: a -> String
expand a
i = if a
i a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
10 then String
"0"String -> ShowS
forall a. [a] -> [a] -> [a]
++ (a -> String
forall a. Show a => a -> String
show a
i) else a -> String
forall a. Show a => a -> String
show a
i
in ColumnName -> RDataType
RText (ColumnName -> RDataType) -> ColumnName -> RDataType
forall a b. (a -> b) -> a -> b
$ String -> ColumnName
T.pack String
timeString
data RTableMData = RTableMData {
RTableMData -> ColumnName
rtname :: RTableName
,RTableMData -> RTupleMData
rtuplemdata :: RTupleMData
,RTableMData -> [ColumnName]
pkColumns :: [ColumnName]
,RTableMData -> [[ColumnName]]
uniqueKeys :: [[ColumnName]]
} deriving (Int -> RTableMData -> ShowS
[RTableMData] -> ShowS
RTableMData -> String
(Int -> RTableMData -> ShowS)
-> (RTableMData -> String)
-> ([RTableMData] -> ShowS)
-> Show RTableMData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RTableMData] -> ShowS
$cshowList :: [RTableMData] -> ShowS
show :: RTableMData -> String
$cshow :: RTableMData -> String
showsPrec :: Int -> RTableMData -> ShowS
$cshowsPrec :: Int -> RTableMData -> ShowS
Show, RTableMData -> RTableMData -> Bool
(RTableMData -> RTableMData -> Bool)
-> (RTableMData -> RTableMData -> Bool) -> Eq RTableMData
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RTableMData -> RTableMData -> Bool
$c/= :: RTableMData -> RTableMData -> Bool
== :: RTableMData -> RTableMData -> Bool
$c== :: RTableMData -> RTableMData -> Bool
Eq)
createRTableMData ::
(RTableName, [(ColumnName, ColumnDType)])
-> [ColumnName]
-> [[ColumnName]]
-> RTableMData
createRTableMData :: (ColumnName, [(ColumnName, ColumnDType)])
-> [ColumnName] -> [[ColumnName]] -> RTableMData
createRTableMData (ColumnName
n, [(ColumnName, ColumnDType)]
cdts) [ColumnName]
pk [[ColumnName]]
uks =
RTableMData :: ColumnName
-> RTupleMData -> [ColumnName] -> [[ColumnName]] -> RTableMData
RTableMData { rtname :: ColumnName
rtname = ColumnName
n, rtuplemdata :: RTupleMData
rtuplemdata = [(ColumnName, ColumnDType)] -> RTupleMData
createRTupleMdata [(ColumnName, ColumnDType)]
cdts, pkColumns :: [ColumnName]
pkColumns = [ColumnName]
pk, uniqueKeys :: [[ColumnName]]
uniqueKeys = [[ColumnName]]
uks }
createRTupleMdata :: [(ColumnName, ColumnDType)] -> RTupleMData
createRTupleMdata :: [(ColumnName, ColumnDType)] -> RTupleMData
createRTupleMdata [(ColumnName, ColumnDType)]
clist =
let colNamecolInfo :: [(ColumnName, ColumnInfo)]
colNamecolInfo = ((ColumnName, ColumnDType) -> (ColumnName, ColumnInfo))
-> [(ColumnName, ColumnDType)] -> [(ColumnName, ColumnInfo)]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map (\(ColumnName
n,ColumnDType
t) -> (ColumnName
n, ColumnInfo :: ColumnName -> ColumnDType -> ColumnInfo
ColumnInfo{ name :: ColumnName
name = ColumnName
n
,dtype :: ColumnDType
dtype = ColumnDType
t
})) [(ColumnName, ColumnDType)]
clist
colOrdercolName :: [(Int, ColumnName)]
colOrdercolName = ((ColumnName, ColumnDType) -> (Int, ColumnName))
-> [(ColumnName, ColumnDType)] -> [(Int, ColumnName)]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map (\(ColumnName
n,ColumnDType
t) -> (Maybe Int -> Int
forall a. HasCallStack => Maybe a -> a
fromJust ((ColumnName, ColumnDType)
-> [(ColumnName, ColumnDType)] -> Maybe Int
forall a. Eq a => a -> [a] -> Maybe Int
elemIndex (ColumnName
n,ColumnDType
t) [(ColumnName, ColumnDType)]
clist), ColumnName
n)) [(ColumnName, ColumnDType)]
clist
in ([(Int, ColumnName)] -> HashMap Int ColumnName
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HM.fromList [(Int, ColumnName)]
colOrdercolName, [(ColumnName, ColumnInfo)] -> HashMap ColumnName ColumnInfo
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HM.fromList [(ColumnName, ColumnInfo)]
colNamecolInfo)
type RTupleMData = (HM.HashMap ColumnOrder ColumnName, HM.HashMap ColumnName ColumnInfo)
type ColumnOrder = Int
toListColumnName ::
RTupleMData
-> [ColumnName]
toListColumnName :: RTupleMData -> [ColumnName]
toListColumnName RTupleMData
rtupmd =
let mapColOrdColName :: HashMap Int ColumnName
mapColOrdColName = RTupleMData -> HashMap Int ColumnName
forall a b. (a, b) -> a
fst RTupleMData
rtupmd
listColOrdColName :: [(Int, ColumnName)]
listColOrdColName = HashMap Int ColumnName -> [(Int, ColumnName)]
forall k v. HashMap k v -> [(k, v)]
HM.toList HashMap Int ColumnName
mapColOrdColName
ordlistColOrdColName :: [(Int, ColumnName)]
ordlistColOrdColName = ((Int, ColumnName) -> Int)
-> [(Int, ColumnName)] -> [(Int, ColumnName)]
forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn (\(Int
o,ColumnName
c) -> Int
o) [(Int, ColumnName)]
listColOrdColName
in ((Int, ColumnName) -> ColumnName)
-> [(Int, ColumnName)] -> [ColumnName]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map ((Int, ColumnName) -> ColumnName
forall a b. (a, b) -> b
snd) [(Int, ColumnName)]
ordlistColOrdColName
toListColumnInfo ::
RTupleMData
-> [ColumnInfo]
toListColumnInfo :: RTupleMData -> [ColumnInfo]
toListColumnInfo RTupleMData
rtupmd =
let mapColNameColInfo :: HashMap ColumnName ColumnInfo
mapColNameColInfo = RTupleMData -> HashMap ColumnName ColumnInfo
forall a b. (a, b) -> b
snd RTupleMData
rtupmd
in (ColumnName -> ColumnInfo) -> [ColumnName] -> [ColumnInfo]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map (\ColumnName
cname -> HashMap ColumnName ColumnInfo
mapColNameColInfo HashMap ColumnName ColumnInfo -> ColumnName -> ColumnInfo
forall k v.
(Eq k, Hashable k, HasCallStack) =>
HashMap k v -> k -> v
HM.! ColumnName
cname) (RTupleMData -> [ColumnName]
toListColumnName RTupleMData
rtupmd)
toListRDataType ::
RTupleMData
-> RTuple
-> [RDataType]
toListRDataType :: RTupleMData -> RTuple -> [RDataType]
toListRDataType RTupleMData
rtupmd RTuple
rtup = (ColumnName -> RDataType) -> [ColumnName] -> [RDataType]
forall a b. (a -> b) -> [a] -> [b]
Prelude.map (\ColumnName
cname -> RTuple
rtup RTuple -> ColumnName -> RDataType
<!> ColumnName
cname) (RTupleMData -> [ColumnName]
toListColumnName RTupleMData
rtupmd)
data ColumnInfo = ColumnInfo {
ColumnInfo -> ColumnName
name :: ColumnName
,ColumnInfo -> ColumnDType
dtype :: ColumnDType
} deriving (Int -> ColumnInfo -> ShowS
[ColumnInfo] -> ShowS
ColumnInfo -> String
(Int -> ColumnInfo -> ShowS)
-> (ColumnInfo -> String)
-> ([ColumnInfo] -> ShowS)
-> Show ColumnInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ColumnInfo] -> ShowS
$cshowList :: [ColumnInfo] -> ShowS
show :: ColumnInfo -> String
$cshow :: ColumnInfo -> String
showsPrec :: Int -> ColumnInfo -> ShowS
$cshowsPrec :: Int -> ColumnInfo -> ShowS
Show,ColumnInfo -> ColumnInfo -> Bool
(ColumnInfo -> ColumnInfo -> Bool)
-> (ColumnInfo -> ColumnInfo -> Bool) -> Eq ColumnInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ColumnInfo -> ColumnInfo -> Bool
$c/= :: ColumnInfo -> ColumnInfo -> Bool
== :: ColumnInfo -> ColumnInfo -> Bool
$c== :: ColumnInfo -> ColumnInfo -> Bool
Eq)
listOfColInfoRDataType :: [ColumnInfo] -> RTuple -> [(ColumnInfo, RDataType)]
listOfColInfoRDataType :: [ColumnInfo] -> RTuple -> [(ColumnInfo, RDataType)]
listOfColInfoRDataType (ColumnInfo
ci:[]) RTuple
rtup = [(ColumnInfo
ci, RTuple
rtup RTuple -> ColumnName -> RDataType
forall k v.
(Eq k, Hashable k, HasCallStack) =>
HashMap k v -> k -> v
HM.!(ColumnInfo -> ColumnName
name ColumnInfo
ci))]
listOfColInfoRDataType (ColumnInfo
ci:[ColumnInfo]
colInfos) RTuple
rtup = (ColumnInfo
ci, RTuple
rtup RTuple -> ColumnName -> RDataType
forall k v.
(Eq k, Hashable k, HasCallStack) =>
HashMap k v -> k -> v
HM.!(ColumnInfo -> ColumnName
name ColumnInfo
ci))(ColumnInfo, RDataType)
-> [(ColumnInfo, RDataType)] -> [(ColumnInfo, RDataType)]
forall a. a -> [a] -> [a]
:[ColumnInfo] -> RTuple -> [(ColumnInfo, RDataType)]
listOfColInfoRDataType [ColumnInfo]
colInfos RTuple
rtup
createRDataType ::
TB.Typeable a
=> a
-> RDataType
createRDataType :: a -> RDataType
createRDataType a
val =
case TypeRep -> String
forall a. Show a => a -> String
show (a -> TypeRep
forall a. Typeable a => a -> TypeRep
TB.typeOf a
val) of
String
"Int" -> case (Dynamic -> Maybe Integer
forall a. Typeable a => Dynamic -> Maybe a
D.fromDynamic (a -> Dynamic
forall a. Typeable a => a -> Dynamic
D.toDyn a
val)) of
Just Integer
v -> Integer -> RDataType
RInt Integer
v
Maybe Integer
Nothing -> RDataType
Null
String
"Text" -> case (Dynamic -> Maybe ColumnName
forall a. Typeable a => Dynamic -> Maybe a
D.fromDynamic (a -> Dynamic
forall a. Typeable a => a -> Dynamic
D.toDyn a
val)) of
Just ColumnName
v -> ColumnName -> RDataType
RText ColumnName
v
Maybe ColumnName
Nothing -> RDataType
Null
String
"Double" -> case (Dynamic -> Maybe Double
forall a. Typeable a => Dynamic -> Maybe a
D.fromDynamic (a -> Dynamic
forall a. Typeable a => a -> Dynamic
D.toDyn a
val)) of
Just Double
v -> Double -> RDataType
RDouble Double
v
Maybe Double
Nothing -> RDataType
Null
String
_ -> RDataType
Null
type RPredicate = RTuple -> Bool
data ROperation =
ROperationEmpty
| RUnion
| RInter
| RDiff
| RPrj { ROperation -> [ColumnName]
colPrjList :: [ColumnName] }
| RFilter { ROperation -> RTuple -> Bool
fpred :: RPredicate }
| RInJoin { ROperation -> RJoinPredicate
jpred :: RJoinPredicate }
| RLeftJoin { jpred :: RJoinPredicate }
| RRightJoin { jpred :: RJoinPredicate }
| RSemiJoin { jpred :: RJoinPredicate }
| RAntiJoin { jpred :: RJoinPredicate }
| RAggregate { ROperation -> [RAggOperation]
aggList :: [RAggOperation]
}
| RGroupBy {
ROperation -> RJoinPredicate
gpred :: RGroupPredicate
,aggList :: [RAggOperation]
,ROperation -> [ColumnName]
colGrByList :: [ColumnName]
}
| RCombinedOp { ROperation -> RTable -> RTable
rcombOp :: UnaryRTableOperation }
| RBinOp { ROperation -> BinaryRTableOperation
rbinOp :: BinaryRTableOperation }
| ROrderBy { ROperation -> [(ColumnName, OrderingSpec)]
colOrdList :: [(ColumnName, OrderingSpec)] }
data OrderingSpec = Asc | Desc deriving (Int -> OrderingSpec -> ShowS
[OrderingSpec] -> ShowS
OrderingSpec -> String
(Int -> OrderingSpec -> ShowS)
-> (OrderingSpec -> String)
-> ([OrderingSpec] -> ShowS)
-> Show OrderingSpec
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OrderingSpec] -> ShowS
$cshowList :: [OrderingSpec] -> ShowS
show :: OrderingSpec -> String
$cshow :: OrderingSpec -> String
showsPrec :: Int -> OrderingSpec -> ShowS
$cshowsPrec :: Int -> OrderingSpec -> ShowS
Show, OrderingSpec -> OrderingSpec -> Bool
(OrderingSpec -> OrderingSpec -> Bool)
-> (OrderingSpec -> OrderingSpec -> Bool) -> Eq OrderingSpec
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OrderingSpec -> OrderingSpec -> Bool
$c/= :: OrderingSpec -> OrderingSpec -> Bool
== :: OrderingSpec -> OrderingSpec -> Bool
$c== :: OrderingSpec -> OrderingSpec -> Bool
Eq)
type UnaryRTableOperation = RTable -> RTable
type BinaryRTableOperation = RTable -> RTable -> RTable
type RJoinPredicate = RTuple -> RTuple -> Bool
data RUpsertPredicate = RUpsertPredicate {
RUpsertPredicate -> [ColumnName]
matchCols :: [ColumnName]
,RUpsertPredicate -> RJoinPredicate
matchPred :: RTuple -> RTuple -> Bool
}
type RGroupPredicate = RTuple -> RTuple -> Bool
data RAggOperation = RAggOperation {
RAggOperation -> ColumnName
sourceCol :: ColumnName
,RAggOperation -> ColumnName
targetCol :: ColumnName
,RAggOperation -> RTable -> RTuple
aggFunc :: RTable -> RTuple
}
type AggFunction = ColumnName -> RTable -> RDataType
raggGenericAgg ::
AggFunction
-> ColumnName
-> ColumnName
-> RAggOperation
raggGenericAgg :: AggFunction -> ColumnName -> ColumnName -> RAggOperation
raggGenericAgg AggFunction
aggf ColumnName
src ColumnName
trg = RAggOperation :: ColumnName -> ColumnName -> (RTable -> RTuple) -> RAggOperation
RAggOperation {
sourceCol :: ColumnName
sourceCol = ColumnName
src
,targetCol :: ColumnName
targetCol = ColumnName
trg
,aggFunc :: RTable -> RTuple
aggFunc = \RTable
rtab -> [(ColumnName, RDataType)] -> RTuple
createRTuple [(ColumnName
trg, AggFunction
aggf ColumnName
src RTable
rtab)]
}
type Delimiter = String
raggStrAgg ::
ColumnName
-> ColumnName
-> Delimiter
-> RAggOperation
raggStrAgg :: ColumnName -> ColumnName -> String -> RAggOperation
raggStrAgg ColumnName
src ColumnName
trg String
delimiter = RAggOperation :: ColumnName -> ColumnName -> (RTable -> RTuple) -> RAggOperation
RAggOperation {
sourceCol :: ColumnName
sourceCol = ColumnName
src
,targetCol :: ColumnName
targetCol = ColumnName
trg
,aggFunc :: RTable -> RTuple
aggFunc = \RTable
rtab -> [(ColumnName, RDataType)] -> RTuple
createRTuple [(ColumnName
trg, String -> AggFunction
strAggFold String
delimiter ColumnName
src RTable
rtab)]
}
strAggFold :: Delimiter -> AggFunction
strAggFold :: String -> AggFunction
strAggFold String
dlmt ColumnName
col RTable
rtab =
(RTuple -> RDataType -> RDataType)
-> RDataType -> RTable -> RDataType
rdatatypeFoldr' ( \RTuple
rtup RDataType
accValue ->
if RDataType -> Bool
isNotNull (RTuple
rtup RTuple -> ColumnName -> RDataType
<!> ColumnName
col) Bool -> Bool -> Bool
&& (RDataType -> Bool
isNotNull RDataType
accValue)
then
RTuple
rtup RTuple -> ColumnName -> RDataType
<!> ColumnName
col RDataType -> RDataType -> RDataType
`rdtappend` (ColumnName -> RDataType
RText ColumnName
delimiter) RDataType -> RDataType -> RDataType
`rdtappend` RDataType
accValue
else
if RDataType -> Bool
isNull (RTuple
rtup RTuple -> ColumnName -> RDataType
<!> ColumnName
col) Bool -> Bool -> Bool
&& (RDataType -> Bool
isNotNull RDataType
accValue)
then
RDataType
accValue
else
if RDataType -> Bool
isNotNull (RTuple
rtup RTuple -> ColumnName -> RDataType
<!> ColumnName
col) Bool -> Bool -> Bool
&& (RDataType -> Bool
isNull RDataType
accValue)
then
case RDataType -> Bool
isText (RTuple
rtup RTuple -> ColumnName -> RDataType
<!> ColumnName
col) of
Bool
True -> (RTuple
rtup RTuple -> ColumnName -> RDataType
<!> ColumnName
col)
Bool
False -> RDataType
Null
else
RDataType
Null
)
RDataType
Null
RTable
rtab
where
delimiter :: ColumnName
delimiter = String -> ColumnName
pack String
dlmt
raggSum ::
ColumnName
-> ColumnName
-> RAggOperation
raggSum :: ColumnName -> ColumnName -> RAggOperation
raggSum ColumnName
src ColumnName
trg = RAggOperation :: ColumnName -> ColumnName -> (RTable -> RTuple) -> RAggOperation
RAggOperation {
sourceCol :: ColumnName
sourceCol = ColumnName
src
,targetCol :: ColumnName
targetCol = ColumnName
trg
,aggFunc :: RTable -> RTuple
aggFunc = \RTable
rtab -> [(ColumnName, RDataType)] -> RTuple
createRTuple [(ColumnName
trg, AggFunction
sumFold ColumnName
src RTable
rtab)]
}
sumFold :: AggFunction
sumFold :: AggFunction
sumFold ColumnName
src RTable
rtab =
(RTuple -> RDataType -> RDataType)
-> RDataType -> RTable -> RDataType
forall a b. (a -> b -> b) -> b -> Vector a -> b
V.foldr' ( \RTuple
rtup RDataType
accValue ->
if (RDataType -> Bool
isNotNull (RDataType -> Bool) -> RDataType -> Bool
forall a b. (a -> b) -> a -> b
$ (ColumnName -> RTuple -> RDataType
getRTupColValue ColumnName
src) RTuple
rtup) Bool -> Bool -> Bool
&& (RDataType -> Bool
isNotNull RDataType
accValue)
then
(ColumnName -> RTuple -> RDataType
getRTupColValue ColumnName
src) RTuple
rtup RDataType -> RDataType -> RDataType
forall a. Num a => a -> a -> a
+ RDataType
accValue
else
if (RDataType -> Bool
isNull (RDataType -> Bool) -> RDataType -> Bool
forall a b. (a -> b) -> a -> b
$ (ColumnName -> RTuple -> RDataType
getRTupColValue ColumnName
src) RTuple
rtup) Bool -> Bool -> Bool
&& (RDataType -> Bool
isNotNull RDataType
accValue)
then
RDataType
accValue
else
if (RDataType -> Bool
isNotNull (RDataType -> Bool) -> RDataType -> Bool
forall a b. (a -> b) -> a -> b
$ (ColumnName -> RTuple -> RDataType
getRTupColValue ColumnName
src) RTuple
rtup) Bool -> Bool -> Bool
&& (RDataType -> Bool
isNull RDataType
accValue)
then
(ColumnName -> RTuple -> RDataType
getRTupColValue ColumnName
src) RTuple
rtup RDataType -> RDataType -> RDataType
forall a. Num a => a -> a -> a
+ Integer -> RDataType
RInt Integer
0
else
RDataType
Null
) (RDataType
Null) RTable
rtab
raggCount ::
ColumnName
-> ColumnName
-> RAggOperation
raggCount :: ColumnName -> ColumnName -> RAggOperation
raggCount ColumnName
src ColumnName
trg = RAggOperation :: ColumnName -> ColumnName -> (RTable -> RTuple) -> RAggOperation
RAggOperation {
sourceCol :: ColumnName
sourceCol = ColumnName
src
,targetCol :: ColumnName
targetCol = ColumnName
trg
,aggFunc :: RTable -> RTuple
aggFunc = \RTable
rtab -> [(ColumnName, RDataType)] -> RTuple
createRTuple [(ColumnName
trg, AggFunction
countFold ColumnName
src RTable
rtab)]
}
countFold :: AggFunction
countFold :: AggFunction
countFold ColumnName
src RTable
rtab =
(RTuple -> RDataType -> RDataType)
-> RDataType -> RTable -> RDataType
forall a b. (a -> b -> b) -> b -> Vector a -> b
V.foldr' ( \RTuple
rtup RDataType
accValue ->
if (RDataType -> Bool
isNotNull (RDataType -> Bool) -> RDataType -> Bool
forall a b. (a -> b) -> a -> b
$ (ColumnName -> RTuple -> RDataType
getRTupColValue ColumnName
src) RTuple
rtup) Bool -> Bool -> Bool
&& (RDataType -> Bool
isNotNull RDataType
accValue)
then
Integer -> RDataType
RInt Integer
1 RDataType -> RDataType -> RDataType
forall a. Num a => a -> a -> a
+ RDataType
accValue
else
if (RDataType -> Bool
isNull (RDataType -> Bool) -> RDataType -> Bool
forall a b. (a -> b) -> a -> b
$ (ColumnName -> RTuple -> RDataType
getRTupColValue ColumnName
src) RTuple
rtup) Bool -> Bool -> Bool
&& (RDataType -> Bool
isNotNull RDataType
accValue)
then
RDataType
accValue
else
if (RDataType -> Bool
isNotNull (RDataType -> Bool) -> RDataType -> Bool
forall a b. (a -> b) -> a -> b
$ (ColumnName -> RTuple -> RDataType
getRTupColValue ColumnName
src) RTuple
rtup) Bool -> Bool -> Bool
&& (RDataType -> Bool
isNull RDataType
accValue)
then
Integer -> RDataType
RInt Integer
1
else
RDataType
Null
) (RDataType
Null) RTable
rtab
raggCountStar ::
ColumnName
-> RAggOperation
raggCountStar :: ColumnName -> RAggOperation
raggCountStar ColumnName
trg = RAggOperation :: ColumnName -> ColumnName -> (RTable -> RTuple) -> RAggOperation
RAggOperation {
sourceCol :: ColumnName
sourceCol = ColumnName
""
,targetCol :: ColumnName
targetCol = ColumnName
trg
,aggFunc :: RTable -> RTuple
aggFunc = \RTable
rtab -> [(ColumnName, RDataType)] -> RTuple
createRTuple [(ColumnName
trg, RTable -> RDataType
countStarFold RTable
rtab)]
}
countStarFold :: RTable -> RDataType
countStarFold :: RTable -> RDataType
countStarFold RTable
rtab = Integer -> RDataType
RInt (Integer -> RDataType) -> Integer -> RDataType
forall a b. (a -> b) -> a -> b
$ Int -> Integer
forall a. Integral a => a -> Integer
toInteger (Int -> Integer) -> Int -> Integer
forall a b. (a -> b) -> a -> b
$ [RTuple] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length ([RTuple] -> Int) -> [RTuple] -> Int
forall a b. (a -> b) -> a -> b
$ RTable -> [RTuple]
rtableToList RTable
rtab
raggCountDist ::
ColumnName
-> ColumnName
-> RAggOperation
raggCountDist :: ColumnName -> ColumnName -> RAggOperation
raggCountDist ColumnName
src ColumnName
trg = RAggOperation :: ColumnName -> ColumnName -> (RTable -> RTuple) -> RAggOperation
RAggOperation {
sourceCol :: ColumnName
sourceCol = ColumnName
src
,targetCol :: ColumnName
targetCol = ColumnName
trg
,aggFunc :: RTable -> RTuple
aggFunc = \RTable
rtab -> [(ColumnName, RDataType)] -> RTuple
createRTuple [(ColumnName
trg, AggFunction
countDistFold ColumnName
src RTable
rtab)]
}
countDistFold :: AggFunction
countDistFold :: AggFunction
countDistFold ColumnName
src RTable
rtab =
let
rtabDist :: RTable
rtabDist = RJoinPredicate
-> [RAggOperation] -> [ColumnName] -> RTable -> RTable
runGroupBy (\RTuple
t1 RTuple
t2 -> RTuple
t1 RTuple -> ColumnName -> RDataType
<!> ColumnName
src RDataType -> RDataType -> Bool
forall a. Eq a => a -> a -> Bool
== RTuple
t2 RTuple -> ColumnName -> RDataType
<!> ColumnName
src)
[ColumnName -> ColumnName -> RAggOperation
raggCount ColumnName
src ColumnName
"dummy"]
[ColumnName
src]
RTable
rtab
in (RTuple -> RDataType -> RDataType)
-> RDataType -> RTable -> RDataType
forall a b. (a -> b -> b) -> b -> Vector a -> b
V.foldr' ( \RTuple
rtup RDataType
accValue ->
if (RDataType -> Bool
isNotNull (RDataType -> Bool) -> RDataType -> Bool
forall a b. (a -> b) -> a -> b
$ (ColumnName -> RTuple -> RDataType
getRTupColValue ColumnName
src) RTuple
rtup) Bool -> Bool -> Bool
&& (RDataType -> Bool
isNotNull RDataType
accValue)
then
Integer -> RDataType
RInt Integer
1 RDataType -> RDataType -> RDataType
forall a. Num a => a -> a -> a
+ RDataType
accValue
else
if (RDataType -> Bool
isNull (RDataType -> Bool) -> RDataType -> Bool
forall a b. (a -> b) -> a -> b
$ (ColumnName -> RTuple -> RDataType
getRTupColValue ColumnName
src) RTuple
rtup) Bool -> Bool -> Bool
&& (RDataType -> Bool
isNotNull RDataType
accValue)
then
RDataType
accValue
else
if (RDataType -> Bool
isNotNull (RDataType -> Bool) -> RDataType -> Bool
forall a b. (a -> b) -> a -> b
$ (ColumnName -> RTuple -> RDataType
getRTupColValue ColumnName
src) RTuple
rtup) Bool -> Bool -> Bool
&& (RDataType -> Bool
isNull RDataType
accValue)
then
Integer -> RDataType
RInt Integer
1
else
RDataType
Null
) (RDataType
Null) RTable
rtabDist
raggAvg ::
ColumnName
-> ColumnName
-> RAggOperation
raggAvg :: ColumnName -> ColumnName -> RAggOperation
raggAvg ColumnName
src ColumnName
trg = RAggOperation :: ColumnName -> ColumnName -> (RTable -> RTuple) -> RAggOperation
RAggOperation {
sourceCol :: ColumnName
sourceCol = ColumnName
src
,targetCol :: ColumnName
targetCol = ColumnName
trg
,aggFunc :: RTable -> RTuple
aggFunc = \RTable
rtab -> [(ColumnName, RDataType)] -> RTuple
createRTuple [(ColumnName
trg, let
sum :: RDataType
sum = AggFunction
sumFold ColumnName
src RTable
rtab
cnt :: RDataType
cnt = AggFunction
countFold ColumnName
src RTable
rtab
in case (RDataType
sum,RDataType
cnt) of
(RInt Integer
s, RInt Integer
c) -> Double -> RDataType
RDouble (Integer -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
s Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Integer -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
c)
(RDouble Double
s, RInt Integer
c) -> Double -> RDataType
RDouble (Double
s Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Integer -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
c)
(RDataType
_, RDataType
_) -> RDataType
Null
)]
}
raggMax ::
ColumnName
-> ColumnName
-> RAggOperation
raggMax :: ColumnName -> ColumnName -> RAggOperation
raggMax ColumnName
src ColumnName
trg = RAggOperation :: ColumnName -> ColumnName -> (RTable -> RTuple) -> RAggOperation
RAggOperation {
sourceCol :: ColumnName
sourceCol = ColumnName
src
,targetCol :: ColumnName
targetCol = ColumnName
trg
,aggFunc :: RTable -> RTuple
aggFunc = \RTable
rtab -> [(ColumnName, RDataType)] -> RTuple
createRTuple [(ColumnName
trg, AggFunction
maxFold ColumnName
src RTable
rtab)]
}
maxFold :: AggFunction
maxFold :: AggFunction
maxFold ColumnName
src RTable
rtab =
(RTuple -> RDataType -> RDataType)
-> RDataType -> RTable -> RDataType
forall a b. (a -> b -> b) -> b -> Vector a -> b
V.foldr' ( \RTuple
rtup RDataType
accValue ->
if (RDataType -> Bool
isNotNull (RDataType -> Bool) -> RDataType -> Bool
forall a b. (a -> b) -> a -> b
$ (ColumnName -> RTuple -> RDataType
getRTupColValue ColumnName
src) RTuple
rtup) Bool -> Bool -> Bool
&& (RDataType -> Bool
isNotNull RDataType
accValue)
then
RDataType -> RDataType -> RDataType
forall a. Ord a => a -> a -> a
max ((ColumnName -> RTuple -> RDataType
getRTupColValue ColumnName
src) RTuple
rtup) RDataType
accValue
else
if (RDataType -> Bool
isNull (RDataType -> Bool) -> RDataType -> Bool
forall a b. (a -> b) -> a -> b
$ (ColumnName -> RTuple -> RDataType
getRTupColValue ColumnName
src) RTuple
rtup) Bool -> Bool -> Bool
&& (RDataType -> Bool
isNotNull RDataType
accValue)
then
RDataType
accValue
else
if (RDataType -> Bool
isNotNull (RDataType -> Bool) -> RDataType -> Bool
forall a b. (a -> b) -> a -> b
$ (ColumnName -> RTuple -> RDataType
getRTupColValue ColumnName
src) RTuple
rtup) Bool -> Bool -> Bool
&& (RDataType -> Bool
isNull RDataType
accValue)
then
(ColumnName -> RTuple -> RDataType
getRTupColValue ColumnName
src) RTuple
rtup
else
RDataType
Null
) RDataType
Null RTable
rtab
raggMin ::
ColumnName
-> ColumnName
-> RAggOperation
raggMin :: ColumnName -> ColumnName -> RAggOperation
raggMin ColumnName
src ColumnName
trg = RAggOperation :: ColumnName -> ColumnName -> (RTable -> RTuple) -> RAggOperation
RAggOperation {
sourceCol :: ColumnName
sourceCol = ColumnName
src
,targetCol :: ColumnName
targetCol = ColumnName
trg
,aggFunc :: RTable -> RTuple
aggFunc = \RTable
rtab -> [(ColumnName, RDataType)] -> RTuple
createRTuple [(ColumnName
trg, AggFunction
minFold ColumnName
src RTable
rtab)]
}
minFold :: AggFunction
minFold :: AggFunction
minFold ColumnName
src RTable
rtab =
(RTuple -> RDataType -> RDataType)
-> RDataType -> RTable -> RDataType
forall a b. (a -> b -> b) -> b -> Vector a -> b
V.foldr' ( \RTuple
rtup RDataType
accValue ->
if (RDataType -> Bool
isNotNull (RDataType -> Bool) -> RDataType -> Bool
forall a b. (a -> b) -> a -> b
$ (ColumnName -> RTuple -> RDataType
getRTupColValue ColumnName
src) RTuple
rtup) Bool -> Bool -> Bool
&& (RDataType -> Bool
isNotNull RDataType
accValue)
then
RDataType -> RDataType -> RDataType
forall a. Ord a => a -> a -> a
min ((ColumnName -> RTuple -> RDataType
getRTupColValue ColumnName
src) RTuple
rtup) RDataType
accValue
else
if (RDataType -> Bool
isNull (RDataType -> Bool) -> RDataType -> Bool
forall a b. (a -> b) -> a -> b
$ (ColumnName -> RTuple -> RDataType
getRTupColValue ColumnName
src) RTuple
rtup) Bool -> Bool -> Bool
&& (RDataType -> Bool
isNotNull RDataType
accValue)
then
RDataType
accValue
else
if (RDataType -> Bool
isNotNull (RDataType -> Bool) -> RDataType -> Bool
forall a b. (a -> b) -> a -> b
$ (ColumnName -> RTuple -> RDataType
getRTupColValue ColumnName
src) RTuple
rtup) Bool -> Bool -> Bool
&& (RDataType -> Bool
isNull RDataType
accValue)
then
(ColumnName -> RTuple -> RDataType
getRTupColValue ColumnName
src) RTuple
rtup
else
RDataType
Null
) RDataType
Null RTable
rtab
ropU :: ROperation -> RTable -> RTable
ropU = ROperation -> RTable -> RTable
runUnaryROperation
runUnaryROperation ::
ROperation
-> RTable
-> RTable
runUnaryROperation :: ROperation -> RTable -> RTable
runUnaryROperation ROperation
rop RTable
irtab =
case ROperation
rop of
RFilter { fpred :: ROperation -> RTuple -> Bool
fpred = RTuple -> Bool
rpredicate } -> (RTuple -> Bool) -> RTable -> RTable
runRfilter RTuple -> Bool
rpredicate RTable
irtab
RPrj { colPrjList :: ROperation -> [ColumnName]
colPrjList = [ColumnName]
colNames } -> [ColumnName] -> RTable -> RTable
runProjection [ColumnName]
colNames RTable
irtab
RAggregate { aggList :: ROperation -> [RAggOperation]
aggList = [RAggOperation]
aggFunctions } -> [RAggOperation] -> RTable -> RTable
runAggregation [RAggOperation]
aggFunctions RTable
irtab
RGroupBy { gpred :: ROperation -> RJoinPredicate
gpred = RJoinPredicate
groupingpred, aggList :: ROperation -> [RAggOperation]
aggList = [RAggOperation]
aggFunctions, colGrByList :: ROperation -> [ColumnName]
colGrByList = [ColumnName]
cols } -> RJoinPredicate
-> [RAggOperation] -> [ColumnName] -> RTable -> RTable
runGroupBy RJoinPredicate
groupingpred [RAggOperation]
aggFunctions [ColumnName]
cols RTable
irtab
RCombinedOp { rcombOp :: ROperation -> RTable -> RTable
rcombOp = RTable -> RTable
comb } -> (RTable -> RTable) -> RTable -> RTable
runCombinedROp RTable -> RTable
comb RTable
irtab
ROrderBy { colOrdList :: ROperation -> [(ColumnName, OrderingSpec)]
colOrdList = [(ColumnName, OrderingSpec)]
colist } -> [(ColumnName, OrderingSpec)] -> RTable -> RTable
runOrderBy [(ColumnName, OrderingSpec)]
colist RTable
irtab
ropUres :: ROperation -> RTable -> RTabResult
ropUres = ROperation -> RTable -> RTabResult
runUnaryROperationRes
runUnaryROperationRes ::
ROperation
-> RTable
-> RTabResult
runUnaryROperationRes :: ROperation -> RTable -> RTabResult
runUnaryROperationRes ROperation
rop RTable
irtab =
let resultRtab :: RTable
resultRtab = ROperation -> RTable -> RTable
runUnaryROperation ROperation
rop RTable
irtab
returnedRtups :: RTuplesRet
returnedRtups = Int -> RTuplesRet
rtuplesRet (Int -> RTuplesRet) -> Int -> RTuplesRet
forall a b. (a -> b) -> a -> b
$ RTable -> Int
forall a. Vector a -> Int
V.length RTable
resultRtab
in (RTable, RTuplesRet) -> RTabResult
rtabResult (RTable
resultRtab, RTuplesRet
returnedRtups)
ropB :: ROperation -> BinaryRTableOperation
ropB = ROperation -> BinaryRTableOperation
runBinaryROperation
runBinaryROperation ::
ROperation
-> RTable
-> RTable
-> RTable
runBinaryROperation :: ROperation -> BinaryRTableOperation
runBinaryROperation ROperation
rop RTable
irtab1 RTable
irtab2 =
case ROperation
rop of
RInJoin { jpred :: ROperation -> RJoinPredicate
jpred = RJoinPredicate
jpredicate } -> RJoinPredicate -> BinaryRTableOperation
runInnerJoinO RJoinPredicate
jpredicate RTable
irtab1 RTable
irtab2
RLeftJoin { jpred :: ROperation -> RJoinPredicate
jpred = RJoinPredicate
jpredicate } -> RJoinPredicate -> BinaryRTableOperation
runLeftJoin RJoinPredicate
jpredicate RTable
irtab1 RTable
irtab2
RRightJoin { jpred :: ROperation -> RJoinPredicate
jpred = RJoinPredicate
jpredicate } -> RJoinPredicate -> BinaryRTableOperation
runRightJoin RJoinPredicate
jpredicate RTable
irtab1 RTable
irtab2
RSemiJoin { jpred :: ROperation -> RJoinPredicate
jpred = RJoinPredicate
jpredicate } -> RJoinPredicate -> BinaryRTableOperation
runSemiJoin RJoinPredicate
jpredicate RTable
irtab1 RTable
irtab2
RAntiJoin { jpred :: ROperation -> RJoinPredicate
jpred = RJoinPredicate
jpredicate } -> RJoinPredicate -> BinaryRTableOperation
runAntiJoin RJoinPredicate
jpredicate RTable
irtab1 RTable
irtab2
ROperation
RUnion -> BinaryRTableOperation
runUnion RTable
irtab1 RTable
irtab2
ROperation
RInter -> BinaryRTableOperation
runIntersect RTable
irtab1 RTable
irtab2
ROperation
RDiff -> BinaryRTableOperation
runDiff RTable
irtab1 RTable
irtab2
RBinOp { rbinOp :: ROperation -> BinaryRTableOperation
rbinOp = BinaryRTableOperation
bop } -> BinaryRTableOperation
bop RTable
irtab1 RTable
irtab2
ropBres :: ROperation -> RTable -> RTable -> RTabResult
ropBres = ROperation -> RTable -> RTable -> RTabResult
runBinaryROperationRes
runBinaryROperationRes ::
ROperation
-> RTable
-> RTable
-> RTabResult
runBinaryROperationRes :: ROperation -> RTable -> RTable -> RTabResult
runBinaryROperationRes ROperation
rop RTable
irtab1 RTable
irtab2 =
let resultRtab :: RTable
resultRtab = ROperation -> BinaryRTableOperation
runBinaryROperation ROperation
rop RTable
irtab1 RTable
irtab2
returnedRtups :: RTuplesRet
returnedRtups = Int -> RTuplesRet
rtuplesRet (Int -> RTuplesRet) -> Int -> RTuplesRet
forall a b. (a -> b) -> a -> b
$ RTable -> Int
forall a. Vector a -> Int
V.length RTable
resultRtab
in (RTable, RTuplesRet) -> RTabResult
rtabResult (RTable
resultRtab, RTuplesRet
returnedRtups)
isRTabEmpty :: RTable -> Bool
isRTabEmpty :: RTable -> Bool
isRTabEmpty = RTable -> Bool
forall a. Vector a -> Bool
V.null
isRTupEmpty :: RTuple -> Bool
isRTupEmpty :: RTuple -> Bool
isRTupEmpty = RTuple -> Bool
forall k v. HashMap k v -> Bool
HM.null
emptyRTable :: RTable
emptyRTable :: RTable
emptyRTable = RTable
forall a. Vector a
V.empty :: RTable
emptyRTuple :: RTuple
emptyRTuple :: RTuple
emptyRTuple = RTuple
forall k v. HashMap k v
HM.empty
createSingletonRTable ::
RTuple
-> RTable
createSingletonRTable :: RTuple -> RTable
createSingletonRTable RTuple
rt = RTuple -> RTable
forall a. a -> Vector a
V.singleton RTuple
rt
createRTuple ::
[(ColumnName, RDataType)]
-> RTuple
createRTuple :: [(ColumnName, RDataType)] -> RTuple
createRTuple [(ColumnName, RDataType)]
l = [(ColumnName, RDataType)] -> RTuple
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HM.fromList [(ColumnName, RDataType)]
l
createNullRTuple ::
[ColumnName]
-> RTuple
createNullRTuple :: [ColumnName] -> RTuple
createNullRTuple [ColumnName]
cnames = [(ColumnName, RDataType)] -> RTuple
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HM.fromList ([(ColumnName, RDataType)] -> RTuple)
-> [(ColumnName, RDataType)] -> RTuple
forall a b. (a -> b) -> a -> b
$ [(ColumnName, RDataType)]
zipped
where zipped :: [(ColumnName, RDataType)]
zipped = [ColumnName] -> [RDataType] -> [(ColumnName, RDataType)]
forall a b. [a] -> [b] -> [(a, b)]
Data.List.zip [ColumnName]
cnames (Int -> [RDataType] -> [RDataType]
forall a. Int -> [a] -> [a]
Data.List.take ([ColumnName] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length [ColumnName]
cnames) (RDataType -> [RDataType]
forall a. a -> [a]
repeat RDataType
Null))
isNullRTuple ::
RTuple
-> Bool
isNullRTuple :: RTuple -> Bool
isNullRTuple RTuple
t =
let
checkt :: RTuple
checkt = (RDataType -> Bool) -> RTuple -> RTuple
forall v k. (v -> Bool) -> HashMap k v -> HashMap k v
HM.filter (\RDataType
v -> RDataType -> Bool
isNotNull RDataType
v) RTuple
t
in if RTuple -> Bool
isRTupEmpty RTuple
checkt
then Bool
True
else Bool
False
rtabFoldr' :: (RTuple -> RTable -> RTable) -> RTable -> RTable -> RTable
rtabFoldr' :: (RTuple -> RTable -> RTable) -> BinaryRTableOperation
rtabFoldr' RTuple -> RTable -> RTable
f RTable
accum RTable
rtab = (RTuple -> RTable -> RTable) -> BinaryRTableOperation
forall a b. (a -> b -> b) -> b -> Vector a -> b
V.foldr' RTuple -> RTable -> RTable
f RTable
accum RTable
rtab
rdatatypeFoldr' :: (RTuple -> RDataType -> RDataType) -> RDataType -> RTable -> RDataType
rdatatypeFoldr' :: (RTuple -> RDataType -> RDataType)
-> RDataType -> RTable -> RDataType
rdatatypeFoldr' RTuple -> RDataType -> RDataType
f RDataType
accum RTable
rtab = (RTuple -> RDataType -> RDataType)
-> RDataType -> RTable -> RDataType
forall a b. (a -> b -> b) -> b -> Vector a -> b
V.foldr' RTuple -> RDataType -> RDataType
f RDataType
accum RTable
rtab
rtabFoldl' :: (RTable -> RTuple -> RTable) -> RTable -> RTable -> RTable
rtabFoldl' :: (RTable -> RTuple -> RTable) -> BinaryRTableOperation
rtabFoldl' RTable -> RTuple -> RTable
f RTable
accum RTable
rtab = (RTable -> RTuple -> RTable) -> BinaryRTableOperation
forall a b. (a -> b -> a) -> a -> Vector b -> a
V.foldl' RTable -> RTuple -> RTable
f RTable
accum RTable
rtab
rdatatypeFoldl' :: (RDataType -> RTuple -> RDataType) -> RDataType -> RTable -> RDataType
rdatatypeFoldl' :: (RDataType -> RTuple -> RDataType)
-> RDataType -> RTable -> RDataType
rdatatypeFoldl' RDataType -> RTuple -> RDataType
f RDataType
accum RTable
rtab = (RDataType -> RTuple -> RDataType)
-> RDataType -> RTable -> RDataType
forall a b. (a -> b -> a) -> a -> Vector b -> a
V.foldl' RDataType -> RTuple -> RDataType
f RDataType
accum RTable
rtab
rtabMap :: (RTuple -> RTuple) -> RTable -> RTable
rtabMap :: (RTuple -> RTuple) -> RTable -> RTable
rtabMap RTuple -> RTuple
f RTable
rtab = (RTuple -> RTuple) -> RTable -> RTable
forall a b. (a -> b) -> Vector a -> Vector b
V.map RTuple -> RTuple
f RTable
rtab
rtupleMap :: (RDataType -> RDataType) -> RTuple -> RTuple
rtupleMap :: (RDataType -> RDataType) -> RTuple -> RTuple
rtupleMap RDataType -> RDataType
f RTuple
t = (RDataType -> RDataType) -> RTuple -> RTuple
forall v1 v2 k. (v1 -> v2) -> HashMap k v1 -> HashMap k v2
HM.map RDataType -> RDataType
f RTuple
t
rtupleMapWithKey :: (ColumnName -> RDataType -> RDataType) -> RTuple -> RTuple
rtupleMapWithKey :: (ColumnName -> RDataType -> RDataType) -> RTuple -> RTuple
rtupleMapWithKey ColumnName -> RDataType -> RDataType
f RTuple
t = (ColumnName -> RDataType -> RDataType) -> RTuple -> RTuple
forall k v1 v2. (k -> v1 -> v2) -> HashMap k v1 -> HashMap k v2
HM.mapWithKey ColumnName -> RDataType -> RDataType
f RTuple
t
type RTuplesRet = Sum Int
rtuplesRet :: Int -> RTuplesRet
rtuplesRet :: Int -> RTuplesRet
rtuplesRet Int
i = (Int -> RTuplesRet
forall a. a -> Sum a
M.Sum Int
i) :: RTuplesRet
getRTuplesRet :: RTuplesRet -> Int
getRTuplesRet :: RTuplesRet -> Int
getRTuplesRet = RTuplesRet -> Int
forall a. Sum a -> a
M.getSum
type RTabResult = Writer RTuplesRet RTable
rtabResult ::
(RTable, RTuplesRet)
-> RTabResult
rtabResult :: (RTable, RTuplesRet) -> RTabResult
rtabResult (RTable
rtab, RTuplesRet
rtupRet) = (RTable, RTuplesRet) -> RTabResult
forall (m :: * -> *) a w. Monad m => (a, w) -> WriterT w m a
writer (RTable
rtab, RTuplesRet
rtupRet)
runRTabResult ::
RTabResult
-> (RTable, RTuplesRet)
runRTabResult :: RTabResult -> (RTable, RTuplesRet)
runRTabResult RTabResult
rtr = RTabResult -> (RTable, RTuplesRet)
forall w a. Writer w a -> (a, w)
runWriter RTabResult
rtr
execRTabResult ::
RTabResult
-> RTuplesRet
execRTabResult :: RTabResult -> RTuplesRet
execRTabResult RTabResult
rtr = RTabResult -> RTuplesRet
forall w a. Writer w a -> w
execWriter RTabResult
rtr
removeColumn ::
ColumnName
-> RTable
-> RTable
removeColumn :: ColumnName -> RTable -> RTable
removeColumn ColumnName
col RTable
rtabSrc = do
RTuple
srcRtup <- RTable
rtabSrc
let targetRtup :: RTuple
targetRtup = ColumnName -> RTuple -> RTuple
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> HashMap k v
HM.delete ColumnName
col RTuple
srcRtup
RTuple -> RTable
forall (m :: * -> *) a. Monad m => a -> m a
return RTuple
targetRtup
addColumn ::
ColumnName
-> RDataType
-> RTable
-> RTable
addColumn :: ColumnName -> RDataType -> RTable -> RTable
addColumn ColumnName
name RDataType
initVal RTable
rtabSrc = do
RTuple
srcRtup <- RTable
rtabSrc
let targetRtup :: RTuple
targetRtup = ColumnName -> RDataType -> RTuple -> RTuple
forall k v.
(Eq k, Hashable k) =>
k -> v -> HashMap k v -> HashMap k v
HM.insert ColumnName
name RDataType
initVal RTuple
srcRtup
RTuple -> RTable
forall (m :: * -> *) a. Monad m => a -> m a
return RTuple
targetRtup
f :: (RTuple -> Bool) -> RTable -> RTable
f = (RTuple -> Bool) -> RTable -> RTable
runRfilter
runRfilter ::
RPredicate
-> RTable
-> RTable
runRfilter :: (RTuple -> Bool) -> RTable -> RTable
runRfilter RTuple -> Bool
rpred RTable
rtab =
if RTable -> Bool
isRTabEmpty RTable
rtab
then RTable
emptyRTable
else
(RTuple -> Bool) -> RTable -> RTable
forall a. (a -> Bool) -> Vector a -> Vector a
V.filter RTuple -> Bool
rpred RTable
rtab
p :: [ColumnName] -> RTable -> RTable
p = [ColumnName] -> RTable -> RTable
runProjection
runProjection ::
[ColumnName]
-> RTable
-> RTable
runProjection :: [ColumnName] -> RTable -> RTable
runProjection [ColumnName]
colNamList RTable
irtab =
if RTable -> Bool
isRTabEmpty RTable
irtab
then
RTable
emptyRTable
else
do
RTuple
srcRtuple <- RTable
irtab
let
srcValueL :: [Maybe RDataType]
srcValueL = (ColumnName -> Maybe RDataType)
-> [ColumnName] -> [Maybe RDataType]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\ColumnName
colName -> ColumnName -> RTuple -> Maybe RDataType
rtupLookup ColumnName
colName RTuple
srcRtuple) [ColumnName]
colNamList
if Maybe RDataType -> [Maybe RDataType] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
Data.List.elem Maybe RDataType
forall a. Maybe a
Nothing [Maybe RDataType]
srcValueL
then
RTable
emptyRTable
else
let
valList :: [RDataType]
valList = (Maybe RDataType -> RDataType) -> [Maybe RDataType] -> [RDataType]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\(Just RDataType
v) -> RDataType
v) [Maybe RDataType]
srcValueL
targetRtuple :: RTuple
targetRtuple = [(ColumnName, RDataType)] -> RTuple
rtupleFromList ([ColumnName] -> [RDataType] -> [(ColumnName, RDataType)]
forall a b. [a] -> [b] -> [(a, b)]
Data.List.zip [ColumnName]
colNamList [RDataType]
valList)
in RTuple -> RTable
forall (m :: * -> *) a. Monad m => a -> m a
return RTuple
targetRtuple
runProjectionMissedHits ::
[ColumnName]
-> RTable
-> RTable
runProjectionMissedHits :: [ColumnName] -> RTable -> RTable
runProjectionMissedHits [ColumnName]
colNamList RTable
irtab =
if RTable -> Bool
isRTabEmpty RTable
irtab
then
RTable
emptyRTable
else
do
RTuple
srcRtuple <- RTable
irtab
let
srcValueL :: [RDataType]
srcValueL = (ColumnName -> RDataType) -> [ColumnName] -> [RDataType]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\ColumnName
src -> RDataType -> ColumnName -> RTuple -> RDataType
forall k v. (Eq k, Hashable k) => v -> k -> HashMap k v -> v
HM.lookupDefault RDataType
Null
ColumnName
src
RTuple
srcRtuple
) [ColumnName]
colNamList
targetRtuple :: RTuple
targetRtuple = [(ColumnName, RDataType)] -> RTuple
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HM.fromList ([ColumnName] -> [RDataType] -> [(ColumnName, RDataType)]
forall a b. [a] -> [b] -> [(a, b)]
Data.List.zip [ColumnName]
colNamList [RDataType]
srcValueL)
RTuple -> RTable
forall (m :: * -> *) a. Monad m => a -> m a
return RTuple
targetRtuple
limit ::
Int
-> RTable
-> RTable
limit :: Int -> RTable -> RTable
limit Int
n RTable
r1 = Int -> RTable -> RTable
forall a. Int -> Vector a -> Vector a
V.take Int
n RTable
r1
aJ :: RJoinPredicate -> BinaryRTableOperation
aJ = RJoinPredicate -> BinaryRTableOperation
runAntiJoin
runAntiJoin ::
RJoinPredicate
-> RTable
-> RTable
-> RTable
runAntiJoin :: RJoinPredicate -> BinaryRTableOperation
runAntiJoin RJoinPredicate
jpred RTable
tabDriver RTable
tabProbed =
if RTable -> Bool
isRTabEmpty RTable
tabDriver Bool -> Bool -> Bool
|| RTable -> Bool
isRTabEmpty RTable
tabProbed
then
RTable
emptyRTable
else
BinaryRTableOperation
d RTable
tabDriver (RTable -> RTable) -> RTable -> RTable
forall a b. (a -> b) -> a -> b
$ RJoinPredicate -> BinaryRTableOperation
sJ RJoinPredicate
jpred RTable
tabDriver RTable
tabProbed
sJ :: RJoinPredicate -> BinaryRTableOperation
sJ = RJoinPredicate -> BinaryRTableOperation
runSemiJoin
runSemiJoin ::
RJoinPredicate
-> RTable
-> RTable
-> RTable
runSemiJoin :: RJoinPredicate -> BinaryRTableOperation
runSemiJoin RJoinPredicate
jpred RTable
tabDriver RTable
tabProbed =
if RTable -> Bool
isRTabEmpty RTable
tabDriver Bool -> Bool -> Bool
|| RTable -> Bool
isRTabEmpty RTable
tabProbed
then
RTable
emptyRTable
else
do
RTuple
rtupDrv <- RTable
tabDriver
(RTuple -> RTable -> RTable) -> BinaryRTableOperation
forall a b. (a -> b -> b) -> b -> Vector a -> b
V.foldr' (\RTuple
t RTable
accum ->
if (RJoinPredicate
jpred RTuple
rtupDrv RTuple
t)
then
RTuple -> RTable -> RTable
insertAppendRTab (RTuple
rtupDrv) RTable
accum
else
RTable
accum
) RTable
emptyRTable RTable
tabProbed
iJ :: RJoinPredicate -> BinaryRTableOperation
iJ = RJoinPredicate -> BinaryRTableOperation
runInnerJoinO
runInnerJoin ::
RJoinPredicate
-> RTable
-> RTable
-> RTable
runInnerJoin :: RJoinPredicate -> BinaryRTableOperation
runInnerJoin RJoinPredicate
jpred RTable
irtab1 RTable
irtab2 =
if (RTable -> Bool
isRTabEmpty RTable
irtab1) Bool -> Bool -> Bool
|| (RTable -> Bool
isRTabEmpty RTable
irtab2)
then
RTable
emptyRTable
else
do
RTuple
rtup1 <- RTable
irtab1
RTuple
rtup2 <- RTable
irtab2
let targetRtuple :: RTuple
targetRtuple =
if (RJoinPredicate
jpred RTuple
rtup1 RTuple
rtup2)
then RTuple -> RTuple -> RTuple
forall k v.
(Eq k, Hashable k) =>
HashMap k v -> HashMap k v -> HashMap k v
HM.union RTuple
rtup1 RTuple
rtup2
else RTuple
forall k v. HashMap k v
HM.empty
RTable -> RTable
removeEmptyRTuples (RTuple -> RTable
forall (m :: * -> *) a. Monad m => a -> m a
return RTuple
targetRtuple)
where removeEmptyRTuples :: RTable -> RTable
removeEmptyRTuples = (RTuple -> Bool) -> RTable -> RTable
f (Bool -> Bool
not(Bool -> Bool) -> (RTuple -> Bool) -> RTuple -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
.RTuple -> Bool
isRTupEmpty)
runInnerJoinO ::
RJoinPredicate
-> RTable
-> RTable
-> RTable
runInnerJoinO :: RJoinPredicate -> BinaryRTableOperation
runInnerJoinO RJoinPredicate
jpred RTable
tabDriver RTable
tabProbed =
if RTable -> Bool
isRTabEmpty RTable
tabDriver Bool -> Bool -> Bool
|| RTable -> Bool
isRTabEmpty RTable
tabProbed
then
RTable
emptyRTable
else
do
RTuple
rtupDrv <- RTable
tabDriver
(RTuple -> RTable -> RTable) -> BinaryRTableOperation
forall a b. (a -> b -> b) -> b -> Vector a -> b
V.foldr' (\RTuple
t RTable
accum ->
if (RJoinPredicate
jpred RTuple
rtupDrv RTuple
t)
then
RTuple -> RTable -> RTable
insertAppendRTab (RTuple -> RTuple -> RTuple
joinRTuples RTuple
rtupDrv RTuple
t) RTable
accum
else
RTable
accum
) RTable
emptyRTable RTable
tabProbed
joinRTuples :: RTuple -> RTuple -> RTuple
joinRTuples :: RTuple -> RTuple -> RTuple
joinRTuples RTuple
tleft RTuple
tright =
let
dontNeedChange :: RTuple
dontNeedChange = RTuple -> RTuple -> RTuple
forall k v w.
(Eq k, Hashable k) =>
HashMap k v -> HashMap k w -> HashMap k v
HM.difference RTuple
tright RTuple
tleft
changedPart :: RTuple
changedPart = RTuple -> RTuple -> RTuple
changeKeys RTuple
tleft RTuple
tright
new_tright :: RTuple
new_tright = RTuple -> RTuple -> RTuple
forall k v.
(Eq k, Hashable k) =>
HashMap k v -> HashMap k v -> HashMap k v
HM.union RTuple
dontNeedChange RTuple
changedPart
in RTuple -> RTuple -> RTuple
forall k v.
(Eq k, Hashable k) =>
HashMap k v -> HashMap k v -> HashMap k v
HM.union RTuple
tleft RTuple
new_tright
where
changeKeys :: RTuple -> RTuple -> RTuple
changeKeys :: RTuple -> RTuple -> RTuple
changeKeys RTuple
tleft RTuple
changedPart =
if RTuple -> Bool
isRTupEmpty (RTuple -> RTuple -> RTuple
forall k v w.
(Eq k, Hashable k) =>
HashMap k v -> HashMap k w -> HashMap k v
HM.intersection RTuple
changedPart RTuple
tleft)
then
RTuple
changedPart
else
let
needChange :: RTuple
needChange = RTuple -> RTuple -> RTuple
forall k v w.
(Eq k, Hashable k) =>
HashMap k v -> HashMap k w -> HashMap k v
HM.intersection RTuple
changedPart RTuple
tleft
dontNeedChange :: RTuple
dontNeedChange = RTuple -> RTuple -> RTuple
forall k v w.
(Eq k, Hashable k) =>
HashMap k v -> HashMap k w -> HashMap k v
HM.difference RTuple
changedPart RTuple
tleft
new_changedPart :: RTuple
new_changedPart = [(ColumnName, RDataType)] -> RTuple
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
fromList ([(ColumnName, RDataType)] -> RTuple)
-> [(ColumnName, RDataType)] -> RTuple
forall a b. (a -> b) -> a -> b
$ ((ColumnName, RDataType) -> (ColumnName, RDataType))
-> [(ColumnName, RDataType)] -> [(ColumnName, RDataType)]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\(ColumnName
k,RDataType
v) -> (ColumnName -> ColumnName
newKey ColumnName
k, RDataType
v)) ([(ColumnName, RDataType)] -> [(ColumnName, RDataType)])
-> [(ColumnName, RDataType)] -> [(ColumnName, RDataType)]
forall a b. (a -> b) -> a -> b
$ RTuple -> [(ColumnName, RDataType)]
forall k v. HashMap k v -> [(k, v)]
toList RTuple
needChange
in RTuple -> RTuple -> RTuple
forall k v.
(Eq k, Hashable k) =>
HashMap k v -> HashMap k v -> HashMap k v
HM.union RTuple
dontNeedChange (RTuple -> RTuple -> RTuple
changeKeys RTuple
tleft RTuple
new_changedPart)
newKey :: ColumnName -> ColumnName
newKey :: ColumnName -> ColumnName
newKey ColumnName
nameT =
let
name :: String
name = ColumnName -> String
T.unpack ColumnName
nameT
lastChar :: Char
lastChar = String -> Char
forall a. [a] -> a
Data.List.last String
name
beforeLastChar :: Char
beforeLastChar = String
name String -> Int -> Char
forall a. [a] -> Int -> a
!! (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length String
name Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
2)
in
if Char
beforeLastChar Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'_' Bool -> Bool -> Bool
&& Char -> Bool
Data.Char.isDigit Char
lastChar
then String -> ColumnName
T.pack (String -> ColumnName) -> String -> ColumnName
forall a b. (a -> b) -> a -> b
$ (Int -> ShowS
forall a. Int -> [a] -> [a]
Data.List.take (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length String
name Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
2) String
name) String -> ShowS
forall a. [a] -> [a] -> [a]
++ ( Char
'_' Char -> ShowS
forall a. a -> [a] -> [a]
: (Int -> String
forall a. Show a => a -> String
show (Int -> String) -> Int -> String
forall a b. (a -> b) -> a -> b
$ (String -> Int
forall a. Read a => String -> a
read (Char
lastChar Char -> ShowS
forall a. a -> [a] -> [a]
: String
"") :: Int) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) )
else String -> ColumnName
T.pack (String -> ColumnName) -> String -> ColumnName
forall a b. (a -> b) -> a -> b
$ String
name String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"_1"
lJ :: RJoinPredicate -> BinaryRTableOperation
lJ = RJoinPredicate -> BinaryRTableOperation
runLeftJoin
runLeftJoin ::
RJoinPredicate
-> RTable
-> RTable
-> RTable
runLeftJoin :: RJoinPredicate -> BinaryRTableOperation
runLeftJoin RJoinPredicate
jpred RTable
preservingTab RTable
tab =
if RTable -> Bool
isRTabEmpty RTable
preservingTab
then
RTable
emptyRTable
else
if RTable -> Bool
isRTabEmpty RTable
tab
then
RTable
preservingTab
else
let
unionFstPart :: RTable
unionFstPart = RJoinPredicate -> BinaryRTableOperation
iJ RJoinPredicate
jpred RTable
preservingTab RTable
tab
fstPartProj :: RTable
fstPartProj = [ColumnName] -> RTable -> RTable
p (RTable -> [ColumnName]
getColumnNamesFromRTab RTable
preservingTab) RTable
unionFstPart
unionSndPart :: RTable
unionSndPart =
let
difftab :: RTable
difftab = BinaryRTableOperation
d RTable
preservingTab RTable
fstPartProj
in RJoinPredicate -> BinaryRTableOperation
iJ (\RTuple
t1 RTuple
t2 -> Bool
True) RTable
difftab (RTuple -> RTable
createSingletonRTable (RTuple -> RTable) -> RTuple -> RTable
forall a b. (a -> b) -> a -> b
$ [ColumnName] -> RTuple
createNullRTuple ([ColumnName] -> RTuple) -> [ColumnName] -> RTuple
forall a b. (a -> b) -> a -> b
$ (RTable -> [ColumnName]
getColumnNamesFromRTab RTable
tab))
in BinaryRTableOperation
u RTable
unionFstPart RTable
unionSndPart
getUniqueColumnNamesAfterJoin :: [ColumnName] -> [ColumnName] -> [ColumnName]
getUniqueColumnNamesAfterJoin :: [ColumnName] -> [ColumnName] -> [ColumnName]
getUniqueColumnNamesAfterJoin [ColumnName]
cl1 [ColumnName]
cl2 =
[ColumnName]
cl1 [ColumnName] -> [ColumnName] -> [ColumnName]
forall a. [a] -> [a] -> [a]
++ (ColumnName -> Bool) -> [ColumnName] -> [ColumnName]
forall a. (a -> Bool) -> [a] -> [a]
Data.List.filter (\ColumnName
n2 -> [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and ([Bool] -> Bool) -> [Bool] -> Bool
forall a b. (a -> b) -> a -> b
$ (ColumnName -> Bool) -> [ColumnName] -> [Bool]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\ColumnName
n1 -> Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ ColumnName -> ColumnName -> Bool
isMyPrefixOf ColumnName
n1 ColumnName
n2) [ColumnName]
cl1) [ColumnName]
cl2
where
isMyPrefixOf :: ColumnName -> ColumnName -> Bool
isMyPrefixOf :: ColumnName -> ColumnName -> Bool
isMyPrefixOf ColumnName
cn1 ColumnName
cn2 =
let
cn2_new :: ColumnName
cn2_new = (Char -> Bool) -> ColumnName -> ColumnName
T.dropWhileEnd (\Char
c -> Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'_') (ColumnName -> ColumnName) -> ColumnName -> ColumnName
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> ColumnName -> ColumnName
T.dropWhileEnd (\Char
c -> Char -> Bool
isDigit Char
c) ColumnName
cn2
in ColumnName
cn1 ColumnName -> ColumnName -> Bool
forall a. Eq a => a -> a -> Bool
== ColumnName
cn2_new
rJ :: RJoinPredicate -> BinaryRTableOperation
rJ = RJoinPredicate -> BinaryRTableOperation
runRightJoin
runRightJoin ::
RJoinPredicate
-> RTable
-> RTable
-> RTable
runRightJoin :: RJoinPredicate -> BinaryRTableOperation
runRightJoin RJoinPredicate
jpred RTable
tab RTable
preservingTab =
if RTable -> Bool
isRTabEmpty RTable
preservingTab
then
RTable
emptyRTable
else
if RTable -> Bool
isRTabEmpty RTable
tab
then
RTable
preservingTab
else
let
unionFstPart :: RTable
unionFstPart =
RJoinPredicate -> BinaryRTableOperation
iJ (RJoinPredicate -> RJoinPredicate
forall a b c. (a -> b -> c) -> b -> a -> c
flip RJoinPredicate
jpred) RTable
preservingTab RTable
tab
fstPartProj :: RTable
fstPartProj =
[ColumnName] -> RTable -> RTable
p (RTable -> [ColumnName]
getColumnNamesFromRTab RTable
preservingTab) RTable
unionFstPart
unionSndPart :: RTable
unionSndPart =
let
difftab :: RTable
difftab =
BinaryRTableOperation
d RTable
preservingTab RTable
fstPartProj
in RJoinPredicate -> BinaryRTableOperation
iJ (\RTuple
t1 RTuple
t2 -> Bool
True) RTable
difftab (RTuple -> RTable
createSingletonRTable (RTuple -> RTable) -> RTuple -> RTable
forall a b. (a -> b) -> a -> b
$ [ColumnName] -> RTuple
createNullRTuple ([ColumnName] -> RTuple) -> [ColumnName] -> RTuple
forall a b. (a -> b) -> a -> b
$ (RTable -> [ColumnName]
getColumnNamesFromRTab RTable
tab))
in BinaryRTableOperation
u RTable
unionFstPart RTable
unionSndPart
foJ :: RJoinPredicate -> BinaryRTableOperation
foJ = RJoinPredicate -> BinaryRTableOperation
runFullOuterJoin
runFullOuterJoin ::
RJoinPredicate
-> RTable
-> RTable
-> RTable
runFullOuterJoin :: RJoinPredicate -> BinaryRTableOperation
runFullOuterJoin RJoinPredicate
jpred RTable
leftRTab RTable
rightRTab =
let
unionFstPart :: RTable
unionFstPart = RJoinPredicate -> BinaryRTableOperation
lJ RJoinPredicate
jpred RTable
leftRTab RTable
rightRTab
unionSndPartTemp1 :: RTable
unionSndPartTemp1 = BinaryRTableOperation
d (RJoinPredicate -> BinaryRTableOperation
rJ RJoinPredicate
jpred RTable
leftRTab RTable
rightRTab) (RJoinPredicate -> BinaryRTableOperation
iJ (RJoinPredicate -> RJoinPredicate
forall a b c. (a -> b -> c) -> b -> a -> c
flip RJoinPredicate
jpred) RTable
rightRTab RTable
leftRTab)
unionSndPartTemp2 :: RTable
unionSndPartTemp2 = [ColumnName] -> RTable -> RTable
p (RTable -> [ColumnName]
getColumnNamesFromRTab RTable
rightRTab) RTable
unionSndPartTemp1
unionSndPart :: RTable
unionSndPart = RJoinPredicate -> BinaryRTableOperation
iJ (\RTuple
t1 RTuple
t2 -> Bool
True) (RTuple -> RTable
createSingletonRTable (RTuple -> RTable) -> RTuple -> RTable
forall a b. (a -> b) -> a -> b
$ [ColumnName] -> RTuple
createNullRTuple ([ColumnName] -> RTuple) -> [ColumnName] -> RTuple
forall a b. (a -> b) -> a -> b
$ (RTable -> [ColumnName]
getColumnNamesFromRTab RTable
leftRTab)) RTable
unionSndPartTemp2
in RTable
unionFstPart BinaryRTableOperation
`u` RTable
unionSndPart
u :: BinaryRTableOperation
u = BinaryRTableOperation
runUnion
runUnion ::
RTable
-> RTable
-> RTable
runUnion :: BinaryRTableOperation
runUnion RTable
rt1 RTable
rt2 =
if RTable -> Bool
isRTabEmpty RTable
rt1 Bool -> Bool -> Bool
&& RTable -> Bool
isRTabEmpty RTable
rt2
then
RTable
emptyRTable
else
if RTable -> Bool
isRTabEmpty RTable
rt1
then RTable
rt2
else
if RTable -> Bool
isRTabEmpty RTable
rt2
then RTable
rt1
else
if RTable -> RTable -> Bool
rtabsSameStructure RTable
rt1 RTable
rt2
then
RTable
rt1 BinaryRTableOperation
forall a. Vector a -> Vector a -> Vector a
V.++ ((RTuple -> RTable -> RTable) -> BinaryRTableOperation
forall a b. (a -> b -> b) -> b -> Vector a -> b
V.foldr (RTuple -> RTable -> RTable
un) RTable
emptyRTable RTable
rt2)
else
ConflictingRTableStructures -> RTable
forall a e. Exception e => e -> a
throw (ConflictingRTableStructures -> RTable)
-> ConflictingRTableStructures -> RTable
forall a b. (a -> b) -> a -> b
$ String -> ConflictingRTableStructures
ConflictingRTableStructures String
"Cannot run: Union, due to conflicting RTable structures."
where
un :: RTuple -> RTable -> RTable
un :: RTuple -> RTable -> RTable
un RTuple
tupRight RTable
acc =
if RTuple -> RTable -> Bool
didYouFindIt RTuple
tupRight RTable
rt1
then RTable
acc
else RTable -> RTuple -> RTable
forall a. Vector a -> a -> Vector a
V.snoc RTable
acc RTuple
tupRight
runUnionAll ::
RTable
-> RTable
-> RTable
runUnionAll :: BinaryRTableOperation
runUnionAll RTable
rt1 RTable
rt2 =
if RTable -> Bool
isRTabEmpty RTable
rt1 Bool -> Bool -> Bool
&& RTable -> Bool
isRTabEmpty RTable
rt2
then
RTable
emptyRTable
else
if RTable -> Bool
isRTabEmpty RTable
rt1
then RTable
rt2
else
if RTable -> Bool
isRTabEmpty RTable
rt2
then RTable
rt1
else
if RTable -> RTable -> Bool
rtabsSameStructure RTable
rt1 RTable
rt2
then
RTable
rt1 BinaryRTableOperation
forall a. Vector a -> Vector a -> Vector a
V.++ RTable
rt2
else
ConflictingRTableStructures -> RTable
forall a e. Exception e => e -> a
throw (ConflictingRTableStructures -> RTable)
-> ConflictingRTableStructures -> RTable
forall a b. (a -> b) -> a -> b
$ String -> ConflictingRTableStructures
ConflictingRTableStructures String
"Cannot run: UnionAll, due to conflicting RTable structures."
i :: BinaryRTableOperation
i = BinaryRTableOperation
runIntersect
runIntersect ::
RTable
-> RTable
-> RTable
runIntersect :: BinaryRTableOperation
runIntersect RTable
rt1 RTable
rt2 =
if RTable -> Bool
isRTabEmpty RTable
rt1 Bool -> Bool -> Bool
|| RTable -> Bool
isRTabEmpty RTable
rt2
then
RTable
emptyRTable
else
if RTable -> RTable -> Bool
rtabsSameStructure RTable
rt1 RTable
rt2
then
(RTuple -> RTable -> RTable) -> BinaryRTableOperation
forall a b. (a -> b -> b) -> b -> Vector a -> b
V.foldr (RTuple -> RTable -> RTable
intsect) RTable
emptyRTable RTable
rt1
else
ConflictingRTableStructures -> RTable
forall a e. Exception e => e -> a
throw (ConflictingRTableStructures -> RTable)
-> ConflictingRTableStructures -> RTable
forall a b. (a -> b) -> a -> b
$ String -> ConflictingRTableStructures
ConflictingRTableStructures String
"Cannot run: Intersect, due to conflicting RTable structures."
where
intsect :: RTuple -> RTable -> RTable
intsect :: RTuple -> RTable -> RTable
intsect RTuple
tupLeft RTable
acc =
if RTuple -> RTable -> Bool
didYouFindIt RTuple
tupLeft RTable
rt2
then RTable -> RTuple -> RTable
forall a. Vector a -> a -> Vector a
V.snoc RTable
acc RTuple
tupLeft
else RTable
acc
d :: BinaryRTableOperation
d = BinaryRTableOperation
runDiff
runDiff ::
RTable
-> RTable
-> RTable
runDiff :: BinaryRTableOperation
runDiff RTable
rt1 RTable
rt2 =
if RTable -> Bool
isRTabEmpty RTable
rt1
then
RTable
emptyRTable
else
if RTable -> Bool
isRTabEmpty RTable
rt2
then
RTable
rt1
else
if RTable -> RTable -> Bool
rtabsSameStructure RTable
rt1 RTable
rt2
then
(RTuple -> RTable -> RTable) -> BinaryRTableOperation
forall a b. (a -> b -> b) -> b -> Vector a -> b
V.foldr (RTuple -> RTable -> RTable
diff) RTable
emptyRTable RTable
rt1
else
ConflictingRTableStructures -> RTable
forall a e. Exception e => e -> a
throw (ConflictingRTableStructures -> RTable)
-> ConflictingRTableStructures -> RTable
forall a b. (a -> b) -> a -> b
$ String -> ConflictingRTableStructures
ConflictingRTableStructures String
"Cannot run: Minus, due to conflicting RTable structures."
where
diff :: RTuple -> RTable -> RTable
diff :: RTuple -> RTable -> RTable
diff RTuple
tupLeft RTable
acc =
if RTuple -> RTable -> Bool
didYouFindIt RTuple
tupLeft RTable
rt2
then RTable
acc
else RTable -> RTuple -> RTable
forall a. Vector a -> a -> Vector a
V.snoc RTable
acc RTuple
tupLeft
didYouFindIt :: RTuple -> RTable -> Bool
didYouFindIt :: RTuple -> RTable -> Bool
didYouFindIt RTuple
searchTup RTable
tab =
(RTuple -> Bool -> Bool) -> Bool -> RTable -> Bool
forall a b. (a -> b -> b) -> b -> Vector a -> b
V.foldr (\RTuple
t Bool
acc -> (RJoinPredicate
areTheyEqual RTuple
searchTup RTuple
t) Bool -> Bool -> Bool
|| Bool
acc) Bool
False RTable
tab
areTheyEqual :: RTuple -> RTuple -> Bool
areTheyEqual :: RJoinPredicate
areTheyEqual RTuple
t1 RTuple
t2 =
(ColumnName -> RDataType -> Bool -> Bool) -> Bool -> RTuple -> Bool
forall k v a. (k -> v -> a -> a) -> a -> HashMap k v -> a
HM.foldrWithKey (ColumnName -> RDataType -> Bool -> Bool
accumulator) Bool
True RTuple
t1
where
accumulator :: ColumnName -> RDataType -> Bool -> Bool
accumulator :: ColumnName -> RDataType -> Bool -> Bool
accumulator ColumnName
colName RDataType
val Bool
acc =
case RDataType
val of
RDataType
Null ->
case (RTuple
t2RTuple -> ColumnName -> RDataType
<!>ColumnName
colName) of
RDataType
Null -> Bool
acc
RDataType
_ -> Bool
False
RDataType
_ -> case (RTuple
t2RTuple -> ColumnName -> RDataType
<!>ColumnName
colName) of
RDataType
Null -> Bool
False
RDataType
_ -> (RDataType
val RDataType -> RDataType -> Bool
forall a. Eq a => a -> a -> Bool
== RTuple
t2RTuple -> ColumnName -> RDataType
<!>ColumnName
colName) Bool -> Bool -> Bool
&& Bool
acc
rAgg :: [RAggOperation] -> RTable -> RTable
rAgg = [RAggOperation] -> RTable -> RTable
runAggregation
runAggregation ::
[RAggOperation]
-> RTable
-> RTable
runAggregation :: [RAggOperation] -> RTable -> RTable
runAggregation [] RTable
rtab = RTable
rtab
runAggregation [RAggOperation]
aggOps RTable
rtab =
if RTable -> Bool
isRTabEmpty RTable
rtab
then RTable
emptyRTable
else
RTuple -> RTable
createSingletonRTable ([RAggOperation] -> RTable -> RTuple
getResultRTuple [RAggOperation]
aggOps RTable
rtab)
where
getResultRTuple :: [RAggOperation] -> RTable -> RTuple
getResultRTuple :: [RAggOperation] -> RTable -> RTuple
getResultRTuple [] RTable
_ = RTuple
emptyRTuple
getResultRTuple (RAggOperation
agg:[RAggOperation]
aggs) RTable
rt =
let RAggOperation { sourceCol :: RAggOperation -> ColumnName
sourceCol = ColumnName
src, targetCol :: RAggOperation -> ColumnName
targetCol = ColumnName
trg, aggFunc :: RAggOperation -> RTable -> RTuple
aggFunc = RTable -> RTuple
aggf } = RAggOperation
agg
in ([RAggOperation] -> RTable -> RTuple
getResultRTuple [RAggOperation]
aggs RTable
rt) RTuple -> RTuple -> RTuple
forall k v.
(Eq k, Hashable k) =>
HashMap k v -> HashMap k v -> HashMap k v
`HM.union` (RTable -> RTuple
aggf RTable
rt)
rO :: [(ColumnName, OrderingSpec)] -> RTable -> RTable
rO = [(ColumnName, OrderingSpec)] -> RTable -> RTable
runOrderBy
runOrderBy ::
[(ColumnName, OrderingSpec)]
-> RTable
-> RTable
runOrderBy :: [(ColumnName, OrderingSpec)] -> RTable -> RTable
runOrderBy [(ColumnName, OrderingSpec)]
ordSpec RTable
rtab =
if RTable -> Bool
isRTabEmpty RTable
rtab
then RTable
emptyRTable
else
let unsortedRTupList :: [RTuple]
unsortedRTupList = RTable -> [RTuple]
rtableToList RTable
rtab
sortedRTupList :: [RTuple]
sortedRTupList = (RTuple -> RTuple -> Ordering) -> [RTuple] -> [RTuple]
forall a. (a -> a -> Ordering) -> [a] -> [a]
Data.List.sortBy (\RTuple
t1 RTuple
t2 -> [(ColumnName, OrderingSpec)] -> RTuple -> RTuple -> Ordering
compareTuples [(ColumnName, OrderingSpec)]
ordSpec RTuple
t1 RTuple
t2) [RTuple]
unsortedRTupList
in [RTuple] -> RTable
rtableFromList [RTuple]
sortedRTupList
where
compareTuples :: [(ColumnName, OrderingSpec)] -> RTuple -> RTuple -> Ordering
compareTuples :: [(ColumnName, OrderingSpec)] -> RTuple -> RTuple -> Ordering
compareTuples [] RTuple
t1 RTuple
t2 = Ordering
EQ
compareTuples ((ColumnName
col, OrderingSpec
colordspec) : [(ColumnName, OrderingSpec)]
rest) RTuple
t1 RTuple
t2 =
if RDataType -> RDataType -> RDataType
nvl (RTuple
t1 RTuple -> ColumnName -> RDataType
<!> ColumnName
col) (ColumnName -> RDataType
RText ColumnName
"I am Null baby!") RDataType -> RDataType -> Bool
forall a. Eq a => a -> a -> Bool
== RDataType -> RDataType -> RDataType
nvl (RTuple
t2 RTuple -> ColumnName -> RDataType
<!> ColumnName
col) (ColumnName -> RDataType
RText ColumnName
"I am Null baby!")
then [(ColumnName, OrderingSpec)] -> RTuple -> RTuple -> Ordering
compareTuples [(ColumnName, OrderingSpec)]
rest RTuple
t1 RTuple
t2
else
if RDataType -> Bool
isNull (RTuple
t1 RTuple -> ColumnName -> RDataType
<!> ColumnName
col)
then
case OrderingSpec
colordspec of
OrderingSpec
Asc -> Ordering
GT
OrderingSpec
Desc -> Ordering
LT
else
if RDataType -> Bool
isNull (RTuple
t2 RTuple -> ColumnName -> RDataType
<!> ColumnName
col)
then
case OrderingSpec
colordspec of
OrderingSpec
Asc -> Ordering
LT
OrderingSpec
Desc -> Ordering
GT
else
case RDataType -> RDataType -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (RTuple
t1 RTuple -> ColumnName -> RDataType
<!> ColumnName
col) (RTuple
t2 RTuple -> ColumnName -> RDataType
<!> ColumnName
col) of
Ordering
GT -> if OrderingSpec
colordspec OrderingSpec -> OrderingSpec -> Bool
forall a. Eq a => a -> a -> Bool
== OrderingSpec
Asc
then Ordering
GT else Ordering
LT
Ordering
LT -> if OrderingSpec
colordspec OrderingSpec -> OrderingSpec -> Bool
forall a. Eq a => a -> a -> Bool
== OrderingSpec
Asc
then Ordering
LT else Ordering
GT
rG :: RJoinPredicate
-> [RAggOperation] -> [ColumnName] -> RTable -> RTable
rG = RJoinPredicate
-> [RAggOperation] -> [ColumnName] -> RTable -> RTable
runGroupBy
groupNoAggList ::
RGroupPredicate
-> [ColumnName]
-> RTable
-> [RTable]
groupNoAggList :: RJoinPredicate -> [ColumnName] -> RTable -> [RTable]
groupNoAggList RJoinPredicate
gpred [ColumnName]
cols RTable
rtab =
if RTable -> Bool
isRTabEmpty RTable
rtab
then [RTable
emptyRTable]
else
let
listOfRTupSorted :: [RTuple]
listOfRTupSorted = RTable -> [RTuple]
rtableToList (RTable -> [RTuple]) -> RTable -> [RTuple]
forall a b. (a -> b) -> a -> b
$ [(ColumnName, OrderingSpec)] -> RTable -> RTable
runOrderBy ([ColumnName] -> [(ColumnName, OrderingSpec)]
createOrderingSpec [ColumnName]
cols) RTable
rtab
listOfRTupGroupLists :: [[RTuple]]
listOfRTupGroupLists = RJoinPredicate -> [RTuple] -> [[RTuple]]
forall a. (a -> a -> Bool) -> [a] -> [[a]]
Data.List.groupBy RJoinPredicate
gpred [RTuple]
listOfRTupSorted
listofGroupRtabs :: [RTable]
listofGroupRtabs = ([RTuple] -> RTable) -> [[RTuple]] -> [RTable]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map ([RTuple] -> RTable
rtableFromList) [[RTuple]]
listOfRTupGroupLists
in [RTable]
listofGroupRtabs
concatRTab :: [RTable] -> RTable
concatRTab :: [RTable] -> RTable
concatRTab [RTable]
rtabsl = BinaryRTableOperation -> [RTable] -> RTable
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
Data.List.foldr1 (BinaryRTableOperation
u) [RTable]
rtabsl
groupNoAgg ::
RGroupPredicate
-> [ColumnName]
-> RTable
-> RTable
groupNoAgg :: RJoinPredicate -> [ColumnName] -> RTable -> RTable
groupNoAgg RJoinPredicate
gpred [ColumnName]
cols RTable
rtab =
if RTable -> Bool
isRTabEmpty RTable
rtab
then RTable
emptyRTable
else
let
listofGroupRtabs :: [RTable]
listofGroupRtabs = RJoinPredicate -> [ColumnName] -> RTable -> [RTable]
groupNoAggList RJoinPredicate
gpred [ColumnName]
cols RTable
rtab
in [RTable] -> RTable
concatRTab [RTable]
listofGroupRtabs
runGroupBy ::
RGroupPredicate
-> [RAggOperation]
-> [ColumnName]
-> RTable
-> RTable
runGroupBy :: RJoinPredicate
-> [RAggOperation] -> [ColumnName] -> RTable -> RTable
runGroupBy RJoinPredicate
gpred [RAggOperation]
aggOps [ColumnName]
cols RTable
rtab =
if RTable -> Bool
isRTabEmpty RTable
rtab
then
RTable
emptyRTable
else
let
listofGroupRtabs :: [RTable]
listofGroupRtabs = RJoinPredicate -> [ColumnName] -> RTable -> [RTable]
groupNoAggList RJoinPredicate
gpred [ColumnName]
cols RTable
rtab
listOfGroupingColumnsRtabs :: [RTable]
listOfGroupingColumnsRtabs = (RTable -> RTable) -> [RTable] -> [RTable]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map ( (Int -> RTable -> RTable
limit Int
1) (RTable -> RTable) -> (RTable -> RTable) -> RTable -> RTable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([ColumnName] -> RTable -> RTable
p [ColumnName]
cols) ) [RTable]
listofGroupRtabs
listOfAggregatedRtabs :: [RTable]
listOfAggregatedRtabs = (RTable -> RTable) -> [RTable] -> [RTable]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map ([RAggOperation] -> RTable -> RTable
rAgg [RAggOperation]
aggOps) [RTable]
listofGroupRtabs
listOfFinalRtabs :: [RTable]
listOfFinalRtabs =
if [RAggOperation] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
Data.List.null [RAggOperation]
aggOps
then
[RTable]
listOfGroupingColumnsRtabs
else
BinaryRTableOperation -> [RTable] -> [RTable] -> [RTable]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
Data.List.zipWith (RJoinPredicate -> BinaryRTableOperation
iJ (\RTuple
t1 RTuple
t2 -> Bool
True)) [RTable]
listOfGroupingColumnsRtabs [RTable]
listOfAggregatedRtabs
in BinaryRTableOperation -> [RTable] -> RTable
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
Data.List.foldr1 (BinaryRTableOperation
u) [RTable]
listOfFinalRtabs
createOrderingSpec :: [ColumnName] -> [(ColumnName, OrderingSpec)]
createOrderingSpec :: [ColumnName] -> [(ColumnName, OrderingSpec)]
createOrderingSpec [ColumnName]
cols = [ColumnName] -> [OrderingSpec] -> [(ColumnName, OrderingSpec)]
forall a b. [a] -> [b] -> [(a, b)]
Data.List.zip [ColumnName]
cols (Int -> [OrderingSpec] -> [OrderingSpec]
forall a. Int -> [a] -> [a]
Data.List.take ([ColumnName] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length [ColumnName]
cols) ([OrderingSpec] -> [OrderingSpec])
-> [OrderingSpec] -> [OrderingSpec]
forall a b. (a -> b) -> a -> b
$ OrderingSpec -> [OrderingSpec]
forall a. a -> [a]
Data.List.repeat OrderingSpec
Asc)
rComb :: (RTable -> RTable) -> RTable -> RTable
rComb = (RTable -> RTable) -> RTable -> RTable
runCombinedROp
runCombinedROp ::
(RTable -> RTable)
-> RTable
-> RTable
runCombinedROp :: (RTable -> RTable) -> RTable -> RTable
runCombinedROp RTable -> RTable
f RTable
rtab = RTable -> RTable
f RTable
rtab
insertAppendRTab :: RTuple -> RTable -> RTable
insertAppendRTab :: RTuple -> RTable -> RTable
insertAppendRTab RTuple
rtup RTable
rtab =
if RTable -> Bool
isRTabEmpty RTable
rtab Bool -> Bool -> Bool
&& RTuple -> Bool
isRTupEmpty RTuple
rtup
then RTable
emptyRTable
else
if RTable -> Bool
isRTabEmpty RTable
rtab Bool -> Bool -> Bool
&& Bool -> Bool
not(RTuple -> Bool
isRTupEmpty RTuple
rtup)
then
RTuple -> RTable
createSingletonRTable RTuple
rtup
else
if Bool -> Bool
not(RTable -> Bool
isRTabEmpty RTable
rtab) Bool -> Bool -> Bool
&& RTuple -> Bool
isRTupEmpty RTuple
rtup
then RTable
rtab
else
if RTable -> RTable -> Bool
rtabsSameStructure (RTuple -> RTable
createSingletonRTable RTuple
rtup) RTable
rtab
then
RTable -> RTuple -> RTable
forall a. Vector a -> a -> Vector a
V.snoc RTable
rtab RTuple
rtup
else
ConflictingRTableStructures -> RTable
forall a e. Exception e => e -> a
throw (ConflictingRTableStructures -> RTable)
-> ConflictingRTableStructures -> RTable
forall a b. (a -> b) -> a -> b
$ String -> ConflictingRTableStructures
ConflictingRTableStructures String
"Cannot run: Insert Into Values (insertAppendRTab), due to conflicting RTable structures."
insertPrependRTab :: RTuple -> RTable -> RTable
insertPrependRTab :: RTuple -> RTable -> RTable
insertPrependRTab RTuple
rtup RTable
rtab =
if RTable -> Bool
isRTabEmpty RTable
rtab Bool -> Bool -> Bool
&& RTuple -> Bool
isRTupEmpty RTuple
rtup
then RTable
emptyRTable
else
if RTable -> Bool
isRTabEmpty RTable
rtab Bool -> Bool -> Bool
&& Bool -> Bool
not(RTuple -> Bool
isRTupEmpty RTuple
rtup)
then
RTuple -> RTable
createSingletonRTable RTuple
rtup
else
if Bool -> Bool
not(RTable -> Bool
isRTabEmpty RTable
rtab) Bool -> Bool -> Bool
&& RTuple -> Bool
isRTupEmpty RTuple
rtup
then RTable
rtab
else
if RTable -> RTable -> Bool
rtabsSameStructure (RTuple -> RTable
createSingletonRTable RTuple
rtup) RTable
rtab
then
RTuple -> RTable -> RTable
forall a. a -> Vector a -> Vector a
V.cons RTuple
rtup RTable
rtab
else
ConflictingRTableStructures -> RTable
forall a e. Exception e => e -> a
throw (ConflictingRTableStructures -> RTable)
-> ConflictingRTableStructures -> RTable
forall a b. (a -> b) -> a -> b
$ String -> ConflictingRTableStructures
ConflictingRTableStructures String
"Cannot run: insertPrependRTab, due to conflicting RTable structures."
insertRTabToRTab ::
RTable
-> RTable
-> RTable
insertRTabToRTab :: BinaryRTableOperation
insertRTabToRTab RTable
src RTable
trg =
if RTable -> Bool
isRTabEmpty RTable
src
then RTable
trg
else
if RTable -> Bool
isRTabEmpty RTable
trg
then RTable
src
else
if RTable -> RTable -> Bool
rtabsSameStructure RTable
src RTable
trg
then
BinaryRTableOperation
runUnionAll RTable
src RTable
trg
else
ConflictingRTableStructures -> RTable
forall a e. Exception e => e -> a
throw (ConflictingRTableStructures -> RTable)
-> ConflictingRTableStructures -> RTable
forall a b. (a -> b) -> a -> b
$ String -> ConflictingRTableStructures
ConflictingRTableStructures String
"Cannot run: Insert Into <TAB> RTuples, due to conflicting RTable structures."
upsertRTab ::
RTable
-> RUpsertPredicate
-> [ColumnName]
-> RPredicate
-> RTable
-> RTable
upsertRTab :: RTable
-> RUpsertPredicate
-> [ColumnName]
-> (RTuple -> Bool)
-> RTable
-> RTable
upsertRTab RTable
srcTab RUpsertPredicate
upsPred [ColumnName]
cols RTuple -> Bool
fpred RTable
trgTab =
if RTable -> Bool
isRTabEmpty RTable
srcTab
then RTable
trgTab
else
if RTable -> Bool
isRTabEmpty RTable
trgTab
then RTable
srcTab
else
if RTable -> RTable -> Bool
rtabsSameStructure RTable
srcTab RTable
trgTab
then
if Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ RTable -> Bool
isRTabEmpty (RTable -> Bool) -> RTable -> Bool
forall a b. (a -> b) -> a -> b
$
(RTuple -> Bool) -> RTable -> RTable
f (\RTuple
t -> RTuple
t RTuple -> ColumnName -> RDataType
<!> ColumnName
"numOfRows" RDataType -> RDataType -> Bool
forall a. Ord a => a -> a -> Bool
> RDataType
1) (RTable -> RTable) -> RTable -> RTable
forall a b. (a -> b) -> a -> b
$
RJoinPredicate
-> [RAggOperation] -> [ColumnName] -> RTable -> RTable
rG (\RTuple
t1 RTuple
t2 -> (ColumnName -> Bool -> Bool) -> Bool -> [ColumnName] -> Bool
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
Data.List.foldr (\ColumnName
col Bool
acc -> (RTuple
t1 RTuple -> ColumnName -> RDataType
<!> ColumnName
col RDataType -> RDataType -> Bool
forall a. Eq a => a -> a -> Bool
== RTuple
t2 RTuple -> ColumnName -> RDataType
<!> ColumnName
col) Bool -> Bool -> Bool
&& Bool
acc) Bool
True (RUpsertPredicate -> [ColumnName]
matchCols RUpsertPredicate
upsPred))
[ColumnName -> RAggOperation
raggCountStar ColumnName
"numOfRows"]
(RUpsertPredicate -> [ColumnName]
matchCols RUpsertPredicate
upsPred)
RTable
srcTab
then
UniquenessViolationInUpsert -> RTable
forall a e. Exception e => e -> a
throw (UniquenessViolationInUpsert -> RTable)
-> UniquenessViolationInUpsert -> RTable
forall a b. (a -> b) -> a -> b
$ String -> UniquenessViolationInUpsert
UniquenessViolationInUpsert String
"Cannot run: Upsert because the source RTable is not unique in the matching columns."
else
let
t1 :: RTable
t1 = let
tab :: RTable
tab = [ColumnName] -> RTable -> RTable
p ([ColumnName]
cols [ColumnName] -> [ColumnName] -> [ColumnName]
forall a. [a] -> [a] -> [a]
++ (RUpsertPredicate -> [ColumnName]
matchCols RUpsertPredicate
upsPred)) (RTable -> RTable) -> RTable -> RTable
forall a b. (a -> b) -> a -> b
$ RJoinPredicate -> BinaryRTableOperation
sJ (RUpsertPredicate -> RJoinPredicate
matchPred RUpsertPredicate
upsPred) RTable
srcTab ((RTuple -> Bool) -> RTable -> RTable
f RTuple -> Bool
fpred RTable
trgTab)
in [ColumnName] -> RTable -> RTable
p (RTable -> [ColumnName]
getColumnNamesFromRTab RTable
trgTab) (RTable -> RTable) -> RTable -> RTable
forall a b. (a -> b) -> a -> b
$ RJoinPredicate -> BinaryRTableOperation
iJ (RUpsertPredicate -> RJoinPredicate
matchPred RUpsertPredicate
upsPred) RTable
tab ((RTuple -> Bool) -> RTable -> RTable
f RTuple -> Bool
fpred RTable
trgTab)
t2 :: RTable
t2 = RJoinPredicate -> BinaryRTableOperation
aJ (RUpsertPredicate -> RJoinPredicate
matchPred RUpsertPredicate
upsPred) ((RTuple -> Bool) -> RTable -> RTable
f RTuple -> Bool
fpred RTable
trgTab) RTable
srcTab
t3 :: RTable
t3 = (RTuple -> Bool) -> RTable -> RTable
f (Bool -> Bool
not (Bool -> Bool) -> (RTuple -> Bool) -> RTuple -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RTuple -> Bool
fpred) RTable
trgTab
s1 :: RTable
s1 = RJoinPredicate -> BinaryRTableOperation
aJ (RUpsertPredicate -> RJoinPredicate
matchPred RUpsertPredicate
upsPred) RTable
srcTab RTable
trgTab
in BinaryRTableOperation
insertRTabToRTab RTable
s1 (RTable -> RTable) -> RTable -> RTable
forall a b. (a -> b) -> a -> b
$ BinaryRTableOperation
u RTable
t1 (RTable -> RTable) -> RTable -> RTable
forall a b. (a -> b) -> a -> b
$ BinaryRTableOperation
u RTable
t2 RTable
t3
else
ConflictingRTableStructures -> RTable
forall a e. Exception e => e -> a
throw (ConflictingRTableStructures -> RTable)
-> ConflictingRTableStructures -> RTable
forall a b. (a -> b) -> a -> b
$ String -> ConflictingRTableStructures
ConflictingRTableStructures String
"Cannot run: Upsert due to conflicting RTable structures."
rtabsSameStructure :: RTable -> RTable -> Bool
rtabsSameStructure :: RTable -> RTable -> Bool
rtabsSameStructure RTable
rtab1 RTable
rtab2 =
let
cinfo_list1 :: [ColumnInfo]
cinfo_list1 = RTable -> [ColumnInfo]
getColumnInfoFromRTab RTable
rtab1
cinfo_list2 :: [ColumnInfo]
cinfo_list2 = RTable -> [ColumnInfo]
getColumnInfoFromRTab RTable
rtab2
cinfo_list1_new :: [ColumnInfo]
cinfo_list1_new = (ColumnInfo -> ColumnInfo) -> [ColumnInfo] -> [ColumnInfo]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map ([ColumnInfo] -> ColumnInfo -> ColumnInfo
normalizeColInfoList [ColumnInfo]
cinfo_list2) [ColumnInfo]
cinfo_list1
cinfo_list2_new :: [ColumnInfo]
cinfo_list2_new = (ColumnInfo -> ColumnInfo) -> [ColumnInfo] -> [ColumnInfo]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map ([ColumnInfo] -> ColumnInfo -> ColumnInfo
normalizeColInfoList [ColumnInfo]
cinfo_list1) [ColumnInfo]
cinfo_list2
in
( ([ColumnInfo]
cinfo_list1_new [ColumnInfo] -> [ColumnInfo] -> [ColumnInfo]
forall a. Eq a => [a] -> [a] -> [a]
\\ [ColumnInfo]
cinfo_list2_new) [ColumnInfo] -> [ColumnInfo] -> Bool
forall a. Eq a => a -> a -> Bool
== [] )
Bool -> Bool -> Bool
&&
( ([ColumnInfo]
cinfo_list2_new [ColumnInfo] -> [ColumnInfo] -> [ColumnInfo]
forall a. Eq a => [a] -> [a] -> [a]
\\ [ColumnInfo]
cinfo_list1_new) [ColumnInfo] -> [ColumnInfo] -> Bool
forall a. Eq a => a -> a -> Bool
== [] )
where
normalizeColInfoList :: [ColumnInfo] -> ColumnInfo -> ColumnInfo
normalizeColInfoList :: [ColumnInfo] -> ColumnInfo -> ColumnInfo
normalizeColInfoList [ColumnInfo]
cinfo_list2 ColumnInfo
ci1 =
case (ColumnInfo -> Bool) -> [ColumnInfo] -> Maybe ColumnInfo
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
Data.List.find (\ColumnInfo
ci2 -> (ColumnInfo -> ColumnName
name ColumnInfo
ci1) ColumnName -> ColumnName -> Bool
forall a. Eq a => a -> a -> Bool
== (ColumnInfo -> ColumnName
name ColumnInfo
ci2)) [ColumnInfo]
cinfo_list2 of
Maybe ColumnInfo
Nothing -> ColumnInfo
ci1
Just ColumnInfo
ci ->
if (ColumnInfo -> ColumnDType
dtype ColumnInfo
ci1) ColumnDType -> ColumnDType -> Bool
forall a. Eq a => a -> a -> Bool
== ColumnDType
UknownType
then
ColumnInfo :: ColumnName -> ColumnDType -> ColumnInfo
ColumnInfo {name :: ColumnName
name = (ColumnInfo -> ColumnName
name ColumnInfo
ci1), dtype :: ColumnDType
dtype = (ColumnInfo -> ColumnDType
dtype ColumnInfo
ci)}
else
ColumnInfo
ci1
rtuplesSameStructure :: RTuple -> RTuple -> Bool
rtuplesSameStructure :: RJoinPredicate
rtuplesSameStructure RTuple
t1 RTuple
t2 =
let
cinfo_list1 :: [ColumnInfo]
cinfo_list1 = RTuple -> [ColumnInfo]
getColumnInfoFromRTuple RTuple
t1
cinfo_list2 :: [ColumnInfo]
cinfo_list2 = RTuple -> [ColumnInfo]
getColumnInfoFromRTuple RTuple
t2
in
( ([ColumnInfo]
cinfo_list1 [ColumnInfo] -> [ColumnInfo] -> [ColumnInfo]
forall a. Eq a => [a] -> [a] -> [a]
\\ [ColumnInfo]
cinfo_list2) [ColumnInfo] -> [ColumnInfo] -> Bool
forall a. Eq a => a -> a -> Bool
== [] )
Bool -> Bool -> Bool
&&
( ([ColumnInfo]
cinfo_list2 [ColumnInfo] -> [ColumnInfo] -> [ColumnInfo]
forall a. Eq a => [a] -> [a] -> [a]
\\ [ColumnInfo]
cinfo_list1) [ColumnInfo] -> [ColumnInfo] -> Bool
forall a. Eq a => a -> a -> Bool
== [] )
deleteRTab ::
RPredicate
-> RTable
-> RTable
deleteRTab :: (RTuple -> Bool) -> RTable -> RTable
deleteRTab RTuple -> Bool
rpred RTable
rtab = (RTuple -> Bool) -> RTable -> RTable
f (Bool -> Bool
not (Bool -> Bool) -> (RTuple -> Bool) -> RTuple -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RTuple -> Bool
rpred) RTable
rtab
updateRTab ::
[(ColumnName, RDataType)]
-> RPredicate
-> RTable
-> RTable
updateRTab :: [(ColumnName, RDataType)] -> (RTuple -> Bool) -> RTable -> RTable
updateRTab [] RTuple -> Bool
_ RTable
inputRtab = RTable
inputRtab
updateRTab ((ColumnName
colName, RDataType
newVal) : [(ColumnName, RDataType)]
rest) RTuple -> Bool
rpred RTable
inputRtab =
if RTable -> Bool
isRTabEmpty RTable
inputRtab
then RTable
emptyRTable
else
let
tabA :: RTable
tabA = (RTuple -> RTuple) -> RTable -> RTable
rtabMap (ColumnName -> RDataType -> RTuple -> RTuple
updateRTuple ColumnName
colName RDataType
newVal) ((RTuple -> Bool) -> RTable -> RTable
f RTuple -> Bool
rpred RTable
inputRtab)
tabB :: RTable
tabB = (RTuple -> Bool) -> RTable -> RTable
f (Bool -> Bool
not (Bool -> Bool) -> (RTuple -> Bool) -> RTuple -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RTuple -> Bool
rpred) RTable
inputRtab
in [(ColumnName, RDataType)] -> (RTuple -> Bool) -> RTable -> RTable
updateRTab [(ColumnName, RDataType)]
rest RTuple -> Bool
rpred (BinaryRTableOperation
u RTable
tabA RTable
tabB)
updateRTuple ::
ColumnName
-> RDataType
-> RTuple
-> RTuple
updateRTuple :: ColumnName -> RDataType -> RTuple -> RTuple
updateRTuple ColumnName
cname RDataType
newVal RTuple
tupsrc =
case ColumnName -> RTuple -> Maybe RDataType
rtupLookup ColumnName
cname RTuple
tupsrc of
Maybe RDataType
Nothing -> ColumnDoesNotExist -> RTuple
forall a e. Exception e => e -> a
throw (ColumnDoesNotExist -> RTuple) -> ColumnDoesNotExist -> RTuple
forall a b. (a -> b) -> a -> b
$ ColumnName -> ColumnDoesNotExist
ColumnDoesNotExist ColumnName
cname
Maybe RDataType
_ -> ColumnName -> RDataType -> RTuple -> RTuple
forall k v.
(Eq k, Hashable k) =>
k -> v -> HashMap k v -> HashMap k v
HM.insert ColumnName
cname RDataType
newVal RTuple
tupsrc
upsertRTuple ::
ColumnName
-> RDataType
-> RTuple
-> RTuple
upsertRTuple :: ColumnName -> RDataType -> RTuple -> RTuple
upsertRTuple ColumnName
cname RDataType
newVal RTuple
tupsrc = ColumnName -> RDataType -> RTuple -> RTuple
forall k v.
(Eq k, Hashable k) =>
k -> v -> HashMap k v -> HashMap k v
HM.insert ColumnName
cname RDataType
newVal RTuple
tupsrc
data RTupleFormat = RTupleFormat {
RTupleFormat -> [ColumnName]
colSelectList :: [ColumnName]
,RTupleFormat -> ColFormatMap
colFormatMap :: ColFormatMap
} deriving (RTupleFormat -> RTupleFormat -> Bool
(RTupleFormat -> RTupleFormat -> Bool)
-> (RTupleFormat -> RTupleFormat -> Bool) -> Eq RTupleFormat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RTupleFormat -> RTupleFormat -> Bool
$c/= :: RTupleFormat -> RTupleFormat -> Bool
== :: RTupleFormat -> RTupleFormat -> Bool
$c== :: RTupleFormat -> RTupleFormat -> Bool
Eq, Int -> RTupleFormat -> ShowS
[RTupleFormat] -> ShowS
RTupleFormat -> String
(Int -> RTupleFormat -> ShowS)
-> (RTupleFormat -> String)
-> ([RTupleFormat] -> ShowS)
-> Show RTupleFormat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RTupleFormat] -> ShowS
$cshowList :: [RTupleFormat] -> ShowS
show :: RTupleFormat -> String
$cshow :: RTupleFormat -> String
showsPrec :: Int -> RTupleFormat -> ShowS
$cshowsPrec :: Int -> RTupleFormat -> ShowS
Show)
type ColFormatMap = HM.HashMap ColumnName FormatSpecifier
genDefaultColFormatMap :: ColFormatMap
genDefaultColFormatMap :: ColFormatMap
genDefaultColFormatMap = ColFormatMap
forall k v. HashMap k v
HM.empty
genColFormatMap ::
[(ColumnName, FormatSpecifier)]
-> ColFormatMap
genColFormatMap :: [(ColumnName, FormatSpecifier)] -> ColFormatMap
genColFormatMap [(ColumnName, FormatSpecifier)]
fs = [(ColumnName, FormatSpecifier)] -> ColFormatMap
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HM.fromList [(ColumnName, FormatSpecifier)]
fs
data FormatSpecifier = DefaultFormat | Format String deriving (FormatSpecifier -> FormatSpecifier -> Bool
(FormatSpecifier -> FormatSpecifier -> Bool)
-> (FormatSpecifier -> FormatSpecifier -> Bool)
-> Eq FormatSpecifier
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FormatSpecifier -> FormatSpecifier -> Bool
$c/= :: FormatSpecifier -> FormatSpecifier -> Bool
== :: FormatSpecifier -> FormatSpecifier -> Bool
$c== :: FormatSpecifier -> FormatSpecifier -> Bool
Eq, Int -> FormatSpecifier -> ShowS
[FormatSpecifier] -> ShowS
FormatSpecifier -> String
(Int -> FormatSpecifier -> ShowS)
-> (FormatSpecifier -> String)
-> ([FormatSpecifier] -> ShowS)
-> Show FormatSpecifier
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FormatSpecifier] -> ShowS
$cshowList :: [FormatSpecifier] -> ShowS
show :: FormatSpecifier -> String
$cshow :: FormatSpecifier -> String
showsPrec :: Int -> FormatSpecifier -> ShowS
$cshowsPrec :: Int -> FormatSpecifier -> ShowS
Show)
genRTupleFormat ::
[ColumnName]
-> ColFormatMap
-> RTupleFormat
genRTupleFormat :: [ColumnName] -> ColFormatMap -> RTupleFormat
genRTupleFormat [ColumnName]
colNames ColFormatMap
colfMap = RTupleFormat :: [ColumnName] -> ColFormatMap -> RTupleFormat
RTupleFormat { colSelectList :: [ColumnName]
colSelectList = [ColumnName]
colNames, colFormatMap :: ColFormatMap
colFormatMap = ColFormatMap
colfMap}
genRTupleFormatDefault :: RTupleFormat
genRTupleFormatDefault :: RTupleFormat
genRTupleFormatDefault = RTupleFormat :: [ColumnName] -> ColFormatMap -> RTupleFormat
RTupleFormat { colSelectList :: [ColumnName]
colSelectList = [], colFormatMap :: ColFormatMap
colFormatMap = ColFormatMap
genDefaultColFormatMap }
eitherPrintfRTable :: Exception e => (RTupleFormat -> RTable -> IO()) -> RTupleFormat -> RTable -> IO (Either e ())
eitherPrintfRTable :: (RTupleFormat -> RTable -> IO ())
-> RTupleFormat -> RTable -> IO (Either e ())
eitherPrintfRTable RTupleFormat -> RTable -> IO ()
printFunc RTupleFormat
fmt RTable
rtab = IO () -> IO (Either e ())
forall e a. Exception e => IO a -> IO (Either e a)
try (IO () -> IO (Either e ())) -> IO () -> IO (Either e ())
forall a b. (a -> b) -> a -> b
$ RTupleFormat -> RTable -> IO ()
printFunc RTupleFormat
fmt RTable
rtab
printfRTable :: RTupleFormat -> RTable -> IO()
printfRTable :: RTupleFormat -> RTable -> IO ()
printfRTable RTupleFormat
rtupFmt RTable
rtab =
if RTable -> Bool
isRTabEmpty RTable
rtab
then
do
String -> IO ()
putStrLn String
"-------------------------------------------"
String -> IO ()
putStrLn String
" 0 rows returned"
String -> IO ()
putStrLn String
"-------------------------------------------"
else
do
let listOfLengths :: [Int]
listOfLengths = RTupleFormat -> RTable -> [Int]
getMaxLengthPerColumnFmt RTupleFormat
rtupFmt RTable
rtab
RTupleFormat -> [Int] -> Char -> RTable -> IO ()
printContLineFmt RTupleFormat
rtupFmt [Int]
listOfLengths Char
'-' RTable
rtab
RTupleFormat -> [Int] -> RTable -> IO ()
printRTableHeaderFmt RTupleFormat
rtupFmt [Int]
listOfLengths RTable
rtab
RTupleFormat -> [Int] -> [RTuple] -> IO ()
printRTabBodyFmt RTupleFormat
rtupFmt [Int]
listOfLengths ([RTuple] -> IO ()) -> [RTuple] -> IO ()
forall a b. (a -> b) -> a -> b
$ RTable -> [RTuple]
forall a. Vector a -> [a]
V.toList RTable
rtab
let numrows :: Int
numrows = RTable -> Int
forall a. Vector a -> Int
V.length RTable
rtab
if Int
numrows Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1
then
String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ String
"\n"String -> ShowS
forall a. [a] -> [a] -> [a]
++ (Int -> String
forall a. Show a => a -> String
show (Int -> String) -> Int -> String
forall a b. (a -> b) -> a -> b
$ Int
numrows) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" row returned"
else
String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ String
"\n"String -> ShowS
forall a. [a] -> [a] -> [a]
++ (Int -> String
forall a. Show a => a -> String
show (Int -> String) -> Int -> String
forall a b. (a -> b) -> a -> b
$ Int
numrows) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" rows returned"
RTupleFormat -> [Int] -> Char -> RTable -> IO ()
printContLineFmt RTupleFormat
rtupFmt [Int]
listOfLengths Char
'-' RTable
rtab
where
printRTabBodyFmt :: RTupleFormat -> [Int] -> [RTuple] -> IO()
printRTabBodyFmt :: RTupleFormat -> [Int] -> [RTuple] -> IO ()
printRTabBodyFmt RTupleFormat
_ [Int]
_ [] = String -> IO ()
putStrLn String
""
printRTabBodyFmt RTupleFormat
rtupf [Int]
ws (RTuple
rtup : [RTuple]
rest) = do
RTupleFormat -> [Int] -> RTuple -> IO ()
printRTupleFmt RTupleFormat
rtupf [Int]
ws RTuple
rtup
RTupleFormat -> [Int] -> [RTuple] -> IO ()
printRTabBodyFmt RTupleFormat
rtupf [Int]
ws [RTuple]
rest
eitherPrintRTable :: Exception e => (RTable -> IO ()) -> RTable -> IO (Either e ())
eitherPrintRTable :: (RTable -> IO ()) -> RTable -> IO (Either e ())
eitherPrintRTable RTable -> IO ()
printFunc RTable
rtab = IO () -> IO (Either e ())
forall e a. Exception e => IO a -> IO (Either e a)
try (IO () -> IO (Either e ())) -> IO () -> IO (Either e ())
forall a b. (a -> b) -> a -> b
$ RTable -> IO ()
printFunc RTable
rtab
printRTable ::
RTable
-> IO ()
printRTable :: RTable -> IO ()
printRTable RTable
rtab =
if RTable -> Bool
isRTabEmpty RTable
rtab
then
do
String -> IO ()
putStrLn String
"-------------------------------------------"
String -> IO ()
putStrLn String
" 0 rows returned"
String -> IO ()
putStrLn String
"-------------------------------------------"
else
do
let listOfLengths :: [Int]
listOfLengths = RTable -> [Int]
getMaxLengthPerColumn RTable
rtab
[Int] -> Char -> RTable -> IO ()
printContLine [Int]
listOfLengths Char
'-' RTable
rtab
[Int] -> RTable -> IO ()
printRTableHeader [Int]
listOfLengths RTable
rtab
[Int] -> [RTuple] -> IO ()
printRTabBody [Int]
listOfLengths ([RTuple] -> IO ()) -> [RTuple] -> IO ()
forall a b. (a -> b) -> a -> b
$ RTable -> [RTuple]
forall a. Vector a -> [a]
V.toList RTable
rtab
let numrows :: Int
numrows = RTable -> Int
forall a. Vector a -> Int
V.length RTable
rtab
if Int
numrows Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1
then
String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ String
"\n"String -> ShowS
forall a. [a] -> [a] -> [a]
++ (Int -> String
forall a. Show a => a -> String
show (Int -> String) -> Int -> String
forall a b. (a -> b) -> a -> b
$ Int
numrows) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" row returned"
else
String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ String
"\n"String -> ShowS
forall a. [a] -> [a] -> [a]
++ (Int -> String
forall a. Show a => a -> String
show (Int -> String) -> Int -> String
forall a b. (a -> b) -> a -> b
$ Int
numrows) String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" rows returned"
[Int] -> Char -> RTable -> IO ()
printContLine [Int]
listOfLengths Char
'-' RTable
rtab
where
printRTabBody :: [Int] -> [RTuple] -> IO()
printRTabBody :: [Int] -> [RTuple] -> IO ()
printRTabBody [Int]
_ [] = String -> IO ()
putStrLn String
""
printRTabBody [Int]
ws (RTuple
rtup : [RTuple]
rest) = do
[Int] -> RTuple -> IO ()
printRTuple [Int]
ws RTuple
rtup
[Int] -> [RTuple] -> IO ()
printRTabBody [Int]
ws [RTuple]
rest
getMaxLengthPerColumnFmt :: RTupleFormat -> RTable -> [Int]
getMaxLengthPerColumnFmt :: RTupleFormat -> RTable -> [Int]
getMaxLengthPerColumnFmt RTupleFormat
rtupFmt RTable
rtab =
let
lengthRTab :: RTable
lengthRTab = do
RTuple
rtup <- RTable
rtab
let ls :: [(ColumnName, RDataType)]
ls = ((ColumnName, RDataType) -> (ColumnName, RDataType))
-> [(ColumnName, RDataType)] -> [(ColumnName, RDataType)]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\(ColumnName
c, RDataType
v) -> (ColumnName
c, Integer -> RDataType
RInt (Integer -> RDataType) -> Integer -> RDataType
forall a b. (a -> b) -> a -> b
$ Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Integer) -> Int -> Integer
forall a b. (a -> b) -> a -> b
$ String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length (String -> Int) -> (RDataType -> String) -> RDataType -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDataType -> String
rdataTypeToString (RDataType -> Int) -> RDataType -> Int
forall a b. (a -> b) -> a -> b
$ RDataType
v) ) (RTuple -> [(ColumnName, RDataType)]
rtupleToList RTuple
rtup)
headerLengths :: [(ColumnName, RDataType)]
headerLengths = [ColumnName] -> [RDataType] -> [(ColumnName, RDataType)]
forall a b. [a] -> [b] -> [(a, b)]
Data.List.zip (RTable -> [ColumnName]
getColumnNamesFromRTab RTable
rtab) ((ColumnName -> RDataType) -> [ColumnName] -> [RDataType]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\ColumnName
c -> Integer -> RDataType
RInt (Integer -> RDataType) -> Integer -> RDataType
forall a b. (a -> b) -> a -> b
$ Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Integer) -> Int -> Integer
forall a b. (a -> b) -> a -> b
$ String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length (ColumnName -> String
T.unpack ColumnName
c)) (RTable -> [ColumnName]
getColumnNamesFromRTab RTable
rtab))
(RTuple -> RTable
forall (m :: * -> *) a. Monad m => a -> m a
return (RTuple -> RTable) -> RTuple -> RTable
forall a b. (a -> b) -> a -> b
$ [(ColumnName, RDataType)] -> RTuple
createRTuple [(ColumnName, RDataType)]
ls) BinaryRTableOperation
forall a. Vector a -> Vector a -> Vector a
V.++ (RTuple -> RTable
forall (m :: * -> *) a. Monad m => a -> m a
return (RTuple -> RTable) -> RTuple -> RTable
forall a b. (a -> b) -> a -> b
$ [(ColumnName, RDataType)] -> RTuple
createRTuple [(ColumnName, RDataType)]
headerLengths)
resultRTab :: RTable
resultRTab = RTable -> RTable
findMaxLengthperColumn RTable
lengthRTab
where
findMaxLengthperColumn :: RTable -> RTable
findMaxLengthperColumn :: RTable -> RTable
findMaxLengthperColumn RTable
rt =
let colNames :: [ColumnName]
colNames = (RTable -> [ColumnName]
getColumnNamesFromRTab RTable
rt)
aggOpsList :: [RAggOperation]
aggOpsList = (ColumnName -> RAggOperation) -> [ColumnName] -> [RAggOperation]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\ColumnName
c -> ColumnName -> ColumnName -> RAggOperation
raggMax ColumnName
c ColumnName
c) [ColumnName]
colNames
in [RAggOperation] -> RTable -> RTable
runAggregation [RAggOperation]
aggOpsList RTable
rt
resultRTuple :: RTuple
resultRTuple = RTable -> RTuple
headRTup RTable
resultRTab
in
if RTupleFormat
rtupFmt RTupleFormat -> RTupleFormat -> Bool
forall a. Eq a => a -> a -> Bool
/= RTupleFormat
genRTupleFormatDefault
then
(RDataType -> Int) -> [RDataType] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\(RInt Integer
i) -> Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
i) ([RDataType] -> [Int]) -> [RDataType] -> [Int]
forall a b. (a -> b) -> a -> b
$
(ColumnName -> RDataType) -> [ColumnName] -> [RDataType]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\ColumnName
colname -> RTuple
resultRTuple RTuple -> ColumnName -> RDataType
<!> ColumnName
colname) ([ColumnName] -> [RDataType]) -> [ColumnName] -> [RDataType]
forall a b. (a -> b) -> a -> b
$ RTupleFormat -> [ColumnName]
colSelectList RTupleFormat
rtupFmt
else
((ColumnName, RDataType) -> Int)
-> [(ColumnName, RDataType)] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\(ColumnName
colname, RInt Integer
i) -> Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
i) (RTuple -> [(ColumnName, RDataType)]
rtupleToList RTuple
resultRTuple)
getMaxLengthPerColumn :: RTable -> [Int]
getMaxLengthPerColumn :: RTable -> [Int]
getMaxLengthPerColumn RTable
rtab =
let
lengthRTab :: RTable
lengthRTab = do
RTuple
rtup <- RTable
rtab
let ls :: [(ColumnName, RDataType)]
ls = ((ColumnName, RDataType) -> (ColumnName, RDataType))
-> [(ColumnName, RDataType)] -> [(ColumnName, RDataType)]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\(ColumnName
c, RDataType
v) -> (ColumnName
c, Integer -> RDataType
RInt (Integer -> RDataType) -> Integer -> RDataType
forall a b. (a -> b) -> a -> b
$ Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Integer) -> Int -> Integer
forall a b. (a -> b) -> a -> b
$ String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length (String -> Int) -> (RDataType -> String) -> RDataType -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDataType -> String
rdataTypeToString (RDataType -> Int) -> RDataType -> Int
forall a b. (a -> b) -> a -> b
$ RDataType
v) ) (RTuple -> [(ColumnName, RDataType)]
rtupleToList RTuple
rtup)
headerLengths :: [(ColumnName, RDataType)]
headerLengths = [ColumnName] -> [RDataType] -> [(ColumnName, RDataType)]
forall a b. [a] -> [b] -> [(a, b)]
Data.List.zip (RTable -> [ColumnName]
getColumnNamesFromRTab RTable
rtab) ((ColumnName -> RDataType) -> [ColumnName] -> [RDataType]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\ColumnName
c -> Integer -> RDataType
RInt (Integer -> RDataType) -> Integer -> RDataType
forall a b. (a -> b) -> a -> b
$ Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Integer) -> Int -> Integer
forall a b. (a -> b) -> a -> b
$ String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length (ColumnName -> String
T.unpack ColumnName
c)) (RTable -> [ColumnName]
getColumnNamesFromRTab RTable
rtab))
(RTuple -> RTable
forall (m :: * -> *) a. Monad m => a -> m a
return (RTuple -> RTable) -> RTuple -> RTable
forall a b. (a -> b) -> a -> b
$ [(ColumnName, RDataType)] -> RTuple
createRTuple [(ColumnName, RDataType)]
ls) BinaryRTableOperation
forall a. Vector a -> Vector a -> Vector a
V.++ (RTuple -> RTable
forall (m :: * -> *) a. Monad m => a -> m a
return (RTuple -> RTable) -> RTuple -> RTable
forall a b. (a -> b) -> a -> b
$ [(ColumnName, RDataType)] -> RTuple
createRTuple [(ColumnName, RDataType)]
headerLengths)
resultRTab :: RTable
resultRTab = RTable -> RTable
findMaxLengthperColumn RTable
lengthRTab
where
findMaxLengthperColumn :: RTable -> RTable
findMaxLengthperColumn :: RTable -> RTable
findMaxLengthperColumn RTable
rt =
let colNames :: [ColumnName]
colNames = (RTable -> [ColumnName]
getColumnNamesFromRTab RTable
rt)
aggOpsList :: [RAggOperation]
aggOpsList = (ColumnName -> RAggOperation) -> [ColumnName] -> [RAggOperation]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\ColumnName
c -> ColumnName -> ColumnName -> RAggOperation
raggMax ColumnName
c ColumnName
c) [ColumnName]
colNames
in [RAggOperation] -> RTable -> RTable
runAggregation [RAggOperation]
aggOpsList RTable
rt
resultRTuple :: RTuple
resultRTuple = RTable -> RTuple
headRTup RTable
resultRTab
in
((ColumnName, RDataType) -> Int)
-> [(ColumnName, RDataType)] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\(ColumnName
colname, RInt Integer
i) -> Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
i) (RTuple -> [(ColumnName, RDataType)]
rtupleToList RTuple
resultRTuple)
spaceSeparatorWidth :: Int
spaceSeparatorWidth :: Int
spaceSeparatorWidth = Int
5
addSpace ::
Int
-> String
-> String
addSpace :: Int -> ShowS
addSpace Int
i String
s = String
s String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> ShowS
forall a. Int -> [a] -> [a]
Data.List.take Int
i (Char -> String
forall a. a -> [a]
repeat Char
' ')
addCharacter ::
Int
-> Char
-> String
-> String
addCharacter :: Int -> Char -> ShowS
addCharacter Int
i Char
c String
s = String
s String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> ShowS
forall a. Int -> [a] -> [a]
Data.List.take Int
i (Char -> String
forall a. a -> [a]
repeat Char
c)
printContLineFmt ::
RTupleFormat
-> [Int]
-> Char
-> RTable
-> IO ()
printContLineFmt :: RTupleFormat -> [Int] -> Char -> RTable -> IO ()
printContLineFmt RTupleFormat
rtupFmt [Int]
widths Char
ch RTable
rtab = do
let listOfColNames :: [ColumnName]
listOfColNames = if RTupleFormat
rtupFmt RTupleFormat -> RTupleFormat -> Bool
forall a. Eq a => a -> a -> Bool
/= RTupleFormat
genRTupleFormatDefault
then
RTupleFormat -> [ColumnName]
colSelectList RTupleFormat
rtupFmt
else
RTable -> [ColumnName]
getColumnNamesFromRTab RTable
rtab
listOfLinesCont :: [String]
listOfLinesCont = (ColumnName -> String) -> [ColumnName] -> [String]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\ColumnName
c -> Int -> ShowS
forall a. Int -> [a] -> [a]
Data.List.take (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length (ColumnName -> String
T.unpack ColumnName
c)) (Char -> String
forall a. a -> [a]
repeat Char
ch)) [ColumnName]
listOfColNames
formattedLinesCont :: [String]
formattedLinesCont = ((Int, String) -> String) -> [(Int, String)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\(Int
w,String
l) -> Int -> Char -> ShowS
addCharacter (Int
w Int -> Int -> Int
forall a. Num a => a -> a -> a
- (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length String
l) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
spaceSeparatorWidth) Char
ch String
l) ([Int] -> [String] -> [(Int, String)]
forall a b. [a] -> [b] -> [(a, b)]
Data.List.zip [Int]
widths [String]
listOfLinesCont)
formattedRowOfLinesCont :: String
formattedRowOfLinesCont = (String -> ShowS) -> String -> [String] -> String
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
Data.List.foldr (\String
line String
accum -> String
line String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
accum) String
"" [String]
formattedLinesCont
String -> IO ()
putStrLn String
formattedRowOfLinesCont
printContLine ::
[Int]
-> Char
-> RTable
-> IO ()
printContLine :: [Int] -> Char -> RTable -> IO ()
printContLine [Int]
widths Char
ch RTable
rtab = do
let listOfColNames :: [ColumnName]
listOfColNames = RTable -> [ColumnName]
getColumnNamesFromRTab RTable
rtab
listOfLinesCont :: [String]
listOfLinesCont = (ColumnName -> String) -> [ColumnName] -> [String]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\ColumnName
c -> Int -> ShowS
forall a. Int -> [a] -> [a]
Data.List.take (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length (ColumnName -> String
T.unpack ColumnName
c)) (Char -> String
forall a. a -> [a]
repeat Char
ch)) [ColumnName]
listOfColNames
formattedLinesCont :: [String]
formattedLinesCont = ((Int, String) -> String) -> [(Int, String)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\(Int
w,String
l) -> Int -> Char -> ShowS
addCharacter (Int
w Int -> Int -> Int
forall a. Num a => a -> a -> a
- (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length String
l) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
spaceSeparatorWidth) Char
ch String
l) ([Int] -> [String] -> [(Int, String)]
forall a b. [a] -> [b] -> [(a, b)]
Data.List.zip [Int]
widths [String]
listOfLinesCont)
formattedRowOfLinesCont :: String
formattedRowOfLinesCont = (String -> ShowS) -> String -> [String] -> String
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
Data.List.foldr (\String
line String
accum -> String
line String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
accum) String
"" [String]
formattedLinesCont
String -> IO ()
putStrLn String
formattedRowOfLinesCont
printRTableHeaderFmt ::
RTupleFormat
-> [Int]
-> RTable
-> IO ()
RTupleFormat
rtupFmt [Int]
widths RTable
rtab = do
let listOfColNames :: [ColumnName]
listOfColNames = if RTupleFormat
rtupFmt RTupleFormat -> RTupleFormat -> Bool
forall a. Eq a => a -> a -> Bool
/= RTupleFormat
genRTupleFormatDefault then RTupleFormat -> [ColumnName]
colSelectList RTupleFormat
rtupFmt else RTable -> [ColumnName]
getColumnNamesFromRTab RTable
rtab
formattedList :: [String]
formattedList = ((Int, ColumnName) -> String) -> [(Int, ColumnName)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\(Int
w,ColumnName
c) -> Int -> ShowS
addSpace (Int
w Int -> Int -> Int
forall a. Num a => a -> a -> a
- (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length (ColumnName -> String
T.unpack ColumnName
c)) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
spaceSeparatorWidth) (ColumnName -> String
T.unpack ColumnName
c)) ([Int] -> [ColumnName] -> [(Int, ColumnName)]
forall a b. [a] -> [b] -> [(a, b)]
Data.List.zip [Int]
widths [ColumnName]
listOfColNames)
formattedRow :: String
formattedRow = (String -> ShowS) -> String -> [String] -> String
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
Data.List.foldr (\String
colname String
accum -> String
colname String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
accum) String
"" [String]
formattedList
listOfLines :: [String]
listOfLines = (ColumnName -> String) -> [ColumnName] -> [String]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\ColumnName
c -> Int -> ShowS
forall a. Int -> [a] -> [a]
Data.List.take (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length (ColumnName -> String
T.unpack ColumnName
c)) (Char -> String
forall a. a -> [a]
repeat Char
'~')) [ColumnName]
listOfColNames
formattedLines :: [String]
formattedLines = ((Int, String) -> String) -> [(Int, String)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\(Int
w,String
l) -> Int -> ShowS
addSpace (Int
w Int -> Int -> Int
forall a. Num a => a -> a -> a
- (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length String
l) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
spaceSeparatorWidth) String
l) ([Int] -> [String] -> [(Int, String)]
forall a b. [a] -> [b] -> [(a, b)]
Data.List.zip [Int]
widths [String]
listOfLines)
formattedRowOfLines :: String
formattedRowOfLines = (String -> ShowS) -> String -> [String] -> String
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
Data.List.foldr (\String
line String
accum -> String
line String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
accum) String
"" [String]
formattedLines
String -> IO ()
printHeader String
formattedRow
String -> IO ()
printUnderlines String
formattedRowOfLines
where
printHeader :: String -> IO()
printHeader :: String -> IO ()
printHeader String
h = String -> IO ()
putStrLn String
h
printUnderlines :: String -> IO()
printUnderlines :: String -> IO ()
printUnderlines String
l = String -> IO ()
putStrLn String
l
printRTableHeader ::
[Int]
-> RTable
-> IO ()
[Int]
widths RTable
rtab = do
let listOfColNames :: [ColumnName]
listOfColNames = RTable -> [ColumnName]
getColumnNamesFromRTab RTable
rtab
formattedList :: [String]
formattedList = ((Int, ColumnName) -> String) -> [(Int, ColumnName)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\(Int
w,ColumnName
c) -> Int -> ShowS
addSpace (Int
w Int -> Int -> Int
forall a. Num a => a -> a -> a
- (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length (ColumnName -> String
T.unpack ColumnName
c)) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
spaceSeparatorWidth) (ColumnName -> String
T.unpack ColumnName
c)) ([Int] -> [ColumnName] -> [(Int, ColumnName)]
forall a b. [a] -> [b] -> [(a, b)]
Data.List.zip [Int]
widths [ColumnName]
listOfColNames)
formattedRow :: String
formattedRow = (String -> ShowS) -> String -> [String] -> String
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
Data.List.foldr (\String
colname String
accum -> String
colname String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
accum) String
"" [String]
formattedList
listOfLines :: [String]
listOfLines = (ColumnName -> String) -> [ColumnName] -> [String]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\ColumnName
c -> Int -> ShowS
forall a. Int -> [a] -> [a]
Data.List.take (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length (ColumnName -> String
T.unpack ColumnName
c)) (Char -> String
forall a. a -> [a]
repeat Char
'~')) [ColumnName]
listOfColNames
formattedLines :: [String]
formattedLines = ((Int, String) -> String) -> [(Int, String)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\(Int
w,String
l) -> Int -> ShowS
addSpace (Int
w Int -> Int -> Int
forall a. Num a => a -> a -> a
- (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length String
l) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
spaceSeparatorWidth) String
l) ([Int] -> [String] -> [(Int, String)]
forall a b. [a] -> [b] -> [(a, b)]
Data.List.zip [Int]
widths [String]
listOfLines)
formattedRowOfLines :: String
formattedRowOfLines = (String -> ShowS) -> String -> [String] -> String
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
Data.List.foldr (\String
line String
accum -> String
line String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
accum) String
"" [String]
formattedLines
String -> IO ()
printHeader String
formattedRow
String -> IO ()
printUnderlines String
formattedRowOfLines
where
printHeader :: String -> IO()
printHeader :: String -> IO ()
printHeader String
h = String -> IO ()
putStrLn String
h
printUnderlines :: String -> IO()
printUnderlines :: String -> IO ()
printUnderlines String
l = String -> IO ()
putStrLn String
l
printRTupleFmt :: RTupleFormat -> [Int] -> RTuple -> IO()
printRTupleFmt :: RTupleFormat -> [Int] -> RTuple -> IO ()
printRTupleFmt RTupleFormat
rtupFmt [Int]
widths RTuple
rtup = do
let rtupList :: [String]
rtupList = if RTupleFormat
rtupFmt RTupleFormat -> RTupleFormat -> Bool
forall a. Eq a => a -> a -> Bool
== RTupleFormat
genRTupleFormatDefault
then
((ColumnName, RDataType) -> String)
-> [(ColumnName, RDataType)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (RDataType -> String
rdataTypeToString (RDataType -> String)
-> ((ColumnName, RDataType) -> RDataType)
-> (ColumnName, RDataType)
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ColumnName, RDataType) -> RDataType
forall a b. (a, b) -> b
snd) (RTuple -> [(ColumnName, RDataType)]
rtupleToList RTuple
rtup)
else
if (RTupleFormat -> ColFormatMap
colFormatMap RTupleFormat
rtupFmt) ColFormatMap -> ColFormatMap -> Bool
forall a. Eq a => a -> a -> Bool
== ColFormatMap
genDefaultColFormatMap
then
(ColumnName -> String) -> [ColumnName] -> [String]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\ColumnName
colname -> FormatSpecifier -> RDataType -> String
rdataTypeToStringFmt FormatSpecifier
DefaultFormat (RDataType -> String) -> RDataType -> String
forall a b. (a -> b) -> a -> b
$ RTuple
rtup RTuple -> ColumnName -> RDataType
<!> ColumnName
colname ) ([ColumnName] -> [String]) -> [ColumnName] -> [String]
forall a b. (a -> b) -> a -> b
$ RTupleFormat -> [ColumnName]
colSelectList RTupleFormat
rtupFmt
else
(ColumnName -> String) -> [ColumnName] -> [String]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\ColumnName
colname -> FormatSpecifier -> RDataType -> String
rdataTypeToStringFmt ((RTupleFormat -> ColFormatMap
colFormatMap RTupleFormat
rtupFmt) ColFormatMap -> ColumnName -> FormatSpecifier
forall k v.
(Eq k, Hashable k, HasCallStack) =>
HashMap k v -> k -> v
! ColumnName
colname) (RDataType -> String) -> RDataType -> String
forall a b. (a -> b) -> a -> b
$ RTuple
rtup RTuple -> ColumnName -> RDataType
<!> ColumnName
colname ) ([ColumnName] -> [String]) -> [ColumnName] -> [String]
forall a b. (a -> b) -> a -> b
$ RTupleFormat -> [ColumnName]
colSelectList RTupleFormat
rtupFmt
formattedValueList :: [String]
formattedValueList = ((Int, String) -> String) -> [(Int, String)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\(Int
w,String
v) -> Int -> ShowS
addSpace (Int
w Int -> Int -> Int
forall a. Num a => a -> a -> a
- (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length String
v) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
spaceSeparatorWidth) String
v) ([Int] -> [String] -> [(Int, String)]
forall a b. [a] -> [b] -> [(a, b)]
Data.List.zip [Int]
widths [String]
rtupList)
formattedRow :: String
formattedRow = (String -> ShowS) -> String -> [String] -> String
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
Data.List.foldr (\String
value_box String
accum -> String
value_box String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
accum) String
"" [String]
formattedValueList
String -> IO ()
putStrLn String
formattedRow
printRTuple :: [Int] -> RTuple -> IO()
printRTuple :: [Int] -> RTuple -> IO ()
printRTuple [Int]
widths RTuple
rtup = do
let rtupList :: [String]
rtupList = ((ColumnName, RDataType) -> String)
-> [(ColumnName, RDataType)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (RDataType -> String
rdataTypeToString (RDataType -> String)
-> ((ColumnName, RDataType) -> RDataType)
-> (ColumnName, RDataType)
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ColumnName, RDataType) -> RDataType
forall a b. (a, b) -> b
snd) (RTuple -> [(ColumnName, RDataType)]
rtupleToList RTuple
rtup)
formattedValueList :: [String]
formattedValueList = ((Int, String) -> String) -> [(Int, String)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
Data.List.map (\(Int
w,String
v) -> Int -> ShowS
addSpace (Int
w Int -> Int -> Int
forall a. Num a => a -> a -> a
- (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Data.List.length String
v) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
spaceSeparatorWidth) String
v) ([Int] -> [String] -> [(Int, String)]
forall a b. [a] -> [b] -> [(a, b)]
Data.List.zip [Int]
widths [String]
rtupList)
formattedRow :: String
formattedRow = (String -> ShowS) -> String -> [String] -> String
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
Data.List.foldr (\String
value_box String
accum -> String
value_box String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
accum) String
"" [String]
formattedValueList
String -> IO ()
putStrLn String
formattedRow
rdataTypeToStringFmt :: FormatSpecifier -> RDataType -> String
rdataTypeToStringFmt :: FormatSpecifier -> RDataType -> String
rdataTypeToStringFmt FormatSpecifier
fmt RDataType
rdt =
case FormatSpecifier
fmt of
FormatSpecifier
DefaultFormat -> RDataType -> String
rdataTypeToString RDataType
rdt
Format String
fspec ->
case RDataType
rdt of
RInt Integer
i -> String -> Integer -> String
forall r. PrintfType r => String -> r
printf String
fspec Integer
i
RText ColumnName
t -> String -> ShowS
forall r. PrintfType r => String -> r
printf String
fspec (ColumnName -> String
unpack ColumnName
t)
RDate {rdate :: RDataType -> ColumnName
rdate = ColumnName
d, dtformat :: RDataType -> ColumnName
dtformat = ColumnName
f} -> String -> ShowS
forall r. PrintfType r => String -> r
printf String
fspec (ColumnName -> String
unpack ColumnName
d)
RTime RTimestamp
t -> String -> ShowS
forall r. PrintfType r => String -> r
printf String
fspec ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ ColumnName -> String
unpack (ColumnName -> String) -> ColumnName -> String
forall a b. (a -> b) -> a -> b
$ RDataType -> ColumnName
rtext (String -> RTimestamp -> RDataType
rTimestampToRText String
"DD/MM/YYYY HH24:MI:SS" RTimestamp
t)
RDouble Double
db -> String -> Double -> String
forall r. PrintfType r => String -> r
printf String
fspec Double
db
RDataType
Null -> String
"NULL"
rdataTypeToString :: RDataType -> String
rdataTypeToString :: RDataType -> String
rdataTypeToString RDataType
rdt =
case RDataType
rdt of
RInt Integer
i -> Integer -> String
forall a. Show a => a -> String
show Integer
i
RText ColumnName
t -> ColumnName -> String
unpack ColumnName
t
RDate {rdate :: RDataType -> ColumnName
rdate = ColumnName
d, dtformat :: RDataType -> ColumnName
dtformat = ColumnName
f} -> ColumnName -> String
unpack ColumnName
d
RTime RTimestamp
t -> ColumnName -> String
unpack (ColumnName -> String) -> ColumnName -> String
forall a b. (a -> b) -> a -> b
$ RDataType -> ColumnName
rtext (String -> RTimestamp -> RDataType
rTimestampToRText String
"DD/MM/YYYY HH24:MI:SS" RTimestamp
t)
RDouble Double
db -> String -> Double -> String
forall r. PrintfType r => String -> r
printf String
"%.2f" Double
db
RDataType
Null -> String
"NULL"
data ColumnDoesNotExist = ColumnDoesNotExist ColumnName deriving(ColumnDoesNotExist -> ColumnDoesNotExist -> Bool
(ColumnDoesNotExist -> ColumnDoesNotExist -> Bool)
-> (ColumnDoesNotExist -> ColumnDoesNotExist -> Bool)
-> Eq ColumnDoesNotExist
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ColumnDoesNotExist -> ColumnDoesNotExist -> Bool
$c/= :: ColumnDoesNotExist -> ColumnDoesNotExist -> Bool
== :: ColumnDoesNotExist -> ColumnDoesNotExist -> Bool
$c== :: ColumnDoesNotExist -> ColumnDoesNotExist -> Bool
Eq,Int -> ColumnDoesNotExist -> ShowS
[ColumnDoesNotExist] -> ShowS
ColumnDoesNotExist -> String
(Int -> ColumnDoesNotExist -> ShowS)
-> (ColumnDoesNotExist -> String)
-> ([ColumnDoesNotExist] -> ShowS)
-> Show ColumnDoesNotExist
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ColumnDoesNotExist] -> ShowS
$cshowList :: [ColumnDoesNotExist] -> ShowS
show :: ColumnDoesNotExist -> String
$cshow :: ColumnDoesNotExist -> String
showsPrec :: Int -> ColumnDoesNotExist -> ShowS
$cshowsPrec :: Int -> ColumnDoesNotExist -> ShowS
Show)
instance Exception ColumnDoesNotExist
data UnsupportedTimeStampFormat = UnsupportedTimeStampFormat String deriving(UnsupportedTimeStampFormat -> UnsupportedTimeStampFormat -> Bool
(UnsupportedTimeStampFormat -> UnsupportedTimeStampFormat -> Bool)
-> (UnsupportedTimeStampFormat
-> UnsupportedTimeStampFormat -> Bool)
-> Eq UnsupportedTimeStampFormat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UnsupportedTimeStampFormat -> UnsupportedTimeStampFormat -> Bool
$c/= :: UnsupportedTimeStampFormat -> UnsupportedTimeStampFormat -> Bool
== :: UnsupportedTimeStampFormat -> UnsupportedTimeStampFormat -> Bool
$c== :: UnsupportedTimeStampFormat -> UnsupportedTimeStampFormat -> Bool
Eq,Int -> UnsupportedTimeStampFormat -> ShowS
[UnsupportedTimeStampFormat] -> ShowS
UnsupportedTimeStampFormat -> String
(Int -> UnsupportedTimeStampFormat -> ShowS)
-> (UnsupportedTimeStampFormat -> String)
-> ([UnsupportedTimeStampFormat] -> ShowS)
-> Show UnsupportedTimeStampFormat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UnsupportedTimeStampFormat] -> ShowS
$cshowList :: [UnsupportedTimeStampFormat] -> ShowS
show :: UnsupportedTimeStampFormat -> String
$cshow :: UnsupportedTimeStampFormat -> String
showsPrec :: Int -> UnsupportedTimeStampFormat -> ShowS
$cshowsPrec :: Int -> UnsupportedTimeStampFormat -> ShowS
Show)
instance Exception UnsupportedTimeStampFormat
data EmptyInputStringsInToRTimestamp = EmptyInputStringsInToRTimestamp String String deriving(EmptyInputStringsInToRTimestamp
-> EmptyInputStringsInToRTimestamp -> Bool
(EmptyInputStringsInToRTimestamp
-> EmptyInputStringsInToRTimestamp -> Bool)
-> (EmptyInputStringsInToRTimestamp
-> EmptyInputStringsInToRTimestamp -> Bool)
-> Eq EmptyInputStringsInToRTimestamp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EmptyInputStringsInToRTimestamp
-> EmptyInputStringsInToRTimestamp -> Bool
$c/= :: EmptyInputStringsInToRTimestamp
-> EmptyInputStringsInToRTimestamp -> Bool
== :: EmptyInputStringsInToRTimestamp
-> EmptyInputStringsInToRTimestamp -> Bool
$c== :: EmptyInputStringsInToRTimestamp
-> EmptyInputStringsInToRTimestamp -> Bool
Eq, Int -> EmptyInputStringsInToRTimestamp -> ShowS
[EmptyInputStringsInToRTimestamp] -> ShowS
EmptyInputStringsInToRTimestamp -> String
(Int -> EmptyInputStringsInToRTimestamp -> ShowS)
-> (EmptyInputStringsInToRTimestamp -> String)
-> ([EmptyInputStringsInToRTimestamp] -> ShowS)
-> Show EmptyInputStringsInToRTimestamp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EmptyInputStringsInToRTimestamp] -> ShowS
$cshowList :: [EmptyInputStringsInToRTimestamp] -> ShowS
show :: EmptyInputStringsInToRTimestamp -> String
$cshow :: EmptyInputStringsInToRTimestamp -> String
showsPrec :: Int -> EmptyInputStringsInToRTimestamp -> ShowS
$cshowsPrec :: Int -> EmptyInputStringsInToRTimestamp -> ShowS
Show)
instance Exception EmptyInputStringsInToRTimestamp
data ConflictingRTableStructures =
ConflictingRTableStructures String
deriving(ConflictingRTableStructures -> ConflictingRTableStructures -> Bool
(ConflictingRTableStructures
-> ConflictingRTableStructures -> Bool)
-> (ConflictingRTableStructures
-> ConflictingRTableStructures -> Bool)
-> Eq ConflictingRTableStructures
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConflictingRTableStructures -> ConflictingRTableStructures -> Bool
$c/= :: ConflictingRTableStructures -> ConflictingRTableStructures -> Bool
== :: ConflictingRTableStructures -> ConflictingRTableStructures -> Bool
$c== :: ConflictingRTableStructures -> ConflictingRTableStructures -> Bool
Eq, Int -> ConflictingRTableStructures -> ShowS
[ConflictingRTableStructures] -> ShowS
ConflictingRTableStructures -> String
(Int -> ConflictingRTableStructures -> ShowS)
-> (ConflictingRTableStructures -> String)
-> ([ConflictingRTableStructures] -> ShowS)
-> Show ConflictingRTableStructures
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConflictingRTableStructures] -> ShowS
$cshowList :: [ConflictingRTableStructures] -> ShowS
show :: ConflictingRTableStructures -> String
$cshow :: ConflictingRTableStructures -> String
showsPrec :: Int -> ConflictingRTableStructures -> ShowS
$cshowsPrec :: Int -> ConflictingRTableStructures -> ShowS
Show)
instance Exception ConflictingRTableStructures
data UniquenessViolationInUpsert =
UniquenessViolationInUpsert String
deriving(UniquenessViolationInUpsert -> UniquenessViolationInUpsert -> Bool
(UniquenessViolationInUpsert
-> UniquenessViolationInUpsert -> Bool)
-> (UniquenessViolationInUpsert
-> UniquenessViolationInUpsert -> Bool)
-> Eq UniquenessViolationInUpsert
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UniquenessViolationInUpsert -> UniquenessViolationInUpsert -> Bool
$c/= :: UniquenessViolationInUpsert -> UniquenessViolationInUpsert -> Bool
== :: UniquenessViolationInUpsert -> UniquenessViolationInUpsert -> Bool
$c== :: UniquenessViolationInUpsert -> UniquenessViolationInUpsert -> Bool
Eq, Int -> UniquenessViolationInUpsert -> ShowS
[UniquenessViolationInUpsert] -> ShowS
UniquenessViolationInUpsert -> String
(Int -> UniquenessViolationInUpsert -> ShowS)
-> (UniquenessViolationInUpsert -> String)
-> ([UniquenessViolationInUpsert] -> ShowS)
-> Show UniquenessViolationInUpsert
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UniquenessViolationInUpsert] -> ShowS
$cshowList :: [UniquenessViolationInUpsert] -> ShowS
show :: UniquenessViolationInUpsert -> String
$cshow :: UniquenessViolationInUpsert -> String
showsPrec :: Int -> UniquenessViolationInUpsert -> ShowS
$cshowsPrec :: Int -> UniquenessViolationInUpsert -> ShowS
Show)
instance Exception UniquenessViolationInUpsert