modernize join

This commit is contained in:
nek0 2022-04-15 19:09:44 +02:00
parent 31f6c6d61e
commit 9752f27afb

View file

@ -134,48 +134,22 @@ produceProductOverviews
) )
produceProductOverviews refine = produceProductOverviews refine =
proc () -> do proc () -> do
(p, i2, i6, i6a, i7, i8, i9, i11, i12, i13, a3, a4) (p, i2, i6, i6a, i7, i8, i9, i11, i12, i13) <-
<- orderBy (asc (\(_, a2, _, _, _, _, _, _, _, _, _, _) -> a2)) (leftJoinF selectTable productTable -< ()
(\(pid, pi2, pi6, pi6a, pi7, pi8, pi9, pi11, pi12, pi13) (_, _, a3, a4, _) <- do
(_, _, ai3, ai4, _) -> (a1, a2, a3, a4, a5) <- selectTable amountTable -< ()
(pid, pi2, pi6, pi6a, pi7, pi8, pi9, pi11, pi12, pi13, ai3, ai4) (b1, b2) <- do
) (ib1, ib2, _, _, _) <- selectTable amountTable -< ()
(const (laterally . aggregate)
( toFields (0 :: Int) :: Column SqlInt4 (
, toFields ("ERROR PRODUCT" :: T.Text) :: Column SqlText (,)
, toFields (0 :: Int) :: Column SqlInt4
, toFields (Just (0 :: Int)) :: Column (Nullable SqlInt4)
, toFields (Just (0 :: Int)) :: Column (Nullable SqlInt4)
, toFields (0 :: Int) :: Column SqlInt4
, toFields (0 :: Int) :: Column SqlInt4
, toFields (0 :: Int) :: Column SqlInt4
, toFields (Just (0 :: Int)) :: Column (Nullable SqlInt4)
, toFields (Just ("" :: T.Text)) :: Column (Nullable SqlText)
, toFields (0 :: Int) :: Column SqlInt4
, toFields (0 :: Int) :: Column SqlInt4
)
)
(\(pid, _, _, _, _, _, _, _, _, _)
(aid, _, _, _, _) ->
pid .== aid
)
(selectTable productTable)
(joinF
(\(_, _, a3, a4, a5) (b1, b2) ->
(b1, b2, a3, a4, a5)
)
(\(a1, a2, _, _, _) (b1, b2) ->
(a1 .== b1) .&& (a2 .== b2)
)
(selectTable amountTable)
(aggregate
((,)
<$> P.lmap fst O.groupBy <$> P.lmap fst O.groupBy
<*> P.lmap snd O.max <*> P.lmap snd O.max
) )
(arr (\(a, b, _, _, _) -> (a, b)) <<< selectTable amountTable)) (arr (\(ib1, ib2, _, _, _) -> (ib1, ib2)) <<< selectTable amountTable ) -< ()
)) -< () returnA -< (ib1, ib2)
-- <<< arr (\_ -> (selectTable productTable, selectTable amountTable)) -< () restrict -< a1 .== b1 .&& a2 .== b2
returnA -< (b1, b2, a3, a4, a5)
restrict -< case refine of restrict -< case refine of
AllProducts -> toFields True AllProducts -> toFields True
AvailableProducts -> a3 ./= (toFields (0 :: Int) :: Column SqlInt4) AvailableProducts -> a3 ./= (toFields (0 :: Int) :: Column SqlInt4)