use of org.apache.atlas.groovy.FunctionCallExpression in project incubator-atlas by apache.
the class GremlinExpressionFactory method generateTypeTestExpression.
/**
/**
* Generates a sequence of groovy expressions that filter the vertices to only
* those that match the specified type. If GraphPersistenceStrategies.collectTypeInstancesIntoVar()
* is set and the gremlin optimizer is disabled, the vertices are put into a variable whose name is generated
* from the specified IntSequence. The last item in the result will be a graph traversal restricted to only
* the matching vertices.
*/
public List<GroovyExpression> generateTypeTestExpression(GraphPersistenceStrategies s, GroovyExpression parent, String typeName, IntSequence intSeq) throws AtlasException {
if (AtlasRepositoryConfiguration.isGremlinOptimizerEnabled()) {
GroovyExpression superTypeAttributeNameExpr = new LiteralExpression(s.superTypeAttributeName());
GroovyExpression typeNameExpr = new LiteralExpression(typeName);
GroovyExpression superTypeMatchesExpr = new FunctionCallExpression(TraversalStepType.FILTER, HAS_METHOD, superTypeAttributeNameExpr, typeNameExpr);
GroovyExpression typeAttributeNameExpr = new LiteralExpression(s.typeAttributeName());
GroovyExpression typeMatchesExpr = new FunctionCallExpression(TraversalStepType.FILTER, HAS_METHOD, typeAttributeNameExpr, typeNameExpr);
GroovyExpression result = new FunctionCallExpression(TraversalStepType.FILTER, parent, "or", typeMatchesExpr, superTypeMatchesExpr);
return Collections.singletonList(result);
} else {
if (s.filterBySubTypes()) {
return typeTestExpressionUsingInFilter(s, parent, typeName);
} else if (s.collectTypeInstancesIntoVar()) {
return typeTestExpressionMultiStep(s, typeName, intSeq);
} else {
return typeTestExpressionUsingFilter(s, parent, typeName);
}
}
}
use of org.apache.atlas.groovy.FunctionCallExpression in project incubator-atlas by apache.
the class AbstractGremlinQueryOptimizerTest method testToListWithExtraStuff.
@Test
public void testToListWithExtraStuff() throws AtlasException {
GroovyExpression expr1 = makeHasExpression("prop1", "Fred");
GroovyExpression expr2 = makeHasExpression("prop2", "George");
GroovyExpression toOptimize = getFactory().generateLogicalExpression(getVerticesExpression(), "or", Arrays.asList(expr1, expr2));
toOptimize = new FunctionCallExpression(TraversalStepType.END, toOptimize, "toList");
toOptimize = new FunctionCallExpression(toOptimize, "size");
GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
assertEquals(optimized.toString(), getExpectedGremlinForTestToListWithExtraStuff());
}
Aggregations