{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
module Frames.MapReduce.Maybe where
import qualified Control.MapReduce as MR
import qualified Frames.MapReduce.General as MG
import qualified Control.Foldl as FL
import Data.Maybe ( isJust )
import qualified Frames as F
import Frames ( (:.) )
import qualified Frames.Melt as F
import qualified Frames.InCore as FI
import qualified Data.Vinyl as V
import Data.Vinyl ( ElField )
import qualified Data.Vinyl.TypeLevel as V
unpackNoOp
:: MR.Unpack (record (Maybe :. ElField) rs) (record (Maybe :. ElField) rs)
unpackNoOp = MG.unpackNoOp
unpackFilterRow
:: (record (Maybe :. ElField) rs -> Bool)
-> MR.Unpack (record (Maybe :. ElField) rs) (record (Maybe :. ElField) rs)
unpackFilterRow = MG.unpackFilterRow
unpackFilterOnField
:: forall t rs record
. (V.KnownField t, F.ElemOf rs t, MG.RecGetFieldC t record Maybe rs)
=> (Maybe (V.Snd t) -> Bool)
-> MR.Unpack
(record (Maybe :. ElField) rs)
(record (Maybe :. ElField) rs)
unpackFilterOnField = MG.unpackFilterOnField @t
unpackGoodRows
:: forall cs rs record
. (MG.RCastC cs rs record Maybe)
=> (record (Maybe :. ElField) cs -> Bool)
-> MR.Unpack
(record (Maybe :. ElField) rs)
(record (Maybe :. ElField) rs)
unpackGoodRows = MG.unpackGoodRows
unpackGoodRecRows
:: forall cs rs
. (MG.RCastC cs rs V.Rec Maybe)
=> MR.Unpack (V.Rec (Maybe :. ElField) rs) (V.Rec (Maybe :. ElField) rs)
unpackGoodRecRows = MG.unpackGoodRows @cs (isJust . F.recMaybe)
assignKeysAndData
:: forall ks cs rs record
. (MG.RCastC ks rs record Maybe, MG.RCastC cs rs record Maybe)
=> MR.Assign
(record (Maybe :. ElField) ks)
(record (Maybe :. ElField) rs)
(record (Maybe :. ElField) cs)
assignKeysAndData = MG.assignKeysAndData
{-# INLINABLE assignKeysAndData #-}
splitOnKeys
:: forall ks rs cs record
. ( MG.RCastC ks rs record Maybe
, MG.RCastC cs rs record Maybe
, cs ~ F.RDeleteAll ks rs
)
=> MR.Assign
(record (Maybe :. ElField) ks)
(record (Maybe :. ElField) rs)
(record (Maybe :. ElField) cs)
splitOnKeys = assignKeysAndData @ks @cs
{-# INLINABLE splitOnKeys #-}
assignKeys
:: forall ks rs record
. (MG.RCastC ks rs record Maybe)
=> MR.Assign
(record (Maybe :. ElField) ks)
(record (Maybe :. ElField) rs)
(record (Maybe :. ElField) rs)
assignKeys = MG.assignKeys
{-# INLINABLE assignKeys #-}
reduceAndAddKey
:: forall ks cs x record
. ( MG.IsoRec ks record Maybe
, MG.IsoRec cs record Maybe
, MG.IsoRec (ks V.++ cs) record Maybe
, FI.RecVec ((ks V.++ cs))
)
=> (forall h . Foldable h => h x -> record (Maybe :. ElField) cs)
-> MR.Reduce
(record (Maybe :. ElField) ks)
x
(record (Maybe :. ElField) (ks V.++ cs))
reduceAndAddKey = MG.reduceAndAddKey
{-# INLINABLE reduceAndAddKey #-}
foldAndAddKey
:: ( MG.IsoRec ks record Maybe
, MG.IsoRec cs record Maybe
, MG.IsoRec (ks V.++ cs) record Maybe
, FI.RecVec ((ks V.++ cs))
)
=> FL.Fold x (record (Maybe :. ElField) cs)
-> MR.Reduce
(record (Maybe :. ElField) ks)
x
(record (Maybe :. ElField) (ks V.++ cs))
foldAndAddKey = MG.foldAndAddKey
{-# INLINABLE foldAndAddKey #-}
makeRecsWithKey
:: ( Functor g
, Foldable g
, MG.IsoRec ks record Maybe
, MG.IsoRec as record Maybe
, MG.IsoRec (ks V.++ as) record Maybe
, (FI.RecVec (ks V.++ as))
)
=> (y -> record (Maybe :. ElField) as)
-> MR.Reduce (record (Maybe :. ElField) ks) x (g y)
-> MR.Reduce
(record (Maybe :. ElField) ks)
x
(g (record (Maybe :. ElField) (ks V.++ as)))
makeRecsWithKey = MG.makeRecsWithKey
{-# INLINABLE makeRecsWithKey #-}
makeRecsWithKeyM
:: ( Monad m
, Functor g
, Foldable g
, MG.IsoRec ks record Maybe
, MG.IsoRec as record Maybe
, MG.IsoRec (ks V.++ as) record Maybe
, (FI.RecVec (ks V.++ as))
)
=> (y -> record (Maybe :. ElField) as)
-> MR.ReduceM m (record (Maybe :. ElField) ks) x (g y)
-> MR.ReduceM
m
(record (Maybe :. ElField) ks)
x
(g (record (Maybe :. ElField) (ks V.++ as)))
makeRecsWithKeyM = MG.makeRecsWithKeyM
{-# INLINABLE makeRecsWithKeyM #-}