Commit 57fbb9ce by apoorvnaik Committed by Sarath Subramanian

ATLAS-2184: IS_NULL and NOT_NULL operator support

parent f18555cd
...@@ -346,10 +346,12 @@ public class SearchParameters implements Serializable { ...@@ -346,10 +346,12 @@ public class SearchParameters implements Serializable {
IN(new String[]{"in", "IN"}), IN(new String[]{"in", "IN"}),
LIKE(new String[]{"like", "LIKE"}), LIKE(new String[]{"like", "LIKE"}),
STARTS_WITH(new String[]{"startsWith", "STARTSWITH", "begins_with", "BEGINS_WITH"}), STARTS_WITH(new String[]{"startsWith", "STARTSWITH", "begins_with", "BEGINS_WITH"}),
ENDS_WITH(new String[]{"endsWith", "ENDSWITH", "ends_with", "BEGINS_WITH"}), ENDS_WITH(new String[]{"endsWith", "ENDSWITH", "ends_with", "ENDS_WITH"}),
CONTAINS(new String[]{"contains", "CONTAINS"}), CONTAINS(new String[]{"contains", "CONTAINS"}),
CONTAINS_ANY(new String[]{"containsAny", "CONTAINSANY", "contains_any", "CONTAINS_ANY"}), CONTAINS_ANY(new String[]{"containsAny", "CONTAINSANY", "contains_any", "CONTAINS_ANY"}),
CONTAINS_ALL(new String[]{"containsAll", "CONTAINSALL", "contains_all", "CONTAINS_ALL"}) CONTAINS_ALL(new String[]{"containsAll", "CONTAINSALL", "contains_all", "CONTAINS_ALL"}),
IS_NULL(new String[]{"isNull", "ISNULL", "is_null", "IS_NULL"}),
NOT_NULL(new String[]{"notNull", "NOTNULL", "not_null", "NOT_NULL"}),
; ;
static final Map<String, Operator> operatorsMap = new HashMap<>(); static final Map<String, Operator> operatorsMap = new HashMap<>();
......
...@@ -103,6 +103,14 @@ public abstract class SearchProcessor { ...@@ -103,6 +103,14 @@ public abstract class SearchProcessor {
OPERATOR_MAP.put(SearchParameters.Operator.CONTAINS, "v.\"%s\": (*%s*)"); OPERATOR_MAP.put(SearchParameters.Operator.CONTAINS, "v.\"%s\": (*%s*)");
OPERATOR_PREDICATE_MAP.put(SearchParameters.Operator.CONTAINS, getContainsPredicateGenerator()); OPERATOR_PREDICATE_MAP.put(SearchParameters.Operator.CONTAINS, getContainsPredicateGenerator());
// TODO: Add contains any, contains all mappings here
OPERATOR_MAP.put(SearchParameters.Operator.IS_NULL, "(*:* NOT v.\"%s\":[* TO *])");
OPERATOR_PREDICATE_MAP.put(SearchParameters.Operator.IS_NULL, getIsNullPredicateGenerator());
OPERATOR_MAP.put(SearchParameters.Operator.NOT_NULL, "v.\"%s\":[* TO *]");
OPERATOR_PREDICATE_MAP.put(SearchParameters.Operator.NOT_NULL, getNotNullPredicateGenerator());
} }
protected final SearchContext context; protected final SearchContext context;
...@@ -429,8 +437,9 @@ public abstract class SearchProcessor { ...@@ -429,8 +437,9 @@ public abstract class SearchProcessor {
try { try {
if (OPERATOR_MAP.get(op) != null) { if (OPERATOR_MAP.get(op) != null) {
String qualifiedName = type.getQualifiedAttributeName(attrName); String qualifiedName = type.getQualifiedAttributeName(attrName);
String escapeIndexQueryValue = AtlasAttribute.escapeIndexQueryValue(attrVal);
ret = String.format(OPERATOR_MAP.get(op), qualifiedName, AtlasStructType.AtlasAttribute.escapeIndexQueryValue(attrVal)); ret = String.format(OPERATOR_MAP.get(op), qualifiedName, escapeIndexQueryValue);
} }
} catch (AtlasBaseException ex) { } catch (AtlasBaseException ex) {
LOG.warn(ex.getMessage()); LOG.warn(ex.getMessage());
...@@ -572,7 +581,13 @@ public abstract class SearchProcessor { ...@@ -572,7 +581,13 @@ public abstract class SearchProcessor {
case ENDS_WITH: case ENDS_WITH:
query.has(qualifiedName, AtlasGraphQuery.MatchingOperator.REGEX, getSuffixRegex(attrValue)); query.has(qualifiedName, AtlasGraphQuery.MatchingOperator.REGEX, getSuffixRegex(attrValue));
break; break;
case IN: case IS_NULL:
query.has(qualifiedName, AtlasGraphQuery.ComparisionOperator.EQUAL, null);
break;
case NOT_NULL:
query.has(qualifiedName, AtlasGraphQuery.ComparisionOperator.NOT_EQUAL, null);
break;
default:
LOG.warn("{}: unsupported operator. Ignored", operator); LOG.warn("{}: unsupported operator. Ignored", operator);
break; break;
} }
......
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