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 2017/02/22 07:02:15 UTC

incubator-atlas git commit: ATLAS-1586: type search improvement by avoiding unnecessary instantiation of type objects

Repository: incubator-atlas
Updated Branches:
  refs/heads/master e7eaa9966 -> f5f9fa099


ATLAS-1586: type search improvement by avoiding unnecessary instantiation of type objects


Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/f5f9fa09
Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/f5f9fa09
Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/f5f9fa09

Branch: refs/heads/master
Commit: f5f9fa09948b2e5ade1a084b8063cd2bbe6e80a0
Parents: e7eaa99
Author: Madhan Neethiraj <ma...@apache.org>
Authored: Tue Feb 21 22:27:04 2017 -0800
Committer: Madhan Neethiraj <ma...@apache.org>
Committed: Tue Feb 21 22:27:04 2017 -0800

----------------------------------------------------------------------
 .../graph/AtlasClassificationDefStore.java      |  2 -
 .../store/graph/AtlasEntityDefStore.java        |  2 -
 .../store/graph/AtlasEnumDefStore.java          |  2 -
 .../store/graph/AtlasStructDefStore.java        |  2 -
 .../store/graph/AtlasTypeDefGraphStore.java     | 78 ++++----------------
 .../graph/v1/AtlasClassificationDefStoreV1.java | 28 -------
 .../store/graph/v1/AtlasEntityDefStoreV1.java   | 29 --------
 .../store/graph/v1/AtlasEnumDefStoreV1.java     | 29 --------
 .../store/graph/v1/AtlasStructDefStoreV1.java   | 29 --------
 .../atlas/repository/util/FilterUtil.java       | 48 ++----------
 10 files changed, 21 insertions(+), 228 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/f5f9fa09/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasClassificationDefStore.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasClassificationDefStore.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasClassificationDefStore.java
