on master help sign in
add inclusion dependency tutd test and fix constraint checking function
f0a3d88AgentM
RelationExpr.hs+13−9
@@ -209,25 +209,29 @@ checkConstraints context = case failures of
209 deps = inclusionDependencies context
209 deps = inclusionDependencies context
210 eval expr = runState (evalRelationalExpr expr) context
210 eval expr = runState (evalRelationalExpr expr) context
211 checkIncDep (InclusionDependency depName subsetExpr supersetExpr) = case evaldSub of
211 checkIncDep (InclusionDependency depName subsetExpr supersetExpr) = case evaldSub of
212− Left err -> Just err
212+ (Left err, _) -> Just err
213− Right relSub -> case evaldSub of
213+ (Right relSub, _) -> case evaldSuper of
214− Left err -> Just err
214+ (Left err, _) -> Just err
215− Right relSuper -> case union relSub relSuper of
215+ (Right relSuper, _) -> case union relSub relSuper of
216 Left err -> Just err
216 Left err -> Just err
217− Right resultRel -> case resultRel of
217+ Right resultRel -> case resultRel == relSuper of
218 False -> Just $ InclusionDependencyCheckError depName
218 False -> Just $ InclusionDependencyCheckError depName
219 True -> Nothing
219 True -> Nothing
220 where
220 where
221 evaldSub = eval subsetExpr
221 evaldSub = eval subsetExpr
222 evaldSuper = eval supersetExpr
222 evaldSuper = eval supersetExpr
223
223
224+{-
224checkConstraint :: InclusionDependency -> DatabaseState (Maybe RelationalError)
225checkConstraint :: InclusionDependency -> DatabaseState (Maybe RelationalError)
225checkConstraint (InclusionDependency name subDep superDep) = do
226checkConstraint (InclusionDependency name subDep superDep) = do
226− evalSub <- evalRelExpr subDep
227+ evalSub <- evalRelationalExpr subDep
227− evalSuper <- evalRelExpr superDep
228+ evalSuper <- evalRelationalExpr superDep
229+ case evalSub of
230+ Left err -> Just err
231+ Right relSub
228 result <- liftM2 union evalSub evalSuper
232 result <- liftM2 union evalSub evalSuper
229−
233+ return $ Nothing
230−
234+-}
231
235
232
236
233
237
TutorialDInterpreterTest.hs+3−1
@@ -2,6 +2,7 @@ import TutorialDInterpreter
2import Test.HUnit
2import Test.HUnit
3import RelationExpr
3import RelationExpr
4import Relation
4import Relation
5+import RelationalError
5import RelationType
6import RelationType
6import qualified Data.HashSet as HS
7import qualified Data.HashSet as HS
7import qualified Data.Map as M
8import qualified Data.Map as M
@@ -18,7 +19,8 @@ main = do
18 ("x:=true; x:=false", Right relationFalse),
19 ("x:=true; x:=false", Right relationFalse),
19 ("x:=relation{a int}", mkRelation simpleAAttributes HS.empty),
20 ("x:=relation{a int}", mkRelation simpleAAttributes HS.empty),
20 ("x:=relation{c int} rename {c as d}", mkRelation simpleBAttributes HS.empty),
21 ("x:=relation{c int} rename {c as d}", mkRelation simpleBAttributes HS.empty),
21− ("y:=relation{b int, c int}; x:=y{c}", mkRelation simpleProjectionAttributes HS.empty)
22+ ("y:=relation{b int, c int}; x:=y{c}", mkRelation simpleProjectionAttributes HS.empty),
23+ ("constraint failc true in false; x:=true", Left $ InclusionDependencyCheckError "failc")
22 ]
24 ]
23 simpleAAttributes = M.fromList [("a", Attribute "a" IntAtomType)]
25 simpleAAttributes = M.fromList [("a", Attribute "a" IntAtomType)]
24 simpleBAttributes = M.fromList [("d", Attribute "d" IntAtomType)]
26 simpleBAttributes = M.fromList [("d", Attribute "d" IntAtomType)]