Search in sources :

Example 1 with IdentityPipe

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

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

the class GremlinFluentUtilityTest method testNoEdgeConstraintOptimizations.

public void testNoEdgeConstraintOptimizations() {
    Graph graph = TinkerGraphFactory.createTinkerGraph();
    GremlinPipeline pipeline = new GremlinPipeline(graph.getVertex(1)).outE().sideEffect(null).inV();
    // System.out.println(pipeline);
    assertEquals(pipeline.size(), 4);
    assertTrue(pipeline.get(0) instanceof GremlinStartPipe);
    assertTrue(pipeline.get(1) instanceof VertexQueryPipe);
    assertTrue(pipeline.get(2) instanceof SideEffectFunctionPipe);
    assertTrue(pipeline.get(3) instanceof InVertexPipe);
    pipeline = new GremlinPipeline(graph.getVertex(1)).outE().filter(null).inV();
    //System.out.println(pipeline);
    assertEquals(pipeline.size(), 4);
    assertTrue(pipeline.get(0) instanceof GremlinStartPipe);
    assertTrue(pipeline.get(1) instanceof VertexQueryPipe);
    assertTrue(pipeline.get(2) instanceof FilterPipe);
    assertTrue(pipeline.get(3) instanceof InVertexPipe);
    pipeline = new GremlinPipeline(graph.getVertex(1)).outE().has("weight", 0.5).filter(null).has("date", 2012).inV();
    //System.out.println(pipeline);
    assertEquals(pipeline.size(), 6);
    assertTrue(pipeline.get(0) instanceof GremlinStartPipe);
    assertTrue(pipeline.get(1) instanceof VertexQueryPipe);
    assertTrue(pipeline.get(2) instanceof IdentityPipe);
    assertTrue(pipeline.get(3) instanceof FilterPipe);
    assertTrue(pipeline.get(4) instanceof PropertyFilterPipe);
    assertTrue(pipeline.get(5) instanceof InVertexPipe);
    // TEST OPTIMIZE(BOOLEAN) PARAMETERIZATION
    pipeline = new GremlinPipeline(graph.getVertex(1)).optimize(false).outE("knows").has("weight", 0.5).inV();
    //System.out.println(pipeline);
    assertEquals(pipeline.size(), 4);
    assertTrue(pipeline.get(0) instanceof GremlinStartPipe);
    assertTrue(pipeline.get(1) instanceof OutEdgesPipe);
    assertTrue(pipeline.get(2) instanceof PropertyFilterPipe);
    assertTrue(pipeline.get(3) instanceof InVertexPipe);
    pipeline = new GremlinPipeline(graph.getVertex(1)).optimize(true).outE("knows").has("weight", 0.5).inV();
    //System.out.println(pipeline);
    assertEquals(pipeline.size(), 4);
    assertTrue(pipeline.get(0) instanceof GremlinStartPipe);
    assertTrue(pipeline.get(1) instanceof VertexQueryPipe);
    assertTrue(pipeline.get(2) instanceof IdentityPipe);
    assertTrue(pipeline.get(3) instanceof InVertexPipe);
}
Also used : VertexQueryPipe(com.tinkerpop.pipes.transform.VertexQueryPipe) SideEffectFunctionPipe(com.tinkerpop.pipes.sideeffect.SideEffectFunctionPipe) Graph(com.tinkerpop.blueprints.Graph) PropertyFilterPipe(com.tinkerpop.pipes.filter.PropertyFilterPipe) FilterPipe(com.tinkerpop.pipes.filter.FilterPipe) RangeFilterPipe(com.tinkerpop.pipes.filter.RangeFilterPipe) PropertyFilterPipe(com.tinkerpop.pipes.filter.PropertyFilterPipe) OutEdgesPipe(com.tinkerpop.pipes.transform.OutEdgesPipe) InVertexPipe(com.tinkerpop.pipes.transform.InVertexPipe) IdentityPipe(com.tinkerpop.pipes.IdentityPipe)

Example 3 with IdentityPipe

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

Example 4 with IdentityPipe

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

the class GremlinFluentUtilityTest method testVertexQueryOptimization.

