Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id ED507200D12 for ; Sat, 23 Sep 2017 03:34:38 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id EBC841609D0; Sat, 23 Sep 2017 01:34:38 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 3ED951609E5 for ; Sat, 23 Sep 2017 03:34:38 +0200 (CEST) Received: (qmail 38807 invoked by uid 500); 23 Sep 2017 01:34:37 -0000 Mailing-List: contact commits-help@atlas.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@atlas.apache.org Delivered-To: mailing list commits@atlas.apache.org Received: (qmail 38798 invoked by uid 99); 23 Sep 2017 01:34:37 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 23 Sep 2017 01:34:37 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5F715F5AC5; Sat, 23 Sep 2017 01:34:36 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: madhan@apache.org To: commits@atlas.apache.org Date: Sat, 23 Sep 2017 01:34:37 -0000 Message-Id: <0074ec125e5a450cb7a1c24491323b8d@git.apache.org> In-Reply-To: <8853f6cb7dcd411ca67c2dc9057a57be@git.apache.org> References: <8853f6cb7dcd411ca67c2dc9057a57be@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] atlas git commit: ATLAS-2151: fix incorrect handling of OR condition in index query archived-at: Sat, 23 Sep 2017 01:34:39 -0000 ATLAS-2151: fix incorrect handling of OR condition in index query Signed-off-by: Madhan Neethiraj 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 Authored: Thu Sep 21 21:20:34 2017 -0700 Committer: Madhan Neethiraj 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 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());