index ff00186..92a59f3 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasClassificationDefStore.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasClassificationDefStore.java
@@ -51,6 +51,4 @@ public interface AtlasClassificationDefStore {
     Object preDeleteByGuid(String guid) throws AtlasBaseException;
 
     void deleteByGuid(String guid, Object preDeleteResult) throws AtlasBaseException;
-
-    AtlasClassificationDefs search(SearchFilter filter) throws AtlasBaseException;
 }

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/f5f9fa09/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityDefStore.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityDefStore.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityDefStore.java
index 48f8bce..08391ba 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityDefStore.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityDefStore.java
@@ -51,6 +51,4 @@ public interface AtlasEntityDefStore {
     Object preDeleteByGuid(String guid) throws AtlasBaseException;
 
     void deleteByGuid(String guid, Object preDeleteResult) throws AtlasBaseException;
-
-    AtlasEntityDefs search(SearchFilter filter) throws AtlasBaseException;
 }

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/f5f9fa09/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEnumDefStore.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEnumDefStore.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEnumDefStore.java
index 217a927..d0f98e2 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEnumDefStore.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEnumDefStore.java
@@ -45,6 +45,4 @@ public interface AtlasEnumDefStore {
     void deleteByName(String name) throws AtlasBaseException;
 
     void deleteByGuid(String guid) throws AtlasBaseException;
-
-    AtlasEnumDefs search(SearchFilter filter) throws AtlasBaseException;
 }

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/f5f9fa09/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasStructDefStore.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasStructDefStore.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasStructDefStore.java
index fc3ffb5..ebd2b70 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasStructDefStore.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasStructDefStore.java
@@ -51,6 +51,4 @@ public interface AtlasStructDefStore {
     Object preDeleteByGuid(String name) throws AtlasBaseException;
 
     void deleteByGuid(String guid, Object preDeleteResult) throws AtlasBaseException;
-
-    AtlasStructDefs search(SearchFilter filter) throws AtlasBaseException;
 }

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/f5f9fa09/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java
index 0f5b726..084f09e 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java
@@ -552,79 +552,29 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ
     public AtlasTypesDef searchTypesDef(SearchFilter searchFilter) throws AtlasBaseException {
         final AtlasTypesDef typesDef = new AtlasTypesDef();
         Predicate searchPredicates = FilterUtil.getPredicateFromSearchFilter(searchFilter);
-        try {
-            List<AtlasEnumDef> enumDefs = getEnumDefStore(typeRegistry).getAll();
-            CollectionUtils.filter(enumDefs, searchPredicates);
-            typesDef.setEnumDefs(enumDefs);
-        } catch (AtlasBaseException ex) {
-            LOG.error("Failed to retrieve the EnumDefs", ex);
-        }
 
-        try {
-            List<AtlasStructDef> structDefs = getStructDefStore(typeRegistry).getAll();
-            Collection typeCollection = CollectionUtils.collect(structDefs, new Transformer() {
-                @Override
-                public Object transform(Object o) {
-                    try {
-                        return new AtlasStructType((AtlasStructDef) o, typeRegistry);
-                    } catch (AtlasBaseException e) {
-                        LOG.warn("Type validation failed for {}", ((AtlasStructDef) o).getName(), e);
-                        return null;
-                    }
-                }
-            });
-            CollectionUtils.filter(typeCollection, searchPredicates);
-            for (Object o : typeCollection) {
-                if (o != null)
-                    typesDef.getStructDefs().add(((AtlasStructType)o).getStructDef());
+        for(AtlasEnumType enumType : typeRegistry.getAllEnumTypes()) {
+            if (searchPredicates.evaluate(enumType)) {
+                typesDef.getEnumDefs().add(enumType.getEnumDef());
             }
-        } catch (AtlasBaseException ex) {
-            LOG.error("Failed to retrieve the StructDefs", ex);
         }
 
-        try {
-            List<AtlasClassificationDef> classificationDefs = getClassificationDefStore(typeRegistry).getAll();
+        for(AtlasStructType structType : typeRegistry.getAllStructTypes()) {
+            if (searchPredicates.evaluate(structType)) {
+                typesDef.getStructDefs().add(structType.getStructDef());
+            }
+        }
 
-            Collection typeCollection = CollectionUtils.collect(classificationDefs, new Transformer() {
-                @Override
-                public Object transform(Object o) {
-                    try {
-                        return new AtlasClassificationType((AtlasClassificationDef) o, typeRegistry);
-                    } catch (AtlasBaseException e) {
-                        LOG.warn("Type validation failed for {}", ((AtlasClassificationDef) o).getName(), e);
-                        return null;
-                    }
-                }
-            });
-            CollectionUtils.filter(typeCollection, searchPredicates);
-            for (Object o : typeCollection) {
-                if (o != null)
-                    typesDef.getClassificationDefs().add(((AtlasClassificationType)o).getClassificationDef());
+        for(AtlasClassificationType classificationType : typeRegistry.getAllClassificationTypes()) {
+            if (searchPredicates.evaluate(classificationType)) {
+                typesDef.getClassificationDefs().add(classificationType.getClassificationDef());
             }
-        } catch (AtlasBaseException ex) {
-            LOG.error("Failed to retrieve the ClassificationDefs", ex);
         }
 
-        try {
-            List<AtlasEntityDef> entityDefs = getEntityDefStore(typeRegistry).getAll();
-            Collection typeCollection = CollectionUtils.collect(entityDefs, new Transformer() {
-                @Override
-                public Object transform(Object o) {
-                    try {
-                        return new AtlasEntityType((AtlasEntityDef) o, typeRegistry);
-                    } catch (AtlasBaseException e) {
-                        LOG.warn("Type validation failed for {}", ((AtlasEntityDef) o).getName(), e);
-                        return null;
-                    }
-                }
-            });
-            CollectionUtils.filter(typeCollection, searchPredicates);
-            for (Object o : typeCollection) {
-                if (o != null)
-                    typesDef.getEntityDefs().add(((AtlasEntityType)o).getEntityDef());
+        for(AtlasEntityType entityType : typeRegistry.getAllEntityTypes()) {
+            if (searchPredicates.evaluate(entityType)) {
+                typesDef.getEntityDefs().add(entityType.getEntityDef());
             }
-        } catch (AtlasBaseException ex) {
-            LOG.error("Failed to retrieve the EntityDefs", ex);
         }
 
         return typesDef;

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/f5f9fa09/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasClassificationDefStoreV1.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasClassificationDefStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasClassificationDefStoreV1.java
index f9c17fd..eb6dc03 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasClassificationDefStoreV1.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasClassificationDefStoreV1.java
@@ -338,34 +338,6 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
         }
     }
 
-    @Override
-    public AtlasClassificationDefs search(SearchFilter filter) throws AtlasBaseException {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("==> AtlasClassificationDefStoreV1.search({})", filter);
-        }
-
-        List<AtlasClassificationDef> classificationDefs = new ArrayList<>();
-        Iterator<AtlasVertex>        vertices           = typeDefStore.findTypeVerticesByCategory(TypeCategory.TRAIT);
-
-        while(vertices.hasNext()) {
-            AtlasVertex            vertex            = vertices.next();
-            AtlasClassificationDef classificationDef = toClassificationDef(vertex);
-
-            if (classificationDef != null) {
-                classificationDefs.add(classificationDef);
-            }
-        }
-
-        CollectionUtils.filter(classificationDefs, FilterUtil.getPredicateFromSearchFilter(filter));
-
-        AtlasClassificationDefs ret = new AtlasClassificationDefs(classificationDefs);
-
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("<== AtlasClassificationDefStoreV1.search({}): {}", filter, ret);
-        }
-        return ret;
-    }
-
     private void updateVertexPreCreate(AtlasClassificationDef  classificationDef,
                                        AtlasClassificationType classificationType,
                                        AtlasVertex             vertex) {

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/f5f9fa09/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityDefStoreV1.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityDefStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityDefStoreV1.java
index 32a6d83..e478720 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityDefStoreV1.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityDefStoreV1.java
@@ -336,35 +336,6 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
         }
     }
 
-    @Override
-    public AtlasEntityDefs search(SearchFilter filter) throws AtlasBaseException {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("==> AtlasEntityDefStoreV1.search({})", filter);
-        }
-
-        List<AtlasEntityDef>  entityDefs = new ArrayList<>();
-        Iterator<AtlasVertex> vertices   = typeDefStore.findTypeVerticesByCategory(TypeCategory.CLASS);
-
-        while(vertices.hasNext()) {
-            AtlasVertex    vertex    = vertices.next();
-            AtlasEntityDef entityDef = toEntityDef(vertex);
-
-            if (entityDef != null) {
-                entityDefs.add(entityDef);
-            }
-        }
-
-        CollectionUtils.filter(entityDefs, FilterUtil.getPredicateFromSearchFilter(filter));
-
-        AtlasEntityDefs ret = new AtlasEntityDefs(entityDefs);
-
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("<== AtlasEntityDefStoreV1.search({}): {}", filter, ret);
-        }
-
-        return ret;
-    }
-
     private void updateVertexPreCreate(AtlasEntityDef entityDef, AtlasEntityType entityType, AtlasVertex vertex) {
         AtlasStructDefStoreV1.updateVertexPreCreate(entityDef, entityType, vertex, typeDefStore);
     }

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/f5f9fa09/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEnumDefStoreV1.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEnumDefStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEnumDefStoreV1.java
index 3cb10ff..8832507 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEnumDefStoreV1.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEnumDefStoreV1.java
@@ -250,35 +250,6 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla
         }
     }
 
