Search in sources :

Example 6 with FunctionCallExpression

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

the class Gremlin2ExpressionFactory method getAliasesRequiredByExpression.

public List<String> getAliasesRequiredByExpression(GroovyExpression expr) {
    if (!(expr instanceof FunctionCallExpression)) {
        return Collections.emptyList();
    }
    FunctionCallExpression fc = (FunctionCallExpression) expr;
    if (!fc.getFunctionName().equals(LOOP_METHOD)) {
        return Collections.emptyList();
    }
    LiteralExpression aliasName = (LiteralExpression) fc.getArguments().get(0);
    return Collections.singletonList(aliasName.getValue().toString());
}
Also used : LiteralExpression(org.apache.atlas.groovy.LiteralExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Example 7 with FunctionCallExpression

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

the class Gremlin3ExpressionFactory method getRangeParameters.

@Override
public int[] getRangeParameters(AbstractFunctionExpression expr) {
    if (isRangeExpression(expr)) {
        FunctionCallExpression rangeExpression = (FunctionCallExpression) expr;
        List<GroovyExpression> arguments = rangeExpression.getArguments();
        int startIndex = (int) ((LiteralExpression) arguments.get(0)).getValue();
        int endIndex = (int) ((LiteralExpression) arguments.get(1)).getValue();
        return new int[] { startIndex, endIndex };
    } else {
        return null;
    }
}
Also used : GroovyExpression(org.apache.atlas.groovy.GroovyExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Example 8 with FunctionCallExpression

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

the class Gremlin3ExpressionFactory method generateSelectExpression.

@Override
public GroovyExpression generateSelectExpression(GroovyExpression parent, List<LiteralExpression> sourceNames, List<GroovyExpression> srcExprs) {
    FunctionCallExpression result = new FunctionCallExpression(TraversalStepType.MAP_TO_VALUE, parent, SELECT_METHOD, sourceNames);
    for (GroovyExpression expr : srcExprs) {
        GroovyExpression closure = new ClosureExpression(expr);
        GroovyExpression castClosure = new TypeCoersionExpression(closure, FUNCTION_CLASS);
        result = new FunctionCallExpression(TraversalStepType.SIDE_EFFECT, result, BY_METHOD, castClosure);
    }
    return result;
}
Also used : TypeCoersionExpression(org.apache.atlas.groovy.TypeCoersionExpression) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) ClosureExpression(org.apache.atlas.groovy.ClosureExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Example 9 with FunctionCallExpression

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

the class Gremlin3ExpressionFactory method setRangeParameters.

@Override
public void setRangeParameters(GroovyExpression expr, int startIndex, int endIndex) {
    if (isRangeExpression(expr)) {
        FunctionCallExpression rangeExpression = (FunctionCallExpression) expr;
        rangeExpression.setArgument(0, new LiteralExpression(Integer.valueOf(startIndex)));
        rangeExpression.setArgument(1, new LiteralExpression(Integer.valueOf(endIndex)));
    } else {
        throw new IllegalArgumentException(expr + " is not a valid range expression");
    }
}
Also used : LiteralExpression(org.apache.atlas.groovy.LiteralExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Example 10 with FunctionCallExpression

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

the class Gremlin3ExpressionFactory method generateLoopExpression.

@Override
public GroovyExpression generateLoopExpression(GroovyExpression parent, GraphPersistenceStrategies s, IDataType dataType, GroovyExpression loopExpr, String alias, Integer times) {
    GroovyExpression emitExpr = generateLoopEmitExpression(s, dataType);
    GroovyExpression result = new FunctionCallExpression(TraversalStepType.BRANCH, parent, REPEAT_METHOD, loopExpr);
    if (times != null) {
        GroovyExpression timesExpr = new LiteralExpression(times);
        result = new FunctionCallExpression(TraversalStepType.SIDE_EFFECT, result, TIMES_METHOD, timesExpr);
    }
    result = new FunctionCallExpression(TraversalStepType.SIDE_EFFECT, result, EMIT_METHOD, emitExpr);
    return result;
}
Also used : LiteralExpression(org.apache.atlas.groovy.LiteralExpression) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) 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