Commit f5f9fa09 by Madhan Neethiraj

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

parent e7eaa996
......@@ -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;
}
......@@ -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;
}
......@@ -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;
}
......@@ -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;
}
......@@ -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;
......
......@@ -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) {
......
......@@ -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);
}
......
......@@ -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());
......
......@@ -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;
......
......@@ -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;
}
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment