Search in sources :

Example 1 with ComparisonOperatorExpression

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

the class Gremlin3ExpressionFactory method generateOrderByExpression.

@Override
public GroovyExpression generateOrderByExpression(GroovyExpression parent, List<GroovyExpression> translatedOrderBy, boolean isAscending) {
    GroovyExpression orderByExpr = translatedOrderBy.get(0);
    GroovyExpression orderByClosure = new ClosureExpression(orderByExpr);
    GroovyExpression orderByClause = new TypeCoersionExpression(orderByClosure, FUNCTION_CLASS);
    GroovyExpression aExpr = new IdentifierExpression("a");
    GroovyExpression bExpr = new IdentifierExpression("b");
    GroovyExpression aCompExpr = new FunctionCallExpression(new FunctionCallExpression(aExpr, TO_STRING_METHOD), TO_LOWER_CASE_METHOD);
    GroovyExpression bCompExpr = new FunctionCallExpression(new FunctionCallExpression(bExpr, TO_STRING_METHOD), TO_LOWER_CASE_METHOD);
    GroovyExpression comparisonExpr = null;
    if (isAscending) {
        comparisonExpr = new ComparisonOperatorExpression(aCompExpr, bCompExpr);
    } else {
        comparisonExpr = new ComparisonOperatorExpression(bCompExpr, aCompExpr);
    }
    ClosureExpression comparisonFunction = new ClosureExpression(comparisonExpr, "a", "b");
    FunctionCallExpression orderCall = new FunctionCallExpression(TraversalStepType.BARRIER, parent, ORDER_METHOD);
    return new FunctionCallExpression(TraversalStepType.SIDE_EFFECT, orderCall, BY_METHOD, orderByClause, comparisonFunction);
}
Also used : TypeCoersionExpression(org.apache.atlas.groovy.TypeCoersionExpression) ComparisonOperatorExpression(org.apache.atlas.groovy.ComparisonOperatorExpression) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) ClosureExpression(org.apache.atlas.groovy.ClosureExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression) IdentifierExpression(org.apache.atlas.groovy.IdentifierExpression)

Example 2 with ComparisonOperatorExpression

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

the class Gremlin2ExpressionFactory method generateOrderByExpression.

@Override
public GroovyExpression generateOrderByExpression(GroovyExpression parent, List<GroovyExpression> translatedOrderBy, boolean isAscending) {
    GroovyExpression aPropertyExpr = translatedOrderBy.get(0);
    GroovyExpression bPropertyExpr = translatedOrderBy.get(1);
    GroovyExpression aPropertyNotNull = new ComparisonExpression(aPropertyExpr, ComparisonOperator.NOT_EQUALS, LiteralExpression.NULL);
    GroovyExpression bPropertyNotNull = new ComparisonExpression(bPropertyExpr, ComparisonOperator.NOT_EQUALS, LiteralExpression.NULL);
    GroovyExpression aCondition = new TernaryOperatorExpression(aPropertyNotNull, new FunctionCallExpression(aPropertyExpr, TO_LOWER_CASE_METHOD), aPropertyExpr);
    GroovyExpression bCondition = new TernaryOperatorExpression(bPropertyNotNull, new FunctionCallExpression(bPropertyExpr, TO_LOWER_CASE_METHOD), bPropertyExpr);
    GroovyExpression comparisonFunction = null;
    if (isAscending) {
        comparisonFunction = new ComparisonOperatorExpression(aCondition, bCondition);
    } else {
        comparisonFunction = new ComparisonOperatorExpression(bCondition, aCondition);
    }
    return new FunctionCallExpression(TraversalStepType.BARRIER, parent, ORDER_METHOD, new ClosureExpression(comparisonFunction));
}
Also used : ComparisonExpression(org.apache.atlas.groovy.ComparisonExpression) ComparisonOperatorExpression(org.apache.atlas.groovy.ComparisonOperatorExpression) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) TernaryOperatorExpression(org.apache.atlas.groovy.TernaryOperatorExpression) ClosureExpression(org.apache.atlas.groovy.ClosureExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Aggregations

ClosureExpression (org.apache.atlas.groovy.ClosureExpression)2 ComparisonOperatorExpression (org.apache.atlas.groovy.ComparisonOperatorExpression)2 FunctionCallExpression (org.apache.atlas.groovy.FunctionCallExpression)2 GroovyExpression (org.apache.atlas.groovy.GroovyExpression)2 ComparisonExpression (org.apache.atlas.groovy.ComparisonExpression)1 IdentifierExpression (org.apache.atlas.groovy.IdentifierExpression)1 TernaryOperatorExpression (org.apache.atlas.groovy.TernaryOperatorExpression)1 TypeCoersionExpression (org.apache.atlas.groovy.TypeCoersionExpression)1