@@ -13,6 +13,7 @@ module Rel8.Aggregate.Legacy
13 , aggregate
13 , aggregate
14 , aggregateTabulation
14 , aggregateTabulation
17 , nonEmptyAgg
18 , nonEmptyAgg
@@ -33,14 +34,18 @@ import qualified Opaleye.Aggregate as Opaleye
34import Rel8.Aggregate ( Aggregate, Aggregates, Col( A ) )
35import Rel8.Aggregate ( Aggregate, Aggregates, Col( A ) )
35import Rel8.Expr ( Col( E ), Expr )
36import Rel8.Expr ( Col( E ), Expr )
37+import Rel8.Expr.Aggregate
36−import Rel8.Expr.Aggregate ( groupByExpr, listAggExpr, nonEmptyAggExpr )
40+ , listAggExpr, nonEmptyAggExpr
37import Rel8.Generic.Construction ( GGAggregate', ggaggregate' )
42import Rel8.Generic.Construction ( GGAggregate', ggaggregate' )
38import Rel8.Generic.Table ( GAlgebra )
43import Rel8.Generic.Table ( GAlgebra )
39import Rel8.Kind.Algebra ( Algebra( Sum ) )
44import Rel8.Kind.Algebra ( Algebra( Sum ) )
40import Rel8.Query ( Query )
45import Rel8.Query ( Query )
41import Rel8.Query.Opaleye ( mapOpaleye )
46import Rel8.Query.Opaleye ( mapOpaleye )
42import Rel8.Schema.Dict ( Dict( Dict ) )
47import Rel8.Schema.Dict ( Dict( Dict ) )
43−import Rel8.Schema.HTable ( htabulate, hfield )
48+import Rel8.Schema.HTable ( hmap, hfield, htabulate )
44import Rel8.Schema.HTable.Vectorize ( hvectorize )
49import Rel8.Schema.HTable.Vectorize ( hvectorize )
45import Rel8.Schema.Kind ( Rel8able )
50import Rel8.Schema.Kind ( Rel8able )
46import Rel8.Table ( toColumns, fromColumns )
51import Rel8.Table ( toColumns, fromColumns )
@@ -76,6 +81,11 @@ groupBy (toColumns -> exprs) = fromColumns $ htabulate $ \field ->
76 E expr -> A $ groupByExpr expr
81 E expr -> A $ groupByExpr expr
84+-- | Keep only the first row's values.
85+headAgg :: Aggregates aggregates exprs => exprs -> aggregates
86+headAgg = fromColumns . hmap (\(E a) -> A $ headAggExpr a) . toColumns
79-- | Aggregate rows into a single row containing an array of all aggregated
89-- | Aggregate rows into a single row containing an array of all aggregated
80-- rows. This can be used to associate multiple rows with a single row, without
90-- rows. This can be used to associate multiple rows with a single row, without
81-- changing the over cardinality of the query. This allows you to essentially
91-- changing the over cardinality of the query. This allows you to essentially