From 88ca02c623345890e42bab300602f8f733949012 Mon Sep 17 00:00:00 2001 From: Madhan Neethiraj <madhan@apache.org> Date: Wed, 1 Mar 2017 00:43:30 -0800 Subject: [PATCH] ATLAS-1603: fix to handle null value for object_id type attributes --- release-log.txt | 4 ++++ repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java | 25 ++++++++++++++++--------- repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1Test.java | 20 ++++++++++++++++++++ 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/release-log.txt b/release-log.txt index 4f59f57..3148c70 100644 --- a/release-log.txt +++ b/release-log.txt @@ -9,6 +9,10 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai) ALL CHANGES: +ATLAS-1603: fix to handle null value for object_id type attributes (mneethiraj via kevalbhatt) +ATLAS 1607: notify listeners on classification addition/deletion (sarathkumarsubramanian via mneethiraj) +ATLAS-1606: introduced query provider to handle Gremlin version specific queries (apoorvnaik via mneethiraj) +ATLAS-1602 fixed IT failures in QuickStart and issues identified in coverity scan (sarathkumarsubramanian via mneethiraj) ATLAS-1584 Fix issues with owned map reference and add tests (sumasai) ATLAS-1589 DSL queries return wrong object when filter traverses an edge (jnhagelberg) ATLAS-1590 UI : Edit Button is enabled for Deleted entities. (kevalbhatt) diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java index e6a7f41..e2b82cc 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java @@ -282,15 +282,19 @@ public class EntityGraphMapper { } case OBJECT_ID_TYPE: { - String edgeLabel = AtlasGraphUtilsV1.getEdgeLabel(ctx.getVertexProperty()); - AtlasEdge currentEdge = graphHelper.getEdgeForLabel(ctx.getReferringVertex(), edgeLabel); - AtlasEntityType instanceType = getInstanceType(ctx.getValue()); - AtlasEdge edge = currentEdge != null ? currentEdge : null; + String edgeLabel = AtlasGraphUtilsV1.getEdgeLabel(ctx.getVertexProperty()); + AtlasEdge currentEdge = graphHelper.getEdgeForLabel(ctx.getReferringVertex(), edgeLabel); + AtlasEdge newEdge = null; - ctx.setElementType(instanceType); - ctx.setExistingEdge(edge); + if (ctx.getValue() != null) { + AtlasEntityType instanceType = getInstanceType(ctx.getValue()); + AtlasEdge edge = currentEdge != null ? currentEdge : null; + + ctx.setElementType(instanceType); + ctx.setExistingEdge(edge); - AtlasEdge newEdge = mapObjectIdValue(ctx, context); + newEdge = mapObjectIdValue(ctx, context); + } if (currentEdge != null && !currentEdge.equals(newEdge)) { deleteHandler.deleteEdgeReference(currentEdge, ctx.getAttrType().getTypeCategory(), ctx.getAttribute().isOwnedRef(), true); @@ -371,11 +375,14 @@ public class EntityGraphMapper { if (entityVertex == null) { AtlasObjectId objId = getObjectId(ctx.getValue()); - entityVertex = context.getDiscoveryContext().getResolvedEntityVertex(objId); + + if (objId != null) { + entityVertex = context.getDiscoveryContext().getResolvedEntityVertex(objId); + } } if (entityVertex == null) { - throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, ctx.getValue().toString()); + throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, (ctx.getValue() == null ? null : ctx.getValue().toString())); } if (ctx.getCurrentEdge() != null) { diff --git a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1Test.java b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1Test.java index 94d313f..47c9fc9 100644 --- a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1Test.java +++ b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1Test.java @@ -75,6 +75,7 @@ import static org.apache.atlas.TestUtils.randomString; import static org.apache.atlas.TestUtilsV2.TABLE_TYPE; import static org.mockito.Mockito.mock; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; @Guice(modules = RepositoryMetadataModule.class) @@ -811,6 +812,25 @@ public class AtlasEntityStoreV1Test { assertEquals(col3.getAttribute("description"), updatedCol3Entity.getAttribute("description")); } + @Test + public void testSetObjectIdAttrToNull() throws Exception { + final AtlasEntity dbEntity = TestUtilsV2.createDBEntity(); + EntityMutationResponse dbCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false); + final AtlasEntity tableEntity = TestUtilsV2.createTableEntity(dbEntity); + final EntityMutationResponse tblCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(tableEntity), false); + final AtlasEntityHeader createdTblHeader = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(TABLE_TYPE, NAME, (String) tableEntity.getAttribute(NAME)); + final AtlasEntity createdTblEntity = getEntityFromStore(createdTblHeader); + + init(); + + createdTblEntity.setAttribute("database", null); + + final EntityMutationResponse tblUpdateResponse = entityStore.createOrUpdate(new AtlasEntityStream(createdTblEntity), true); + final AtlasEntityHeader updatedTblHeader = tblUpdateResponse.getFirstEntityPartialUpdated(); + final AtlasEntity updatedTblEntity = getEntityFromStore(updatedTblHeader); + + assertNull(updatedTblEntity.getAttribute("database")); + } private String randomStrWithReservedChars() { return randomString() + "\"${}%"; -- libgit2 0.27.1