-    @Override
-    public AtlasEnumDefs search(SearchFilter filter) throws AtlasBaseException {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("==> AtlasEnumDefStoreV1.search({})", filter);
-        }
-
-        List<AtlasEnumDef>    enumDefs = new ArrayList<>();
-        Iterator<AtlasVertex> vertices = typeDefStore.findTypeVerticesByCategory(TypeCategory.ENUM);
-
-        while(vertices.hasNext()) {
-            AtlasVertex  vertex  = vertices.next();
-            AtlasEnumDef enumDef = toEnumDef(vertex);
-
-            if (enumDef != null) {
-                enumDefs.add(enumDef);
-            }
-        }
-
-        CollectionUtils.filter(enumDefs, FilterUtil.getPredicateFromSearchFilter(filter));
-
-        AtlasEnumDefs ret = new AtlasEnumDefs(enumDefs);
-
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("<== AtlasEnumDefStoreV1.search({}): {}", filter, ret);
-        }
-
-        return ret;
-    }
-
     private void toVertex(AtlasEnumDef enumDef, AtlasVertex vertex) {
         List<String> values = new ArrayList<>(enumDef.getElementDefs().size());
 

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/f5f9fa09/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasStructDefStoreV1.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasStructDefStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasStructDefStoreV1.java
index 61314a6..3f87e69 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasStructDefStoreV1.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasStructDefStoreV1.java
@@ -347,35 +347,6 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
         }
     }
 
