use of org.apache.atlas.groovy.FunctionCallExpression in project incubator-atlas by apache.
the class AbstractGremlinQueryOptimizerTest method testSimpleRangeExpression.
@Test
public void testSimpleRangeExpression() throws AtlasException {
GroovyExpression expr1 = makeHasExpression(null, "name", "Fred");
GroovyExpression expr2 = makeHasExpression(null, "name", "George");
GroovyExpression expr3 = makeHasExpression(null, "age", "34");
GroovyExpression expr4 = makeHasExpression(null, "size", "small");
GroovyExpression toOptimize = getVerticesExpression();
toOptimize = getFactory().generateLogicalExpression(toOptimize, "or", Arrays.asList(expr1, expr2));
toOptimize = getFactory().generateLogicalExpression(toOptimize, "and", Collections.singletonList(expr3));
toOptimize = getFactory().generateAdjacentVerticesExpression(toOptimize, AtlasEdgeDirection.OUT, "eats");
toOptimize = getFactory().generateLogicalExpression(toOptimize, "and", Collections.singletonList(expr4));
toOptimize = makeHasExpression(toOptimize, "color", "blue");
toOptimize = getFactory().generateRangeExpression(toOptimize, 0, 10);
toOptimize = new FunctionCallExpression(TraversalStepType.END, toOptimize, "toList");
toOptimize = new FunctionCallExpression(toOptimize, "size");
GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
assertEquals(optimized.toString(), getExpectedGremlinForTestSimpleRangeExpression());
}
use of org.apache.atlas.groovy.FunctionCallExpression in project incubator-atlas by apache.
the class AbstractGremlinQueryOptimizerTest method testToListConversion.
@Test
public void testToListConversion() 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");
GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
assertEquals(optimized.toString(), getExpectedGremlinForTestToListConversion());
}
use of org.apache.atlas.groovy.FunctionCallExpression in project incubator-atlas by apache.
the class Gremlin2ExpressionFactory method generateSelectExpression.
@Override
public GroovyExpression generateSelectExpression(GroovyExpression parent, List<LiteralExpression> sourceNames, List<GroovyExpression> srcExprs) {
GroovyExpression srcNamesExpr = new ListExpression(sourceNames);
List<GroovyExpression> selectArgs = new ArrayList<>();
selectArgs.add(srcNamesExpr);
for (GroovyExpression expr : srcExprs) {
selectArgs.add(new ClosureExpression(expr));
}
return new FunctionCallExpression(TraversalStepType.MAP_TO_VALUE, parent, SELECT_METHOD, selectArgs);
}
use of org.apache.atlas.groovy.FunctionCallExpression in project incubator-atlas by apache.
the class Gremlin3ExpressionFactory method typeTestExpression.
@Override
public GroovyExpression typeTestExpression(GraphPersistenceStrategies s, String typeName, GroovyExpression itRef) {
LiteralExpression superTypeAttrExpr = new LiteralExpression(s.superTypeAttributeName());
LiteralExpression typeNameExpr = new LiteralExpression(typeName);
LiteralExpression typeAttrExpr = new LiteralExpression(s.typeAttributeName());
FunctionCallExpression result = new FunctionCallExpression(TraversalStepType.FILTER, HAS_METHOD, typeAttrExpr, new FunctionCallExpression(EQ_METHOD, typeNameExpr));
result = new FunctionCallExpression(TraversalStepType.FILTER, result, "or");
result = new FunctionCallExpression(TraversalStepType.FILTER, result, HAS_METHOD, superTypeAttrExpr, new FunctionCallExpression(EQ_METHOD, typeNameExpr));
return result;
}
use of org.apache.atlas.groovy.FunctionCallExpression in project incubator-atlas by apache.
the class Gremlin3ExpressionFactory method initialExpression.
@Override
protected GroovyExpression initialExpression(GroovyExpression varExpr, GraphPersistenceStrategies s) {
// this bit of groovy magic converts the set of vertices in varName into
// a String containing the ids of all the vertices. This becomes the
// argument
// to g.V(). This is needed because Gremlin 3 does not support
// _()
// s"g.V(${varName}.collect{it.id()} as String[])"
GroovyExpression gExpr = getGraphExpression();
GroovyExpression varRefExpr = new TypeCoersionExpression(varExpr, OBJECT_ARRAY_CLASS);
GroovyExpression matchingVerticesExpr = new FunctionCallExpression(TraversalStepType.START, gExpr, V_METHOD, varRefExpr);
GroovyExpression isEmpty = new FunctionCallExpression(varExpr, "isEmpty");
GroovyExpression emptyGraph = getEmptyTraversalExpression();
GroovyExpression expr = new TernaryOperatorExpression(isEmpty, emptyGraph, matchingVerticesExpr);
return s.addInitialQueryCondition(expr);
}
Aggregations