You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ma...@apache.org on 2019/06/27 13:53:31 UTC

[atlas] branch branch-0.8 updated: ATLAS-3049: updates to avoid repeated calls to encode-property-key

This is an automated email from the ASF dual-hosted git repository.

madhan pushed a commit to branch branch-0.8
in repository https://gitbox.apache.org/repos/asf/atlas.git


The following commit(s) were added to refs/heads/branch-0.8 by this push:
     new b58a679  ATLAS-3049: updates to avoid repeated calls to encode-property-key
b58a679 is described below

commit b58a679ffc70c35e900344be44acc65e9d6649ab
Author: Madhan Neethiraj <ma...@apache.org>
AuthorDate: Thu Feb 7 22:31:23 2019 -0800

    ATLAS-3049: updates to avoid repeated calls to encode-property-key
---
 .../java/org/apache/atlas/type/AtlasTypeUtil.java  |  4 +--
 .../apache/atlas/discovery/SearchProcessor.java    |  2 +-
 .../graph/GraphBackedMetadataRepository.java       |  5 +---
 .../graph/GraphToTypedInstanceMapper.java          | 29 +++++++++++-----------
 .../store/graph/v1/AtlasEntityStoreV1.java         |  2 +-
 .../store/graph/v1/AtlasGraphUtilsV1.java          | 12 ---------
 .../org/apache/atlas/util/SearchPredicateUtil.java |  2 +-
 .../typesystem/types/AttributeDefinition.java      |  9 +++++++
 .../atlas/typesystem/types/AttributeInfo.java      |  9 +++++++
 .../typesystem/types/StructTypeDefinition.java     | 12 +++++++++
 10 files changed, 50 insertions(+), 36 deletions(-)

