atlas-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject incubator-atlas git commit: ATLAS-1710: added entity-lookup API for entity create/update UI
Date Thu, 13 Apr 2017 00:53:23 GMT
Repository: incubator-atlas
Updated Branches:
  refs/heads/master 8a32ccaae -> 5dfe20232


ATLAS-1710: added entity-lookup API for entity create/update UI

Signed-off-by: Madhan Neethiraj <madhan@apache.org>


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

Branch: refs/heads/master
Commit: 5dfe20232548079cc716d4cd532507351e7a078e
Parents: 8a32cca
Author: Sarath Subramanian <ssubramanian@hortonworks.com>
Authored: Mon Apr 3 15:26:00 2017 -0700
Committer: Madhan Neethiraj <madhan@apache.org>
Committed: Wed Apr 12 17:27:46 2017 -0700

----------------------------------------------------------------------
 .../model/discovery/AtlasSearchResult.java      |  2 +-
 .../atlas/discovery/AtlasDiscoveryService.java  |  5 +-
 .../atlas/discovery/EntityDiscoveryService.java | 45 +++++++++++++++-
 .../apache/atlas/web/rest/DiscoveryREST.java    | 55 +++++++++++++++++---
 4 files changed, 98 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/5dfe2023/intg/src/main/java/org/apache/atlas/model/discovery/AtlasSearchResult.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/model/discovery/AtlasSearchResult.java b/intg/src/main/java/org/apache/atlas/model/discovery/AtlasSearchResult.java
index bf1c80e..a402c62 100644
--- a/intg/src/main/java/org/apache/atlas/model/discovery/AtlasSearchResult.java
+++ b/intg/src/main/java/org/apache/atlas/model/discovery/AtlasSearchResult.java
@@ -149,7 +149,7 @@ public class AtlasSearchResult implements Serializable {
         }
     }
 
-    public enum AtlasQueryType { DSL, FULL_TEXT, GREMLIN, BASIC }
+    public enum AtlasQueryType { DSL, FULL_TEXT, GREMLIN, BASIC, ATTRIBUTE }
 
     @JsonAutoDetect(getterVisibility = PUBLIC_ONLY, setterVisibility = PUBLIC_ONLY, fieldVisibility
= NONE)
     @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/5dfe2023/repository/src/main/java/org/apache/atlas/discovery/AtlasDiscoveryService.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/discovery/AtlasDiscoveryService.java
b/repository/src/main/java/org/apache/atlas/discovery/AtlasDiscoveryService.java
index 1044aaa..24b09dc 100644
--- a/repository/src/main/java/org/apache/atlas/discovery/AtlasDiscoveryService.java
+++ b/repository/src/main/java/org/apache/atlas/discovery/AtlasDiscoveryService.java
@@ -46,9 +46,12 @@ public interface AtlasDiscoveryService {
      * @param query search query.
      * @param type entity type.
      * @param classification classification name.
+     * @param attrName attribute name.
+     * @param attrValue attribute value.
      * @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.
      * @return AtlasSearchResult
      */
-    AtlasSearchResult searchUsingBasicQuery(String query, String type, String classification,
int limit, int offset) throws AtlasBaseException;
+    AtlasSearchResult searchUsingBasicQuery(String query, String type, String classification,
String attrName,
+                                            String attrValue, int limit, int offset) throws
AtlasBaseException;
 }

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/5dfe2023/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
index 571ce6e..e7d6523 100644
--- a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
+++ b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
@@ -18,6 +18,7 @@
 package org.apache.atlas.discovery;
 
 import org.apache.atlas.AtlasConfiguration;
+import org.apache.atlas.AtlasErrorCode;
 import org.apache.atlas.model.discovery.AtlasSearchResult.AtlasFullTextResult;
 import org.apache.atlas.model.discovery.AtlasSearchResult.AtlasQueryType;
 import org.apache.atlas.model.discovery.AtlasSearchResult.AttributeSearchResult;
@@ -45,6 +46,8 @@ import org.apache.atlas.repository.graphdb.AtlasVertex;
 import org.apache.atlas.repository.store.graph.v1.EntityGraphRetriever;
 import org.apache.atlas.type.AtlasClassificationType;
 import org.apache.atlas.type.AtlasEntityType;
+import org.apache.atlas.type.AtlasStructType;
+import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
 import org.apache.atlas.type.AtlasTypeRegistry;
 import org.apache.atlas.util.AtlasGremlinQueryProvider;
 import org.apache.atlas.util.AtlasGremlinQueryProvider.AtlasGremlinQuery;
@@ -156,7 +159,8 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
     }
 
     @Override
