atlas-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject [2/2] atlas git commit: ATLAS-2151: fix incorrect handling of OR condition in index query
Date Sat, 23 Sep 2017 01:34:37 GMT
ATLAS-2151: fix incorrect handling of OR condition in index query

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


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

Branch: refs/heads/master
Commit: 6a64cd9c284d3bdf5bdd9100c3d6580e74187c41
Parents: 944a99b
Author: apoorvnaik <apoorvnaik@apache.org>
Authored: Thu Sep 21 21:20:34 2017 -0700
Committer: Madhan Neethiraj <madhan@apache.org>
Committed: Fri Sep 22 18:18:42 2017 -0700

----------------------------------------------------------------------
 .../org/apache/atlas/discovery/SearchProcessor.java  | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/6a64cd9c/repository/src/main/java/org/apache/atlas/discovery/SearchProcessor.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/discovery/SearchProcessor.java b/repository/src/main/java/org/apache/atlas/discovery/SearchProcessor.java
index 64a86b9..b380e1e 100644
--- a/repository/src/main/java/org/apache/atlas/discovery/SearchProcessor.java
+++ b/repository/src/main/java/org/apache/atlas/discovery/SearchProcessor.java
@@ -366,7 +366,8 @@ public abstract class SearchProcessor {
     }
 
     private String toIndexQuery(AtlasStructType type, FilterCriteria criteria, Set<String>
indexAttributes, StringBuilder sb, int level) {
-        if (criteria.getCondition() != null && CollectionUtils.isNotEmpty(criteria.getCriterion()))
{
+        Condition condition = criteria.getCondition();
+        if (condition != null && CollectionUtils.isNotEmpty(criteria.getCriterion()))
{
             StringBuilder nestedExpression = new StringBuilder();
 
             for (FilterCriteria filterCriteria : criteria.getCriterion()) {
@@ -374,16 +375,20 @@ public abstract class SearchProcessor {
 
                 if (StringUtils.isNotEmpty(nestedQuery)) {
                     if (nestedExpression.length() > 0) {
-                        nestedExpression.append(SPACE_STRING).append(criteria.getCondition()).append(SPACE_STRING);
+                        nestedExpression.append(SPACE_STRING).append(condition).append(SPACE_STRING);
                     }
                     nestedExpression.append(nestedQuery);
                 }
             }
 
-            if (level == 0) {
-                return nestedExpression.length() > 0 ? sb.append(nestedExpression).toString()
: EMPTY_STRING;
+            boolean needSurroundingBraces = level != 0 || (condition == Condition.OR &&
criteria.getCriterion().size() > 1);
+            if (nestedExpression.length() > 0) {
+                return sb.append(needSurroundingBraces ? BRACE_OPEN_STR : EMPTY_STRING)
+                         .append(nestedExpression)
+                         .append(needSurroundingBraces ? BRACE_CLOSE_STR : EMPTY_STRING)
+                         .toString();
             } else {
-                return nestedExpression.length() > 0 ? sb.append(BRACE_OPEN_STR).append(nestedExpression).append(BRACE_CLOSE_STR).toString()
: EMPTY_STRING;
+                return EMPTY_STRING;
             }
         } else if (indexAttributes.contains(criteria.getAttributeName())){
             return toIndexExpression(type, criteria.getAttributeName(), criteria.getOperator(),
criteria.getAttributeValue());


Mime
View raw message