This is an automated email from the ASF dual-hosted git repository.

madhan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git


The following commit(s) were added to refs/heads/master by this push:
     new 40081d4  ATLAS-3269: fixed basic-search handing of search for entities 
with no-classication
40081d4 is described below

commit 40081d4853ae9923e601f62c150c165f1cea902d
Author: Madhan Neethiraj <mad...@apache.org>
AuthorDate: Fri Jun 7 10:30:02 2019 -0700

    ATLAS-3269: fixed basic-search handing of search for entities with 
no-classication
---
 .../discovery/ClassificationSearchProcessor.java   |  4 +-
 .../atlas/discovery/EntitySearchProcessor.java     |  4 +-
 .../org/apache/atlas/util/SearchPredicateUtil.java | 44 ++++++++++++++++++++++
 3 files changed, 48 insertions(+), 4 deletions(-)

diff --git 
a/repository/src/main/java/org/apache/atlas/discovery/ClassificationSearchProcessor.java
 
b/repository/src/main/java/org/apache/atlas/discovery/ClassificationSearchProcessor.java
index 1cd507c..c929d9a 100644
--- 
a/repository/src/main/java/org/apache/atlas/discovery/ClassificationSearchProcessor.java
+++ 
b/repository/src/main/java/org/apache/atlas/discovery/ClassificationSearchProcessor.java
@@ -176,8 +176,8 @@ public class ClassificationSearchProcessor extends 
SearchProcessor {
 
                 entityGraphQueryTraitNames = graph.query().or(orConditions);
                 entityPredicateTraitNames  = PredicateUtils.andPredicate(
-                        
SearchPredicateUtil.getIsNullPredicateGenerator().generatePredicate(TRAIT_NAMES_PROPERTY_KEY,
 null, List.class),
-                        
SearchPredicateUtil.getIsNullPredicateGenerator().generatePredicate(PROPAGATED_TRAIT_NAMES_PROPERTY_KEY,
 null, List.class));
+                        
SearchPredicateUtil.getIsNullOrEmptyPredicateGenerator().generatePredicate(TRAIT_NAMES_PROPERTY_KEY,
 null, List.class),
+                        
SearchPredicateUtil.getIsNullOrEmptyPredicateGenerator().generatePredicate(PROPAGATED_TRAIT_NAMES_PROPERTY_KEY,
 null, List.class));
             } else {
                 
orConditions.add(graph.query().createChildQuery().in(TRAIT_NAMES_PROPERTY_KEY, 
typeAndSubTypes));
                 
orConditions.add(graph.query().createChildQuery().in(PROPAGATED_TRAIT_NAMES_PROPERTY_KEY,
 typeAndSubTypes));
diff --git 
a/repository/src/main/java/org/apache/atlas/discovery/EntitySearchProcessor.java
 
b/repository/src/main/java/org/apache/atlas/discovery/EntitySearchProcessor.java
index c4b5ffb..e4a315f 100644
--- 
a/repository/src/main/java/org/apache/atlas/discovery/EntitySearchProcessor.java
+++ 
b/repository/src/main/java/org/apache/atlas/discovery/EntitySearchProcessor.java
@@ -103,8 +103,8 @@ public class EntitySearchProcessor extends SearchProcessor {
             traitPredicate = 
PredicateUtils.orPredicate(SearchPredicateUtil.getNotEmptyPredicateGenerator().generatePredicate(TRAIT_NAMES_PROPERTY_KEY,
 null, List.class),
                                                         
SearchPredicateUtil.getNotEmptyPredicateGenerator().generatePredicate(PROPAGATED_TRAIT_NAMES_PROPERTY_KEY,
 null, List.class));
         } else if (classificationType == MATCH_ALL_NOT_CLASSIFIED) {
-            traitPredicate = 
PredicateUtils.andPredicate(SearchPredicateUtil.getIsNullPredicateGenerator().generatePredicate(TRAIT_NAMES_PROPERTY_KEY,
 null, List.class),
-                                                         
SearchPredicateUtil.getIsNullPredicateGenerator().generatePredicate(PROPAGATED_TRAIT_NAMES_PROPERTY_KEY,
 null, List.class));
+            traitPredicate = 
PredicateUtils.andPredicate(SearchPredicateUtil.getIsNullOrEmptyPredicateGenerator().generatePredicate(TRAIT_NAMES_PROPERTY_KEY,
 null, List.class),
+                                                         
SearchPredicateUtil.getIsNullOrEmptyPredicateGenerator().generatePredicate(PROPAGATED_TRAIT_NAMES_PROPERTY_KEY,
 null, List.class));
         } else {
             traitPredicate = 
PredicateUtils.orPredicate(SearchPredicateUtil.getContainsAnyPredicateGenerator().generatePredicate(TRAIT_NAMES_PROPERTY_KEY,
 classificationTypeAndSubTypes, List.class),
                                                         
SearchPredicateUtil.getContainsAnyPredicateGenerator().generatePredicate(PROPAGATED_TRAIT_NAMES_PROPERTY_KEY,
 classificationTypeAndSubTypes, List.class));
diff --git 
a/repository/src/main/java/org/apache/atlas/util/SearchPredicateUtil.java 
b/repository/src/main/java/org/apache/atlas/util/SearchPredicateUtil.java
index 38de885..bb1e9f6 100644
--- a/repository/src/main/java/org/apache/atlas/util/SearchPredicateUtil.java
+++ b/repository/src/main/java/org/apache/atlas/util/SearchPredicateUtil.java
@@ -650,6 +650,50 @@ public class SearchPredicateUtil {
         return ret;
     }
 
+    public static VertexAttributePredicateGenerator 
getIsNullOrEmptyPredicateGenerator() {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("==> getIsNullOrEmptyPredicateGenerator");
+        }
+
+        VertexAttributePredicateGenerator ret = new 
VertexAttributePredicateGenerator() {
+            @Override
+            public Predicate generatePredicate(final String attrName, final 
Object attrVal, final Class attrClass) {
+                final Predicate ret;
+
+                if (attrName == null || attrClass == null) {
+                    ret = ALWAYS_FALSE;
+                } else {
+                    ret = new VertexAttributePredicate(attrName, attrClass, 
true) {
+                        @Override
+                        protected boolean compareValue(final Object 
vertexAttrVal) {
+                            final boolean ret;
+
+                            if (vertexAttrVal == null) {
+                                ret = true;
+                            } else if (vertexAttrVal instanceof Collection) {
+                                ret = CollectionUtils.isEmpty((Collection) 
vertexAttrVal);
+                            } else if (vertexAttrVal instanceof String) {
+                                ret = StringUtils.isEmpty((String) 
vertexAttrVal);
+                            } else {
+                                ret = false;
+                            }
+
+                            return ret;
+                        }
+                    };
+                }
+
+                return ret;
+            }
+        };
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("<== getIsNullOrEmptyPredicateGenerator");
+        }
+
+        return ret;
+    }
+
     public interface VertexAttributePredicateGenerator {
         Predicate generatePredicate(String attrName, Object attrVal, Class 
attrClass);
     }

Reply via email to