use of org.apache.atlas.groovy.FunctionCallExpression in project incubator-atlas by apache.
the class AbstractGremlinQueryOptimizerTest method testAddClosureWithExitExpressionDifferentFromExpr.
public void testAddClosureWithExitExpressionDifferentFromExpr() throws AtlasException {
GroovyExpression expr1 = makeHasExpression("prop1", "Fred");
GroovyExpression expr2 = makeHasExpression("prop2", "George");
GroovyExpression toOptimize = getFactory().generateLogicalExpression(getVerticesExpression(), "or", Arrays.asList(expr1, expr2));
toOptimize = makeOutExpression(toOptimize, "knows");
toOptimize = makeOutExpression(toOptimize, "livesIn");
toOptimize = new FunctionCallExpression(TraversalStepType.END, toOptimize, "toList");
toOptimize = new FunctionCallExpression(toOptimize, "size");
GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
assertEquals(optimized.toString(), getExpectedGremlinForTestAddClosureWithExitExpressionDifferentFromExpr());
}
use of org.apache.atlas.groovy.FunctionCallExpression in project incubator-atlas by apache.
the class AbstractGremlinQueryOptimizerTest method testAddClosureWithExitExpressionEqualToExpr.
@Test
public void testAddClosureWithExitExpressionEqualToExpr() throws AtlasException {
GroovyExpression expr1 = makeHasExpression("prop1", "Fred");
GroovyExpression expr2 = makeHasExpression("prop2", "George");
GroovyExpression toOptimize = getFactory().generateLogicalExpression(getVerticesExpression(), "or", Arrays.asList(expr1, expr2));
toOptimize = makeOutExpression(toOptimize, "knows");
toOptimize = makeOutExpression(toOptimize, "livesIn");
toOptimize = new FunctionCallExpression(TraversalStepType.END, toOptimize, "toList");
GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
assertEquals(optimized.toString(), getExpectedGremlinForTestAddClosureWithExitExpressionEqualToExpr());
}
use of org.apache.atlas.groovy.FunctionCallExpression in project incubator-atlas by apache.
the class GremlinExpressionFactory method getAliasNameIfRelevant.
/**
* Checks if the given expression is an alias expression, and if so
* returns the alias from the expression. Otherwise, null is
* returned.
*/
public String getAliasNameIfRelevant(GroovyExpression expr) {
if (!(expr instanceof FunctionCallExpression)) {
return null;
}
FunctionCallExpression fc = (FunctionCallExpression) expr;
if (!fc.getFunctionName().equals(AS_METHOD)) {
return null;
}
LiteralExpression aliasName = (LiteralExpression) fc.getArguments().get(0);
return aliasName.getValue().toString();
}
use of org.apache.atlas.groovy.FunctionCallExpression in project incubator-atlas by apache.
the class GremlinExpressionFactory method typeTestExpressionUsingFilter.
private List<GroovyExpression> typeTestExpressionUsingFilter(GraphPersistenceStrategies s, GroovyExpression parent, String typeName) {
GroovyExpression itExpr = getItVariable();
GroovyExpression typeTestExpr = typeTestExpression(s, typeName, itExpr);
GroovyExpression closureExpr = new ClosureExpression(typeTestExpr);
GroovyExpression filterExpr = new FunctionCallExpression(parent, FILTER_METHOD, closureExpr);
return Collections.singletonList(filterExpr);
}
use of org.apache.atlas.groovy.FunctionCallExpression in project incubator-atlas by apache.
the class GremlinExpressionFactory method getAggregrationExpression.
private GroovyExpression getAggregrationExpression(GroovyExpression itExpr, GroovyExpression mapFunction, String functionName) {
GroovyExpression collectionExpr = new CastExpression(itExpr, "Collection");
ClosureExpression collectFunction = new ClosureExpression(mapFunction);
GroovyExpression transformedList = new FunctionCallExpression(collectionExpr, "collect", collectFunction);
return new FunctionCallExpression(transformedList, functionName);
}
Aggregations