1{-# language FlexibleContexts #-}
2{-# language NamedFieldPuns #-}
3{-# language ScopedTypeVariables #-}
4{-# language TypeApplications #-}
5{-# language TypeFamilies #-}
6{-# language ViewPatterns #-}
8module Rel8.Table.Aggregate
17import Data.Functor.Identity ( Identity( Identity ) )
21import Rel8.Aggregate ( Aggregate )
22import Rel8.Expr.Aggregate ( listAggExpr, nonEmptyAggExpr, sgroupByExpr )
23import Rel8.Schema.Context ( Aggregation( Aggregation ), DB( DB ) )
24import Rel8.Schema.Dict ( Dict( Dict ) )
25import Rel8.Schema.HTable ( htabulate, hfield, hdicts, hspecs )
26import Rel8.Schema.HTable.Vectorize ( hvectorize )
27import Rel8.Schema.Spec ( SSpec(..) )
28import Rel8.Schema.Spec.ConstrainDBType ( ConstrainDBType )
29import Rel8.Table ( Table, Columns, toColumns, fromColumns )
30import Rel8.Table.Eq ( EqTable )
31import Rel8.Table.List ( ListTable )
32import Rel8.Table.NonEmpty ( NonEmptyTable )
33import Rel8.Table.Recontextualize ( Aggregates )
34import Rel8.Type.Eq ( DBEq )
37groupBy :: forall exprs. EqTable exprs => exprs -> Aggregate exprs
38groupBy (toColumns -> exprs) = fromColumns $ htabulate $ \field ->
39 case hfield dicts field of
40 Dict -> case hfield hspecs field of
41 SSpec {nullability} -> case hfield exprs field of
42 DB expr -> Aggregation $ sgroupByExpr nullability expr
44 dicts = hdicts @(Columns exprs) @(ConstrainDBType DBEq)
47listAgg :: Table DB exprs => exprs -> Aggregate (ListTable exprs)
48listAgg (toColumns -> exprs) = fromColumns $
50 (\_ (Identity (DB a)) -> Aggregation $ listAggExpr a)
54nonEmptyAgg :: Table DB exprs => exprs -> Aggregate (NonEmptyTable exprs)
55nonEmptyAgg (toColumns -> exprs) = fromColumns $
57 (\_ (Identity (DB a)) -> Aggregation $ nonEmptyAggExpr a)
61runAggregation :: Aggregates aggregates exprs => aggregates -> Aggregate exprs
62runAggregation = fromColumns . toColumns
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list