Repository: atlas Updated Branches: refs/heads/branch-1.0 905cdc226 -> 3483b71c7
ATLAS-2836: Remove redundant encoding of vertex property keys - #2 (cherry picked from commit 9c45d2e8e88b8845330632ad2a164448c13840fd) Project: http://git-wip-us.apache.org/repos/asf/atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/3483b71c Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/3483b71c Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/3483b71c Branch: refs/heads/branch-1.0 Commit: 3483b71c7f13164ea8fbaf7e16050f503f2e460e Parents: 905cdc2 Author: Madhan Neethiraj <mad...@apache.org> Authored: Sun Aug 26 14:43:11 2018 -0700 Committer: Madhan Neethiraj <mad...@apache.org> Committed: Sun Aug 26 19:10:45 2018 -0700 ---------------------------------------------------------------------- .../atlas/repository/graph/GraphHelper.java | 108 ------------------- .../store/graph/v2/EntityGraphMapper.java | 2 +- .../store/graph/v2/EntityGraphRetriever.java | 41 ++++--- .../migration/MigrationBaseAsserts.java | 16 +-- .../atlas/repository/migration/PathTest.java | 5 +- 5 files changed, 33 insertions(+), 139 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/atlas/blob/3483b71c/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java b/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java index 19069ba..7885da3 100755 --- a/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java +++ b/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java @@ -646,83 +646,6 @@ public final class GraphHelper { + edge.getInVertex() + "]"; } - public static <T extends AtlasElement> void setProperty(T element, String propertyName, Object value) { - String actualPropertyName = AtlasGraphUtilsV2.encodePropertyKey(propertyName); - - String elementStr = null; - - if (LOG.isDebugEnabled()) { - elementStr = string(element); - - LOG.debug("Setting property {} = \"{}\" to {}", actualPropertyName, value, elementStr); - } - - Object existValue = element.getProperty(actualPropertyName, Object.class); - if(value == null || (value instanceof Collection && ((Collection) value).isEmpty())) { - if(existValue != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("Removing property - {} value from {}", actualPropertyName, elementStr); - } - - element.removeProperty(actualPropertyName); - } - } else { - if (!value.equals(existValue)) { - element.setProperty(actualPropertyName, value); - - if (LOG.isDebugEnabled()) { - LOG.debug("Set property {} = \"{}\" to {}", actualPropertyName, value, elementStr); - } - } - } - } - - /** - * Gets the value of a property that is stored in the graph as a single property value. If - * a multi-property such as {@link Constants#TRAIT_NAMES_PROPERTY_KEY} or {@link Constants#SUPER_TYPES_PROPERTY_KEY} - * is used, an exception will be thrown. - * - * @param element - * @param propertyName - * @param clazz - * @return - */ - public static <T> T getSingleValuedProperty(AtlasElement element, String propertyName, Class<T> clazz) { - String actualPropertyName = AtlasGraphUtilsV2.encodePropertyKey(propertyName); - - if (LOG.isTraceEnabled()) { - LOG.trace("Reading property {} from {}", actualPropertyName, string(element)); - } - - return element.getProperty(actualPropertyName, clazz); - } - - - public static Object getProperty(AtlasVertex<?,?> vertex, String propertyName) { - String actualPropertyName = AtlasGraphUtilsV2.encodePropertyKey(propertyName); - - if (LOG.isTraceEnabled()) { - LOG.trace("Reading property {} from {}", actualPropertyName, string(vertex)); - } - - if(AtlasGraphProvider.getGraphInstance().isMultiProperty(actualPropertyName)) { - return vertex.getPropertyValues(actualPropertyName, String.class); - } - else { - return vertex.getProperty(actualPropertyName, Object.class); - } - } - - public static Object getProperty(AtlasEdge<?,?> edge, String propertyName) { - String actualPropertyName = AtlasGraphUtilsV2.encodePropertyKey(propertyName); - - if (LOG.isTraceEnabled()) { - LOG.trace("Reading property {} from {}", actualPropertyName, string(edge)); - } - - return edge.getProperty(actualPropertyName, Object.class); - } - private static <T extends AtlasElement> String string(T element) { if (element instanceof AtlasVertex) { return string((AtlasVertex) element); @@ -732,23 +655,6 @@ public final class GraphHelper { return element.toString(); } - /** - * Adds an additional value to a multi-property (SET). - * - * @param vertex - * @param propertyName - * @param value - */ - public static void addProperty(AtlasVertex vertex, String propertyName, Object value) { - String actualPropertyName = AtlasGraphUtilsV2.encodePropertyKey(propertyName); - - if (LOG.isDebugEnabled()) { - LOG.debug("Adding property {} = \"{}\" to vertex {}", actualPropertyName, value, string(vertex)); - } - - vertex.addProperty(actualPropertyName, value); - } - public static void addToPropagatedTraitNames(AtlasVertex entityVertex, String classificationName) { if (LOG.isDebugEnabled()) { LOG.debug("Adding property {} = \"{}\" to vertex {}", PROPAGATED_TRAIT_NAMES_PROPERTY_KEY, classificationName, string(entityVertex)); @@ -757,20 +663,6 @@ public final class GraphHelper { entityVertex.addListProperty(PROPAGATED_TRAIT_NAMES_PROPERTY_KEY, classificationName); } - public static void removeFromPropagatedTraitNames(AtlasVertex entityVertex, String classificationName) { - if (entityVertex != null && StringUtils.isNotEmpty(classificationName)) { - List<String> propagatedTraitNames = getTraitNames(entityVertex, true); - - propagatedTraitNames.remove(classificationName); - - entityVertex.removeProperty(PROPAGATED_TRAIT_NAMES_PROPERTY_KEY); - - for (String propagatedTraitName : propagatedTraitNames) { - addToPropagatedTraitNames(entityVertex, propagatedTraitName); - } - } - } - /** * Remove the specified edge from the graph. * http://git-wip-us.apache.org/repos/asf/atlas/blob/3483b71c/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java index 9496946..c0a868c 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java @@ -961,7 +961,7 @@ public class EntityGraphMapper { Object element = newElementsCreated.get(index); if (element instanceof AtlasEdge) { - AtlasGraphUtilsV2.setProperty((AtlasEdge) element, ATTRIBUTE_INDEX_PROPERTY_KEY, index); + AtlasGraphUtilsV2.setEncodedProperty((AtlasEdge) element, ATTRIBUTE_INDEX_PROPERTY_KEY, index); } } http://git-wip-us.apache.org/repos/asf/atlas/blob/3483b71c/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java index 625f776..f0bb73b 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java @@ -588,7 +588,7 @@ public final class EntityGraphRetriever { ret.setRelationGuid(relationGuid); } - Object displayName = GraphHelper.getProperty(termVertex, GLOSSARY_TERM_DISPLAY_NAME_ATTR); + Object displayName = AtlasGraphUtilsV2.getEncodedProperty(termVertex, GLOSSARY_TERM_DISPLAY_NAME_ATTR, Object.class); if (displayName instanceof String) { ret.setDisplayText((String) displayName); } @@ -651,8 +651,7 @@ public final class EntityGraphRetriever { private Object mapVertexToAttribute(AtlasVertex entityVertex, AtlasAttribute attribute, AtlasEntityExtInfo entityExtInfo, final boolean isMinExtInfo) throws AtlasBaseException { Object ret = null; AtlasType attrType = attribute.getAttributeType(); - String vertexPropertyName = attribute.getQualifiedName(); - String edgeLabel = EDGE_LABEL_PREFIX + vertexPropertyName; + String edgeLabel = EDGE_LABEL_PREFIX + attribute.getQualifiedName(); boolean isOwnedAttribute = attribute.isOwnedRef(); AtlasRelationshipEdgeDirection edgeDirection = attribute.getRelationshipEdgeDirection(); @@ -662,10 +661,10 @@ public final class EntityGraphRetriever { switch (attrType.getTypeCategory()) { case PRIMITIVE: - ret = mapVertexToPrimitive(entityVertex, vertexPropertyName, attribute.getAttributeDef()); + ret = mapVertexToPrimitive(entityVertex, attribute.getVertexPropertyName(), attribute.getAttributeDef()); break; case ENUM: - ret = GraphHelper.getProperty(entityVertex, vertexPropertyName); + ret = AtlasGraphUtilsV2.getEncodedProperty(entityVertex, attribute.getVertexPropertyName(), Object.class); break; case STRUCT: ret = mapVertexToStruct(entityVertex, edgeLabel, null, entityExtInfo, isMinExtInfo); @@ -677,7 +676,7 @@ public final class EntityGraphRetriever { ret = mapVertexToArray(entityVertex, entityExtInfo, isOwnedAttribute, attribute, isMinExtInfo); break; case MAP: - ret = mapVertexToMap(entityVertex, vertexPropertyName, entityExtInfo, isOwnedAttribute, attribute, isMinExtInfo); + ret = mapVertexToMap(entityVertex, entityExtInfo, isOwnedAttribute, attribute, isMinExtInfo); break; case CLASSIFICATION: // do nothing @@ -687,7 +686,7 @@ public final class EntityGraphRetriever { return ret; } - private Map<String, Object> mapVertexToMap(AtlasVertex entityVertex, final String propertyName, AtlasEntityExtInfo entityExtInfo, + private Map<String, Object> mapVertexToMap(AtlasVertex entityVertex, AtlasEntityExtInfo entityExtInfo, boolean isOwnedAttribute, AtlasAttribute attribute, final boolean isMinExtInfo) throws AtlasBaseException { Map<String, Object> ret = null; @@ -715,7 +714,7 @@ public final class EntityGraphRetriever { } } } else { - ret = getPrimitiveMap(entityVertex, propertyName); + ret = getPrimitiveMap(entityVertex, attribute.getVertexPropertyName()); } if (MapUtils.isEmpty(ret)) { @@ -797,43 +796,43 @@ public final class EntityGraphRetriever { public Object mapVertexToPrimitive(AtlasElement entityVertex, final String vertexPropertyName, AtlasAttributeDef attrDef) { Object ret = null; - if (GraphHelper.getSingleValuedProperty(entityVertex, vertexPropertyName, Object.class) == null) { + if (AtlasGraphUtilsV2.getEncodedProperty(entityVertex, vertexPropertyName, Object.class) == null) { return null; } switch (attrDef.getTypeName().toLowerCase()) { case ATLAS_TYPE_STRING: - ret = GraphHelper.getSingleValuedProperty(entityVertex, vertexPropertyName, String.class); + ret = AtlasGraphUtilsV2.getEncodedProperty(entityVertex, vertexPropertyName, String.class); break; case ATLAS_TYPE_SHORT: - ret = GraphHelper.getSingleValuedProperty(entityVertex, vertexPropertyName, Short.class); + ret = AtlasGraphUtilsV2.getEncodedProperty(entityVertex, vertexPropertyName, Short.class); break; case ATLAS_TYPE_INT: - ret = GraphHelper.getSingleValuedProperty(entityVertex, vertexPropertyName, Integer.class); + ret = AtlasGraphUtilsV2.getEncodedProperty(entityVertex, vertexPropertyName, Integer.class); break; case ATLAS_TYPE_BIGINTEGER: - ret = GraphHelper.getSingleValuedProperty(entityVertex, vertexPropertyName, BigInteger.class); + ret = AtlasGraphUtilsV2.getEncodedProperty(entityVertex, vertexPropertyName, BigInteger.class); break; case ATLAS_TYPE_BOOLEAN: - ret = GraphHelper.getSingleValuedProperty(entityVertex, vertexPropertyName, Boolean.class); + ret = AtlasGraphUtilsV2.getEncodedProperty(entityVertex, vertexPropertyName, Boolean.class); break; case ATLAS_TYPE_BYTE: - ret = GraphHelper.getSingleValuedProperty(entityVertex, vertexPropertyName, Byte.class); + ret = AtlasGraphUtilsV2.getEncodedProperty(entityVertex, vertexPropertyName, Byte.class); break; case ATLAS_TYPE_LONG: - ret = GraphHelper.getSingleValuedProperty(entityVertex, vertexPropertyName, Long.class); + ret = AtlasGraphUtilsV2.getEncodedProperty(entityVertex, vertexPropertyName, Long.class); break; case ATLAS_TYPE_FLOAT: - ret = GraphHelper.getSingleValuedProperty(entityVertex, vertexPropertyName, Float.class); + ret = AtlasGraphUtilsV2.getEncodedProperty(entityVertex, vertexPropertyName, Float.class); break; case ATLAS_TYPE_DOUBLE: - ret = GraphHelper.getSingleValuedProperty(entityVertex, vertexPropertyName, Double.class); + ret = AtlasGraphUtilsV2.getEncodedProperty(entityVertex, vertexPropertyName, Double.class); break; case ATLAS_TYPE_BIGDECIMAL: - ret = GraphHelper.getSingleValuedProperty(entityVertex, vertexPropertyName, BigDecimal.class); + ret = AtlasGraphUtilsV2.getEncodedProperty(entityVertex, vertexPropertyName, BigDecimal.class); break; case ATLAS_TYPE_DATE: - ret = new Date(GraphHelper.getSingleValuedProperty(entityVertex, vertexPropertyName, Long.class)); + ret = new Date(AtlasGraphUtilsV2.getEncodedProperty(entityVertex, vertexPropertyName, Long.class)); break; default: break; @@ -1157,7 +1156,7 @@ public final class EntityGraphRetriever { for (AtlasAttribute attribute : relationshipType.getAllAttributes().values()) { // mapping only primitive attributes - Object attrValue = mapVertexToPrimitive(edge, attribute.getQualifiedName(), attribute.getAttributeDef()); + Object attrValue = mapVertexToPrimitive(edge, attribute.getVertexPropertyName(), attribute.getAttributeDef()); relationship.setAttribute(attribute.getName(), attrValue); } http://git-wip-us.apache.org/repos/asf/atlas/blob/3483b71c/repository/src/test/java/org/apache/atlas/repository/migration/MigrationBaseAsserts.java ---------------------------------------------------------------------- diff --git a/repository/src/test/java/org/apache/atlas/repository/migration/MigrationBaseAsserts.java b/repository/src/test/java/org/apache/atlas/repository/migration/MigrationBaseAsserts.java index 632fa8c..5077cf0 100644 --- a/repository/src/test/java/org/apache/atlas/repository/migration/MigrationBaseAsserts.java +++ b/repository/src/test/java/org/apache/atlas/repository/migration/MigrationBaseAsserts.java @@ -25,6 +25,7 @@ import org.apache.atlas.repository.graph.GraphBackedSearchIndexer; import org.apache.atlas.repository.graph.GraphHelper; import org.apache.atlas.repository.graphdb.*; import org.apache.atlas.repository.store.bootstrap.AtlasTypeDefStoreInitializer; +import org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2; import org.apache.atlas.runner.LocalSolrRunner; import org.apache.atlas.store.AtlasTypeDefStore; import org.apache.atlas.type.AtlasTypeRegistry; @@ -143,11 +144,11 @@ public class MigrationBaseAsserts { e = it.next(); } - assertNotNull(GraphHelper.getProperty(e, R_GUID_PROPERTY_NAME)); - assertNotNull(GraphHelper.getProperty(e, "tagPropagation")); + assertNotNull(AtlasGraphUtilsV2.getEncodedProperty(e, R_GUID_PROPERTY_NAME, Object.class)); + assertNotNull(AtlasGraphUtilsV2.getEncodedProperty(e, "tagPropagation", Object.class)); if(StringUtils.isNotEmpty(edgeTypeName)) { - assertEquals(GraphHelper.getProperty(e, TYPE_NAME_PROPERTY), edgeTypeName, edgeTypeName); + assertEquals(AtlasGraphUtilsV2.getEncodedProperty(e, TYPE_NAME_PROPERTY, Object.class), edgeTypeName, edgeTypeName); } assertEquals(count, expectedItems, String.format("%s", edgeTypeName)); @@ -160,8 +161,8 @@ public class MigrationBaseAsserts { e = it.next(); } - assertNotNull(GraphHelper.getProperty(e, R_GUID_PROPERTY_NAME)); - assertNotNull(GraphHelper.getProperty(e, "tagPropagation")); + assertNotNull(AtlasGraphUtilsV2.getEncodedProperty(e, R_GUID_PROPERTY_NAME, Object.class)); + assertNotNull(AtlasGraphUtilsV2.getEncodedProperty(e, "tagPropagation", Object.class)); if(StringUtils.isNotEmpty(edgeTypeName)) { assertEquals(e.getLabel(), edgeTypeName, edgeTypeName); @@ -182,7 +183,7 @@ public class MigrationBaseAsserts { } if(StringUtils.isNotEmpty(name)) { - assertEquals(GraphHelper.getProperty(v, ASSERT_NAME_PROPERTY), name, name); + assertEquals(AtlasGraphUtilsV2.getEncodedProperty(v, ASSERT_NAME_PROPERTY, String.class), name, name); } count++; @@ -193,6 +194,7 @@ public class MigrationBaseAsserts { protected void assertMigrationStatus(int expectedTotalCount) { AtlasVertex v = getVertex("__MigrationStatus", ""); - assertEquals((long) GraphHelper.getProperty(v, "currentIndex"), expectedTotalCount); + + assertEquals(AtlasGraphUtilsV2.getEncodedProperty(v, "currentIndex", Number.class).intValue(), expectedTotalCount); } } http://git-wip-us.apache.org/repos/asf/atlas/blob/3483b71c/repository/src/test/java/org/apache/atlas/repository/migration/PathTest.java ---------------------------------------------------------------------- diff --git a/repository/src/test/java/org/apache/atlas/repository/migration/PathTest.java b/repository/src/test/java/org/apache/atlas/repository/migration/PathTest.java index c87d9a2..1b26ed2 100644 --- a/repository/src/test/java/org/apache/atlas/repository/migration/PathTest.java +++ b/repository/src/test/java/org/apache/atlas/repository/migration/PathTest.java @@ -24,6 +24,7 @@ import org.apache.atlas.repository.graph.GraphHelper; import org.apache.atlas.repository.graphdb.AtlasGraph; import org.apache.atlas.repository.graphdb.AtlasVertex; import org.apache.atlas.repository.graphdb.GraphDBMigrator; +import org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2; import org.apache.atlas.type.AtlasBuiltInTypes; import org.testng.annotations.Guice; import org.testng.annotations.Test; @@ -64,8 +65,8 @@ public class PathTest extends MigrationBaseAsserts { BigInteger bitExpected = bitRef.getNormalizedValue(612361213421234L); BigDecimal bdtExpected = bdtRef.getNormalizedValue(125353); - BigInteger bit = GraphHelper.getSingleValuedProperty(v, HASH_CODE_PROPERTY, BigInteger.class); - BigDecimal bdt = GraphHelper.getSingleValuedProperty(v, RETENTION_PROPERTY, BigDecimal.class); + BigInteger bit = AtlasGraphUtilsV2.getEncodedProperty(v, HASH_CODE_PROPERTY, BigInteger.class); + BigDecimal bdt = AtlasGraphUtilsV2.getEncodedProperty(v, RETENTION_PROPERTY, BigDecimal.class); assertEquals(bit, bitExpected); assertEquals(bdt.compareTo(bdtExpected), 0);