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;
}
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;
}
Aggregations