@@ -3,14 +3,10 @@
3module Relation where
3module Relation where
4import qualified Data.Map as M
4import qualified Data.Map as M
5import qualified Data.Set as S
5import qualified Data.Set as S
6−import qualified Data.List as L
7import qualified Data.HashSet as HS
6import qualified Data.HashSet as HS
8−import qualified Data.Hashable as Hash
9import qualified Control.Monad.Error as Err
7import qualified Control.Monad.Error as Err
12import RelationType
9import RelationType
14import RelationTuple
10import RelationTuple
15import RelationAttribute
11import RelationAttribute
16import RelationTupleSet
12import RelationTupleSet
@@ -153,7 +149,6 @@ group groupAttrNames newAttrName rel@(Relation attrs tupleSet) = do
153 newAttrs = M.insert newAttrName groupAttr (attributesForNames nonGroupAttrNames rel)
149 newAttrs = M.insert newAttrName groupAttr (attributesForNames nonGroupAttrNames rel)
154 groupAttr = Attribute newAttrName (RelationAtomType (attributesForNames nonGroupAttrNames rel))
150 groupAttr = Attribute newAttrName (RelationAtomType (attributesForNames nonGroupAttrNames rel))
155 nonGroupAttrNames = nonMatchingAttributeNameSet groupAttrNames (attributeNames rel)
151 nonGroupAttrNames = nonMatchingAttributeNameSet groupAttrNames (attributeNames rel)
156− newAttrNames = S.insert newAttrName nonGroupAttrNames
157 folder tupleIn acc = case acc of
152 folder tupleIn acc = case acc of
158 Left err -> Left err
153 Left err -> Left err
159 Right acc -> union acc (Relation newAttrs (HS.singleton (tupleExtend tupleIn (matchingRelTuple tupleIn))))
154 Right acc -> union acc (Relation newAttrs (HS.singleton (tupleExtend tupleIn (matchingRelTuple tupleIn))))
@@ -174,7 +169,6 @@ restrictEq (RelationTuple tupMap) rel = restrict filter rel
174ungroup :: AttributeName -> Relation -> Either RelationalError Relation
169ungroup :: AttributeName -> Relation -> Either RelationalError Relation
175ungroup relvalAttrName rel = relFold relFolder (Right $ Relation newAttrs emptyTupleSet) rel
170ungroup relvalAttrName rel = relFold relFolder (Right $ Relation newAttrs emptyTupleSet) rel
177− newAttrNames = M.keysSet newAttrs
178 newAttrs = M.union (attributesForRelval relvalAttrName rel) nonGroupAttrs
172 newAttrs = M.union (attributesForRelval relvalAttrName rel) nonGroupAttrs
179 nonGroupAttrs = M.delete relvalAttrName (attributes rel)
173 nonGroupAttrs = M.delete relvalAttrName (attributes rel)
180 relFolder :: RelationTuple -> Either RelationalError Relation -> Either RelationalError Relation
174 relFolder :: RelationTuple -> Either RelationalError Relation -> Either RelationalError Relation
@@ -191,7 +185,6 @@ tupleUngroup :: AttributeName -> Attributes -> RelationTuple -> Either Relationa
191tupleUngroup relvalAttrName newAttrs tuple@(RelationTuple tupMap) = case (tupMap M.! relvalAttrName) of
185tupleUngroup relvalAttrName newAttrs tuple@(RelationTuple tupMap) = case (tupMap M.! relvalAttrName) of
192 (RelationAtom relvalRelation) -> relFold folder (Right $ Relation newAttrs emptyTupleSet) relvalRelation
186 (RelationAtom relvalRelation) -> relFold folder (Right $ Relation newAttrs emptyTupleSet) relvalRelation
194− newAttrNameSet = M.keysSet newAttrs
195 nonGroupTupleProjection = tupleProject nonGroupAttrNames tuple
188 nonGroupTupleProjection = tupleProject nonGroupAttrNames tuple
196 nonGroupAttrNames = M.keysSet newAttrs
189 nonGroupAttrNames = M.keysSet newAttrs
197 folder tupleIn acc = case acc of
190 folder tupleIn acc = case acc of
@@ -207,7 +200,6 @@ tupleUngroup relvalAttrName newAttrs tuple@(RelationTuple tupMap) = case (tupMap
207attributesForRelval :: AttributeName -> Relation -> Attributes
200attributesForRelval :: AttributeName -> Relation -> Attributes
208attributesForRelval relvalAttrName relIn@(Relation attrs tupleSet) = attributes relvalRelation
201attributesForRelval relvalAttrName relIn@(Relation attrs tupleSet) = attributes relvalRelation
210− relvalRelationAttrs = attributes relvalRelation
211 --this is only temporarily needed until the Relation stores the types of the columns as data- hack alert
203 --this is only temporarily needed until the Relation stores the types of the columns as data- hack alert
212 --find a tuple with attributes to steal to ungroup
204 --find a tuple with attributes to steal to ungroup
213 oneTuple :: RelationTupleSet -> RelationTuple
205 oneTuple :: RelationTupleSet -> RelationTuple