on master help sign in
delete some dud data from Relation.hs
commit57e1596ab28b2203623ec41ec3d7cce41ba51bc2 authorAgentM <agentm@themactionfaction.com> dateFri 31 Oct 2014, 10:37 (12 years ago) parentd284af9
1 file changed+4−40
Relation.hs+4−40
Relation.hs+4−40
@@ -42,7 +42,6 @@ atomValueType :: Atom -> AtomType
4242atomValueType (StringAtom _) = StringAtomType
4343atomValueType (IntAtom _) = IntAtomType
4444atomValueType (RelationAtom rel) = RelationAtomType (attributes rel)
45−
4645
4746instance Err.Error RelationalError where
4847
@@ -52,6 +51,8 @@ mkRelation attrs tupleSet =
5251 --check that all tuples have keys (1-N) where N is the attribute count
5352 if differentTupleCounts
5453 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"
5556 else if attrCountMismatch
5657 then Left $ RelationalError 1 "Attribute count mismatch"
5758 else
@@ -64,35 +65,6 @@ mkRelation attrs tupleSet =
6465 else False --empty tuple set is always OK
6566 differentTupleCounts = HS.size tupleCounts > 1
6667
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−
9668relationTrue = Relation M.empty $ HS.singleton (RelationTuple M.empty)
9769relationFalse = Relation M.empty emptyTupleSet
9870
@@ -173,8 +145,8 @@ group groupAttrNames newAttrName rel@(Relation oldAttrs tupleSet) = do
173145-}
174146
175147--algorithm: self-join with image relation
176−group2 :: S.Set AttributeName -> AttributeName -> Relation -> Either RelationalError Relation
177−group2 groupAttrNames newAttrName rel@(Relation attrs tupleSet) = do
148+group :: S.Set AttributeName -> AttributeName -> Relation -> Either RelationalError Relation
149+group groupAttrNames newAttrName rel@(Relation attrs tupleSet) = do
178150 nonGroupProjection <- project nonGroupAttrNames rel
179151 relFold folder (Right $ Relation newAttrs emptyTupleSet) nonGroupProjection
180152 where
@@ -335,11 +307,3 @@ relvarSP = mkRelation attributes tupleSet
335307
336308sp = case relvarSP of { Right r -> r }
337309
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