-    public AtlasSearchResult searchUsingBasicQuery(String query, String typeName, String
classification, int limit, int offset) throws AtlasBaseException {
+    public AtlasSearchResult searchUsingBasicQuery(String query, String typeName, String
classification, String attrName,
+                                                   String attrValue, int limit, int offset)
throws AtlasBaseException {
         AtlasSearchResult ret = new AtlasSearchResult(AtlasQueryType.BASIC);
 
         if (LOG.isDebugEnabled()) {
@@ -166,6 +170,7 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
         final QueryParams params              = validateSearchParams(limit, offset);
         Set<String>       typeNames           = null;
         Set<String>       classificationNames = null;
+        String            attrQualifiedName   = null;
 
         if (StringUtils.isNotEmpty(typeName)) {
             AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName);
@@ -191,6 +196,36 @@ public class EntityDiscoveryService implements AtlasDiscoveryService
{
             ret.setClassification(classification);
         }
 
+        boolean isAttributeSearch = StringUtils.isNotEmpty(attrName) && StringUtils.isNotEmpty(attrValue);
+
+        if (isAttributeSearch) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Executing attribute search attrName: {} and attrValue: {}", attrName,
attrValue);
+            }
+
+            AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName);
+
+            if (entityType != null) {
+                AtlasAttribute attribute = entityType.getAttribute(attrName);
+
+                if (attribute == null) {
+                    throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_ATTRIBUTE, attrName,
typeName);
+                }
+
+                attrQualifiedName = entityType.getAttribute(attrName).getQualifiedName();
+            }
+
+            String attrQuery = String.format("%s AND (%s *)", attrName, attrValue.replaceAll("\\.",
" "));
+
+            if (StringUtils.isEmpty(query)) {
+                query = attrQuery;
+            } else {
+                query = String.format("(%s) AND (%s)", query, attrQuery);
+            }
+
+            ret.setQueryType(AtlasQueryType.ATTRIBUTE);
+        }
+
         // if query was provided, perform indexQuery and filter for typeName & classification
in memory; this approach
         // results in a faster and accurate results than using CONTAINS/CONTAINS_PREFIX filter
on entityText property
         if (StringUtils.isNotEmpty(query)) {
@@ -224,6 +259,14 @@ public class EntityDiscoveryService implements AtlasDiscoveryService
{
                     }
                 }
 
+                if (isAttributeSearch) {
+                    String vertexAttrValue = vertex.getProperty(attrQualifiedName, String.class);
+
+                    if (StringUtils.isNotEmpty(vertexAttrValue) && !vertexAttrValue.startsWith(attrValue))
{
+                        continue;
+                    }
+                }
+
                 resultIdx++;
 
                 if (resultIdx <= startIdx) {

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/5dfe2023/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java b/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java
index 61f9847..c294187 100644
--- a/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java
+++ b/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java
@@ -17,6 +17,7 @@
  */
 package org.apache.atlas.web.rest;
 
+import org.apache.atlas.AtlasErrorCode;
 import org.apache.atlas.exception.AtlasBaseException;
 import org.apache.atlas.discovery.AtlasDiscoveryService;
 import org.apache.atlas.model.discovery.AtlasSearchResult;
@@ -146,11 +147,11 @@ public class DiscoveryREST {
     @Path("/basic")
     @Consumes(Servlets.JSON_MEDIA_TYPE)
     @Produces(Servlets.JSON_MEDIA_TYPE)
-    public AtlasSearchResult searchUsingBasic(@QueryParam("query")          String query,
-                                              @QueryParam("typeName")       String typeName,
-                                              @QueryParam("classification") String classification,
-                                              @QueryParam("limit")          int    limit,
-                                              @QueryParam("offset")         int    offset)
throws AtlasBaseException {
+    public AtlasSearchResult searchUsingBasic(@QueryParam("query")          String  query,
+                                              @QueryParam("typeName")       String  typeName,
+                                              @QueryParam("classification") String  classification,
+                                              @QueryParam("limit")          int     limit,
+                                              @QueryParam("offset")         int     offset)
throws AtlasBaseException {
         AtlasPerfTracer perf = null;
 
         try {
@@ -159,7 +160,49 @@ public class DiscoveryREST {
                                                     typeName + "," + classification + ","
+ limit + "," + offset + ")");
             }
 
-            return atlasDiscoveryService.searchUsingBasicQuery(query, typeName, classification,
limit, offset);
+            return atlasDiscoveryService.searchUsingBasicQuery(query, typeName, classification,
null, null, limit, offset);
+        } finally {
+            AtlasPerfTracer.log(perf);
+        }
+    }
+
+    /**
+     * Retrieve data for the specified attribute search query
+     * @param attrName  Attribute name
+     * @param attrValue Attibute value to search on
+     * @param typeName limit the result to only entities of specified type or its sub-types
+     * @param limit limit the result set to only include the specified number of entries
+     * @param offset start offset of the result set (useful for pagination)
+     * @return Search results
+     * @throws AtlasBaseException
+     * @HTTP 200 On successful FullText lookup with some results, might return an empty list
if execution succeeded
+     * without any results
+     * @HTTP 400 Invalid wildcard or query parameters
+     */
+    @GET
+    @Path("/attribute")
+    @Consumes(Servlets.JSON_MEDIA_TYPE)
+    @Produces(Servlets.JSON_MEDIA_TYPE)
+    public AtlasSearchResult searchUsingAttribute(@QueryParam("stringName")  String attrName,
+                                                  @QueryParam("stringValue") String attrValue,
+                                                  @QueryParam("typeName")    String typeName,
+                                                  @QueryParam("limit")       int    limit,
+                                                  @QueryParam("offset")      int    offset)
throws AtlasBaseException {
+        AtlasPerfTracer perf = null;
+
+        try {
+            if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
+                perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.searchUsingAttribute("
+ attrName + "," +
+                        attrValue + "," + typeName + "," + limit + "," + offset + ")");
+            }
+
+            if (StringUtils.isEmpty(attrName) || StringUtils.isEmpty(attrValue)) {
+                throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS,
+                        String.format("attrName : {0}, attrValue: {1} for attribute search.",
attrName, attrValue));
+            }
+
+            return atlasDiscoveryService.searchUsingBasicQuery(null, typeName, null, attrName,
attrValue, limit, offset);
+
         } finally {
             AtlasPerfTracer.log(perf);
         }


Mime
View raw message