@@ -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)
47instance Err.Error RelationalError where
46instance Err.Error RelationalError where
@@ -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"
@@ -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
67−r1 = case mkRelation attributes tupleSet1 of
69− Left x -> relationFalse
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)
76−testr1 = Relation attributes tupleSet
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")]]
81−testr2 = Relation attributes tupleSet
83− attributes = M.singleton "hair" (Attribute "hair" StringAtomType)
84− tupleSet = HS.fromList $ mkRelationTuples attributes [M.fromList [("name", StringAtom "spammo")],M.fromList [("name", StringAtom "gonk")]]
86−testcitiesr = Relation attributes tupleSet
88− attributes = M.singleton "name" (Attribute "name" StringAtomType)
89− tupleSet = HS.fromList $ mkRelationTuples attributes [M.fromList [("name", StringAtom "Boston"), ("name", StringAtom "Cambridge")]]
91−testrinr = Relation attributes tupleSet
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)]]
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
@@ -173,8 +145,8 @@ group groupAttrNames newAttrName rel@(Relation oldAttrs tupleSet) = do
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
@@ -335,11 +307,3 @@ relvarSP = mkRelation attributes tupleSet
336sp = case relvarSP of { Right r -> r }
308sp = case relvarSP of { Right r -> r }
338−grouptest = case x of
341− x = group2 (S.fromList ["CITY", "SNAME", "S#"]) "X" s
343−ungrouptest = case x of
345− where x = ungroup "X" grouptest