diff --git a/intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java b/intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java
index ca38857..c738491 100644
--- a/intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java
+++ b/intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java
@@ -357,7 +357,7 @@ public class AtlasTypeUtil {
     }
 
     public static boolean isValidGuid(String guid) {
-        return isAssignedGuid(guid) || isUnAssignedGuid(guid);
+        return guid != null && (isUnAssignedGuid(guid) || isAssignedGuid(guid));
     }
 
     public static boolean isAssignedGuid(String guid) {
@@ -377,7 +377,7 @@ public class AtlasTypeUtil {
     }
 
     public static boolean isValid(AtlasObjectId objId) {
-        if (isAssignedGuid(objId) || isUnAssignedGuid(objId)) {
+        if (isUnAssignedGuid(objId) || isAssignedGuid(objId)) {
             return true;
         } else if (StringUtils.isNotEmpty(objId.getTypeName()) && MapUtils.isNotEmpty(objId.getUniqueAttributes())) {
             return true;
diff --git a/repository/src/main/java/org/apache/atlas/discovery/SearchProcessor.java b/repository/src/main/java/org/apache/atlas/discovery/SearchProcessor.java
index e8249eb..fab7074 100644
--- a/repository/src/main/java/org/apache/atlas/discovery/SearchProcessor.java
+++ b/repository/src/main/java/org/apache/atlas/discovery/SearchProcessor.java
@@ -523,7 +523,7 @@ public abstract class SearchProcessor {
                     break;
             }
 
-            ret = predicate.generatePredicate(attribute.getQualifiedName(), attrValue, attrClass);
+            ret = predicate.generatePredicate(attribute.getVertexPropertyName(), attrValue, attrClass);
         }
 
         return ret;
diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java
index 10c7f3e..61e1623 100755
--- a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java
+++ b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java
@@ -121,10 +121,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
 
     @Override
     public String getFieldNameInVertex(IDataType<?> dataType, AttributeInfo aInfo) throws AtlasException {
-        if (aInfo.name.startsWith(Constants.INTERNAL_PROPERTY_KEY_PREFIX)) {
-            return aInfo.name;
-        }
-        return AtlasGraphUtilsV1.encodePropertyKey(GraphHelper.getQualifiedFieldName(dataType, aInfo.name));
+        return aInfo.encodedVertexPropertyName;
     }
 
     public String getFieldNameInVertex(IDataType<?> dataType, String attrName) throws AtlasException {
diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/GraphToTypedInstanceMapper.java b/repository/src/main/java/org/apache/atlas/repository/graph/GraphToTypedInstanceMapper.java
index 638078c..e39ae4d 100644
--- a/repository/src/main/java/org/apache/atlas/repository/graph/GraphToTypedInstanceMapper.java
+++ b/repository/src/main/java/org/apache/atlas/repository/graph/GraphToTypedInstanceMapper.java
@@ -416,71 +416,71 @@ public final class GraphToTypedInstanceMapper {
 
         final Object ret;
 
-        final String vertexPropertyName = GraphHelper.getQualifiedFieldName(typedInstance, attributeInfo);
+        final String vertexPropertyName = attributeInfo.encodedVertexPropertyName;
 
-        if (AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName, Object.class) != null) {
+        if (AtlasGraphUtilsV1.getEncodedProperty(instanceVertex, vertexPropertyName, Object.class) != null) {
             if (attributeInfo.dataType() == DataTypes.STRING_TYPE) {
-                String attrValue = AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName, String.class);
+                String attrValue = AtlasGraphUtilsV1.getEncodedProperty(instanceVertex, vertexPropertyName, String.class);
 
                 typedInstance.setString(attributeInfo.name, attrValue);
 
                 ret = attrValue;
             } else if (attributeInfo.dataType() == DataTypes.SHORT_TYPE) {
-                Short attrValue = AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName, Short.class);
+                Short attrValue = AtlasGraphUtilsV1.getEncodedProperty(instanceVertex, vertexPropertyName, Short.class);
 
                 typedInstance.setShort(attributeInfo.name, attrValue);
 
                 ret = attrValue;
             } else if (attributeInfo.dataType() == DataTypes.INT_TYPE) {
-                Integer attrValue = AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName, Integer.class);
+                Integer attrValue = AtlasGraphUtilsV1.getEncodedProperty(instanceVertex, vertexPropertyName, Integer.class);
 
                 typedInstance.setInt(attributeInfo.name, attrValue);
 
                 ret = attrValue;
             } else if (attributeInfo.dataType() == DataTypes.BIGINTEGER_TYPE) {
-                BigInteger attrValue = AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName, BigInteger.class);
+                BigInteger attrValue = AtlasGraphUtilsV1.getEncodedProperty(instanceVertex, vertexPropertyName, BigInteger.class);
 
                 typedInstance.setBigInt(attributeInfo.name, attrValue);
 
                 ret = attrValue;
             } else if (attributeInfo.dataType() == DataTypes.BOOLEAN_TYPE) {
-                Boolean attrValue = AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName, Boolean.class);
+                Boolean attrValue = AtlasGraphUtilsV1.getEncodedProperty(instanceVertex, vertexPropertyName, Boolean.class);
 
                 typedInstance.setBoolean(attributeInfo.name, attrValue);
 
                 ret = attrValue;
             } else if (attributeInfo.dataType() == DataTypes.BYTE_TYPE) {
-                Byte attrValue = AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName, Byte.class);
+                Byte attrValue = AtlasGraphUtilsV1.getEncodedProperty(instanceVertex, vertexPropertyName, Byte.class);
 
                 typedInstance.setByte(attributeInfo.name, attrValue);
 
                 ret = attrValue;
             } else if (attributeInfo.dataType() == DataTypes.LONG_TYPE) {
-                Long attrValue = AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName, Long.class);
+                Long attrValue = AtlasGraphUtilsV1.getEncodedProperty(instanceVertex, vertexPropertyName, Long.class);
 
                 typedInstance.setLong(attributeInfo.name, attrValue);
 
                 ret = attrValue;
             } else if (attributeInfo.dataType() == DataTypes.FLOAT_TYPE) {
-                Float attrValue = AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName, Float.class);
+                Float attrValue = AtlasGraphUtilsV1.getEncodedProperty(instanceVertex, vertexPropertyName, Float.class);
 
                 typedInstance.setFloat(attributeInfo.name, attrValue);
 
                 ret = attrValue;
             } else if (attributeInfo.dataType() == DataTypes.DOUBLE_TYPE) {
-                Double attrValue = AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName, Double.class);
+                Double attrValue = AtlasGraphUtilsV1.getEncodedProperty(instanceVertex, vertexPropertyName, Double.class);
 
                 typedInstance.setDouble(attributeInfo.name, attrValue);
 
                 ret = attrValue;
             } else if (attributeInfo.dataType() == DataTypes.BIGDECIMAL_TYPE) {
-                BigDecimal attrValue = AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName, BigDecimal.class);
+                BigDecimal attrValue = AtlasGraphUtilsV1.getEncodedProperty(instanceVertex, vertexPropertyName, BigDecimal.class);
 
                 typedInstance.setBigDecimal(attributeInfo.name, attrValue);
 
                 ret = attrValue;
             } else if (attributeInfo.dataType() == DataTypes.DATE_TYPE) {
-                final Long dateVal   = AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName, Long.class);
+                final Long dateVal   = AtlasGraphUtilsV1.getEncodedProperty(instanceVertex, vertexPropertyName, Long.class);
                 Date       attrValue = new Date(dateVal);
 
                 typedInstance.setDate(attributeInfo.name, attrValue);
