Search in sources :

Example 11 with AbstractFunctionExpression

use of org.apache.atlas.groovy.AbstractFunctionExpression in project incubator-atlas by apache.

the class ExpandOrsOptimization method addCallToUpdateResultVariable.

/**
     * This method adds steps to the end of the initial traversal to add the vertices
     * that were found into an intermediate variable (defined as a Set).  If there is one alias,
     * this set will contain the vertices associated with that Alias.  If there are multiple
     * aliases, the values in the set will be alias->vertex maps that have the vertex
     * associated with the alias for each result.

     * @param expr
     * @param aliasNames
     * @param context
     * @return
     */
private GroovyExpression addCallToUpdateResultVariable(GroovyExpression expr, List<LiteralExpression> aliasNames, OptimizationContext context) {
    GroovyExpression result = expr;
    // If there is one range expression in the unoptimized gremlin,
    // add a range expression here so that the intermediate variable will only contain
    // the specified range of vertices.
    AbstractFunctionExpression rangeExpression = context.getRangeExpression();
    if (rangeExpression != null) {
        int[] rangeParameters = factory.getRangeParameters(rangeExpression);
        result = factory.generateRangeExpression(result, rangeParameters[0], rangeParameters[1]);
    }
    if (!aliasNames.isEmpty()) {
        result = factory.generateSelectExpression(result, aliasNames, Collections.<GroovyExpression>emptyList());
    }
    return factory.generateFillExpression(result, context.getResultVariable());
}
Also used : GroovyExpression(org.apache.atlas.groovy.GroovyExpression) AbstractFunctionExpression(org.apache.atlas.groovy.AbstractFunctionExpression)

Example 12 with AbstractFunctionExpression

use of org.apache.atlas.groovy.AbstractFunctionExpression in project incubator-atlas by apache.

the class FunctionGenerator method updateCurrentFunction.

/**
     * Adds the caller of parentExpr to the current body of the last
     * function that was created.
     *
     * @param parentExpr
     */
private void updateCurrentFunction(AbstractFunctionExpression parentExpr) {
    GroovyExpression expr = parentExpr.getCaller();
    if (expr instanceof AbstractFunctionExpression) {
        AbstractFunctionExpression exprAsFunction = (AbstractFunctionExpression) expr;
        GroovyExpression exprCaller = exprAsFunction.getCaller();
        parentExpr.setCaller(exprCaller);
        updateCurrentFunctionDefintion(exprAsFunction);
    }
}
Also used : GroovyExpression(org.apache.atlas.groovy.GroovyExpression) AbstractFunctionExpression(org.apache.atlas.groovy.AbstractFunctionExpression)

Aggregations

AbstractFunctionExpression (org.apache.atlas.groovy.AbstractFunctionExpression)12 GroovyExpression (org.apache.atlas.groovy.GroovyExpression)11 FunctionCallExpression (org.apache.atlas.groovy.FunctionCallExpression)4 ArrayList (java.util.ArrayList)3 RangeFinder (org.apache.atlas.gremlin.optimizer.RangeFinder)2 LiteralExpression (org.apache.atlas.groovy.LiteralExpression)2 Test (org.testng.annotations.Test)2 VariableDeclaration (org.apache.atlas.groovy.ClosureExpression.VariableDeclaration)1 IdentifierExpression (org.apache.atlas.groovy.IdentifierExpression)1