on master help sign in
Ensure that joins with attributes of different types for the same named attributes is rejected.
8b7e4e4AgentM
src/lib/ProjectM36/Attribute.hs+8−3
@@ -34,11 +34,16 @@ addAttribute attr attrs = attrs `V.snoc` attr
34
34
35--if some attribute names overlap but the types do not, then spit back an error
35--if some attribute names overlap but the types do not, then spit back an error
36joinAttributes :: Attributes -> Attributes -> Either RelationalError Attributes
36joinAttributes :: Attributes -> Attributes -> Either RelationalError Attributes
37−joinAttributes attrs1 attrs2 = if V.length (vectorUniqueify overlappingAttributes) /= V.length overlappingAttributes then
37+joinAttributes attrs1 attrs2 = if V.length uniqueOverlappingAttributes /= V.length overlappingAttributes then
38 Left $ TupleAttributeTypeMismatchError overlappingAttributes
38 Left $ TupleAttributeTypeMismatchError overlappingAttributes
39− else
39+ else if V.length overlappingAttrsDifferentTypes > 0 then
40+ Left (TupleAttributeTypeMismatchError overlappingAttrsDifferentTypes)
41+ else
40− Right $ vectorUniqueify (attrs1 V.++ attrs2)
42+ Right $ vectorUniqueify (attrs1 V.++ attrs2)
41 where
43 where
44+ overlappingAttrsDifferentTypes = V.filter (\attr -> V.elem (attributeName attr) attrNames2 && V.notElem attr attrs2) attrs1
45+ attrNames2 = V.map attributeName attrs2
46+ uniqueOverlappingAttributes = vectorUniqueify overlappingAttributes
42 overlappingAttributes = V.filter (\attr -> V.elem attr attrs2) attrs1
47 overlappingAttributes = V.filter (\attr -> V.elem attr attrs2) attrs1
43
48
44addAttributes :: Attributes -> Attributes -> Attributes
49addAttributes :: Attributes -> Attributes -> Attributes
src/lib/ProjectM36/RelationalExpression.hs+1
@@ -596,3 +596,4 @@ evalTupleExpr context attrs (TupleExpr tupMap) = do
596 tup' <- resolveTypesInTuple finalAttrs (reorderTuple finalAttrs tup)
596 tup' <- resolveTypesInTuple finalAttrs (reorderTuple finalAttrs tup)
597 _ <- validateTuple tup' tConss
597 _ <- validateTuple tup' tConss
598 pure tup'
598 pure tup'
599+
test/TutorialD/Interpreter.hs+6
@@ -206,6 +206,12 @@ transactionBranchTest = TestCase $ do
206 assertBool "master branch exists" $ isJust (transactionForHead "master" graph)
206 assertBool "master branch exists" $ isJust (transactionForHead "master" graph)
207 assertBool "test branch exists" $ isJust (transactionForHead "test" graph)
207 assertBool "test branch exists" $ isJust (transactionForHead "test" graph)
208
208
209+-- test that overlapping attribute names with different types fail with an error
210+failJoinTest :: Test
211+failJoinTest = TestCase $ assertTutdEqual basicDatabaseContext err "x:=relation{tuple{test Int}} join relation{tuple{test Text}}"
212+ where
213+ err = Left (TupleAttributeTypeMismatchError (A.attributesFromList [Attribute "test" IntAtomType]))
214+
209simpleJoinTest :: Test
215simpleJoinTest :: Test
210simpleJoinTest = TestCase $ assertTutdEqual dateExamples joinedRel "x:=s join sp"
216simpleJoinTest = TestCase $ assertTutdEqual dateExamples joinedRel "x:=s join sp"
211 where
217 where