on 2fbb67a help sign in
project-m36/src/lib/ProjectM36/GraphRefRelationalExpr.hs
46 lines 2.2 kB history raw
1module ProjectM36.GraphRefRelationalExpr where
2--evaluate relational expressions across the entire transaction graph to support cross-transaction referencing
3import ProjectM36.Base
4import ProjectM36.Error
5import qualified Data.Set as S
7-- core evaluation function- all other relational expr forms compile to GraphRefRelationalExpr
8eval :: GraphRefRelationalExpr -> TransactionGraph -> Either RelationalError Relation
9eval = undefined
10{-eval (MakeRelationFromExprs mAttrExprs tupleExprs) graph = do
11 mAttrs <- case mAttrExprs of
12 Just _ ->
13 Just . A.attributesFromList <$> mapM (evalAttrExpr tConss) (fromMaybe [] mAttrExprs)
14 Nothing -> pure Nothing
15 tuples <- mapM (evalTupleExpr mAttrs) tupleExprs
16 let attrs = fromMaybe firstTupleAttrs mAttrs
17 firstTupleAttrs = if null tuples then A.emptyAttributes else tupleAttributes (head tuples)
18 mkRelation attrs (RelationTupleSet tuples)
21-}
23data SingularTransactionRef = SingularTransactionRef GraphRefTransactionMarker |
24 MultipleTransactionsRef |
25 NoTransactionsRef
26 deriving (Eq, Show)
28-- | return `Just transid` if this GraphRefRelationalExpr refers to just one transaction in the graph. This is useful for determining if certain optimizations can apply.
29singularTransaction :: GraphRefRelationalExpr -> SingularTransactionRef
30singularTransaction expr =
31 if S.null transSet then
32 NoTransactionsRef
33 else if S.size transSet == 1 then
34 SingularTransactionRef (head (S.toList transSet))
35 else
36 MultipleTransactionsRef
37 where
38 transSet = foldr (\transId acc -> S.insert transId acc) S.empty expr
40-- | Return True if two 'GraphRefRelationalExpr's both refer exclusively to the same transaction (or none at all).
41inSameTransaction :: GraphRefRelationalExpr -> GraphRefRelationalExpr -> Maybe GraphRefTransactionMarker
42inSameTransaction exprA exprB = case (stA, stB) of
43 (SingularTransactionRef tA, SingularTransactionRef tB) | tA == tB -> Just tA
44 _ -> Nothing
45 where stA = singularTransaction exprA
46 stB = singularTransaction exprB