Search in sources :

Example 1 with Pipe

use of com.tinkerpop.pipes.Pipe in project gremlin by tinkerpop.

the class GremlinFluentUtility method optimizePipelineForVertexQuery.

public static boolean optimizePipelineForVertexQuery(final GremlinPipeline pipeline, final Pipe pipe) {
    VertexQueryPipe queryPipe = null;
    for (int i = pipeline.size() - 1; i > 0; i--) {
        final Pipe temp = pipeline.get(i);
        if (temp instanceof VertexQueryPipe) {
            queryPipe = (VertexQueryPipe) temp;
            break;
        } else if (!(temp instanceof IdentityPipe))
            break;
    }
    if (null != queryPipe) {
        if (pipe instanceof EdgesVerticesPipe) {
            if (queryPipe.getResultElementClass().equals(Vertex.class))
                return false;
            queryPipe.setResultingElementClass(Vertex.class);
        } else if (pipe instanceof VerticesVerticesPipe) {
            if (queryPipe.getResultElementClass().equals(Vertex.class))
                return false;
            queryPipe.setDirection(((VerticesVerticesPipe) pipe).getDirection());
            queryPipe.setLabels(((VerticesVerticesPipe) pipe).getLabels());
            queryPipe.setBranchFactor(((VerticesVerticesPipe) pipe).getBranchFactor());
        } else if (pipe instanceof VerticesEdgesPipe) {
            if (queryPipe.getResultElementClass().equals(Vertex.class))
                return false;
            queryPipe.setResultingElementClass(Edge.class);
            queryPipe.setDirection(((VerticesEdgesPipe) pipe).getDirection());
            queryPipe.setLabels(((VerticesEdgesPipe) pipe).getLabels());
            queryPipe.setBranchFactor(((VerticesEdgesPipe) pipe).getBranchFactor());
        } else if (pipe instanceof PropertyFilterPipe) {
            if (queryPipe.getResultElementClass().equals(Vertex.class))
                return false;
            final PropertyFilterPipe temp = (PropertyFilterPipe) pipe;
            queryPipe.addHasContainer(new QueryPipe.HasContainer(temp.getKey(), temp.getPredicate(), temp.getValue()));
        } else if (pipe instanceof IntervalFilterPipe) {
            if (queryPipe.getResultElementClass().equals(Vertex.class))
                return false;
            final IntervalFilterPipe temp = (IntervalFilterPipe) pipe;
            queryPipe.addIntervalContainer(new QueryPipe.IntervalContainer(temp.getKey(), temp.getStartValue(), temp.getEndValue()));
        } else if (pipe instanceof RangeFilterPipe) {
            queryPipe.setLowRange(((RangeFilterPipe) pipe).getLowRange());
            queryPipe.setHighRange(((RangeFilterPipe) pipe).getHighRange());
        }
        pipeline.addPipe(new IdentityPipe());
        return true;
    } else {
        return false;
    }
}
Also used : VertexQueryPipe(com.tinkerpop.pipes.transform.VertexQueryPipe) Vertex(com.tinkerpop.blueprints.Vertex) EdgesVerticesPipe(com.tinkerpop.pipes.transform.EdgesVerticesPipe) VerticesVerticesPipe(com.tinkerpop.pipes.transform.VerticesVerticesPipe) RangeFilterPipe(com.tinkerpop.pipes.filter.RangeFilterPipe) IdentityPipe(com.tinkerpop.pipes.IdentityPipe) VerticesVerticesPipe(com.tinkerpop.pipes.transform.VerticesVerticesPipe) VertexQueryPipe(com.tinkerpop.pipes.transform.VertexQueryPipe) Pipe(com.tinkerpop.pipes.Pipe) PropertyFilterPipe(com.tinkerpop.pipes.filter.PropertyFilterPipe) GraphQueryPipe(com.tinkerpop.pipes.transform.GraphQueryPipe) IntervalFilterPipe(com.tinkerpop.pipes.filter.IntervalFilterPipe) EdgesVerticesPipe(com.tinkerpop.pipes.transform.EdgesVerticesPipe) QueryPipe(com.tinkerpop.pipes.transform.QueryPipe) VerticesEdgesPipe(com.tinkerpop.pipes.transform.VerticesEdgesPipe) VertexQueryPipe(com.tinkerpop.pipes.transform.VertexQueryPipe) GraphQueryPipe(com.tinkerpop.pipes.transform.GraphQueryPipe) QueryPipe(com.tinkerpop.pipes.transform.QueryPipe) VerticesEdgesPipe(com.tinkerpop.pipes.transform.VerticesEdgesPipe) PropertyFilterPipe(com.tinkerpop.pipes.filter.PropertyFilterPipe) RangeFilterPipe(com.tinkerpop.pipes.filter.RangeFilterPipe) IntervalFilterPipe(com.tinkerpop.pipes.filter.IntervalFilterPipe) IdentityPipe(com.tinkerpop.pipes.IdentityPipe)