-    @Override
-    public AtlasStructDefs search(SearchFilter filter) throws AtlasBaseException {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("==> AtlasStructDefStoreV1.search({})", filter);
-        }
-
-        List<AtlasStructDef>  structDefs = new ArrayList<>();
-        Iterator<AtlasVertex> vertices   = typeDefStore.findTypeVerticesByCategory(TypeCategory.STRUCT);
-
-        while (vertices.hasNext()) {
-            AtlasVertex    vertex    = vertices.next();
-            AtlasStructDef structDef = toStructDef(vertex);
-
-            if (structDef != null) {
-                structDefs.add(structDef);
-            }
-        }
-
-        CollectionUtils.filter(structDefs, FilterUtil.getPredicateFromSearchFilter(filter));
-
-        AtlasStructDefs ret = new AtlasStructDefs(structDefs);
-
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("<== AtlasStructDefStoreV1.search({}): {}", filter, ret);
-        }
-
-        return ret;
-    }
-
     private AtlasStructDef toStructDef(AtlasVertex vertex) throws AtlasBaseException {
         AtlasStructDef ret = null;
 

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/f5f9fa09/repository/src/main/java/org/apache/atlas/repository/util/FilterUtil.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/util/FilterUtil.java b/repository/src/main/java/org/apache/atlas/repository/util/FilterUtil.java
index d0085f9..54d6b40 100644
--- a/repository/src/main/java/org/apache/atlas/repository/util/FilterUtil.java
+++ b/repository/src/main/java/org/apache/atlas/repository/util/FilterUtil.java
@@ -37,9 +37,10 @@ import java.util.Objects;
 public class FilterUtil {
     public static Predicate getPredicateFromSearchFilter(SearchFilter searchFilter) {
         List<Predicate> predicates = new ArrayList<>();
-        final String type = searchFilter.getParam(SearchFilter.PARAM_TYPE);
-        final String name = searchFilter.getParam(SearchFilter.PARAM_NAME);
-        final String supertype = searchFilter.getParam(SearchFilter.PARAM_SUPERTYPE);
+
+        final String type         = searchFilter.getParam(SearchFilter.PARAM_TYPE);
+        final String name         = searchFilter.getParam(SearchFilter.PARAM_NAME);
+        final String supertype    = searchFilter.getParam(SearchFilter.PARAM_SUPERTYPE);
         final String notSupertype = searchFilter.getParam(SearchFilter.PARAM_NOT_SUPERTYPE);
 
         // Add filter for the type/category
@@ -71,33 +72,19 @@ public class FilterUtil {
                 return o instanceof AtlasType;
             }
 
-            private boolean isAtlasTypeDef(Object o) {
-                return o instanceof AtlasBaseTypeDef;
-            }
-
             @Override
             public boolean evaluate(Object o) {
-                return o != null &&
-                        (isAtlasType(o) && Objects.equals(((AtlasType) o).getTypeName(), name)) ||
-                        (isAtlasTypeDef(o) && Objects.equals(((AtlasBaseTypeDef) o).getName(), name));
+                return o != null && isAtlasType(o) && Objects.equals(((AtlasType) o).getTypeName(), name);
             }
         };
     }
 
     private static Predicate getSuperTypePredicate(final String supertype) {
         return new Predicate() {
-            private boolean isClassificationTypeDef(Object o) {
-                return o instanceof AtlasClassificationDef;
-            }
-
             private boolean isClassificationType(Object o) {
                 return o instanceof AtlasClassificationType;
             }
 
-            private boolean isEntityTypeDef(Object o) {
-                return o instanceof AtlasEntityDef;
-            }
-
             private boolean isEntityType(Object o) {
                 return o instanceof AtlasEntityType;
             }
@@ -105,9 +92,7 @@ public class FilterUtil {
             @Override
             public boolean evaluate(Object o) {
                 return (isClassificationType(o) && ((AtlasClassificationType) o).getAllSuperTypes().contains(supertype))||
-                        (isClassificationTypeDef(o) && ((AtlasClassificationDef)o).getSuperTypes().contains(supertype)) ||
-                        (isEntityType(o) && ((AtlasEntityType)o).getAllSuperTypes().contains(supertype)) ||
-                        (isEntityTypeDef(o) && ((AtlasEntityDef)o).getSuperTypes().contains(supertype));
+                       (isEntityType(o) && ((AtlasEntityType)o).getAllSuperTypes().contains(supertype));
             }
         };
     }
@@ -134,27 +119,8 @@ public class FilterUtil {
                             // This shouldn't have happened
                             return false;
                     }
-                } else if (o instanceof AtlasBaseTypeDef){
-                    AtlasBaseTypeDef typeDef = (AtlasBaseTypeDef)o;
-
-                    switch (type.toUpperCase()) {
-                        case "CLASS":
-                        case "ENTITY":
-                            return typeDef.getCategory() == TypeCategory.ENTITY;
-                        case "TRAIT":
-                        case "CLASSIFICATION":
-                            return typeDef.getCategory() == TypeCategory.CLASSIFICATION;
-                        case "STRUCT":
-                            return typeDef.getCategory() == TypeCategory.STRUCT;
-                        case "ENUM":
-                            return typeDef.getCategory() == TypeCategory.ENUM;
-                        default:
-                            // This shouldn't have happened
-                            return false;
-                    }
-                } else {
-                    return false;
                 }
+                return false;
             }
         };
     }