private String toIndexExpression(AtlasStructType type, String attrName, SearchParameters.Operator op, String attrVal) { String ret = EMPTY_STRING; try { if (OPERATOR_MAP.get(op) != null) { String qualifiedName = type.getQualifiedAttributeName(attrName); String escapeIndexQueryValue = AtlasAttribute.escapeIndexQueryValue(attrVal); ret = String.format(OPERATOR_MAP.get(op), qualifiedName, escapeIndexQueryValue); } } catch (AtlasBaseException ex) { LOG.warn(ex.getMessage()); } 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()); } } }
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; }
final String qualifiedName = type.getQualifiedAttributeName(attrName);