public void testVertexQueryOptimization() {
    Graph graph = TinkerGraphFactory.createTinkerGraph();
    GremlinPipeline pipeline = new GremlinPipeline(graph.getVertex(1)).outE().inV();
    // System.out.println(pipeline);
    assertEquals(pipeline.size(), 3);
    assertTrue(pipeline.get(0) instanceof GremlinStartPipe);
    assertTrue(pipeline.get(1) instanceof VertexQueryPipe);
    assertTrue(pipeline.get(2) instanceof InVertexPipe);
    pipeline = new GremlinPipeline(graph.getVertex(1)).outE()._().inV();
    //System.out.println(pipeline);
    assertEquals(pipeline.size(), 4);
    assertTrue(pipeline.get(0) instanceof GremlinStartPipe);
    assertTrue(pipeline.get(1) instanceof VertexQueryPipe);
    assertTrue(pipeline.get(2) instanceof IdentityPipe);
    assertTrue(pipeline.get(3) instanceof InVertexPipe);
    pipeline = new GremlinPipeline(graph.getVertex(1)).outE("knows").has("weight", 0.5).inV();
    //System.out.println(pipeline);
    assertEquals(pipeline.size(), 4);
    assertTrue(pipeline.get(0) instanceof GremlinStartPipe);
    assertTrue(pipeline.get(1) instanceof VertexQueryPipe);
    assertTrue(pipeline.get(2) instanceof IdentityPipe);
    assertTrue(pipeline.get(3) instanceof InVertexPipe);
    pipeline = new GremlinPipeline(graph.getVertex(1)).outE("knows").has("weight", 0.5).interval("since", 10, 2).inV();
    // System.out.println(pipeline);
    assertEquals(pipeline.size(), 5);
    assertTrue(pipeline.get(0) instanceof GremlinStartPipe);
    assertTrue(pipeline.get(1) instanceof VertexQueryPipe);
    assertTrue(pipeline.get(2) instanceof IdentityPipe);
    assertTrue(pipeline.get(3) instanceof IdentityPipe);
    assertTrue(pipeline.get(4) instanceof InVertexPipe);
    pipeline = new GremlinPipeline(graph.getVertex(1)).outE("knows").has("weight", 0.5).interval("since", 10, 2).outV();
    //System.out.println(pipeline);
    assertEquals(pipeline.size(), 5);
    assertTrue(pipeline.get(0) instanceof GremlinStartPipe);
    assertTrue(pipeline.get(1) instanceof VertexQueryPipe);
    assertTrue(pipeline.get(2) instanceof IdentityPipe);
    assertTrue(pipeline.get(3) instanceof IdentityPipe);
    assertTrue(pipeline.get(4) instanceof OutVertexPipe);
    pipeline = new GremlinPipeline(graph.getVertex(1)).inE("knows", "created").has("weight", 0.5).interval("since", 10, 2).outV();
    //System.out.println(pipeline);
    assertEquals(pipeline.size(), 5);
    assertTrue(pipeline.get(0) instanceof GremlinStartPipe);
    assertTrue(pipeline.get(1) instanceof VertexQueryPipe);
    assertTrue(pipeline.get(2) instanceof IdentityPipe);
    assertTrue(pipeline.get(3) instanceof IdentityPipe);
    assertTrue(pipeline.get(4) instanceof OutVertexPipe);
    pipeline = new GremlinPipeline(graph.getVertex(1)).bothE("knows", "created").has("weight", 0.5).interval("since", 10, 2).bothV();
    //System.out.println(pipeline);
    assertEquals(pipeline.size(), 5);
    assertTrue(pipeline.get(0) instanceof GremlinStartPipe);
    assertTrue(pipeline.get(1) instanceof VertexQueryPipe);
    assertTrue(pipeline.get(2) instanceof IdentityPipe);
    assertTrue(pipeline.get(3) instanceof IdentityPipe);
    assertTrue(pipeline.get(4) instanceof BothVerticesPipe);
    pipeline = new GremlinPipeline(graph.getVertex(1)).bothE("knows", "created").has("weight", 0.5)._().interval("since", 10, 2).bothV();
    //System.out.println(pipeline);
    assertEquals(pipeline.size(), 6);
    assertTrue(pipeline.get(0) instanceof GremlinStartPipe);
    assertTrue(pipeline.get(1) instanceof VertexQueryPipe);
    assertTrue(pipeline.get(2) instanceof IdentityPipe);
    assertTrue(pipeline.get(3) instanceof IdentityPipe);
    assertTrue(pipeline.get(4) instanceof IdentityPipe);
    assertTrue(pipeline.get(5) instanceof BothVerticesPipe);
    pipeline = new GremlinPipeline(graph.getVertex(1)).outE("knows", "created").has("weight", 0.5)._().interval("since", 10, 2).range(1, 10).bothV();
    //System.out.println(pipeline);
    assertEquals(pipeline.size(), 7);
    assertTrue(pipeline.get(0) instanceof GremlinStartPipe);
    assertTrue(pipeline.get(1) instanceof VertexQueryPipe);
    assertTrue(pipeline.get(2) instanceof IdentityPipe);
    assertTrue(pipeline.get(3) instanceof IdentityPipe);
    assertTrue(pipeline.get(4) instanceof IdentityPipe);
    assertTrue(pipeline.get(5) instanceof IdentityPipe);
    assertTrue(pipeline.get(6) instanceof BothVerticesPipe);
}
Also used : VertexQueryPipe(com.tinkerpop.pipes.transform.VertexQueryPipe) Graph(com.tinkerpop.blueprints.Graph) BothVerticesPipe(com.tinkerpop.pipes.transform.BothVerticesPipe) InVertexPipe(com.tinkerpop.pipes.transform.InVertexPipe) IdentityPipe(com.tinkerpop.pipes.IdentityPipe) OutVertexPipe(com.tinkerpop.pipes.transform.OutVertexPipe)

