Search in sources :

Example 41 with FunctionCallExpression

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

Example 42 with FunctionCallExpression

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

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