Commit aa441de4 by Pinal Shah Committed by nixonrodrigues

ATLAS-3876 : Relationship Search API not showing correct approximateCount

parent 4a57f92f
...@@ -670,7 +670,7 @@ public class AtlasStructType extends AtlasType { ...@@ -670,7 +670,7 @@ public class AtlasStructType extends AtlasType {
throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_ATTRIBUTE, attrName, structDef.getName()); throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_ATTRIBUTE, attrName, structDef.getName());
} }
AtlasEntityType getReferencedEntityType(AtlasType type) { static AtlasEntityType getReferencedEntityType(AtlasType type) {
if (type instanceof AtlasArrayType) { if (type instanceof AtlasArrayType) {
type = ((AtlasArrayType)type).getElementType(); type = ((AtlasArrayType)type).getElementType();
} }
...@@ -980,6 +980,11 @@ public class AtlasStructType extends AtlasType { ...@@ -980,6 +980,11 @@ public class AtlasStructType extends AtlasType {
return (relationshipLabel == null) ? getEdgeLabel(qualifiedName) : relationshipLabel; return (relationshipLabel == null) ? getEdgeLabel(qualifiedName) : relationshipLabel;
} }
public AtlasEntityType getReferencedEntityType(AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
AtlasType type = typeRegistry.getType(attributeDef.getTypeName());
return AtlasStructType.getReferencedEntityType(type);
}
public static String getQualifiedAttributeName(AtlasStructDef structDef, String attrName) { public static String getQualifiedAttributeName(AtlasStructDef structDef, String attrName) {
if (isRootType(structDef)) { if (isRootType(structDef)) {
return attrName; return attrName;
......
...@@ -87,11 +87,12 @@ public interface AtlasDiscoveryService { ...@@ -87,11 +87,12 @@ public interface AtlasDiscoveryService {
* @param sortByAttribute sort the result using this attribute name, default value is 'name' * @param sortByAttribute sort the result using this attribute name, default value is 'name'
* @param sortOrder sorting order * @param sortOrder sorting order
* @param excludeDeletedEntities exclude deleted entities in search result. * @param excludeDeletedEntities exclude deleted entities in search result.
* @param getApproximateCount
* @param limit number of resultant rows (for pagination). [ limit > 0 ] and [ limit < maxlimit ]. -1 maps to atlas.search.defaultlimit property. * @param limit number of resultant rows (for pagination). [ limit > 0 ] and [ limit < maxlimit ]. -1 maps to atlas.search.defaultlimit property.
* @param offset offset to the results returned (for pagination). [ offset >= 0 ]. -1 maps to offset 0. * @param offset offset to the results returned (for pagination). [ offset >= 0 ]. -1 maps to offset 0.
* @return AtlasSearchResult * @return AtlasSearchResult
*/ */
AtlasSearchResult searchRelatedEntities(String guid, String relation, Set<String> attributes, String sortByAttribute, SortOrder sortOrder, boolean excludeDeletedEntities, int limit, int offset) throws AtlasBaseException; AtlasSearchResult searchRelatedEntities(String guid, String relation, Set<String> attributes, String sortByAttribute, SortOrder sortOrder, boolean excludeDeletedEntities, boolean getApproximateCount, int limit, int offset) throws AtlasBaseException;
/** /**
* *
......
...@@ -75,7 +75,7 @@ public abstract class SearchProcessor { ...@@ -75,7 +75,7 @@ public abstract class SearchProcessor {
public static final String CUSTOM_ATTR_SEARCH_FORMAT = "\"\\\"%s\\\":\\\"%s\\\"\""; public static final String CUSTOM_ATTR_SEARCH_FORMAT = "\"\\\"%s\\\":\\\"%s\\\"\"";
public static final String CUSTOM_ATTR_SEARCH_FORMAT_GRAPH = "\"%s\":\"%s\""; public static final String CUSTOM_ATTR_SEARCH_FORMAT_GRAPH = "\"%s\":\"%s\"";
private static final Map<SearchParameters.Operator, String> OPERATOR_MAP = new HashMap<>(); private static final Map<SearchParameters.Operator, String> OPERATOR_MAP = new HashMap<>();
private static final Map<SearchParameters.Operator, VertexAttributePredicateGenerator> OPERATOR_PREDICATE_MAP = new HashMap<>(); private static final Map<SearchParameters.Operator, ElementAttributePredicateGenerator> OPERATOR_PREDICATE_MAP = new HashMap<>();
static static
{ {
...@@ -697,7 +697,7 @@ public abstract class SearchProcessor { ...@@ -697,7 +697,7 @@ public abstract class SearchProcessor {
Predicate ret = null; Predicate ret = null;
AtlasAttribute attribute = type.getAttribute(attrName); AtlasAttribute attribute = type.getAttribute(attrName);
VertexAttributePredicateGenerator predicate = OPERATOR_PREDICATE_MAP.get(op); ElementAttributePredicateGenerator predicate = OPERATOR_PREDICATE_MAP.get(op);
if (attribute != null && predicate != null) { if (attribute != null && predicate != null) {
final AtlasType attrType = attribute.getAttributeType(); final AtlasType attrType = attribute.getAttributeType();
......
...@@ -201,6 +201,10 @@ public class EntityGraphRetriever { ...@@ -201,6 +201,10 @@ public class EntityGraphRetriever {
return toAtlasEntityHeader(getEntityVertex(guid)); return toAtlasEntityHeader(getEntityVertex(guid));
} }
public AtlasEntityHeader toAtlasEntityHeader(String guid, Set<String> attributes) throws AtlasBaseException {
return toAtlasEntityHeader(getEntityVertex(guid), attributes);
}
public AtlasEntityHeader toAtlasEntityHeader(AtlasVertex entityVertex) throws AtlasBaseException { public AtlasEntityHeader toAtlasEntityHeader(AtlasVertex entityVertex) throws AtlasBaseException {
return toAtlasEntityHeader(entityVertex, Collections.<String>emptySet()); return toAtlasEntityHeader(entityVertex, Collections.<String>emptySet());
} }
......
...@@ -370,6 +370,7 @@ public class DiscoveryREST { ...@@ -370,6 +370,7 @@ public class DiscoveryREST {
@QueryParam("sortBy") String sortByAttribute, @QueryParam("sortBy") String sortByAttribute,
@QueryParam("sortOrder") SortOrder sortOrder, @QueryParam("sortOrder") SortOrder sortOrder,
@QueryParam("excludeDeletedEntities") boolean excludeDeletedEntities, @QueryParam("excludeDeletedEntities") boolean excludeDeletedEntities,
@QueryParam("getApproximateCount") boolean getApproximateCount,
@QueryParam("limit") int limit, @QueryParam("limit") int limit,
@QueryParam("offset") int offset) throws AtlasBaseException { @QueryParam("offset") int offset) throws AtlasBaseException {
Servlets.validateQueryParamLength("guid", guid); Servlets.validateQueryParamLength("guid", guid);
...@@ -380,11 +381,11 @@ public class DiscoveryREST { ...@@ -380,11 +381,11 @@ public class DiscoveryREST {
try { try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.relatedEntitiesSearchUsingGremlin(" + guid + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.relatedEntitiesSearch(" + guid +
", " + relation + ", " + sortByAttribute + ", " + sortOrder + ", " + excludeDeletedEntities + ", " + ", " + limit + ", " + offset + ")"); ", " + relation + ", " + sortByAttribute + ", " + sortOrder + ", " + excludeDeletedEntities + ", " + getApproximateCount + ", " + limit + ", " + offset + ")");
} }
return discoveryService.searchRelatedEntities(guid, relation, attributes, sortByAttribute, sortOrder, excludeDeletedEntities, limit, offset); return discoveryService.searchRelatedEntities(guid, relation, attributes, sortByAttribute, sortOrder, excludeDeletedEntities, getApproximateCount, limit, offset);
} finally { } finally {
AtlasPerfTracer.log(perf); AtlasPerfTracer.log(perf);
} }
......
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