Commit 3af54364 by apoorvnaik

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

parent 57fbb9ce
...@@ -459,6 +459,7 @@ public abstract class SearchProcessor { ...@@ -459,6 +459,7 @@ public abstract class SearchProcessor {
final Class attrClass; final Class attrClass;
final Object attrValue; final Object attrValue;
// Some operators support null comparison, thus the parsing has to be conditional
switch (attrType.getTypeName()) { switch (attrType.getTypeName()) {
case AtlasBaseTypeDef.ATLAS_TYPE_STRING: case AtlasBaseTypeDef.ATLAS_TYPE_STRING:
attrClass = String.class; attrClass = String.class;
...@@ -466,40 +467,40 @@ public abstract class SearchProcessor { ...@@ -466,40 +467,40 @@ public abstract class SearchProcessor {
break; break;
case AtlasBaseTypeDef.ATLAS_TYPE_SHORT: case AtlasBaseTypeDef.ATLAS_TYPE_SHORT:
attrClass = Short.class; attrClass = Short.class;
attrValue = Short.parseShort(attrVal); attrValue = attrVal == null ? null : Short.parseShort(attrVal);
break; break;
case AtlasBaseTypeDef.ATLAS_TYPE_INT: case AtlasBaseTypeDef.ATLAS_TYPE_INT:
attrClass = Integer.class; attrClass = Integer.class;
attrValue = Integer.parseInt(attrVal); attrValue = attrVal == null ? null : Integer.parseInt(attrVal);
break; break;
case AtlasBaseTypeDef.ATLAS_TYPE_BIGINTEGER: case AtlasBaseTypeDef.ATLAS_TYPE_BIGINTEGER:
attrClass = BigInteger.class; attrClass = BigInteger.class;
attrValue = new BigInteger(attrVal); attrValue = attrVal == null ? null : new BigInteger(attrVal);
break; break;
case AtlasBaseTypeDef.ATLAS_TYPE_BOOLEAN: case AtlasBaseTypeDef.ATLAS_TYPE_BOOLEAN:
attrClass = Boolean.class; attrClass = Boolean.class;
attrValue = Boolean.parseBoolean(attrVal); attrValue = attrVal == null ? null : Boolean.parseBoolean(attrVal);
break; break;
case AtlasBaseTypeDef.ATLAS_TYPE_BYTE: case AtlasBaseTypeDef.ATLAS_TYPE_BYTE:
attrClass = Byte.class; attrClass = Byte.class;
attrValue = Byte.parseByte(attrVal); attrValue = attrVal == null ? null : Byte.parseByte(attrVal);
break; break;
case AtlasBaseTypeDef.ATLAS_TYPE_LONG: case AtlasBaseTypeDef.ATLAS_TYPE_LONG:
case AtlasBaseTypeDef.ATLAS_TYPE_DATE: case AtlasBaseTypeDef.ATLAS_TYPE_DATE:
attrClass = Long.class; attrClass = Long.class;
attrValue = Long.parseLong(attrVal); attrValue = attrVal == null ? null : Long.parseLong(attrVal);
break; break;
case AtlasBaseTypeDef.ATLAS_TYPE_FLOAT: case AtlasBaseTypeDef.ATLAS_TYPE_FLOAT:
attrClass = Float.class; attrClass = Float.class;
attrValue = Float.parseFloat(attrVal); attrValue = attrVal == null ? null : Float.parseFloat(attrVal);
break; break;
case AtlasBaseTypeDef.ATLAS_TYPE_DOUBLE: case AtlasBaseTypeDef.ATLAS_TYPE_DOUBLE:
attrClass = Double.class; attrClass = Double.class;
attrValue = Double.parseDouble(attrVal); attrValue = attrVal == null ? null : Double.parseDouble(attrVal);
break; break;
case AtlasBaseTypeDef.ATLAS_TYPE_BIGDECIMAL: case AtlasBaseTypeDef.ATLAS_TYPE_BIGDECIMAL:
attrClass = BigDecimal.class; attrClass = BigDecimal.class;
attrValue = new BigDecimal(attrVal); attrValue = attrVal == null ? null : new BigDecimal(attrVal);
break; break;
default: default:
if (attrType instanceof AtlasEnumType) { if (attrType instanceof AtlasEnumType) {
...@@ -637,6 +638,12 @@ public abstract class SearchProcessor { ...@@ -637,6 +638,12 @@ public abstract class SearchProcessor {
case CONTAINS: case CONTAINS:
queryTemplate = queryProvider.getQuery(AtlasGremlinQueryProvider.AtlasGremlinQuery.COMPARE_CONTAINS); queryTemplate = queryProvider.getQuery(AtlasGremlinQueryProvider.AtlasGremlinQuery.COMPARE_CONTAINS);
break; 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)) { if (org.apache.commons.lang3.StringUtils.isNotEmpty(queryTemplate)) {
...@@ -695,6 +702,10 @@ public abstract class SearchProcessor { ...@@ -695,6 +702,10 @@ public abstract class SearchProcessor {
} }
private static boolean hasIndexQuerySpecialChar(String attributeValue) { private static boolean hasIndexQuerySpecialChar(String attributeValue) {
if (attributeValue == null) {
return false;
}
for (int i = 0; i < attributeValue.length(); i++) { for (int i = 0; i < attributeValue.length(); i++) {
if (isIndexQuerySpecialChar(attributeValue.charAt(i))) { if (isIndexQuerySpecialChar(attributeValue.charAt(i))) {
return true; return true;
......
...@@ -95,6 +95,10 @@ public class AtlasGremlin2QueryProvider extends AtlasGremlinQueryProvider { ...@@ -95,6 +95,10 @@ public class AtlasGremlin2QueryProvider extends AtlasGremlinQueryProvider {
return ".filter({it.getProperty('%s').endsWith(%s)})"; return ".filter({it.getProperty('%s').endsWith(%s)})";
case COMPARE_CONTAINS: case COMPARE_CONTAINS:
return ".filter({it.getProperty('%s').contains(%s)})"; return ".filter({it.getProperty('%s').contains(%s)})";
case COMPARE_IS_NULL:
return ".hasNot('%s')";
case COMPARE_NOT_NULL:
return ".has('%s')";
case RELATIONSHIP_SEARCH: case RELATIONSHIP_SEARCH:
return "g.V('__guid', guid).both(relation).has('__state', T.in, states)"; return "g.V('__guid', guid).both(relation).has('__state', T.in, states)";
case RELATIONSHIP_SEARCH_ASCENDING_SORT: case RELATIONSHIP_SEARCH_ASCENDING_SORT:
......
...@@ -75,6 +75,8 @@ public abstract class AtlasGremlinQueryProvider { ...@@ -75,6 +75,8 @@ public abstract class AtlasGremlinQueryProvider {
COMPARE_MATCHES, COMPARE_MATCHES,
COMPARE_STARTS_WITH, COMPARE_STARTS_WITH,
COMPARE_ENDS_WITH, COMPARE_ENDS_WITH,
COMPARE_CONTAINS COMPARE_CONTAINS,
COMPARE_IS_NULL,
COMPARE_NOT_NULL
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment