module Database.HaskRel.Relational.Algebra (
rename, extend, restrict, project, projectAllBut,
naturalJoin, nJoin, times, matching, semiJoin, notMatching, semiDiff,
union, dUnion, intersect, minus, xUnion, group, groupAllBut, ungroup,
summarize,
interJoin, iJoin, dExtend, aSummarize,
imageExtendL, minus_,
extendA, dExtendA, renameA,
isProperSubsetOf, isSubsetOf, image, count, isEmpty,
rafoldr, rafoldrU, agg, aggU, relRearrange,
NotEmpty, Relabel
) where
import Data.Set ( Set, fromList, toList, size, intersection, difference )
import qualified Data.Set
import Database.HaskRel.HFWTabulation ( showHRecSetTab, HPresentRecAttr )
import Database.HaskRel.Relational.Definition ( Relation, unordRecEq, relRearrange )
import Data.HList.CommonMain
import Data.Typeable
data Relabel tr = Relabel tr
instance (HasFieldM l r v, Label dl ~ (DemoteMaybe (Label l) v),
b ~ Tagged dl a) =>
ApplyAB (Relabel r) (Tagged l a) b
where
applyAB _ (Tagged a) = Tagged a
rhRenameLabels
:: (HLabelSet (LabelsOf r), HMapAux HList (Relabel tr) a r,
SameLength' r a, SameLength' a r, HAllTaggedLV r) =>
tr -> Record a -> Record r
rhRenameLabels a (Record r) = mkRecord $ hMap (Relabel a) r
rename
:: (Ord (HList r), HLabelSet (LabelsOf r),
HMapAux HList (Relabel tr) a r, SameLength' r a, SameLength' a r,
HAllTaggedLV r) =>
Relation a -> tr -> Relation r
rename r l = Data.Set.map (rhRenameLabels l) r
renameA
:: forall l1 v1 r v' v l . (Ord (HExtendR (Tagged l1 v1) (r v')), HasField l (r v) v1,
HExtend (Tagged l1 v1) (r v'), HDeleteAtLabel r l v v') =>
Set (r v) -> Tagged l (Label l1) -> Set (HExtendR (Tagged l1 v1) (r v'))
renameA r frto = Data.Set.map (hRenameLabel (Label::Label l) (untag frto)) r
extend
:: (Ord (HList (HAppendListR r r'1)),
HLabelSet (LabelsOf (HAppendListR r r'1)),
HDeleteLabels (LabelsOf r) r' r'1, HAppendList r r'1,
HAllTaggedLV (HAppendListR r r'1)) =>
Relation r' -> (Record r' -> Record r) -> Relation (HAppendListR r r'1)
extend r f = Data.Set.map (\t -> f t .<++. t ) r
extendA :: forall r l e v v'.
(Ord (HExtendR (Tagged l e) (r v')), HExtend (Tagged l e) (r v'),
HDeleteAtLabel r l v v') =>
Set (r v) -> (r v -> Tagged l e) -> Set (HExtendR (Tagged l e) (r v'))
extendA r f = Data.Set.map (\t -> f t .*. hDeleteAtLabel (Label::Label l) t) r
dExtend
:: (Ord (HList (HAppendListR r r'1)),
HLabelSet (LabelsOf (HAppendListR r r'1)),
HDeleteLabels (LabelsOf r) r' r'1, HAppendList r r'1,
HAllTaggedLV (HAppendListR r r'1),
HRLabelSet (HAppendListR r' r)
) =>
Relation r' -> (Record r' -> Record r) -> Relation (HAppendListR r r'1)
dExtend = extend
dExtendA :: (Ord (HExtendR e l), HExtend e l) =>
Set l -> (l -> e) -> Set (HExtendR e l)
dExtendA r f = Data.Set.map (\t -> f t .*. t) r
imageExtendL
:: (Eq (HList l), Ord (HList l1), Ord (HList r'),
HLabelSet (LabelsOf l), HLabelSet (Label t ': LabelsOf l1),
HDeleteLabels (LabelsOf l1) r r',
H2ProjectByLabels (LabelsOf l) r l b,
H2ProjectByLabels (LabelsOf r) l1 l b1, HAllTaggedLV l1,
HAllTaggedLV l) =>
Set (Record l1)
-> Relation r
-> Label t
-> Set (Record (Tagged t (Relation r') ': l1))
imageExtendL r1 r2 l = dExtendA r1 (\t -> l .=. t `image` r2)
restrict :: Set a -> (a -> Bool) -> Set a
restrict r f = Data.Set.filter f r
project
:: (Ord (HList a), HLabelSet (LabelsOf a),
H2ProjectByLabels ls t a b, HAllTaggedLV a) =>
Relation t -> proxy ls -> Relation a
project r h = Data.Set.map ( hProjectByLabels h ) r
projectAllBut
:: (Ord (HList r'), HDeleteLabels ks r r') =>
Relation r -> proxy ks -> Relation r'
projectAllBut r a = Data.Set.map ( hDeleteLabels a ) r
union
:: (Ord (HList l), HRearrange3 (LabelsOf l) r l,
HLabelSet (LabelsOf l), SameLength' r l,
SameLength' r (LabelsOf l), SameLength' l r,
SameLength' (LabelsOf l) r) =>
Relation l -> Relation r -> Relation l
union r1 r2 = Data.Set.union r1 ( relRearrange r2 )
dUnion
:: (Ord (HList a), Typeable a, RecordValues a,
HRearrange3 (LabelsOf a) r a, HLabelSet (LabelsOf a),
HFoldr (Mapcar HPresentRecAttr) [[String]] (RecordValuesR a) [[String]],
SameLength' a r, SameLength' r a, SameLength' r (LabelsOf a),
SameLength' (LabelsOf a) r) =>
Relation a -> Relation r -> Relation a
dUnion l r =
let u = Data.Set.union l $ relRearrange r
in if size l + size r > size u
then error $ "Arguments to dUnion are not disjoint, intersection:\n" ++
showHRecSetTab ( Data.Set.intersection l $ relRearrange r )
else u
intersect
:: (Ord (HList l), HRearrange3 (LabelsOf l) r l,
HLabelSet (LabelsOf l), SameLength' r l,
SameLength' r (LabelsOf l), SameLength' l r,
SameLength' (LabelsOf l) r) =>
Relation l -> Relation r -> Relation l
intersect l r = intersection l $ relRearrange r
minus
:: (Ord (HList l), HRearrange3 (LabelsOf l) r l,
HLabelSet (LabelsOf l), SameLength' r l,
SameLength' r (LabelsOf l), SameLength' l r,
SameLength' (LabelsOf l) r) =>
Relation l -> Relation r -> Relation l
minus l r = difference l $ relRearrange r
minus_
:: (Ord (HList l), HRearrange3 (LabelsOf l) r l,
HLabelSet (LabelsOf l), SameLength' r l,
SameLength' r (LabelsOf l), SameLength' l r,
SameLength' (LabelsOf l) r) =>
Relation r -> Relation l -> Relation l
minus_ = difference . relRearrange
xUnion
:: (Ord (HList r1), HRearrange3 (LabelsOf r1) r r1,
HRearrange3 (LabelsOf r1) r1 r1, HLabelSet (LabelsOf r1),
SameLength' r r1, SameLength' r (LabelsOf r1), SameLength' r1 r,
SameLength' r1 r1, SameLength' r1 (LabelsOf r1),
SameLength' (LabelsOf r1) r, SameLength' (LabelsOf r1) r1) =>
Relation r1 -> Relation r -> Relation r1
xUnion l r =
let r1 = relRearrange r
in Data.Set.union l r1 `minus` intersection l r1
naturalJoin
:: (Eq (HList l), Ord (HList (HAppendListR t1 t2)),
HRearrange3 (LabelsOf l) r l, HLabelSet (LabelsOf l),
HLabelSet (LabelsOf t2), HLabelSet (LabelsOf r),
HLabelSet (LabelsOf (HAppendListR t1 t2)),
H2ProjectByLabels (LabelsOf t1) t l t2,
H2ProjectByLabels (LabelsOf t) t1 r b, HAppendList t1 t2,
SameLength' l r, SameLength' r l, SameLength' r (LabelsOf l),
SameLength' (LabelsOf l) r, HAllTaggedLV t2, HAllTaggedLV l,
HAllTaggedLV r, HAllTaggedLV (HAppendListR t1 t2)) =>
Relation t1
-> Relation t -> Relation (HAppendListR t1 t2)
naturalJoin r1 r2 = fromList $ Data.Set.foldr (\t1 b -> joinTOnR t1 r2 ++ b ) [] r1
nJoin
:: (Eq (HList l), Ord (HList (HAppendListR t1 t2)),
HRearrange3 (LabelsOf l) r l, HLabelSet (LabelsOf l),
HLabelSet (LabelsOf t2), HLabelSet (LabelsOf r),
HLabelSet (LabelsOf (HAppendListR t1 t2)),
H2ProjectByLabels (LabelsOf t1) t l t2,
H2ProjectByLabels (LabelsOf t) t1 r b, HAppendList t1 t2,
SameLength' l r, SameLength' r l, SameLength' r (LabelsOf l),
SameLength' (LabelsOf l) r, HAllTaggedLV t2, HAllTaggedLV l,
HAllTaggedLV r, HAllTaggedLV (HAppendListR t1 t2)) =>
Relation t1 -> Relation t -> Relation (HAppendListR t1 t2)
nJoin = naturalJoin
joinTOnR
:: (Eq (HList l), HRearrange3 (LabelsOf l) r l,
HLabelSet (LabelsOf l), HLabelSet (LabelsOf t2),
HLabelSet (LabelsOf r), HLabelSet (LabelsOf (HAppendListR t1 t2)),
H2ProjectByLabels (LabelsOf t1) t l t2,
H2ProjectByLabels (LabelsOf t) t1 r b, HAppendList t1 t2,
SameLength' l r, SameLength' r l, SameLength' r (LabelsOf l),
SameLength' (LabelsOf l) r, HAllTaggedLV t2, HAllTaggedLV l,
HAllTaggedLV r, HAllTaggedLV (HAppendListR t1 t2)) =>
Record t1 -> Relation t -> [Record (HAppendListR t1 t2)]
joinTOnR t1 r2 = Data.Set.foldr (tupJoin t1) [] r2
where
tupJoin t1' t2' b =
let
(p',cP) = hProjectByLabels2 ( labelsOf t1' ) t2'
in
if p' `unordRecEq` hProjectByLabels ( labelsOf t2' ) t1'
then hAppend t1' cP : b
else b
times
:: (HRLabelSet (HAppendListR t r),
Eq (HList l), Ord (HList (HAppendListR t1 t2)),
HRearrange3 (LabelsOf l) r l, HLabelSet (LabelsOf l),
HLabelSet (LabelsOf t2), HLabelSet (LabelsOf r),
HLabelSet (LabelsOf (HAppendListR t1 t2)),
H2ProjectByLabels (LabelsOf t1) t l t2,
H2ProjectByLabels (LabelsOf t) t1 r b, HAppendList t1 t2,
SameLength' l r, SameLength' r l, SameLength' r (LabelsOf l),
SameLength' (LabelsOf l) r, HAllTaggedLV t2, HAllTaggedLV l,
HAllTaggedLV r, HAllTaggedLV (HAppendListR t1 t2)) =>
Relation t1
-> Relation t -> Relation (HAppendListR t1 t2)
times = naturalJoin
data IsEmpty
class NotEmpty ( l :: [*] )
instance NotEmpty l
instance ( Fail IsEmpty ) => NotEmpty '[]
interJoin
:: (HTIntersect (LabelsOf r) (LabelsOf t) i, NotEmpty i,
Eq (HList l), Ord (HList (HAppendListR t1 t2)),
HRearrange3 (LabelsOf l) r l, HLabelSet (LabelsOf l),
HLabelSet (LabelsOf t2), HLabelSet (LabelsOf r),
HLabelSet (LabelsOf (HAppendListR t1 t2)),
H2ProjectByLabels (LabelsOf t1) t l t2,
H2ProjectByLabels (LabelsOf t) t1 r b, HAppendList t1 t2,
SameLength' l r, SameLength' r l, SameLength' r (LabelsOf l),
SameLength' (LabelsOf l) r, HAllTaggedLV t2, HAllTaggedLV l,
HAllTaggedLV r, HAllTaggedLV (HAppendListR t1 t2)) =>
Relation t1 -> Relation t -> Relation (HAppendListR t1 t2)
interJoin = naturalJoin
iJoin
:: (Eq (HList l), Ord (HList (HAppendListR t1 t2)),
HRearrange3 (LabelsOf l) r l, HLabelSet (LabelsOf l),
HLabelSet (LabelsOf r), HLabelSet (LabelsOf t2),
HLabelSet (LabelsOf (HAppendListR t1 t2)),
H2ProjectByLabels (LabelsOf t) t1 r b,
H2ProjectByLabels (LabelsOf t1) t l t2,
HTIntersect (LabelsOf r) (LabelsOf t) i, HAppendList t1 t2,
SameLength' r l, SameLength' r (LabelsOf l), SameLength' l r,
SameLength' (LabelsOf l) r, HAllTaggedLV t2, HAllTaggedLV r,
HAllTaggedLV l, HAllTaggedLV (HAppendListR t1 t2), NotEmpty i) =>
Relation t1 -> Relation t -> Relation (HAppendListR t1 t2)
iJoin = interJoin
matching
:: (Eq (HList l), Ord (HList t), HRearrange3 (LabelsOf l) r l,
HLabelSet (LabelsOf l), HLabelSet (LabelsOf r),
H2ProjectByLabels (LabelsOf t) l1 l b,
H2ProjectByLabels (LabelsOf l1) t r b1, SameLength' l r,
SameLength' r l, SameLength' r (LabelsOf l),
SameLength' (LabelsOf l) r, HAllTaggedLV l, HAllTaggedLV r) =>
Relation t -> Relation l1 -> Relation t
matching = semiJoin
semiJoin
:: (Eq (HList l), Ord (HList t), HRearrange3 (LabelsOf l) r l,
HLabelSet (LabelsOf l), HLabelSet (LabelsOf r),
H2ProjectByLabels (LabelsOf t) l1 l b,
H2ProjectByLabels (LabelsOf l1) t r b1, SameLength' l r,
SameLength' r l, SameLength' r (LabelsOf l),
SameLength' (LabelsOf l) r, HAllTaggedLV l, HAllTaggedLV r) =>
Relation t -> Relation l1 -> Relation t
semiJoin r1 r2 = fromList $ Data.Set.foldr (\t1 b -> semiJoinTOnR t1 ( toList r2 ) ++ b) [] r1
semiJoinTOnR
:: (Eq (HList l), HRearrange3 (LabelsOf l) r l,
HLabelSet (LabelsOf l), HLabelSet (LabelsOf r),
H2ProjectByLabels (LabelsOf t) l1 l b,
H2ProjectByLabels (LabelsOf l1) t r b1, SameLength' l r,
SameLength' r l, SameLength' r (LabelsOf l),
SameLength' (LabelsOf l) r, HAllTaggedLV l, HAllTaggedLV r) =>
Record t -> [Record l1] -> [Record t]
semiJoinTOnR _ [] = []
semiJoinTOnR t1 [t2] =
if tIntersectEq t1 t2 then [t1]
else []
semiJoinTOnR t1 (t2:r2) =
if tIntersectEq t1 t2 then [t1]
else semiJoinTOnR t1 r2
tIntersectEq
:: (Eq (HList l), HRearrange3 (LabelsOf l) r l,
HLabelSet (LabelsOf l), HLabelSet (LabelsOf r),
H2ProjectByLabels (LabelsOf t) l1 l b,
H2ProjectByLabels (LabelsOf l1) t r b1, SameLength' l r,
SameLength' r l, SameLength' r (LabelsOf l),
SameLength' (LabelsOf l) r, HAllTaggedLV l, HAllTaggedLV r) =>
Record t -> Record l1 -> Bool
tIntersectEq t1 t2 = hProjectByLabels ( labelsOf t1 ) t2 `unordRecEq` hProjectByLabels ( labelsOf t2 ) t1
notMatching
:: (Eq (HList l), Ord (HList t), HRearrange3 (LabelsOf l) r l,
HLabelSet (LabelsOf l), HLabelSet (LabelsOf r),
H2ProjectByLabels (LabelsOf t) l1 l b,
H2ProjectByLabels (LabelsOf l1) t r b1, SameLength' l r,
SameLength' r l, SameLength' r (LabelsOf l),
SameLength' (LabelsOf l) r, HAllTaggedLV l, HAllTaggedLV r) =>
Relation t -> Relation l1 -> Relation t
notMatching = semiDiff
semiDiff
:: (Eq (HList l), Ord (HList t), HRearrange3 (LabelsOf l) r l,
HLabelSet (LabelsOf l), HLabelSet (LabelsOf r),
H2ProjectByLabels (LabelsOf t) l1 l b,
H2ProjectByLabels (LabelsOf l1) t r b1, SameLength' l r,
SameLength' r l, SameLength' r (LabelsOf l),
SameLength' (LabelsOf l) r, HAllTaggedLV l, HAllTaggedLV r) =>
Relation t -> Relation l1 -> Relation t
semiDiff r1 r2 =
let tl2 = toList r2
in fromList $ Data.Set.foldr (\t1 b -> semiDiffTOnR t1 tl2 ++ b) [] r1
semiDiffTOnR
:: (Eq (HList l), HRearrange3 (LabelsOf l) r l,
HLabelSet (LabelsOf l), HLabelSet (LabelsOf r),
H2ProjectByLabels (LabelsOf t) l1 l b,
H2ProjectByLabels (LabelsOf l1) t r b1, SameLength' l r,
SameLength' r l, SameLength' r (LabelsOf l),
SameLength' (LabelsOf l) r, HAllTaggedLV l, HAllTaggedLV r) =>
Record t -> [Record l1] -> [Record t]
semiDiffTOnR t1 [] = [t1]
semiDiffTOnR t1 [t2] =
if tIntersectEq t1 t2 then []
else [t1]
semiDiffTOnR t1 (t2:r2) =
if tIntersectEq t1 t2 then []
else semiDiffTOnR t1 r2
projectTOnR :: forall a b ls t proxy .
(HLabelSet (LabelsOf a), H2ProjectByLabels ( LabelsOf ls ) t a b,
HAllTaggedLV a) =>
Record t -> Relation ls -> Record a
projectTOnR t _ = hProjectByLabels ( undefined :: Proxy ( LabelsOf ls ) ) t
restrictByRTuple
:: (Eq (HList l), HLabelSet (LabelsOf l),
H2ProjectByLabels (LabelsOf l) t l b, HAllTaggedLV l) =>
Relation t -> Record l -> Relation t
restrictByRTuple r t = Data.Set.filter ( ( t == ) . hProjectByLabels ( labelsOf t ) ) r
image
:: (Eq (HList l), Ord (HList r'), HLabelSet (LabelsOf l),
HDeleteLabels (LabelsOf l1) r r',
H2ProjectByLabels (LabelsOf l) r l b,
H2ProjectByLabels (LabelsOf r) l1 l b1, HAllTaggedLV l) =>
Record l1 -> Relation r -> Relation r'
image t r = projectAllBut (restrictByRTuple r $ projectTOnR t r) (labelsOf t)
extendAByImage
:: (Eq (HList l), Ord v, Ord (HList l1), Ord (HList r'),
HLabelSet (LabelsOf l), HLabelSet (Label t ': LabelsOf l1),
HDeleteLabels (LabelsOf l1) r r',
H2ProjectByLabels (LabelsOf l) r l b,
H2ProjectByLabels (LabelsOf r) l1 l b1, HAllTaggedLV l1,
HAllTaggedLV l) =>
Relation r -> Relation l1
-> (Relation r' -> Tagged t v) -> Relation (Tagged t v ': l1)
extendAByImage rel relP fOut = dExtendA relP $ fOut . ( `image` rel )
group
:: (Eq (HList l), Ord v, Ord (HList l1), Ord (HList r'),
HLabelSet (LabelsOf l), HLabelSet (Label t ': LabelsOf l1),
HDeleteLabels ks r l1, HDeleteLabels (LabelsOf l1) r r',
H2ProjectByLabels (LabelsOf l) r l b,
H2ProjectByLabels (LabelsOf r) l1 l b1, HAllTaggedLV l1,
HAllTaggedLV l) =>
Relation r
-> proxy ks -> (Relation r' -> Tagged t v) -> Relation (Tagged t v ': l1)
group rel attsIn = extendAByImage rel $ rel `projectAllBut` attsIn
groupAllBut
:: (Eq (HList l), Ord v, Ord (HList l1), Ord (HList r'),
HLabelSet (LabelsOf l), HLabelSet (LabelsOf l1),
HLabelSet (Label t ': LabelsOf l1),
HDeleteLabels (LabelsOf l1) t1 r', H2ProjectByLabels ls t1 l1 b2,
H2ProjectByLabels (LabelsOf l) t1 l b,
H2ProjectByLabels (LabelsOf t1) l1 l b1, HAllTaggedLV l1,
HAllTaggedLV l) =>
Relation t1
-> proxy ls -> (Relation r' -> Tagged t v) -> Relation (Tagged t v ': l1)
groupAllBut rel attsIn = extendAByImage rel $ rel `project` attsIn
ungroup
:: (Eq (HList l), Ord (HList (HAppendListR t1 t2)),
HasField l1 (Record v) (Relation t), HRearrange3 (LabelsOf l) r l,
HLabelSet (LabelsOf l), HLabelSet (LabelsOf t2),
HLabelSet (LabelsOf r), HLabelSet (LabelsOf (HAppendListR t1 t2)),
H2ProjectByLabels (LabelsOf t1) t l t2,
H2ProjectByLabels (LabelsOf t) t1 r b,
H2ProjectByLabels '[Label l1] v t3 t1, HAppendList t1 t2,
SameLength' l r, SameLength' r l, SameLength' r (LabelsOf l),
SameLength' (LabelsOf l) r, HAllTaggedLV t2, HAllTaggedLV l,
HAllTaggedLV r, HAllTaggedLV (HAppendListR t1 t2)) =>
Relation v -> Label l1 -> Relation (HAppendListR t1 t2)
ungroup r a = fromList $ Data.Set.foldr f [] r
where f t b = joinTOnR (hDeleteAtLabel a t) (t .!. a) ++ b
extendByImage
:: (Eq (HList l), Ord (HList r'2),
Ord (HList (HAppendListR r r'1)),
HLabelSet (LabelsOf (HAppendListR r r'1)),
HLabelSet (LabelsOf (HAppendListR r' r)), HLabelSet (LabelsOf l),
HDeleteLabels (LabelsOf r) r' r'1,
HDeleteLabels (LabelsOf r') r1 r'2,
H2ProjectByLabels (LabelsOf l) r1 l b,
H2ProjectByLabels (LabelsOf r1) r' l b1, HAppendList r r'1,
HAllTaggedLV l, HAllTaggedLV (HAppendListR r r'1),
HAllTaggedLV (HAppendListR r' r)) =>
Relation r1
-> Relation r'
-> (Relation r'2 -> Record r)
-> Relation (HAppendListR r r'1)
extendByImage rel relP fOut = dExtend relP $ fOut . ( `image` rel )
summarize
:: (Eq (HList l), Ord (HList r'), Ord (HList r'2),
Ord (HList (HAppendListR r r'1)),
HLabelSet (LabelsOf (HAppendListR r r'1)),
HLabelSet (LabelsOf (HAppendListR r' r)), HLabelSet (LabelsOf l),
HDeleteLabels ks r2 r', HDeleteLabels (LabelsOf r) r' r'1,
HDeleteLabels (LabelsOf r') r1 r'2,
H2ProjectByLabels (LabelsOf l) r1 l b,
H2ProjectByLabels (LabelsOf r1) r' l b1, HAppendList r r'1,
HAllTaggedLV l, HAllTaggedLV (HAppendListR r r'1),
HAllTaggedLV (HAppendListR r' r)) =>
Relation r1
-> Relation r2
-> proxy ks
-> (Relation r'2 -> Record r)
-> Relation (HAppendListR r r'1)
summarize relA relB attsIn f = extendByImage relA ( relB `projectAllBut` attsIn ) f
aSummarize
:: (Eq (HList l), Ord (HList r'), Ord (HList r'2),
Ord (HList (HAppendListR r r'1)),
HLabelSet (LabelsOf (HAppendListR r r'1)),
HLabelSet (LabelsOf (HAppendListR r' r)), HLabelSet (LabelsOf l),
HDeleteLabels ks r1 r', HDeleteLabels (LabelsOf r) r' r'1,
HDeleteLabels (LabelsOf r') r1 r'2,
H2ProjectByLabels (LabelsOf l) r1 l b,
H2ProjectByLabels (LabelsOf r1) r' l b1, HAppendList r r'1,
HAllTaggedLV l, HAllTaggedLV (HAppendListR r r'1),
HAllTaggedLV (HAppendListR r' r)) =>
Relation r1
-> proxy ks
-> (Relation r'2 -> Record r)
-> Relation (HAppendListR r r'1)
aSummarize rel attsIn f = extendByImage rel ( rel `projectAllBut` attsIn ) f
count :: Set a -> Int
count = Data.Set.size
isEmpty :: Set a -> Bool
isEmpty = Data.Set.null
isProperSubsetOf
:: (Ord (HList l), HRearrange3 (LabelsOf l) r l,
HLabelSet (LabelsOf l), SameLength' r l,
SameLength' r (LabelsOf l), SameLength' l r,
SameLength' (LabelsOf l) r) =>
Relation l -> Relation r -> Bool
isProperSubsetOf l r = Data.Set.isProperSubsetOf l ( relRearrange r )
isSubsetOf
:: (Ord (HList l), HRearrange3 (LabelsOf l) r l,
HLabelSet (LabelsOf l), SameLength' r l,
SameLength' r (LabelsOf l), SameLength' l r,
SameLength' (LabelsOf l) r) =>
Relation l -> Relation r -> Bool
isSubsetOf l r = Data.Set.isSubsetOf l ( relRearrange r )
rafoldr
:: (Foldable t, HasField l a b1) =>
(b1 -> b -> b) -> b -> Label l -> t a -> b
rafoldr f b a r = foldr ( f . (.!. a) ) b r
agg :: (Foldable t, HasField l a a1) => Label l -> t a -> [a1]
agg = rafoldr (:) []
unwrapUnary :: Record '[Tagged t t1] -> t1
unwrapUnary ( Record (Tagged v `HCons` HNil) ) = v
rafoldrU :: Foldable t => (b1 -> b -> b) -> b -> t (Record '[Tagged t1 b1]) -> b
rafoldrU f b r = foldr ( f . unwrapUnary ) b r
aggU :: Foldable t => t (Record '[Tagged t1 a]) -> [a]
aggU = rafoldrU (:) []