Search in sources :

Example 1 with Relation

use of org.apache.atlas.catalog.projection.Relation in project incubator-atlas by apache.

the class ProjectionQueryExpression method asPipe.

@Override
public Pipe asPipe() {
    //todo: encapsulate all of this path logic including path sep escaping and normalizing
    final int sepIdx = getField().indexOf(QueryFactory.PATH_SEP_TOKEN);
    final String edgeToken = getField().substring(0, sepIdx);
    GremlinPipeline pipeline = new GremlinPipeline();
    Relation relation = resourceDefinition.getRelations().get(fieldSegments[0]);
    if (relation != null) {
        pipeline = pipeline.outE();
        pipeline.add(relation.asPipe()).inV();
    } else {
        if (resourceDefinition.getProjections().get(fieldSegments[0]) != null) {
            return super.asPipe();
        } else {
            //todo: default Relation implementation
            pipeline = pipeline.outE().has("label", Text.REGEX, String.format(".*\\.%s", edgeToken)).inV();
        }
    }
    //todo: set resource definition from relation on underlying expression where appropriate
    String childFieldName = getField().substring(sepIdx + QueryFactory.PATH_SEP_TOKEN.length());
    underlyingExpression.setField(childFieldName);
    Pipe childPipe;
    if (childFieldName.contains(QueryFactory.PATH_SEP_TOKEN)) {
        childPipe = new ProjectionQueryExpression(underlyingExpression, resourceDefinition).asPipe();
    } else {
        childPipe = underlyingExpression.asPipe();
    }
    pipeline.add(childPipe);
    return negate ? new FilterFunctionPipe(new ExcludePipeFunction(pipeline)) : pipeline;
}
Also used : GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) Relation(org.apache.atlas.catalog.projection.Relation) Pipe(com.tinkerpop.pipes.Pipe) FilterFunctionPipe(com.tinkerpop.pipes.filter.FilterFunctionPipe) FilterFunctionPipe(com.tinkerpop.pipes.filter.FilterFunctionPipe)

Aggregations

GremlinPipeline (com.tinkerpop.gremlin.java.GremlinPipeline)1 Pipe (com.tinkerpop.pipes.Pipe)1 FilterFunctionPipe (com.tinkerpop.pipes.filter.FilterFunctionPipe)1 Relation (org.apache.atlas.catalog.projection.Relation)1