Search in sources :

Example 21 with FunctionCallExpression

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());
}
Also used : GroovyExpression(org.apache.atlas.groovy.GroovyExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression) Test(org.testng.annotations.Test)

Example 22 with FunctionCallExpression

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());
}
Also used : GroovyExpression(org.apache.atlas.groovy.GroovyExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression) Test(org.testng.annotations.Test)

Example 23 with FunctionCallExpression

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);
}
Also used : ListExpression(org.apache.atlas.groovy.ListExpression) ArrayList(java.util.ArrayList) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) ClosureExpression(org.apache.atlas.groovy.ClosureExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Example 24 with FunctionCallExpression

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;
}
Also used : LiteralExpression(org.apache.atlas.groovy.LiteralExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Example 25 with FunctionCallExpression

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);
}
Also used : TypeCoersionExpression(org.apache.atlas.groovy.TypeCoersionExpression) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) TernaryOperatorExpression(org.apache.atlas.groovy.TernaryOperatorExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Aggregations

FunctionCallExpression (org.apache.atlas.groovy.FunctionCallExpression)42 GroovyExpression (org.apache.atlas.groovy.GroovyExpression)34 LiteralExpression (org.apache.atlas.groovy.LiteralExpression)15 ClosureExpression (org.apache.atlas.groovy.ClosureExpression)14 CastExpression (org.apache.atlas.groovy.CastExpression)5 TypeCoersionExpression (org.apache.atlas.groovy.TypeCoersionExpression)5 AbstractFunctionExpression (org.apache.atlas.groovy.AbstractFunctionExpression)4 ComparisonExpression (org.apache.atlas.groovy.ComparisonExpression)4 FieldExpression (org.apache.atlas.groovy.FieldExpression)4 IdentifierExpression (org.apache.atlas.groovy.IdentifierExpression)4 TernaryOperatorExpression (org.apache.atlas.groovy.TernaryOperatorExpression)4 Test (org.testng.annotations.Test)4 ArrayList (java.util.ArrayList)3 ComparisonOperatorExpression (org.apache.atlas.groovy.ComparisonOperatorExpression)2 LogicalExpression (org.apache.atlas.groovy.LogicalExpression)2 AttributeInfo (org.apache.atlas.typesystem.types.AttributeInfo)2 IDataType (org.apache.atlas.typesystem.types.IDataType)2 VariableDeclaration (org.apache.atlas.groovy.ClosureExpression.VariableDeclaration)1 ListExpression (org.apache.atlas.groovy.ListExpression)1 TraversalStepType (org.apache.atlas.groovy.TraversalStepType)1