Example 5 with IdentityPipe

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

the class GremlinFluentUtilityTest method testVertexRangeOptimization.

public void testVertexRangeOptimization() {
    Graph graph = TinkerGraphFactory.createTinkerGraph();
    GremlinPipeline pipeline = new GremlinPipeline(graph.getVertex(1)).out().out();
    //System.out.println(pipeline);
    assertEquals(pipeline.size(), 3);
    assertTrue(pipeline.get(0) instanceof GremlinStartPipe);
    assertTrue(pipeline.get(1) instanceof VertexQueryPipe);
    assertTrue(pipeline.get(2) instanceof VertexQueryPipe);
    pipeline = new GremlinPipeline(graph.getVertex(1)).out().out().range(0, 10);
    //System.out.println(pipeline);
    assertEquals(pipeline.size(), 4);
    assertTrue(pipeline.get(0) instanceof GremlinStartPipe);
    assertTrue(pipeline.get(1) instanceof VertexQueryPipe);
    assertTrue(pipeline.get(2) instanceof VertexQueryPipe);
    assertTrue(pipeline.get(3) instanceof IdentityPipe);
    pipeline = new GremlinPipeline(graph.getVertex(1)).out("knows").out().range(5, 10);
    //System.out.println(pipeline);
    assertEquals(pipeline.size(), 4);
    assertTrue(pipeline.get(0) instanceof GremlinStartPipe);
    assertTrue(pipeline.get(1) instanceof VertexQueryPipe);
    assertTrue(pipeline.get(2) instanceof VertexQueryPipe);
    assertTrue(pipeline.get(3) instanceof IdentityPipe);
    // no optimization should occur
    pipeline = new GremlinPipeline(graph.getVertex(1)).out("knows").out().has("name", "marko").range(0, 10);
    // System.out.println(pipeline);
    assertEquals(pipeline.size(), 5);
    assertTrue(pipeline.get(0) instanceof GremlinStartPipe);
    assertTrue(pipeline.get(1) instanceof VertexQueryPipe);
    assertTrue(pipeline.get(2) instanceof VertexQueryPipe);
    assertTrue(pipeline.get(3) instanceof PropertyFilterPipe);
    assertTrue(pipeline.get(4) instanceof RangeFilterPipe);
}
Also used : VertexQueryPipe(com.tinkerpop.pipes.transform.VertexQueryPipe) Graph(com.tinkerpop.blueprints.Graph) PropertyFilterPipe(com.tinkerpop.pipes.filter.PropertyFilterPipe) RangeFilterPipe(com.tinkerpop.pipes.filter.RangeFilterPipe) IdentityPipe(com.tinkerpop.pipes.IdentityPipe)

Aggregations

IdentityPipe (com.tinkerpop.pipes.IdentityPipe)5 VertexQueryPipe (com.tinkerpop.pipes.transform.VertexQueryPipe)5 PropertyFilterPipe (com.tinkerpop.pipes.filter.PropertyFilterPipe)4 RangeFilterPipe (com.tinkerpop.pipes.filter.RangeFilterPipe)4 Graph (com.tinkerpop.blueprints.Graph)3 Pipe (com.tinkerpop.pipes.Pipe)2 IntervalFilterPipe (com.tinkerpop.pipes.filter.IntervalFilterPipe)2 EdgesVerticesPipe (com.tinkerpop.pipes.transform.EdgesVerticesPipe)2 GraphQueryPipe (com.tinkerpop.pipes.transform.GraphQueryPipe)2 InVertexPipe (com.tinkerpop.pipes.transform.InVertexPipe)2 QueryPipe (com.tinkerpop.pipes.transform.QueryPipe)2 VerticesEdgesPipe (com.tinkerpop.pipes.transform.VerticesEdgesPipe)2 VerticesVerticesPipe (com.tinkerpop.pipes.transform.VerticesVerticesPipe)2 Vertex (com.tinkerpop.blueprints.Vertex)1 FilterPipe (com.tinkerpop.pipes.filter.FilterPipe)1 SideEffectFunctionPipe (com.tinkerpop.pipes.sideeffect.SideEffectFunctionPipe)1 BothVerticesPipe (com.tinkerpop.pipes.transform.BothVerticesPipe)1 OutEdgesPipe (com.tinkerpop.pipes.transform.OutEdgesPipe)1 OutVertexPipe (com.tinkerpop.pipes.transform.OutVertexPipe)1