Search in sources :

Example 1 with FieldExpression

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

the class Gremlin2ExpressionFactory method typeTestExpression.

@Override
public GroovyExpression typeTestExpression(GraphPersistenceStrategies s, String typeName, GroovyExpression itRef) {
    GroovyExpression superTypeAttrExpr = new FieldExpression(itRef, s.superTypeAttributeName());
    GroovyExpression typeNameExpr = new LiteralExpression(typeName);
    GroovyExpression isSuperTypeExpr = new FunctionCallExpression(superTypeAttrExpr, CONTAINS, typeNameExpr);
    GroovyExpression superTypeMatchesExpr = new TernaryOperatorExpression(superTypeAttrExpr, isSuperTypeExpr, LiteralExpression.FALSE);
    GroovyExpression typeAttrExpr = new FieldExpression(itRef, s.typeAttributeName());
    GroovyExpression typeMatchesExpr = new ComparisonExpression(typeAttrExpr, ComparisonOperator.EQUALS, typeNameExpr);
    return new LogicalExpression(typeMatchesExpr, LogicalOperator.OR, superTypeMatchesExpr);
}
Also used : ComparisonExpression(org.apache.atlas.groovy.ComparisonExpression) LogicalExpression(org.apache.atlas.groovy.LogicalExpression) LiteralExpression(org.apache.atlas.groovy.LiteralExpression) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) TernaryOperatorExpression(org.apache.atlas.groovy.TernaryOperatorExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression) FieldExpression(org.apache.atlas.groovy.FieldExpression)

Example 2 with FieldExpression

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

the class Gremlin2ExpressionFactory method getOrderFieldParents.

@Override
public List<GroovyExpression> getOrderFieldParents() {
    GroovyExpression itExpr = getItVariable();
    List<GroovyExpression> result = new ArrayList<>(2);
    result.add(new FieldExpression(itExpr, "a"));
    result.add(new FieldExpression(itExpr, "b"));
    return result;
}
Also used : ArrayList(java.util.ArrayList) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) FieldExpression(org.apache.atlas.groovy.FieldExpression)

Example 3 with FieldExpression

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

the class Gremlin2ExpressionFactory method generateLikeExpressionUsingFilter.

@Override
public GroovyExpression generateLikeExpressionUsingFilter(GroovyExpression parent, String propertyName, GroovyExpression propertyValue) throws AtlasException {
    GroovyExpression itExpr = getItVariable();
    GroovyExpression nameExpr = new FieldExpression(itExpr, propertyName);
    GroovyExpression matchesExpr = new FunctionCallExpression(nameExpr, MATCHES, escapePropertyValue(propertyValue));
    GroovyExpression closureExpr = new ClosureExpression(matchesExpr);
    GroovyExpression filterExpr = new FunctionCallExpression(parent, FILTER_METHOD, closureExpr);
    return filterExpr;
}
Also used : GroovyExpression(org.apache.atlas.groovy.GroovyExpression) ClosureExpression(org.apache.atlas.groovy.ClosureExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression) FieldExpression(org.apache.atlas.groovy.FieldExpression)

Example 4 with FieldExpression

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

the class Gremlin2ExpressionFactory method generateLoopExpression.

@Override
public GroovyExpression generateLoopExpression(GroovyExpression parent, GraphPersistenceStrategies s, IDataType dataType, GroovyExpression loopExpr, String alias, Integer times) {
    GroovyExpression emitExpr = generateLoopEmitExpression(s, dataType);
    //note that in Gremlin 2 (unlike Gremlin 3), the parent is not explicitly used.  It is incorporated
    //in the loopExpr.
    GroovyExpression whileFunction = null;
    if (times != null) {
        GroovyExpression loopsExpr = new FieldExpression(getItVariable(), LOOP_COUNT_FIELD);
        GroovyExpression timesExpr = new LiteralExpression(times);
        whileFunction = new ClosureExpression(new ComparisonExpression(loopsExpr, ComparisonOperator.LESS_THAN, timesExpr));
    } else {
        GroovyExpression pathExpr = new FieldExpression(getItVariable(), PATH_FIELD);
        GroovyExpression itObjectExpr = getCurrentObjectExpression();
        GroovyExpression pathContainsExpr = new FunctionCallExpression(pathExpr, CONTAINS, itObjectExpr);
        whileFunction = new ClosureExpression(new TernaryOperatorExpression(pathContainsExpr, LiteralExpression.FALSE, LiteralExpression.TRUE));
    }
    GroovyExpression emitFunction = new ClosureExpression(emitExpr);
    GroovyExpression loopCall = new FunctionCallExpression(TraversalStepType.BRANCH, loopExpr, LOOP_METHOD, new LiteralExpression(alias), whileFunction, emitFunction);
    return new FunctionCallExpression(TraversalStepType.SIDE_EFFECT, loopCall, ENABLE_PATH_METHOD);
}
Also used : ComparisonExpression(org.apache.atlas.groovy.ComparisonExpression) LiteralExpression(org.apache.atlas.groovy.LiteralExpression) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) TernaryOperatorExpression(org.apache.atlas.groovy.TernaryOperatorExpression) ClosureExpression(org.apache.atlas.groovy.ClosureExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression) FieldExpression(org.apache.atlas.groovy.FieldExpression)

Example 5 with FieldExpression

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

the class Gremlin3ExpressionFactory method generateLikeExpressionUsingFilter.

@Override
public GroovyExpression generateLikeExpressionUsingFilter(GroovyExpression parent, String propertyName, GroovyExpression propertyValue) throws AtlasException {
    GroovyExpression itExpr = getItVariable();
    GroovyExpression nameExpr = new FieldExpression(itExpr, propertyName);
    GroovyExpression matchesExpr = new FunctionCallExpression(nameExpr, MATCHES, escapePropertyValue(propertyValue));
    GroovyExpression closureExpr = new ClosureExpression(matchesExpr);
    GroovyExpression filterExpr = new FunctionCallExpression(parent, FILTER_METHOD, closureExpr);
    return filterExpr;
}
Also used : GroovyExpression(org.apache.atlas.groovy.GroovyExpression) ClosureExpression(org.apache.atlas.groovy.ClosureExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression) FieldExpression(org.apache.atlas.groovy.FieldExpression)

Aggregations

FieldExpression (org.apache.atlas.groovy.FieldExpression)5 GroovyExpression (org.apache.atlas.groovy.GroovyExpression)5 FunctionCallExpression (org.apache.atlas.groovy.FunctionCallExpression)4 ClosureExpression (org.apache.atlas.groovy.ClosureExpression)3 ComparisonExpression (org.apache.atlas.groovy.ComparisonExpression)2 LiteralExpression (org.apache.atlas.groovy.LiteralExpression)2 TernaryOperatorExpression (org.apache.atlas.groovy.TernaryOperatorExpression)2 ArrayList (java.util.ArrayList)1 LogicalExpression (org.apache.atlas.groovy.LogicalExpression)1