Search in sources :

Example 1 with CastExpression

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

the class Gremlin3ExpressionFactory method generateHasExpression.

@Override
public GroovyExpression generateHasExpression(GraphPersistenceStrategies s, GroovyExpression parent, String propertyName, String symbol, GroovyExpression requiredValue, FieldInfo fInfo) throws AtlasException {
    AttributeInfo attrInfo = fInfo.attrInfo();
    IDataType attrType = attrInfo.dataType();
    GroovyExpression propertNameExpr = new LiteralExpression(propertyName);
    if (s.isPropertyValueConversionNeeded(attrType)) {
        // for some types, the logical value cannot be stored directly in
        // the underlying graph,
        // and conversion logic is needed to convert the persistent form of
        // the value
        // to the actual value. In cases like this, we generate a conversion
        // expression to
        // do this conversion and use the filter step to perform the
        // comparsion in the gremlin query
        GroovyExpression itExpr = getItVariable();
        GroovyExpression vertexExpr = new CastExpression(new FunctionCallExpression(itExpr, GET_METHOD), VERTEX_CLASS);
        GroovyExpression propertyValueExpr = new FunctionCallExpression(vertexExpr, VALUE_METHOD, propertNameExpr);
        GroovyExpression conversionExpr = s.generatePersisentToLogicalConversionExpression(propertyValueExpr, attrType);
        GroovyExpression propertyIsPresentExpression = new FunctionCallExpression(new FunctionCallExpression(vertexExpr, PROPERTY_METHOD, propertNameExpr), IS_PRESENT_METHOD);
        GroovyExpression valueMatchesExpr = new ComparisonExpression(conversionExpr, getGroovyOperator(symbol), requiredValue);
        GroovyExpression filterCondition = new LogicalExpression(propertyIsPresentExpression, LogicalOperator.AND, valueMatchesExpr);
        GroovyExpression filterFunction = new ClosureExpression(filterCondition);
        return new FunctionCallExpression(TraversalStepType.FILTER, parent, FILTER_METHOD, filterFunction);
    } else {
        GroovyExpression valueMatches = new FunctionCallExpression(getComparisonFunction(symbol), requiredValue);
        return new FunctionCallExpression(TraversalStepType.FILTER, parent, HAS_METHOD, propertNameExpr, valueMatches);
    }
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) ComparisonExpression(org.apache.atlas.groovy.ComparisonExpression) LogicalExpression(org.apache.atlas.groovy.LogicalExpression) LiteralExpression(org.apache.atlas.groovy.LiteralExpression) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) CastExpression(org.apache.atlas.groovy.CastExpression) ClosureExpression(org.apache.atlas.groovy.ClosureExpression) IDataType(org.apache.atlas.typesystem.types.IDataType) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Example 2 with CastExpression

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

the class Gremlin3ExpressionFactory method generateGetSelectedValueExpression.

@Override
public GroovyExpression generateGetSelectedValueExpression(LiteralExpression key, GroovyExpression rowMapExpr) {
    rowMapExpr = new CastExpression(rowMapExpr, "Map");
    GroovyExpression getExpr = new FunctionCallExpression(rowMapExpr, "get", key);
    return getExpr;
}
Also used : GroovyExpression(org.apache.atlas.groovy.GroovyExpression) CastExpression(org.apache.atlas.groovy.CastExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Example 3 with CastExpression

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

the class Gremlin2ExpressionFactory method generateGetSelectedValueExpression.

@Override
public GroovyExpression generateGetSelectedValueExpression(LiteralExpression key, GroovyExpression rowMap) {
    rowMap = new CastExpression(rowMap, "Row");
    GroovyExpression getExpr = new FunctionCallExpression(rowMap, "getColumn", key);
    return getExpr;
}
Also used : GroovyExpression(org.apache.atlas.groovy.GroovyExpression) CastExpression(org.apache.atlas.groovy.CastExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Example 4 with CastExpression

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

the class GremlinExpressionFactory method getAggregrationExpression.

private GroovyExpression getAggregrationExpression(GroovyExpression itExpr, GroovyExpression mapFunction, String functionName) {
    GroovyExpression collectionExpr = new CastExpression(itExpr, "Collection");
    ClosureExpression collectFunction = new ClosureExpression(mapFunction);
    GroovyExpression transformedList = new FunctionCallExpression(collectionExpr, "collect", collectFunction);
    return new FunctionCallExpression(transformedList, functionName);
}
Also used : GroovyExpression(org.apache.atlas.groovy.GroovyExpression) CastExpression(org.apache.atlas.groovy.CastExpression) ClosureExpression(org.apache.atlas.groovy.ClosureExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Example 5 with CastExpression

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

the class Gremlin3ExpressionFactory method generateGroupByExpression.

@Override
public GroovyExpression generateGroupByExpression(GroovyExpression parent, GroovyExpression groupByExpression, GroovyExpression aggregationFunction) {
    GroovyExpression result = new FunctionCallExpression(TraversalStepType.BARRIER, parent, "group");
    GroovyExpression groupByClosureExpr = new TypeCoersionExpression(new ClosureExpression(groupByExpression), "Function");
    result = new FunctionCallExpression(TraversalStepType.SIDE_EFFECT, result, "by", groupByClosureExpr);
    result = new FunctionCallExpression(TraversalStepType.END, result, "toList");
    GroovyExpression mapValuesClosure = new ClosureExpression(new FunctionCallExpression(new CastExpression(getItVariable(), "Map"), "values"));
    result = new FunctionCallExpression(result, "collect", mapValuesClosure);
    //when we call Map.values(), we end up with an extra list around the result.  We remove this by calling toList().get(0).  This
    //leaves us with a list of lists containing the vertices that match each group.  We then apply the aggregation functions
    //specified in the select list to each of these inner lists.
    result = new FunctionCallExpression(result, "toList");
    result = new FunctionCallExpression(result, "get", new LiteralExpression(0));
    GroovyExpression aggregrationFunctionClosure = new ClosureExpression(aggregationFunction);
    result = new FunctionCallExpression(result, "collect", aggregrationFunctionClosure);
    return result;
}
Also used : TypeCoersionExpression(org.apache.atlas.groovy.TypeCoersionExpression) LiteralExpression(org.apache.atlas.groovy.LiteralExpression) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) ClosureExpression(org.apache.atlas.groovy.ClosureExpression) CastExpression(org.apache.atlas.groovy.CastExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Aggregations

CastExpression (org.apache.atlas.groovy.CastExpression)5 FunctionCallExpression (org.apache.atlas.groovy.FunctionCallExpression)5 GroovyExpression (org.apache.atlas.groovy.GroovyExpression)5 ClosureExpression (org.apache.atlas.groovy.ClosureExpression)3 LiteralExpression (org.apache.atlas.groovy.LiteralExpression)2 ComparisonExpression (org.apache.atlas.groovy.ComparisonExpression)1 LogicalExpression (org.apache.atlas.groovy.LogicalExpression)1 TypeCoersionExpression (org.apache.atlas.groovy.TypeCoersionExpression)1 AttributeInfo (org.apache.atlas.typesystem.types.AttributeInfo)1 IDataType (org.apache.atlas.typesystem.types.IDataType)1