Frames-map-reduce 0.4.0.0 → 0.4.1.1
raw patch · 3 files changed
+50/−18 lines, 3 filesdep ~basedep ~profunctorsPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: base, profunctors
API changes (from Hackage documentation)
- Frames.Folds: instance forall k1 k (c :: k -> GHC.Types.Constraint) (t :: (k1, k)). c (Data.Vinyl.TypeLevel.Snd t) => Frames.Folds.ConstrainedField c t
- Frames.Folds.General: instance forall k1 k (c :: k -> GHC.Types.Constraint) (t :: (k1, k)). c (Data.Vinyl.TypeLevel.Snd t) => Frames.Folds.General.ConstrainedField c t
- Frames.MapReduce.General: instance (Data.Vinyl.TypeLevel.IndexWitnesses (Data.Vinyl.TypeLevel.RImage rs ss), Data.Vinyl.TypeLevel.NatToInt (Data.Vinyl.TypeLevel.RLength rs)) => Frames.MapReduce.General.RCastC rs ss Data.Vinyl.ARec.ARec f
- Frames.MapReduce.General: instance (Data.Vinyl.TypeLevel.NatToInt (Data.Vinyl.TypeLevel.RLength rs), Data.Vinyl.Core.RecApplicative rs, Data.Vinyl.Core.RPureConstrained (Data.Vinyl.ARec.IndexableField rs) rs) => Frames.MapReduce.General.IsoRec rs Data.Vinyl.ARec.ARec f
- Frames.MapReduce.General: instance Frames.MapReduce.General.RecGetFieldC t Data.Vinyl.ARec.ARec f rs
+ Frames.Aggregation: type AggregateAllC ak ak' d = ((ak' ++ d) ⊆ ((ak ++ d) ++ ak'), ak ⊆ (ak ++ d), ak' ⊆ (ak' ++ d), d ⊆ (ak' ++ d), Ord (Record ak'), Ord (Record ak), RecVec (ak' ++ d))
+ Frames.Aggregation: type AggregateC k ak ak' d = (CombineKeyAggregationsC k k ak ak', AggregateAllC (k ++ ak) (k ++ ak') d)
+ Frames.Aggregation: type CombineKeyAggregationsC a a' b b' = (a ⊆ (a ++ b), b ⊆ (a ++ b), Disjoint a' b' ~ 'True)
+ Frames.Folds: instance forall k k1 (c :: k -> GHC.Types.Constraint) (t :: (k1, k)). c (Data.Vinyl.TypeLevel.Snd t) => Frames.Folds.ConstrainedField c t
+ Frames.Folds.General: instance forall k k1 (c :: k -> GHC.Types.Constraint) (t :: (k1, k)). c (Data.Vinyl.TypeLevel.Snd t) => Frames.Folds.General.ConstrainedField c t
+ Frames.MapReduce.General: instance (Data.Vinyl.TypeLevel.IndexWitnesses (Data.Vinyl.TypeLevel.RImage rs ss), Data.Vinyl.TypeLevel.NatToInt (Data.Vinyl.TypeLevel.RLength rs)) => Frames.MapReduce.General.RCastC rs ss Data.Vinyl.ARec.Internal.ARec f
+ Frames.MapReduce.General: instance (Data.Vinyl.TypeLevel.NatToInt (Data.Vinyl.TypeLevel.RLength rs), Data.Vinyl.Core.RecApplicative rs, Data.Vinyl.Core.RPureConstrained (Data.Vinyl.ARec.Internal.IndexableField rs) rs) => Frames.MapReduce.General.IsoRec rs Data.Vinyl.ARec.Internal.ARec f
+ Frames.MapReduce.General: instance Frames.MapReduce.General.RecGetFieldC t Data.Vinyl.ARec.Internal.ARec f rs
- Frames.Aggregation: aggregateFold :: forall k ak ak' d. ((ak' ++ d) ⊆ ((ak ++ d) ++ ak'), ak ⊆ (ak ++ d), ak' ⊆ (ak' ++ d), d ⊆ (ak' ++ d), Ord (Record ak'), RecVec (ak' ++ d), Ord (Record ak), (k ++ (ak' ++ d)) ~ ((k ++ ak') ++ d), Ord (Record k), k ⊆ ((k ++ ak') ++ d), k ⊆ ((k ++ ak) ++ d), (ak ++ d) ⊆ ((k ++ ak) ++ d), RecVec ((k ++ ak') ++ d)) => RecordKeyMap ak ak' -> Fold (Record d) (Record d) -> Fold (Record ((k ++ ak) ++ d)) (FrameRec ((k ++ ak') ++ d))
+ Frames.Aggregation: aggregateFold :: forall k ak ak' d. AggregateC k ak ak' d => RecordKeyMap ak ak' -> Fold (Record d) (Record d) -> Fold (Record ((k ++ ak) ++ d)) (FrameRec ((k ++ ak') ++ d))
- Frames.Aggregation: combineKeyAggregations :: (a ⊆ (a ++ b), b ⊆ (a ++ b), Disjoint a' b' ~ 'True) => RecordKeyMap a a' -> RecordKeyMap b b' -> RecordKeyMap (a ++ b) (a' ++ b')
+ Frames.Aggregation: combineKeyAggregations :: forall a a' b b'. CombineKeyAggregationsC a a' b b' => RecordKeyMap a a' -> RecordKeyMap b b' -> RecordKeyMap (a ++ b) (a' ++ b')
- Frames.Aggregation.General: combineKeyAggregations :: forall (a :: [(Symbol, Type)]) b a' b' record f. (a ⊆ (a ++ b), b ⊆ (a ++ b), Disjoint a' b' ~ 'True, RCastC a (a ++ b) record f, RCastC b (a ++ b) record f, IsoRec a' record f, IsoRec b' record f, IsoRec (a' ++ b') record f) => RecordKeyMap record f a a' -> RecordKeyMap record f b b' -> RecordKeyMap record f (a ++ b) (a' ++ b')
+ Frames.Aggregation.General: combineKeyAggregations :: forall (a :: [(Symbol, Type)]) b a' b' record f. (a ⊆ (a ++ b), b ⊆ (a ++ b), Disjoint a' b' ~ 'True, RCastC a (a ++ b) record f, RCastC b (a ++ b) record f, IsoRec a' record f, IsoRec b' record f, IsoRec (a' ++ b') record f) => RecordKeyMap record f a a' -> RecordKeyMap record f b b' -> RecordKeyMap record f (a ++ b) (a' ++ b')
- Frames.Aggregation.Maybe: combineKeyAggregations :: forall (a :: [(Symbol, Type)]) b a' b' record. (a ⊆ (a ++ b), b ⊆ (a ++ b), Disjoint a' b' ~ 'True, RCastC a (a ++ b) record Maybe, RCastC b (a ++ b) record Maybe, IsoRec a' record Maybe, IsoRec b' record Maybe, IsoRec (a' ++ b') record Maybe) => RecordKeyMap record Maybe a a' -> RecordKeyMap record Maybe b b' -> RecordKeyMap record Maybe (a ++ b) (a' ++ b')
+ Frames.Aggregation.Maybe: combineKeyAggregations :: forall (a :: [(Symbol, Type)]) b a' b' record. (a ⊆ (a ++ b), b ⊆ (a ++ b), Disjoint a' b' ~ 'True, RCastC a (a ++ b) record Maybe, RCastC b (a ++ b) record Maybe, IsoRec a' record Maybe, IsoRec b' record Maybe, IsoRec (a' ++ b') record Maybe) => RecordKeyMap record Maybe a a' -> RecordKeyMap record Maybe b b' -> RecordKeyMap record Maybe (a ++ b) (a' ++ b')
Files
- CHANGELOG.md +6/−3
- Frames-map-reduce.cabal +10/−10
- src/Frames/Aggregation.hs +34/−5
CHANGELOG.md view
@@ -1,4 +1,7 @@-v 0.4.0.0 +v 0.4.1.1+* Bumped some upper bounds++v 0.4.0.0 * Added ```splitOnData``` for assigning via a given set of data cols. * Bumped upper bounds * Checked compilation w/ghc-8.10.2@@ -16,13 +19,13 @@ instances should properly be in Vinyl. * Bumped some upper bounds for GHC 8.8. Still can't compile with 8.8+ until discrimination is updated. -v 0.2.0.0 +v 0.2.0.0 * Added Combinators for ```record (Maybe :. ElField) rs``` (Much thanks to Tim Pierson, @o1lo01ol1o, for the idea and the work!). * Added Combinators polymorphic in record type (```Rec```, ```ARec``` or ```SRec``` are supported) and composed interpretation functor ```f :. ElField``` * ```Maybe :. ElField``` case now uses the general case in order to avoid code duplication * ```Record``` case still uses separate code because the amount of new coercion code required was enough to not seem worth the re-use of the polymorphic case. -v 0.1.0.2 +v 0.1.0.2 * Changed example from "executable" to "test-suite". Now it doens't need to be built and its dependencies don't leak to library users. v 0.1.0.1
Frames-map-reduce.cabal view
@@ -1,28 +1,28 @@ cabal-version: 2.2 name: Frames-map-reduce-version: 0.4.0.0+version: 0.4.1.1 synopsis: Frames wrapper for map-reduce-folds and some extra folds helpers. description: Frames-map-reduce provides some helpers for using the map-reduce-folds library with vinyl records and Frames. These include functions for filtering Frames, splitting records into key columns and data columns and recombining key columns with other columns after reducing. This package also provides some tools for building folds over records from folds over each column, e.g, summing multiple numerical columns into a multi-column result.-bug-reports: https://github.com/adamConnerSax/Frames-map-reduce/issues +bug-reports: https://github.com/adamConnerSax/Frames-map-reduce/issues license: BSD-3-Clause license-file: LICENSE author: Adam Conner-Sax maintainer: adam_conner_sax@yahoo.com copyright: 2019 Adam Conner-Sax category: Data-extra-source-files: CHANGELOG.md +extra-source-files: CHANGELOG.md Build-type: Simple tested-with: GHC ==8.6.5 || ==8.8.3 || ==8.10.2 source-repository head Type: git- Location: https://github.com/adamConnerSax/Frames-map-reduce - + Location: https://github.com/adamConnerSax/Frames-map-reduce+ library ghc-options: -Wall -funbox-strict-fields exposed-modules: Frames.Folds@@ -36,11 +36,11 @@ , Frames.Aggregation.Maybe build-depends: Frames >= 0.6.1 && < 0.8,- base >= 4.12.0 && < 4.15,+ base >= 4.12.0 && < 4.17, containers >= 0.5.0 && < 0.7, hashable >= 1.2.7 && < 1.4,- map-reduce-folds >= 0.1.0 && < 0.2, - profunctors >= 5.3 && < 5.6,+ map-reduce-folds >= 0.1.0 && < 0.2,+ profunctors >= 5.3 && < 5.7, vinyl >= 0.11.0 && < 0.14, foldl >= 1.4.5 && < 1.5, newtype >= 0.2 && < 0.3@@ -54,11 +54,11 @@ ghc-options: -Wall build-depends: base,- foldl, + foldl, Frames, Frames-map-reduce, text >= 1.2.3 && < 1.3, vector, vinyl,- random >= 1.2 && < 1.3, + random >= 1.2 && < 1.3, default-language: Haskell2010
src/Frames/Aggregation.hs view
@@ -19,7 +19,7 @@ {-# OPTIONS_GHC -fwarn-incomplete-patterns #-} {-| Module : Frames.Aggregation-Description : A specialised Map/Reduce for aggregating one set of keys to a smaller one given some operation to merge data. +Description : A specialised Map/Reduce for aggregating one set of keys to a smaller one given some operation to merge data. Copyright : (c) Adam Conner-Sax 2019 License : BSD Maintainer : adam_conner_sax@yahoo.com@@ -32,8 +32,12 @@ -} module Frames.Aggregation (- -- * Type-alias for maps from one record key to another+ -- * Types RecordKeyMap+ -- * Constraint Helpers+ , AggregateAllC+ , AggregateC+ , CombineKeyAggregationsC -- * Aggregation Function combinators , combineKeyAggregations , keyMap@@ -58,9 +62,11 @@ -- | Type-alias for key aggregation functions. type RecordKeyMap k k' = F.Record k -> F.Record k' +type CombineKeyAggregationsC a a' b b' = (a F.⊆ (a V.++ b), b F.⊆ (a V.++ b), F.Disjoint a' b' ~ 'True)+ -- | Combine 2 key aggregation functions over disjoint columns. combineKeyAggregations- :: (a F.⊆ (a V.++ b), b F.⊆ (a V.++ b), F.Disjoint a' b' ~ 'True)+ :: forall a a' b b'.CombineKeyAggregationsC a a' b b' => RecordKeyMap a a' -> RecordKeyMap b b' -> RecordKeyMap (a V.++ b) (a' V.++ b')@@ -76,6 +82,15 @@ -> RecordKeyMap '[a] '[b] keyMap f r = f (F.rgetField @a r) F.&: V.RNil +type AggregateAllC ak ak' d = ((ak' V.++ d) F.⊆ ((ak V.++ d) V.++ ak')+ , ak F.⊆ (ak V.++ d)+ , ak' F.⊆ (ak' V.++ d)+ , d F.⊆ (ak' V.++ d)+ , Ord (F.Record ak')+ , Ord (F.Record ak)+ , FI.RecVec (ak' V.++ d)+ )+ -- | Given some group keys in columns k, -- some keys to aggregate over in columns ak, -- some keys to aggregate into in (new) columns ak',@@ -112,9 +127,23 @@ in FMR.concatFold $ FMR.mapReduceFold aggUnpack aggAssign (FMR.foldAndAddKey aggDataF) --- | Aggregate key columns @ak@ into @ak'@ while leaving key columns @k@ along.+type AggregateC k ak ak' d = (CombineKeyAggregationsC k k ak ak'+ ,AggregateAllC (k V.++ ak) (k V.++ ak') d+ )++-- | Aggregate key columns @ak@ into @ak'@ while leaving key columns @k@ alone. -- Allows aggregation over only some fields. Will often require a typeapplication -- to specify what @k@ is.+aggregateFold :: forall k ak ak' d.AggregateC k ak ak' d+ => RecordKeyMap ak ak' -- ^ get aggregated key from key+ -> (FL.Fold (F.Record d) (F.Record d)) -- ^ aggregate data+ -> FL.Fold+ (F.Record (k V.++ ak V.++ d))+ (F.FrameRec (k V.++ ak' V.++ d))+aggregateFold f = aggregateAllFold (combineKeyAggregations @k @k id f)+++{- aggregateFold :: forall k ak ak' d . ( (ak' V.++ d) F.⊆ ((ak V.++ d) V.++ ak')@@ -142,7 +171,7 @@ ( FMR.makeRecsWithKey id $ MR.ReduceFold (const $ aggregateAllFold keyAgg aggDataF) )-+-} mergeDataFolds :: FL.Fold (F.Record d) (F.Record '[a])