Search in sources :

Example 1 with QueryPipe

use of com.tinkerpop.pipes.transform.QueryPipe 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 QueryPipe

use of com.tinkerpop.pipes.transform.QueryPipe in project gremlin by tinkerpop.

the class GremlinFluentUtility method optimizePipelineForGraphQuery.

private static boolean optimizePipelineForGraphQuery(final GremlinPipeline pipeline, final Pipe pipe) {
    GraphQueryPipe queryPipe = null;
    for (int i = pipeline.size() - 1; i > 0; i--) {
        final Pipe temp = pipeline.get(i);
        if (temp instanceof GraphQueryPipe) {
            queryPipe = (GraphQueryPipe) temp;
            break;
        } else if (!(temp instanceof IdentityPipe))
            break;
    }
    if (null != queryPipe) {
        if (pipe instanceof PropertyFilterPipe) {
            final PropertyFilterPipe temp = (PropertyFilterPipe) pipe;
            queryPipe.addHasContainer(new QueryPipe.HasContainer(temp.getKey(), temp.getPredicate(), temp.getValue()));
        } else if (pipe instanceof IntervalFilterPipe) {
            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 : PropertyFilterPipe(com.tinkerpop.pipes.filter.PropertyFilterPipe) RangeFilterPipe(com.tinkerpop.pipes.filter.RangeFilterPipe) GraphQueryPipe(com.tinkerpop.pipes.transform.GraphQueryPipe) IntervalFilterPipe(com.tinkerpop.pipes.filter.IntervalFilterPipe) 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) IdentityPipe(com.tinkerpop.pipes.IdentityPipe) VertexQueryPipe(com.tinkerpop.pipes.transform.VertexQueryPipe) GraphQueryPipe(com.tinkerpop.pipes.transform.GraphQueryPipe) QueryPipe(com.tinkerpop.pipes.transform.QueryPipe)

Aggregations

IdentityPipe (com.tinkerpop.pipes.IdentityPipe)2 Pipe (com.tinkerpop.pipes.Pipe)2 IntervalFilterPipe (com.tinkerpop.pipes.filter.IntervalFilterPipe)2 PropertyFilterPipe (com.tinkerpop.pipes.filter.PropertyFilterPipe)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 Vertex (com.tinkerpop.blueprints.Vertex)1