@@ -497,8 +497,7 @@ public final class GraphToTypedInstanceMapper {
     }
 
     public static Object mapVertexToEnum(AtlasVertex<?,?> instanceVertex, ITypedInstance typedInstance, AttributeInfo attributeInfo) throws AtlasException {
-        final String vertexPropertyName = GraphHelper.getQualifiedFieldName(typedInstance, attributeInfo);
-        final Object propertyValue      = AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName);
+        final Object propertyValue = AtlasGraphUtilsV1.getEncodedProperty(instanceVertex, attributeInfo.encodedVertexPropertyName);
         final Object ret;
 
         if (propertyValue != null) {
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java
index 96b7667..39c763f 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java
@@ -242,8 +242,8 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
                         }
 
                         Object currVal = entityRetriever.getEntityAttribute(vertex, attribute);
-
                         Object newVal  = entity.getAttribute(attribute.getName());
+
                         if (!attribute.getAttributeType().areEqualValues(currVal, newVal, context.getGuidAssignments())) {
                             hasUpdates = true;
 
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasGraphUtilsV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasGraphUtilsV1.java
index bd3ba3c..bf46c47 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasGraphUtilsV1.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasGraphUtilsV1.java
@@ -174,8 +174,6 @@ public class AtlasGraphUtilsV1 {
             LOG.debug("==> setProperty({}, {}, {})", toString(element), propertyName, value);
         }
 
-        propertyName = encodePropertyKey(propertyName);
-
         Object existingValue = element.getProperty(propertyName, Object.class);
 
         if (value == null || (value instanceof Collection && ((Collection)value).isEmpty())) {
@@ -202,16 +200,6 @@ public class AtlasGraphUtilsV1 {
         }
     }
 
-    public static <T extends AtlasVertex> Object getProperty(T vertex, String propertyName) {
-        String encodePropertyName = encodePropertyKey(propertyName);
-
-        if(AtlasGraphProvider.getGraphInstance().isMultiProperty(encodePropertyName)) {
-            return vertex.getPropertyValues(encodePropertyName, String.class);
-        }
-
-        return vertex.getProperty(encodePropertyName, Object.class);
-    }
-
     public static <T extends AtlasElement, O> O getProperty(T element, String propertyName, Class<O> returnType) {
         return getEncodedProperty(element, encodePropertyKey(propertyName), returnType);
     }
diff --git a/repository/src/main/java/org/apache/atlas/util/SearchPredicateUtil.java b/repository/src/main/java/org/apache/atlas/util/SearchPredicateUtil.java
index 6f55485..0a1aad3 100644
--- a/repository/src/main/java/org/apache/atlas/util/SearchPredicateUtil.java
+++ b/repository/src/main/java/org/apache/atlas/util/SearchPredicateUtil.java
@@ -680,7 +680,7 @@ public class SearchPredicateUtil {
                 if (Collection.class.isAssignableFrom(attrClass)) {
                     attrValue = vertex.getPropertyValues(attrName, attrClass);
                 } else {
-                    attrValue = AtlasGraphUtilsV1.getProperty(vertex, attrName, attrClass);
+                    attrValue = AtlasGraphUtilsV1.getEncodedProperty(vertex, attrName, attrClass);
                 }
 
                 ret = (isNullValid || attrValue != null) && compareValue(attrValue);
diff --git a/typesystem/src/main/java/org/apache/atlas/typesystem/types/AttributeDefinition.java b/typesystem/src/main/java/org/apache/atlas/typesystem/types/AttributeDefinition.java
index 370d43d..29f1148 100755
--- a/typesystem/src/main/java/org/apache/atlas/typesystem/types/AttributeDefinition.java
+++ b/typesystem/src/main/java/org/apache/atlas/typesystem/types/AttributeDefinition.java
@@ -31,6 +31,7 @@ public final class AttributeDefinition {
     public final boolean isComposite;
     public final boolean isUnique;
     public final boolean isIndexable;
+    private      String  qualifiedName;
 
     /**
      * If this is a reference attribute, then the name of the attribute on the Class
@@ -56,6 +57,14 @@ public final class AttributeDefinition {
         this.reverseAttributeName = ParamChecker.notEmptyIfNotNull(reverseAttributeName, "Reverse attribute name");
     }
 
+    public void setDefinedInTypeName(String definedInTypeName) {
+        this.qualifiedName = name.contains(".") ? name : String.format("%s.%s", definedInTypeName, name);
+    }
+
+    public String getQualifiedName() {
+        return qualifiedName;
+    }
+
     @Override
     public boolean equals(Object o) {
         if (this == o) return true;
diff --git a/typesystem/src/main/java/org/apache/atlas/typesystem/types/AttributeInfo.java b/typesystem/src/main/java/org/apache/atlas/typesystem/types/AttributeInfo.java
index 59d98e2..6d801af 100755
--- a/typesystem/src/main/java/org/apache/atlas/typesystem/types/AttributeInfo.java
+++ b/typesystem/src/main/java/org/apache/atlas/typesystem/types/AttributeInfo.java
@@ -19,6 +19,8 @@
 package org.apache.atlas.typesystem.types;
 
 import org.apache.atlas.AtlasException;
+import org.apache.atlas.repository.Constants;
+import org.apache.atlas.type.AtlasStructType;
 import org.apache.atlas.type.AtlasType;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
@@ -42,6 +44,7 @@ public class AttributeInfo {
      */
     public final String reverseAttributeName;
     public final boolean isSoftRef;
+    public final String encodedVertexPropertyName;
     private IDataType dataType;
 
     public AttributeInfo(TypeSystem t, AttributeDefinition def, Map<String, IDataType> tempTypes) throws AtlasException {
@@ -55,6 +58,12 @@ public class AttributeInfo {
         this.isIndexable = def.isIndexable;
         this.reverseAttributeName = def.reverseAttributeName;
         this.isSoftRef = def.isSoftRef;
+
+        if (name.startsWith(Constants.INTERNAL_PROPERTY_KEY_PREFIX)) {
+            this.encodedVertexPropertyName = name;
+        } else {
+            this.encodedVertexPropertyName = AtlasStructType.AtlasAttribute.encodePropertyKey(def.getQualifiedName());
+        }
     }
 
     public IDataType dataType() {
diff --git a/typesystem/src/main/java/org/apache/atlas/typesystem/types/StructTypeDefinition.java b/typesystem/src/main/java/org/apache/atlas/typesystem/types/StructTypeDefinition.java
index 4f8695b..7886692 100755
--- a/typesystem/src/main/java/org/apache/atlas/typesystem/types/StructTypeDefinition.java
+++ b/typesystem/src/main/java/org/apache/atlas/typesystem/types/StructTypeDefinition.java
@@ -45,6 +45,14 @@ public class StructTypeDefinition {
         }
         this.attributeDefinitions = attributeDefinitions;
         this.typeVersion = typeVersion;
+
+        if (this.attributeDefinitions != null) {
+            for (AttributeDefinition attrDef : this.attributeDefinitions) {
+                if (attrDef != null) {
+                    attrDef.setDefinedInTypeName(typeName);
+                }
+            }
+        }
     }
 
     public StructTypeDefinition(String typeName, AttributeDefinition[] attributeDefinitions) {
@@ -63,6 +71,10 @@ public class StructTypeDefinition {
         this.typeDescription = typeDescription;
         this.typeVersion = typeVersion;
         this.attributeDefinitions = ParamChecker.notNullElements(attributeDefinitions, "Attribute definitions");
+
+        for (AttributeDefinition attrDef : this.attributeDefinitions) {
+            attrDef.setDefinedInTypeName(typeName);
+        }
     }