on master help sign in
switch to NoSuchAttributeNamesError
5866ddbAgentM
ProjectM36/Attribute.hs+4−1
@@ -66,7 +66,7 @@ atomTypeForAttributeName attrName attrs = do
66
66
67attributeForName :: AttributeName -> Attributes -> Either RelationalError Attribute
67attributeForName :: AttributeName -> Attributes -> Either RelationalError Attribute
68attributeForName attrName attrs = case V.find ((attrName ==) . attributeName) attrs of
68attributeForName attrName attrs = case V.find ((attrName ==) . attributeName) attrs of
69− Nothing -> Left $ NoSuchAttributeNameError attrName
69+ Nothing -> Left $ NoSuchAttributeNamesError (S.singleton attrName)
70 Just attr -> Right attr
70 Just attr -> Right attr
71
71
72attributesForNames :: S.Set AttributeName -> Attributes -> Attributes
72attributesForNames :: S.Set AttributeName -> Attributes -> Attributes
@@ -77,6 +77,9 @@ attributesForNames attrNameSet attrs = V.filter filt attrs
77attributeNameSet :: Attributes -> S.Set AttributeName
77attributeNameSet :: Attributes -> S.Set AttributeName
78attributeNameSet attrVec = S.fromList $ V.toList $ V.map (\(Attribute name _) -> name) attrVec
78attributeNameSet attrVec = S.fromList $ V.toList $ V.map (\(Attribute name _) -> name) attrVec
79
79
80+attributeNames :: Attributes -> V.Vector AttributeName
81+attributeNames = V.map attributeName
82+
80--checks if set s1 is wholly contained in the set s2
83--checks if set s1 is wholly contained in the set s2
81attributesContained :: Attributes -> Attributes -> Bool
84attributesContained :: Attributes -> Attributes -> Bool
82attributesContained attrs1 attrs2 = attributeNamesContained (attributeNameSet attrs1) (attributeNameSet attrs2)
85attributesContained attrs1 attrs2 = attributeNamesContained (attributeNameSet attrs1) (attributeNameSet attrs2)
ProjectM36/Tuple.hs+25−9
@@ -28,9 +28,9 @@ tupleAtoms (RelationTuple _ tupVec) = tupVec
28
28
29atomForAttributeName :: AttributeName -> RelationTuple -> Either RelationalError Atom
29atomForAttributeName :: AttributeName -> RelationTuple -> Either RelationalError Atom
30atomForAttributeName attrName (RelationTuple tupAttrs tupVec) = case V.findIndex (\attr -> attributeName attr == attrName) tupAttrs of
30atomForAttributeName attrName (RelationTuple tupAttrs tupVec) = case V.findIndex (\attr -> attributeName attr == attrName) tupAttrs of
31− Nothing -> Left $ NoSuchAttributeNameError attrName
31+ Nothing -> Left $ NoSuchAttributeNamesError (S.singleton attrName)
32 Just index -> case tupVec V.!? index of
32 Just index -> case tupVec V.!? index of
33− Nothing -> Left $ NoSuchAttributeNameError attrName
33+ Nothing -> Left $ NoSuchAttributeNamesError (S.singleton attrName)
34 Just atom -> Right atom
34 Just atom -> Right atom
35
35
36{- -- resolve naming clash with Attribute and Relation later
36{- -- resolve naming clash with Attribute and Relation later
@@ -40,12 +40,21 @@ atomTypeForAttributeName attrName tup = do
40 return $ atomTypeForAtom atom
40 return $ atomTypeForAtom atom
41-}
41-}
42
42
43−atomsForAttributeNames :: V.Vector AttributeName -> RelationTuple -> V.Vector Atom
43+atomsForAttributeNames :: V.Vector AttributeName -> RelationTuple -> Either RelationalError (V.Vector Atom)
44−atomsForAttributeNames attrNames tuple = V.foldr folder V.empty attrNames
44+atomsForAttributeNames attrNames tuple = do
45+ vindices <- vectorIndicesForAttributeNames attrNames (tupleAttributes tuple)
46+ return $ V.map (\index -> tupleAtoms tuple V.! index) vindices
47+
48+vectorIndicesForAttributeNames :: V.Vector AttributeName -> Attributes -> Either RelationalError (V.Vector Int)
49+vectorIndicesForAttributeNames attrNameVec attrs = if not $ V.null unknownAttrNames then
50+ Left $ NoSuchAttributeNamesError (S.fromList (V.toList unknownAttrNames))
51+ else
52+ Right $ V.map mapper attrNameVec
45 where
53 where
46− folder attrName acc = case atomForAttributeName attrName tuple of
54+ unknownAttrNames = V.filter ((flip V.notElem) (attributeNames attrs)) attrNameVec
47− Left _ -> acc
55+ mapper attrName = case V.elemIndex attrName (V.map attributeName attrs) of
48− Right atom -> V.snoc acc atom
56+ Nothing -> undefined
57+ Just index -> index
49
58
50relationForAttributeName :: AttributeName -> RelationTuple -> Either RelationalError Relation
59relationForAttributeName :: AttributeName -> RelationTuple -> Either RelationalError Relation
51relationForAttributeName attrName tuple = do
60relationForAttributeName attrName tuple = do
@@ -71,13 +80,20 @@ mkRelationTuples attrs atomsVec = map mapper atomsVec
71 mapper = mkRelationTuple attrs
80 mapper = mkRelationTuple attrs
72
81
73singleTupleSetJoin :: RelationTuple -> RelationTupleSet -> RelationTupleSet
82singleTupleSetJoin :: RelationTuple -> RelationTupleSet -> RelationTupleSet
74−singleTupleSetJoin tup tupSet = HS.foldr tupleJoiner HS.empty tupSet
83+singleTupleSetJoin tup tupSet = HS.foldr tupleJoiner HS.empty tupSet --get rid of this fold here
75 where
84 where
76 tupleJoiner tuple2 accumulator = case joinedTuple of
85 tupleJoiner tuple2 accumulator = case joinedTuple of
77 Nothing -> accumulator
86 Nothing -> accumulator
78 Just relTuple -> HS.insert relTuple accumulator
87 Just relTuple -> HS.insert relTuple accumulator
79 where joinedTuple = singleTupleJoin tup tuple2
88 where joinedTuple = singleTupleJoin tup tuple2
80−
89+
90+{-
91+singleTupleSetJoin :: RelationTuple -> RelationTupleSet -> RelationTupleSet
92+singleTupleSetJoin tup1 tupSet = HS.union
93+ where
94+ mapper tup2 = singleTupleJoin tup1 tup2
95+-}
96+
81-- the keys/values don't need to be resorted
97-- the keys/values don't need to be resorted
82-- if the keys share some keys and values, then merge the tuples
98-- if the keys share some keys and values, then merge the tuples
83singleTupleJoin :: RelationTuple -> RelationTuple -> Maybe RelationTuple
99singleTupleJoin :: RelationTuple -> RelationTuple -> Maybe RelationTuple