Search in sources :

Example 1 with GremlinTranslator

use of org.apache.atlas.query.GremlinTranslator in project incubator-atlas by apache.

the class GraphBackedDiscoveryService method parseAndTranslateDsl.

private GremlinQuery parseAndTranslateDsl(String dslQuery, QueryParams queryParams) throws DiscoveryException {
    CompiledQueryCacheKey entry = new CompiledQueryCacheKey(dslQuery, queryParams);
    GremlinQuery gremlinQuery = QueryProcessor.compiledQueryCache().get(entry);
    if (gremlinQuery == null) {
        Expressions.Expression validatedExpression = parseQuery(dslQuery, queryParams);
        //If the final limit is 0, don't launch the query, return with 0 rows
        if (validatedExpression instanceof Expressions.LimitExpression && ((Integer) ((Expressions.LimitExpression) validatedExpression).limit().rawValue()) == 0) {
            gremlinQuery = new NoopGremlinQuery(validatedExpression.dataType());
        } else {
            gremlinQuery = new GremlinTranslator(validatedExpression, graphPersistenceStrategy).translate();
            if (LOG.isDebugEnabled()) {
                LOG.debug("Query = {}", validatedExpression);
                LOG.debug("Expression Tree = {}", validatedExpression.treeString());
                LOG.debug("Gremlin Query = {}", gremlinQuery.queryStr());
            }
        }
        QueryProcessor.compiledQueryCache().put(entry, gremlinQuery);
    }
    return gremlinQuery;
}
Also used : GremlinTranslator(org.apache.atlas.query.GremlinTranslator) NoopGremlinQuery(org.apache.atlas.util.NoopGremlinQuery) CompiledQueryCacheKey(org.apache.atlas.util.CompiledQueryCacheKey) Expressions(org.apache.atlas.query.Expressions) GremlinQuery(org.apache.atlas.query.GremlinQuery) NoopGremlinQuery(org.apache.atlas.util.NoopGremlinQuery)

Example 2 with GremlinTranslator

use of org.apache.atlas.query.GremlinTranslator in project incubator-atlas by apache.

the class EntityDiscoveryService method toGremlinQuery.

private GremlinQuery toGremlinQuery(String query, int limit, int offset) throws AtlasBaseException {
    QueryParams params = validateSearchParams(limit, offset);
    Either<NoSuccess, Expression> either = QueryParser.apply(query, params);
    if (either.isLeft()) {
        throw new AtlasBaseException(DISCOVERY_QUERY_FAILED, query);
    }
    Expression expression = either.right().get();
    Expression validExpression = QueryProcessor.validate(expression);
    GremlinQuery gremlinQuery = new GremlinTranslator(validExpression, graphPersistenceStrategy).translate();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Translated Gremlin Query: {}", gremlinQuery.queryStr());
    }
    return gremlinQuery;
}
Also used : GremlinTranslator(org.apache.atlas.query.GremlinTranslator) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AliasExpression(org.apache.atlas.query.Expressions.AliasExpression) Expression(org.apache.atlas.query.Expressions.Expression) SelectExpression(org.apache.atlas.query.Expressions.SelectExpression) NoSuccess(scala.util.parsing.combinator.Parsers.NoSuccess) QueryParams(org.apache.atlas.query.QueryParams) GremlinQuery(org.apache.atlas.query.GremlinQuery) AtlasGremlinQuery(org.apache.atlas.util.AtlasGremlinQueryProvider.AtlasGremlinQuery)

Aggregations

GremlinQuery (org.apache.atlas.query.GremlinQuery)2 GremlinTranslator (org.apache.atlas.query.GremlinTranslator)2 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)1 Expressions (org.apache.atlas.query.Expressions)1 AliasExpression (org.apache.atlas.query.Expressions.AliasExpression)1 Expression (org.apache.atlas.query.Expressions.Expression)1 SelectExpression (org.apache.atlas.query.Expressions.SelectExpression)1 QueryParams (org.apache.atlas.query.QueryParams)1 AtlasGremlinQuery (org.apache.atlas.util.AtlasGremlinQueryProvider.AtlasGremlinQuery)1 CompiledQueryCacheKey (org.apache.atlas.util.CompiledQueryCacheKey)1 NoopGremlinQuery (org.apache.atlas.util.NoopGremlinQuery)1 NoSuccess (scala.util.parsing.combinator.Parsers.NoSuccess)1