on master help sign in
delete some dud data from Relation.hs
57e1596AgentM
Relation.hs+4−40
@@ -42,7 +42,6 @@ atomValueType :: Atom -> AtomType
42atomValueType (StringAtom _) = StringAtomType
42atomValueType (StringAtom _) = StringAtomType
43atomValueType (IntAtom _) = IntAtomType
43atomValueType (IntAtom _) = IntAtomType
44atomValueType (RelationAtom rel) = RelationAtomType (attributes rel)
44atomValueType (RelationAtom rel) = RelationAtomType (attributes rel)
45−
46
45
47instance Err.Error RelationalError where
46instance Err.Error RelationalError where
48
47
@@ -52,6 +51,8 @@ mkRelation attrs tupleSet =
52 --check that all tuples have keys (1-N) where N is the attribute count
51 --check that all tuples have keys (1-N) where N is the attribute count
53 if differentTupleCounts
52 if differentTupleCounts
54 then Left $ RelationalError 1 "Tuple attribute count mismatch"
53 then Left $ RelationalError 1 "Tuple attribute count mismatch"
54+ else if not (fst (verifyRelationTupleSet tupleSet))
55+ then Left $ RelationalError 1 "Tuple values not of the same type for same keys"
55 else if attrCountMismatch
56 else if attrCountMismatch
56 then Left $ RelationalError 1 "Attribute count mismatch"
57 then Left $ RelationalError 1 "Attribute count mismatch"
57 else
58 else
@@ -64,35 +65,6 @@ mkRelation attrs tupleSet =
64 else False --empty tuple set is always OK
65 else False --empty tuple set is always OK
65 differentTupleCounts = HS.size tupleCounts > 1
66 differentTupleCounts = HS.size tupleCounts > 1
66
67
67−r1 = case mkRelation attributes tupleSet1 of
68− Right x -> x
69− Left x -> relationFalse
70− where
71− tupleSet1 = HS.fromList [tuple1,tuple2]
72− tuple1 = mkRelationTuple (S.fromList ["hair"]) $ M.fromList [("hair", StringAtom "brown")]
73− tuple2 = mkRelationTuple (S.fromList ["hair"]) $ M.fromList [("hair", StringAtom "blonde")]
74− attributes = M.singleton "hair" (Attribute "hair" StringAtomType)
75−
76−testr1 = Relation attributes tupleSet
77− where
78− attributes = M.fromList [("hair", Attribute "hair" StringAtomType), ("name", Attribute "name" StringAtomType)]
79− tupleSet = HS.fromList $ mkRelationTuples attributes [M.fromList [("name", StringAtom "spammo"),("hair", StringAtom "brown")]]
80−
81−testr2 = Relation attributes tupleSet
82− where
83− attributes = M.singleton "hair" (Attribute "hair" StringAtomType)
84− tupleSet = HS.fromList $ mkRelationTuples attributes [M.fromList [("name", StringAtom "spammo")],M.fromList [("name", StringAtom "gonk")]]
85−
86−testcitiesr = Relation attributes tupleSet
87− where
88− attributes = M.singleton "name" (Attribute "name" StringAtomType)
89− tupleSet = HS.fromList $ mkRelationTuples attributes [M.fromList [("name", StringAtom "Boston"), ("name", StringAtom "Cambridge")]]
90−
91−testrinr = Relation attributes tupleSet
92− where
93− attributes = M.fromList [("state", Attribute "state" StringAtomType), ("cities", Attribute "cities" StringAtomType)]
94− tupleSet = HS.fromList $ mkRelationTuples attributes [M.fromList [("state", StringAtom "MA"), ("cities", RelationAtom testcitiesr)]]
95−
96relationTrue = Relation M.empty $ HS.singleton (RelationTuple M.empty)
68relationTrue = Relation M.empty $ HS.singleton (RelationTuple M.empty)
97relationFalse = Relation M.empty emptyTupleSet
69relationFalse = Relation M.empty emptyTupleSet
98
70
@@ -173,8 +145,8 @@ group groupAttrNames newAttrName rel@(Relation oldAttrs tupleSet) = do
173-}
145-}
174
146
175--algorithm: self-join with image relation
147--algorithm: self-join with image relation
176−group2 :: S.Set AttributeName -> AttributeName -> Relation -> Either RelationalError Relation
148+group :: S.Set AttributeName -> AttributeName -> Relation -> Either RelationalError Relation
177−group2 groupAttrNames newAttrName rel@(Relation attrs tupleSet) = do
149+group groupAttrNames newAttrName rel@(Relation attrs tupleSet) = do
178 nonGroupProjection <- project nonGroupAttrNames rel
150 nonGroupProjection <- project nonGroupAttrNames rel
179 relFold folder (Right $ Relation newAttrs emptyTupleSet) nonGroupProjection
151 relFold folder (Right $ Relation newAttrs emptyTupleSet) nonGroupProjection
180 where
152 where
@@ -335,11 +307,3 @@ relvarSP = mkRelation attributes tupleSet
335
307
336sp = case relvarSP of { Right r -> r }
308sp = case relvarSP of { Right r -> r }
337
309
338−grouptest = case x of
339− Right x -> x
340− where
341− x = group2 (S.fromList ["CITY", "SNAME", "S#"]) "X" s
342−
343−ungrouptest = case x of
344− Right x -> x
345− where x = ungroup "X" grouptest