You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by pi...@apache.org on 2021/01/12 06:17:21 UTC

[atlas] branch master updated: ATLAS-4095 : DSL Search : __isIncomplete System Attribute returns incorrect results or throws error

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

pinal 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 85c9507  ATLAS-4095 : DSL Search : __isIncomplete System Attribute returns incorrect results or throws error
85c9507 is described below

commit 85c95078d5c02e17a0356bb7f1589c91b435508e
Author: Pinal <pinal-shah>
AuthorDate: Thu Jan 7 13:14:52 2021 +0530

    ATLAS-4095 : DSL Search : __isIncomplete System Attribute returns incorrect results or throws error
    
    Signed-off-by: Pinal <pinal-shah>
---
 .../apache/atlas/query/GremlinQueryComposer.java   | 52 +++++++++++++++++-----
 .../org/apache/atlas/query/IdentifierHelper.java   |  7 +++
 2 files changed, 48 insertions(+), 11 deletions(-)

diff --git a/repository/src/main/java/org/apache/atlas/query/GremlinQueryComposer.java b/repository/src/main/java/org/apache/atlas/query/GremlinQueryComposer.java
index 2493810..36b514e 100644
--- a/repository/src/main/java/org/apache/atlas/query/GremlinQueryComposer.java
+++ b/repository/src/main/java/org/apache/atlas/query/GremlinQueryComposer.java
@@ -23,6 +23,7 @@ import org.apache.atlas.exception.AtlasBaseException;
 import org.apache.atlas.model.TypeCategory;
 import org.apache.atlas.model.discovery.SearchParameters;
 import org.apache.atlas.model.typedef.AtlasStructDef;
+import org.apache.atlas.repository.Constants;
 import org.apache.atlas.type.AtlasEntityType;
 import org.apache.atlas.type.AtlasStructType;
 import org.apache.atlas.type.AtlasType;
@@ -191,25 +192,30 @@ public class GremlinQueryComposer {
 
         if (lhsI.isDate()) {
             rhs = parseDate(rhs);
-        } else if (lhsI.isNumeric()) {
+        } else if (lhsI.isNumeric() && !StringUtils.equals(lhsI.getAttributeName(), Constants.IS_INCOMPLETE_PROPERTY_KEY)) {
             rhs = parseNumber(rhs, this.context);
         }
 
         rhs = addQuotesIfNecessary(lhsI, rhs);
+
         SearchParameters.Operator op = SearchParameters.Operator.fromString(operator);
-        if (op == SearchParameters.Operator.LIKE) {
-            final AtlasStructType.AtlasAttribute attribute = context.getActiveEntityType().getAttribute(lhsI.getAttributeName());
-            final AtlasStructDef.AtlasAttributeDef.IndexType indexType = attribute.getAttributeDef().getIndexType();
+        if (StringUtils.equals(lhsI.getAttributeName(), Constants.IS_INCOMPLETE_PROPERTY_KEY)) {
+            addForIsIncompleteClause(lhsI, op, rhs);
+        } else {
+            if (op == SearchParameters.Operator.LIKE) {
+                final AtlasStructType.AtlasAttribute attribute = context.getActiveEntityType().getAttribute(lhsI.getAttributeName());
+                final AtlasStructDef.AtlasAttributeDef.IndexType indexType = attribute.getAttributeDef().getIndexType();
 
-            if (indexType == AtlasStructDef.AtlasAttributeDef.IndexType.STRING || !containsNumberAndLettersOnly(rhs)) {
-                add(GremlinClause.STRING_CONTAINS, getPropertyForClause(lhsI), IdentifierHelper.getFixedRegEx(rhs));
+                if (indexType == AtlasStructDef.AtlasAttributeDef.IndexType.STRING || !containsNumberAndLettersOnly(rhs)) {
+                    add(GremlinClause.STRING_CONTAINS, getPropertyForClause(lhsI), IdentifierHelper.getFixedRegEx(rhs));
+                } else {
+                    add(GremlinClause.TEXT_CONTAINS, getPropertyForClause(lhsI), IdentifierHelper.getFixedRegEx(rhs));
+                }
+            } else if (op == SearchParameters.Operator.IN) {
+                add(GremlinClause.HAS_OPERATOR, getPropertyForClause(lhsI), "within", rhs);
             } else {
-                add(GremlinClause.TEXT_CONTAINS, getPropertyForClause(lhsI), IdentifierHelper.getFixedRegEx(rhs));
+                add(GremlinClause.HAS_OPERATOR, getPropertyForClause(lhsI), op.getSymbols()[1], rhs);
             }
-        } else if (op == SearchParameters.Operator.IN) {
-            add(GremlinClause.HAS_OPERATOR, getPropertyForClause(lhsI), "within", rhs);
-        } else {
-            add(GremlinClause.HAS_OPERATOR, getPropertyForClause(lhsI), op.getSymbols()[1], rhs);
         }
         // record that the attribute has been processed so that the select clause doesn't add a attr presence check
         attributesProcessed.add(lhsI.getQualifiedName());
@@ -226,6 +232,30 @@ public class GremlinQueryComposer {
         }
     }
 
+    private void addForIsIncompleteClause(IdentifierHelper.Info lhsI,SearchParameters.Operator op, String rhs ) {
+        GremlinClause clause = GremlinClause.HAS_OPERATOR;
+        rhs = rhs.replace("'", "").replace("\"", "");
+        switch (op) {
+            case EQ:
+                if (IdentifierHelper.isCompleteValue(rhs)) {
+                    clause = GremlinClause.HAS_NOT_PROPERTY;
+                } else if (IdentifierHelper.isInCompleteValue(rhs)) {
+                    rhs    = Constants.INCOMPLETE_ENTITY_VALUE.toString();
+                }
+                break;
+
+            case NEQ:
+                if (IdentifierHelper.isCompleteValue(rhs)) {
+                    op     = SearchParameters.Operator.EQ;
+                    rhs    = Constants.INCOMPLETE_ENTITY_VALUE.toString();
+                } else if (IdentifierHelper.isInCompleteValue(rhs)) {
+                    clause = GremlinClause.HAS_NOT_PROPERTY;
+                }
+                break;
+        }
+        add(clause, getPropertyForClause(lhsI), op.getSymbols()[1], rhs);
+    }
+
     private boolean containsNumberAndLettersOnly(String rhs) {
         return Pattern.matches(REGEX_ALPHA_NUMERIC_PATTERN, IdentifierHelper.removeWildcards(rhs));
     }
diff --git a/repository/src/main/java/org/apache/atlas/query/IdentifierHelper.java b/repository/src/main/java/org/apache/atlas/query/IdentifierHelper.java
index 7b03d11..a1278f4 100644
--- a/repository/src/main/java/org/apache/atlas/query/IdentifierHelper.java
+++ b/repository/src/main/java/org/apache/atlas/query/IdentifierHelper.java
@@ -120,6 +120,13 @@ public class IdentifierHelper {
         return removeQuotes(s).replace("*", "").replace("?", "");
     }
 
+    public static boolean isCompleteValue(String s) {
+        return (StringUtils.isEmpty(s) || StringUtils.equals(s, "0") || StringUtils.equalsIgnoreCase(s, "false"));
+    }
+
+    public static boolean isInCompleteValue(String s) {
+        return StringUtils.isNotEmpty(s) && (StringUtils.equals(s, "1") || StringUtils.equalsIgnoreCase(s, "true"));
+    }
     public static class Info {
         private String   raw;
         private String   actual;