Example 2 with Pipe

use of com.tinkerpop.pipes.Pipe in project gremlin by tinkerpop.

the class GremlinStartPipeTest method testNoGraphInPath.

public void testNoGraphInPath() {
    Graph graph = TinkerGraphFactory.createTinkerGraph();
    Pipe pipe = new GremlinStartPipe(graph);
    pipe.enablePath(true);
    assertEquals(pipe.getCurrentPath().size(), 0);
    pipe = new StartPipe(graph);
    pipe.enablePath(true);
    assertEquals(pipe.getCurrentPath().size(), 1);
}
Also used : Graph(com.tinkerpop.blueprints.Graph) StartPipe(com.tinkerpop.pipes.util.StartPipe) Pipe(com.tinkerpop.pipes.Pipe) StartPipe(com.tinkerpop.pipes.util.StartPipe)

Example 3 with Pipe

use of com.tinkerpop.pipes.Pipe 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)

Example 4 with Pipe

use of com.tinkerpop.pipes.Pipe in project incubator-atlas by apache.

the class BooleanQueryExpression method processAndClauses.

private Collection<Pipe> processAndClauses(Map<BooleanClause.Occur, Collection<BooleanClause>> groupedClauses) {
    Collection<BooleanClause> andClauses = groupedClauses.get(BooleanClause.Occur.MUST);
    Collection<Pipe> andPipes = new ArrayList<>();
    if (andClauses != null) {
        for (BooleanClause andClause : andClauses) {
            QueryExpression queryExpression = queryFactory.create(andClause.getQuery(), resourceDefinition);
            properties.addAll(queryExpression.getProperties());
            andPipes.add(queryExpression.asPipe());
        }
    }
    return andPipes;
}
Also used : BooleanClause(org.apache.lucene.search.BooleanClause) Pipe(com.tinkerpop.pipes.Pipe) OrFilterPipe(com.tinkerpop.pipes.filter.OrFilterPipe) AndFilterPipe(com.tinkerpop.pipes.filter.AndFilterPipe)

Example 5 with Pipe

use of com.tinkerpop.pipes.Pipe in project incubator-atlas by apache.

the class BooleanQueryExpression method processNotClauses.

private Collection<Pipe> processNotClauses(Map<BooleanClause.Occur, Collection<BooleanClause>> groupedClauses) {
    Collection<BooleanClause> notClauses = groupedClauses.get(BooleanClause.Occur.MUST_NOT);
    Collection<Pipe> notPipes = new ArrayList<>();
    if (notClauses != null) {
        for (BooleanClause notClause : notClauses) {
            QueryExpression queryExpression = queryFactory.create(notClause.getQuery(), resourceDefinition);
            queryExpression.setNegate();
            properties.addAll(queryExpression.getProperties());
            notPipes.add(queryExpression.asPipe());
        }
    }
    return notPipes;
}
Also used : BooleanClause(org.apache.lucene.search.BooleanClause) Pipe(com.tinkerpop.pipes.Pipe) OrFilterPipe(com.tinkerpop.pipes.filter.OrFilterPipe) AndFilterPipe(com.tinkerpop.pipes.filter.AndFilterPipe)

Aggregations

Pipe (com.tinkerpop.pipes.Pipe)14 GremlinPipeline (com.tinkerpop.gremlin.java.GremlinPipeline)6 Vertex (com.tinkerpop.blueprints.Vertex)4 AndFilterPipe (com.tinkerpop.pipes.filter.AndFilterPipe)4 OrFilterPipe (com.tinkerpop.pipes.filter.OrFilterPipe)4 PropertyFilterPipe (com.tinkerpop.pipes.filter.PropertyFilterPipe)4 Request (org.apache.atlas.catalog.Request)3 ResourceDefinition (org.apache.atlas.catalog.definition.ResourceDefinition)3 AtlasGraph (org.apache.atlas.repository.graphdb.AtlasGraph)3 BooleanClause (org.apache.lucene.search.BooleanClause)3 Test (org.testng.annotations.Test)3 IdentityPipe (com.tinkerpop.pipes.IdentityPipe)2 IntervalFilterPipe (com.tinkerpop.pipes.filter.IntervalFilterPipe)2 RangeFilterPipe (com.tinkerpop.pipes.filter.RangeFilterPipe)2 EdgesVerticesPipe (com.tinkerpop.pipes.transform.EdgesVerticesPipe)2 GraphQueryPipe (com.tinkerpop.pipes.transform.GraphQueryPipe)2 QueryPipe (com.tinkerpop.pipes.transform.QueryPipe)2 VertexQueryPipe (com.tinkerpop.pipes.transform.VertexQueryPipe)2 VerticesEdgesPipe (com.tinkerpop.pipes.transform.VerticesEdgesPipe)2 VerticesVerticesPipe (com.tinkerpop.pipes.transform.VerticesVerticesPipe)2