Skip to content

Commit

Permalink
Add a rebind step to alignWith (#213)
Browse files Browse the repository at this point in the history
`Rel8.Tabulate.alignWith` uses `theseTable` to recover the key, which translates to a mess of nested `CASE` expressions. This becomes exponential with repeated uses of `alignWith`. Adding a `rebind` step to `alignWith` to rewrite this `key` expression each time makes this linear.
  • Loading branch information
shane-circuithub committed Nov 1, 2022
1 parent 38cbebc commit fd0b449
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Rel8/Tabulate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ import Rel8.Query.Filter ( where_ )
import Rel8.Query.List ( catNonEmptyTable )
import qualified Rel8.Query.Maybe as Q ( optional )
import Rel8.Query.Opaleye ( mapOpaleye, unsafePeekQuery )
import Rel8.Query.Rebind ( rebind )
import Rel8.Query.These ( alignBy )
import Rel8.Table ( Table, fromColumns, toColumns )
import Rel8.Table.Aggregate ( hgroupBy, listAgg, nonEmptyAgg )
Expand Down Expand Up @@ -508,8 +509,8 @@ alignWith :: EqTable k
-> Tabulation k a -> Tabulation k b -> Tabulation k c
alignWith f (Tabulation as) (Tabulation bs) = Tabulation $ \p -> do
tkab <- liftF2 (alignBy condition) as bs p
k <- traverse (rebind "key") $ recover $ bimap fst fst tkab
let
k = recover $ bimap fst fst tkab
tab = bimap snd snd tkab
pure (k, f tab)
where
Expand Down

0 comments on commit fd0b449

Please sign in to comment.