private boolean hasAttributeFilter(FilterCriteria filterCriteria) { return filterCriteria != null && (CollectionUtils.isNotEmpty(filterCriteria.getCriterion()) || StringUtils.isNotEmpty(filterCriteria.getAttributeName())); }
private boolean isEmpty(SearchParameters.FilterCriteria filterCriteria) { return filterCriteria == null || (StringUtils.isEmpty(filterCriteria.getAttributeName()) && CollectionUtils.isEmpty(filterCriteria.getCriterion())); }
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; } }
return nestedExpression.length() > 0 ? sb.append(BRACE_OPEN_STR).append(nestedExpression).append(BRACE_CLOSE_STR).toString() : EMPTY_STRING; } else if (solrAttributes.contains(criteria.getAttributeName())){ return toSolrExpression(type, criteria.getAttributeName(), criteria.getOperator(), criteria.getAttributeValue()); } else { return EMPTY_STRING;
} else if (graphAttributes.contains(criteria.getAttributeName())) { String attrName = criteria.getAttributeName(); String attrValue = criteria.getAttributeValue(); SearchParameters.Operator operator = criteria.getOperator();
String attributeName = filterCriteria.getAttributeName(); AtlasAttribute attribute = structType.getAttribute(attributeName);
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; }
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()); } } }
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()); } } } }