private String toIndexQuery(AtlasStructType type, FilterCriteria criteria, Set<String> indexAttributes, StringBuilder sb, int level) { Condition condition = criteria.getCondition(); if (condition != null && CollectionUtils.isNotEmpty(criteria.getCriterion())) { StringBuilder nestedExpression = new StringBuilder(); for (FilterCriteria filterCriteria : criteria.getCriterion()) { String nestedQuery = toIndexQuery(type, filterCriteria, indexAttributes, level + 1); if (StringUtils.isNotEmpty(nestedQuery)) { if (nestedExpression.length() > 0) { nestedExpression.append(SPACE_STRING).append(condition).append(SPACE_STRING); } nestedExpression.append(nestedQuery); } } 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 EMPTY_STRING; } } else if (indexAttributes.contains(criteria.getAttributeName())){ return toIndexExpression(type, criteria.getAttributeName(), criteria.getOperator(), criteria.getAttributeValue()); } else { return EMPTY_STRING; } }
SearchParameters.Operator operator = filterCriteria.getOperator(); String attributeValue = filterCriteria.getAttributeValue();
private boolean isIndexSearchable(FilterCriteria filterCriteria, AtlasStructType structType) throws AtlasBaseException { String qualifiedName = structType.getQualifiedAttributeName(filterCriteria.getAttributeName()); Set<String> indexedKeys = context.getIndexedKeys(); boolean ret = indexedKeys != null && indexedKeys.contains(qualifiedName); if (ret) { // index exists // for string type attributes, don't use index query in the following cases: // - operation is NEQ, as it might return fewer entries due to tokenization of vertex property value // - value-to-compare has special characters AtlasType attributeType = structType.getAttributeType(filterCriteria.getAttributeName()); if (AtlasBaseTypeDef.ATLAS_TYPE_STRING.equals(attributeType.getTypeName())) { if (filterCriteria.getOperator() == SearchParameters.Operator.NEQ) { if (LOG.isDebugEnabled()) { LOG.debug("NEQ operator found for string attribute {}, deferring to in-memory or graph query (might cause poor performance)", qualifiedName); } ret = false; } else if (hasIndexQuerySpecialChar(filterCriteria.getAttributeValue())) { if (LOG.isDebugEnabled()) { LOG.debug("special characters found in filter value {}, deferring to in-memory or graph query (might cause poor performance)", filterCriteria.getAttributeValue()); } ret = false; } } } if (LOG.isDebugEnabled()) { if (!ret) { LOG.debug("Not using index query for: attribute='{}', operator='{}', value='{}'", qualifiedName, filterCriteria.getOperator(), filterCriteria.getAttributeValue()); } } return ret; }
String attrName = criteria.getAttributeName(); String attrValue = criteria.getAttributeValue(); SearchParameters.Operator operator = criteria.getOperator();
private Predicate toInMemoryPredicate(AtlasStructType type, FilterCriteria criteria, Set<String> indexAttributes) { if (criteria.getCondition() != null && CollectionUtils.isNotEmpty(criteria.getCriterion())) { List<Predicate> predicates = new ArrayList<>(); for (FilterCriteria filterCriteria : criteria.getCriterion()) { Predicate predicate = toInMemoryPredicate(type, filterCriteria, indexAttributes); if (predicate != null) { predicates.add(predicate); } } if (CollectionUtils.isNotEmpty(predicates)) { if (criteria.getCondition() == Condition.AND) { return PredicateUtils.allPredicate(predicates); } else { return PredicateUtils.anyPredicate(predicates); } } } else if (indexAttributes.contains(criteria.getAttributeName())){ return toInMemoryPredicate(type, criteria.getAttributeName(), criteria.getOperator(), criteria.getAttributeValue()); } return null; }