1module ProjectM36.GraphRefRelationalExpr where
2--evaluate relational expressions across the entire transaction graph to support cross-transaction referencing
5import qualified Data.Set as S
7-- core evaluation function- all other relational expr forms compile to GraphRefRelationalExpr
8eval :: GraphRefRelationalExpr -> TransactionGraph -> Either RelationalError Relation
10{-eval (MakeRelationFromExprs mAttrExprs tupleExprs) graph = do
11 mAttrs <- case mAttrExprs of
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)
23data SingularTransactionRef = SingularTransactionRef GraphRefTransactionMarker |
24 MultipleTransactionsRef |
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
33 else if S.size transSet == 1 then
34 SingularTransactionRef (head (S.toList transSet))
36 MultipleTransactionsRef
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
45 where stA = singularTransaction exprA
46 stB = singularTransaction exprB
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list