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-1761: improve attribute search to enable search based on display text
Date Mon, 01 May 2017 00:48:16 GMT
Repository: incubator-atlas
Updated Branches:
  refs/heads/master c4fc5b4f5 -> d30fa2c26


ATLAS-1761: improve attribute search to enable search based on display text

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/d30fa2c2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/d30fa2c2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/d30fa2c2

Branch: refs/heads/master
Commit: d30fa2c2624038026e690eabb90f7f6436d626d8
Parents: c4fc5b4
Author: Sarath Subramanian <ssubramanian@hortonworks.com>
Authored: Mon Apr 3 15:26:00 2017 -0700
Committer: Madhan Neethiraj <madhan@apache.org>
Committed: Sun Apr 30 17:47:52 2017 -0700

----------------------------------------------------------------------
 .../atlas/discovery/EntityDiscoveryService.java | 58 ++++++++++++++------
 .../atlas/util/AtlasGremlin2QueryProvider.java  |  2 +
 .../atlas/util/AtlasGremlinQueryProvider.java   |  3 +-
 .../apache/atlas/web/rest/DiscoveryREST.java    |  2 +-
 4 files changed, 47 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/d30fa2c2/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 f3f6ee2..874487c 100644
--- a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
+++ b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
@@ -64,6 +64,7 @@ import javax.inject.Inject;
 import javax.script.ScriptEngine;
 import javax.script.ScriptException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -199,34 +200,53 @@ public class EntityDiscoveryService implements AtlasDiscoveryService
{
             ret.setClassification(classification);
         }
 
-        boolean isAttributeSearch = StringUtils.isNotEmpty(attrName) && StringUtils.isNotEmpty(attrValuePrefix);
+        boolean isAttributeSearch  = StringUtils.isNotEmpty(attrName) || StringUtils.isNotEmpty(attrValuePrefix);
+        boolean isGuidPrefixSearch = false;
 
         if (isAttributeSearch) {
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Executing attribute search attrName: {} and attrValue: {}", attrName,
attrValuePrefix);
-            }
-
             AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName);
 
+            ret.setQueryType(AtlasQueryType.ATTRIBUTE);
+
             if (entityType != null) {
-                AtlasAttribute attribute = entityType.getAttribute(attrName);
+                AtlasAttribute attribute = null;
 
-                if (attribute == null) {
-                    throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_ATTRIBUTE, attrName,
typeName);
+                if (StringUtils.isNotEmpty(attrName)) {
+                    attribute = entityType.getAttribute(attrName);
+
+                    if (attribute == null) {
+                        throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_ATTRIBUTE, attrName,
typeName);
+                    }
+                    
+                } else {
+                    // if attrName is null|empty iterate defaultAttrNames to get attribute
value
+                    final List<String> defaultAttrNames = new ArrayList<>(Arrays.asList("qualifiedName",
"name"));
+                    Iterator<String>   iter             = defaultAttrNames.iterator();
+
+                    while (iter.hasNext() && attribute == null) {
+                        attrName  = iter.next();
+                        attribute = entityType.getAttribute(attrName);
+                    }
                 }
 
-                attrQualifiedName = entityType.getAttribute(attrName).getQualifiedName();
-            }
+                if (attribute == null) {
+                    // for guid prefix search use gremlin and nullify query to avoid using
fulltext
+                    // (guids cannot be searched in fulltext)
+                    isGuidPrefixSearch = true;
+                    query              = null;
+
+                } else {
+                    attrQualifiedName = attribute.getQualifiedName();
 
-            String attrQuery = String.format("%s AND (%s *)", attrName, attrValuePrefix.replaceAll("\\.",
" "));
+                    String  attrQuery = String.format("%s AND (%s *)", attrName, attrValuePrefix.replaceAll("\\.",
" "));
 
-            if (StringUtils.isEmpty(query)) {
-                query = attrQuery;
-            } else {
-                query = String.format("(%s) AND (%s)", query, attrQuery);
+                    query = StringUtils.isEmpty(query) ? attrQuery : String.format("(%s)
AND (%s)", query, attrQuery);
+                }
             }
 
-            ret.setQueryType(AtlasQueryType.ATTRIBUTE);
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Executing attribute search attrName: {} and attrValue: {}", attrName,
attrValuePrefix);
+            }
         }
 
         // if query was provided, perform indexQuery and filter for typeName & classification
in memory; this approach
@@ -304,6 +324,12 @@ public class EntityDiscoveryService implements AtlasDiscoveryService
{
                 basicQuery += gremlinQueryProvider.getQuery(AtlasGremlinQuery.BASIC_SEARCH_TYPE_FILTER);
             }
 
+            if (isGuidPrefixSearch) {
+                bindings.put("guid", attrValuePrefix + ".*");
+
+                basicQuery += gremlinQueryProvider.getQuery(AtlasGremlinQuery.GUID_PREFIX_FILTER);
+            }
+
             bindings.put("startIdx", params.offset());
             bindings.put("endIdx", params.offset() + params.limit());
 

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/d30fa2c2/repository/src/main/java/org/apache/atlas/util/AtlasGremlin2QueryProvider.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/util/AtlasGremlin2QueryProvider.java
b/repository/src/main/java/org/apache/atlas/util/AtlasGremlin2QueryProvider.java
index d3413c2..139e7c3 100644
--- a/repository/src/main/java/org/apache/atlas/util/AtlasGremlin2QueryProvider.java
+++ b/repository/src/main/java/org/apache/atlas/util/AtlasGremlin2QueryProvider.java
@@ -71,6 +71,8 @@ public class AtlasGremlin2QueryProvider extends AtlasGremlinQueryProvider
{
                 return ".has('__traitNames', T.in, traitNames)";
             case TO_RANGE_LIST:
                 return " [startIdx..<endIdx].toList()";
+            case GUID_PREFIX_FILTER:
+                return ".filter{it.'__guid'.matches(guid)}";
         }
         // Should never reach this point
         return null;

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/d30fa2c2/repository/src/main/java/org/apache/atlas/util/AtlasGremlinQueryProvider.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/util/AtlasGremlinQueryProvider.java
b/repository/src/main/java/org/apache/atlas/util/AtlasGremlinQueryProvider.java
index 633fad0..8fb1793 100644
--- a/repository/src/main/java/org/apache/atlas/util/AtlasGremlinQueryProvider.java
+++ b/repository/src/main/java/org/apache/atlas/util/AtlasGremlinQueryProvider.java
@@ -58,6 +58,7 @@ public abstract class AtlasGremlinQueryProvider {
         // Discovery Queries
         BASIC_SEARCH_TYPE_FILTER,
         BASIC_SEARCH_CLASSIFICATION_FILTER,
-        TO_RANGE_LIST
+        TO_RANGE_LIST,
+        GUID_PREFIX_FILTER
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/d30fa2c2/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 81dbe25..edaf3ef 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
@@ -199,7 +199,7 @@ public class DiscoveryREST {
                         attrValuePrefix + "," + typeName + "," + limit + "," + offset + ")");
             }
 
-            if (StringUtils.isEmpty(attrName) || StringUtils.isEmpty(attrValuePrefix)) {
+            if (StringUtils.isEmpty(attrName) && StringUtils.isEmpty(attrValuePrefix))
{
                 throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS,
                         String.format("attrName : {0}, attrValue: {1} for attribute search.",
attrName, attrValuePrefix));
             }


Mime
View raw message