-
Notifications
You must be signed in to change notification settings - Fork 900
ATLAS-2933:Empty array attributes are returned as null instead of an empty list #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -725,6 +725,10 @@ private List<AtlasObjectId> mapVertexToArrayForSoftRef(AtlasVertex entityVertex, | |
| List<AtlasObjectId> ret = null; | ||
| List softRefVal = entityVertex.getListProperty(attribute.getVertexPropertyName(), List.class); | ||
|
|
||
| if (CollectionUtils.isEmpty(softRefVal)) { | ||
| return softRefVal; | ||
| } | ||
|
|
||
| if (CollectionUtils.isNotEmpty(softRefVal)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. replace line #732 with: "else {", as the reverse condition is already tested in line #728 above. |
||
| ret = new ArrayList<>(); | ||
|
|
||
|
|
@@ -822,7 +826,7 @@ private List<Object> mapVertexToArray(AtlasVertex entityVertex, AtlasEntityExtIn | |
| List<Object> arrayElements = getArrayElementsProperty(arrayElementType, entityVertex, attribute); | ||
|
|
||
| if (CollectionUtils.isEmpty(arrayElements)) { | ||
| return null; | ||
| return arrayElements; | ||
| } | ||
|
|
||
| if (LOG.isDebugEnabled()) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ | |
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.Date; | ||
| import java.util.HashMap; | ||
| import java.util.Iterator; | ||
|
|
@@ -48,31 +49,37 @@ | |
| import static org.apache.atlas.TestUtilsV2.ENTITY_TYPE_MAP; | ||
| import static org.apache.atlas.TestUtilsV2.ENTITY_TYPE_WITH_COMPLEX_COLLECTION_ATTR; | ||
| import static org.apache.atlas.TestUtilsV2.ENTITY_TYPE_WITH_COMPLEX_COLLECTION_ATTR_DELETE; | ||
| import static org.apache.atlas.TestUtilsV2.ENTITY_TYPE_WITH_NESTED_COLLECTION_ATTR; | ||
| import static org.apache.atlas.TestUtilsV2.NAME; | ||
| import static org.apache.atlas.repository.graph.GraphHelper.getStatus; | ||
| import static org.apache.atlas.type.AtlasTypeUtil.getAtlasObjectId; | ||
| import static org.testng.Assert.assertNull; | ||
| import static org.testng.Assert.assertFalse; | ||
| import static org.testng.Assert.assertTrue; | ||
| import static org.testng.AssertJUnit.assertEquals; | ||
|
|
||
| @Guice(modules = TestModules.TestOnlyModule.class) | ||
| public class AtlasComplexAttributesTest extends AtlasEntityTestBase { | ||
| private AtlasEntityWithExtInfo complexCollectionAttrEntity; | ||
| private AtlasEntityWithExtInfo complexCollectionAttrEntityForDelete; | ||
| private AtlasEntityWithExtInfo mapAttributesEntity; | ||
| private AtlasEntityWithExtInfo nestedCollectionAttrEntity; | ||
|
|
||
| @BeforeClass | ||
| public void setUp() throws Exception { | ||
| super.setUp(); | ||
|
|
||
| // create typeDefs | ||
| AtlasTypesDef[] testTypesDefs = new AtlasTypesDef[] { TestUtilsV2.defineTypeWithComplexCollectionAttributes(), | ||
| TestUtilsV2.defineTypeWithMapAttributes() }; | ||
| TestUtilsV2.defineTypeWithMapAttributes(), | ||
| TestUtilsV2.defineTypeWithNestedCollectionAttributes()}; | ||
| createTypesDef(testTypesDefs); | ||
|
|
||
| // create entity | ||
| complexCollectionAttrEntity = TestUtilsV2.createComplexCollectionAttrEntity(); | ||
| complexCollectionAttrEntityForDelete = TestUtilsV2.createComplexCollectionAttrEntity(); | ||
| mapAttributesEntity = TestUtilsV2.createMapAttrEntity(); | ||
| nestedCollectionAttrEntity = TestUtilsV2.createNestedCollectionAttrEntity(); | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -195,6 +202,39 @@ private void updateEntityMapAttributes(AtlasEntity attrEntity, Map<String, Strin | |
| attrEntity.setAttribute("mapAttr5", map5); | ||
| } | ||
|
|
||
| @Test | ||
| public void testEmptyArrayAttribute() throws Exception { | ||
| init(); | ||
| AtlasEntity nestedEntity = nestedCollectionAttrEntity.getEntity(); | ||
|
|
||
| // set the attribute - arrayOfArrayOfStrings of the nestedEntity to | ||
| // an empty list. Expected behavior is that retrieved entity will | ||
| // have the value of this field as an empty list instead of null. | ||
| nestedEntity.setAttribute("arrayOfArrayOfStrings", Collections.emptyList()); | ||
| AtlasEntitiesWithExtInfo nestedEntitiesInfo = new AtlasEntitiesWithExtInfo(nestedEntity); | ||
|
|
||
| EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(nestedEntitiesInfo), false); | ||
| AtlasEntityHeader updatedNestedEntity = response.getFirstCreatedEntityByTypeName(ENTITY_TYPE_WITH_NESTED_COLLECTION_ATTR); | ||
| validateEntity(nestedEntitiesInfo, getEntityFromStore(updatedNestedEntity)); | ||
| } | ||
|
|
||
| @Test(dependsOnMethods = "testCreateComplexAttributeEntity") | ||
| public void testNullArrayAttribute() throws Exception { | ||
| init(); | ||
|
|
||
| // set the attribute - listOfStructs of the complexEntity to null. | ||
| // Expected behavior is that the retrieved entity will | ||
| // not have the attribute of listOfStructs. | ||
| AtlasEntity complexEntity = getEntityFromStore(complexCollectionAttrEntity.getEntity().getGuid()); | ||
| assertTrue(complexEntity.getAttributes().containsKey("listOfStructs")); | ||
|
|
||
| complexEntity.setAttribute("listOfStructs", null); | ||
| AtlasEntitiesWithExtInfo complexEntityInfo = new AtlasEntitiesWithExtInfo(complexEntity); | ||
| EntityMutationResponse responseUpdated = entityStore.createOrUpdate(new AtlasEntityStream(complexEntityInfo), false); | ||
| AtlasEntityHeader updatedComplexEntity = responseUpdated.getFirstUpdatedEntityByTypeName(ENTITY_TYPE_WITH_COMPLEX_COLLECTION_ATTR); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updatedComplexEntity is a AtlasEntityHeader - which will not have all attributes of an entity, hence the asset at line #235 passes. Please get an entire entity and use that in assert: |
||
| assertFalse(updatedComplexEntity.getAttributes().containsKey("listOfStructs")); | ||
| } | ||
|
|
||
| @Test(dependsOnMethods = "testCreateComplexAttributeEntity") | ||
| public void testStructArray() throws Exception { | ||
| init(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider the following alternate, for easier readability: