on master help sign in
Ensure that joins with attributes of different types for the same named attributes is rejected.

We thought we were handling previously, but the if-statement was not handling same names with differing types. fixes #49

commit8b7e4e444d5d481a58cf12c303d7e9db20d67597 authorAgentM <agentm@themactionfaction.com> dateTue 20 Sep 2016, 22:52 (10 years ago) parente426984
3 files changed+15−3
src/lib/ProjectM36/Attribute.hs+8−3 src/lib/ProjectM36/RelationalExpression.hs+1 test/TutorialD/Interpreter.hs+6
src/lib/ProjectM36/Attribute.hs+8−3
@@ -34,11 +34,16 @@ addAttribute attr attrs = attrs `V.snoc` attr
3434
3535--if some attribute names overlap but the types do not, then spit back an error
3636joinAttributes :: 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
3838 Left $ TupleAttributeTypeMismatchError overlappingAttributes
39− else
40− Right $ vectorUniqueify (attrs1 V.++ attrs2)
39+ else if V.length overlappingAttrsDifferentTypes > 0 then
40+ Left (TupleAttributeTypeMismatchError overlappingAttrsDifferentTypes)
41+ else
42+ Right $ vectorUniqueify (attrs1 V.++ attrs2)
4143 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
4247 overlappingAttributes = V.filter (\attr -> V.elem attr attrs2) attrs1
4348
4449addAttributes :: Attributes -> Attributes -> Attributes
src/lib/ProjectM36/RelationalExpression.hs+1
@@ -596,3 +596,4 @@ evalTupleExpr context attrs (TupleExpr tupMap) = do
596596 tup' <- resolveTypesInTuple finalAttrs (reorderTuple finalAttrs tup)
597597 _ <- validateTuple tup' tConss
598598 pure tup'
599+
test/TutorialD/Interpreter.hs+6
@@ -206,6 +206,12 @@ transactionBranchTest = TestCase $ do
206206 assertBool "master branch exists" $ isJust (transactionForHead "master" graph)
207207 assertBool "test branch exists" $ isJust (transactionForHead "test" graph)
208208
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+
209215simpleJoinTest :: Test
210216simpleJoinTest = TestCase $ assertTutdEqual dateExamples joinedRel "x:=s join sp"
211217 where