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; } }
protected void constructGremlinFilterQuery(StringBuilder gremlinQuery, Map<String, Object> queryBindings, AtlasStructType structType, FilterCriteria filterCriteria) { if (filterCriteria != null) { FilterCriteria.Condition condition = filterCriteria.getCondition();
protected void processSearchAttributes(AtlasStructType structType, FilterCriteria filterCriteria, Set<String> indexFiltered, Set<String> graphFiltered, Set<String> allAttributes) { if (structType == null || filterCriteria == null) { return; } Condition filterCondition = filterCriteria.getCondition(); List<FilterCriteria> criterion = filterCriteria.getCriterion(); if (filterCondition != null && CollectionUtils.isNotEmpty(criterion)) { for (SearchParameters.FilterCriteria criteria : criterion) { processSearchAttributes(structType, criteria, indexFiltered, graphFiltered, allAttributes); } } else if (StringUtils.isNotEmpty(filterCriteria.getAttributeName())) { try { String attributeName = filterCriteria.getAttributeName(); if (isIndexSearchable(filterCriteria, structType)) { indexFiltered.add(attributeName); } else { LOG.warn("not using index-search for attribute '{}'; might cause poor performance", structType.getQualifiedAttributeName(attributeName)); graphFiltered.add(attributeName); } if (structType instanceof AtlasEntityType) { // Capture the entity attributes context.getEntityAttributes().add(attributeName); } allAttributes.add(attributeName); } catch (AtlasBaseException e) { LOG.warn(e.getMessage()); } } }
if (criteria.getCondition() != null && CollectionUtils.isNotEmpty(criteria.getCriterion())) { StringBuilder nestedExpression = new StringBuilder(); nestedExpression.append(SPACE_STRING).append(criteria.getCondition()).append(SPACE_STRING);
protected AtlasGraphQuery toGraphFilterQuery(AtlasStructType type, FilterCriteria criteria, Set<String> graphAttributes, AtlasGraphQuery query) { if (criteria != null) { if (criteria.getCondition() != null) { if (criteria.getCondition() == Condition.AND) { for (FilterCriteria filterCriteria : criteria.getCriterion()) { AtlasGraphQuery nestedQuery = toGraphFilterQuery(type, filterCriteria, graphAttributes, context.getGraph().query());
protected boolean canApplyIndexFilter(AtlasStructType structType, FilterCriteria filterCriteria, boolean insideOrCondition) { if (filterCriteria == null) { return true; } boolean ret = true; Condition filterCondition = filterCriteria.getCondition(); List<FilterCriteria> criterion = filterCriteria.getCriterion(); Set<String> indexedKeys = context.getIndexedKeys(); if (filterCondition != null && CollectionUtils.isNotEmpty(criterion)) { insideOrCondition = insideOrCondition || filterCondition == Condition.OR; // If we have nested criterion let's find any nested ORs with non-indexed attr for (FilterCriteria criteria : criterion) { ret = canApplyIndexFilter(structType, criteria, insideOrCondition); if (!ret) { break; } } } else if (StringUtils.isNotEmpty(filterCriteria.getAttributeName())) { try { if (insideOrCondition && !isIndexSearchable(filterCriteria, structType)) { ret = false; } } catch (AtlasBaseException e) { LOG.warn(e.getMessage()); } } return ret; }
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; }
private void validateAttributes(final AtlasStructType structType, final FilterCriteria filterCriteria) throws AtlasBaseException { if (filterCriteria != null) { FilterCriteria.Condition condition = filterCriteria.getCondition(); if (condition != null && CollectionUtils.isNotEmpty(filterCriteria.getCriterion())) { for (FilterCriteria criteria : filterCriteria.getCriterion()) { validateAttributes(structType, criteria); } } else { String attributeName = filterCriteria.getAttributeName(); if (StringUtils.isNotEmpty(attributeName) && structType.getAttributeType(attributeName) == null) { throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_ATTRIBUTE, attributeName, structType.getTypeName()); } } } }