Search in sources :

Example 1 with AtlasGremlinQueryProvider

use of org.apache.atlas.util.AtlasGremlinQueryProvider in project atlas by apache.

the class SearchProcessor method toGremlinComparisonQuery.

private String toGremlinComparisonQuery(AtlasAttribute attribute, SearchParameters.Operator operator, String attrValue, Map<String, Object> queryBindings) {
    String bindName = "__bind_" + queryBindings.size();
    Object bindValue = attribute.getAttributeType().getNormalizedValue(attrValue);
    AtlasGremlinQueryProvider queryProvider = AtlasGremlinQueryProvider.INSTANCE;
    String queryTemplate = null;
    switch(operator) {
        case LT:
            queryTemplate = queryProvider.getQuery(AtlasGremlinQueryProvider.AtlasGremlinQuery.COMPARE_LT);
            break;
        case GT:
            queryTemplate = queryProvider.getQuery(AtlasGremlinQueryProvider.AtlasGremlinQuery.COMPARE_GT);
            break;
        case LTE:
            queryTemplate = queryProvider.getQuery(AtlasGremlinQueryProvider.AtlasGremlinQuery.COMPARE_LTE);
            break;
        case GTE:
            queryTemplate = queryProvider.getQuery(AtlasGremlinQueryProvider.AtlasGremlinQuery.COMPARE_GTE);
            break;
        case EQ:
            queryTemplate = queryProvider.getQuery(AtlasGremlinQueryProvider.AtlasGremlinQuery.COMPARE_EQ);
            break;
        case NEQ:
            queryTemplate = queryProvider.getQuery(AtlasGremlinQueryProvider.AtlasGremlinQuery.COMPARE_NEQ);
            break;
        case LIKE:
            queryTemplate = queryProvider.getQuery(AtlasGremlinQueryProvider.AtlasGremlinQuery.COMPARE_MATCHES);
            break;
        case STARTS_WITH:
            queryTemplate = queryProvider.getQuery(AtlasGremlinQueryProvider.AtlasGremlinQuery.COMPARE_STARTS_WITH);
            break;
        case ENDS_WITH:
            queryTemplate = queryProvider.getQuery(AtlasGremlinQueryProvider.AtlasGremlinQuery.COMPARE_ENDS_WITH);
            break;
        case CONTAINS:
            queryTemplate = queryProvider.getQuery(AtlasGremlinQueryProvider.AtlasGremlinQuery.COMPARE_CONTAINS);
            break;
        case IS_NULL:
            queryTemplate = queryProvider.getQuery(AtlasGremlinQueryProvider.AtlasGremlinQuery.COMPARE_IS_NULL);
            break;
        case NOT_NULL:
            queryTemplate = queryProvider.getQuery(AtlasGremlinQueryProvider.AtlasGremlinQuery.COMPARE_NOT_NULL);
            break;
    }
    if (org.apache.commons.lang3.StringUtils.isNotEmpty(queryTemplate)) {
        if (bindValue instanceof Date) {
            bindValue = ((Date) bindValue).getTime();
        }
        queryBindings.put(bindName, bindValue);
        return String.format(queryTemplate, attribute.getQualifiedName(), bindName);
    } else {
        return EMPTY_STRING;
    }
}
Also used : AtlasGremlinQueryProvider(org.apache.atlas.util.AtlasGremlinQueryProvider) Date(java.util.Date)

Aggregations

Date (java.util.Date)1 AtlasGremlinQueryProvider (org.apache.atlas.util.AtlasGremlinQueryProvider)1