atlas-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apoorvn...@apache.org
Subject atlas git commit: ATLAS-2184: IS_NULL, NOT_NULL operator support (#2)
Date Sat, 30 Sep 2017 01:37:07 GMT
Repository: atlas
Updated Branches:
  refs/heads/master 57fbb9cea -> 3af543640


ATLAS-2184: IS_NULL, NOT_NULL operator support (#2)


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

Branch: refs/heads/master
Commit: 3af543640c944dc98cdc3334588a2ffc5a12e34c
Parents: 57fbb9c
Author: apoorvnaik <apoorvnaik@apache.org>
Authored: Thu Sep 28 12:56:24 2017 -0700
Committer: apoorvnaik <apoorvnaik@apache.org>
Committed: Fri Sep 29 18:37:04 2017 -0700

----------------------------------------------------------------------
 .../apache/atlas/discovery/SearchProcessor.java | 29 ++++++++++++++------
 .../atlas/util/AtlasGremlin2QueryProvider.java  |  4 +++
 .../atlas/util/AtlasGremlinQueryProvider.java   |  4 ++-
 3 files changed, 27 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/3af54364/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 a20a6c1..ba0cd8a 100644
--- a/repository/src/main/java/org/apache/atlas/discovery/SearchProcessor.java
+++ b/repository/src/main/java/org/apache/atlas/discovery/SearchProcessor.java
@@ -459,6 +459,7 @@ public abstract class SearchProcessor {
             final Class     attrClass;
             final Object    attrValue;
 
+            // Some operators support null comparison, thus the parsing has to be conditional
             switch (attrType.getTypeName()) {
                 case AtlasBaseTypeDef.ATLAS_TYPE_STRING:
                     attrClass = String.class;
@@ -466,40 +467,40 @@ public abstract class SearchProcessor {
                     break;
                 case AtlasBaseTypeDef.ATLAS_TYPE_SHORT:
                     attrClass = Short.class;
-                    attrValue = Short.parseShort(attrVal);
+                    attrValue = attrVal == null ? null : Short.parseShort(attrVal);
                     break;
                 case AtlasBaseTypeDef.ATLAS_TYPE_INT:
                     attrClass = Integer.class;
-                    attrValue = Integer.parseInt(attrVal);
+                    attrValue = attrVal == null ? null : Integer.parseInt(attrVal);
                     break;
                 case AtlasBaseTypeDef.ATLAS_TYPE_BIGINTEGER:
                     attrClass = BigInteger.class;
-                    attrValue = new BigInteger(attrVal);
+                    attrValue = attrVal == null ? null : new BigInteger(attrVal);
                     break;
                 case AtlasBaseTypeDef.ATLAS_TYPE_BOOLEAN:
                     attrClass = Boolean.class;
-                    attrValue = Boolean.parseBoolean(attrVal);
+                    attrValue = attrVal == null ? null : Boolean.parseBoolean(attrVal);
                     break;
                 case AtlasBaseTypeDef.ATLAS_TYPE_BYTE:
                     attrClass = Byte.class;
-                    attrValue = Byte.parseByte(attrVal);
+                    attrValue = attrVal == null ? null : Byte.parseByte(attrVal);
                     break;
                 case AtlasBaseTypeDef.ATLAS_TYPE_LONG:
                 case AtlasBaseTypeDef.ATLAS_TYPE_DATE:
                     attrClass = Long.class;
-                    attrValue = Long.parseLong(attrVal);
+                    attrValue = attrVal == null ? null : Long.parseLong(attrVal);
                     break;
                 case AtlasBaseTypeDef.ATLAS_TYPE_FLOAT:
                     attrClass = Float.class;
-                    attrValue = Float.parseFloat(attrVal);
+                    attrValue = attrVal == null ? null : Float.parseFloat(attrVal);
                     break;
                 case AtlasBaseTypeDef.ATLAS_TYPE_DOUBLE:
                     attrClass = Double.class;
-                    attrValue = Double.parseDouble(attrVal);
+                    attrValue = attrVal == null ? null : Double.parseDouble(attrVal);
                     break;
                 case AtlasBaseTypeDef.ATLAS_TYPE_BIGDECIMAL:
                     attrClass = BigDecimal.class;
-                    attrValue = new BigDecimal(attrVal);
+                    attrValue = attrVal == null ? null : new BigDecimal(attrVal);
                     break;
                 default:
                     if (attrType instanceof AtlasEnumType) {
@@ -637,6 +638,12 @@ public abstract class SearchProcessor {
             case CONTAINS:
                 queryTemplate = queryProvider.getQuery(AtlasGremlinQueryProvider.AtlasGremlinQuery.COMPARE_CONTAINS);
                 break;
+            case IS_NULL:
+                queryTemplate = queryProvider.getQuery(AtlasGremlinQueryProvider.AtlasGremlinQuery.COMPARE_IS_NULL);
+                break;
+            case NOT_NULL:
+                queryTemplate = queryProvider.getQuery(AtlasGremlinQueryProvider.AtlasGremlinQuery.COMPARE_NOT_NULL);
+                break;
         }
 
         if (org.apache.commons.lang3.StringUtils.isNotEmpty(queryTemplate)) {
@@ -695,6 +702,10 @@ public abstract class SearchProcessor {
     }
 
     private static boolean hasIndexQuerySpecialChar(String attributeValue) {
+        if (attributeValue == null) {
+            return false;
+        }
+
         for (int i = 0; i < attributeValue.length(); i++) {
             if (isIndexQuerySpecialChar(attributeValue.charAt(i))) {
                 return true;

http://git-wip-us.apache.org/repos/asf/atlas/blob/3af54364/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 33f9b7a..f1014c5 100644
--- a/repository/src/main/java/org/apache/atlas/util/AtlasGremlin2QueryProvider.java
+++ b/repository/src/main/java/org/apache/atlas/util/AtlasGremlin2QueryProvider.java
@@ -95,6 +95,10 @@ public class AtlasGremlin2QueryProvider extends AtlasGremlinQueryProvider
{
                 return ".filter({it.getProperty('%s').endsWith(%s)})";
             case COMPARE_CONTAINS:
                 return ".filter({it.getProperty('%s').contains(%s)})";
+            case COMPARE_IS_NULL:
+                return ".hasNot('%s')";
+            case COMPARE_NOT_NULL:
+                return ".has('%s')";
             case RELATIONSHIP_SEARCH:
                 return "g.V('__guid', guid).both(relation).has('__state', T.in, states)";
             case RELATIONSHIP_SEARCH_ASCENDING_SORT:

http://git-wip-us.apache.org/repos/asf/atlas/blob/3af54364/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 a602529..e4898bd 100644
--- a/repository/src/main/java/org/apache/atlas/util/AtlasGremlinQueryProvider.java
+++ b/repository/src/main/java/org/apache/atlas/util/AtlasGremlinQueryProvider.java
@@ -75,6 +75,8 @@ public abstract class AtlasGremlinQueryProvider {
         COMPARE_MATCHES,
         COMPARE_STARTS_WITH,
         COMPARE_ENDS_WITH,
-        COMPARE_CONTAINS
+        COMPARE_CONTAINS,
+        COMPARE_IS_NULL,
+        COMPARE_NOT_NULL
     }
 }


Mime
View raw message