Package com.tinkerpop.pipes

Examples of com.tinkerpop.pipes.Pipe


    }

    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());
View Full Code Here


    }

    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());
View Full Code Here

        if (key.equals(Tokens.ID)) {
            return this.add(new IdFilterPipe(predicate, value));
        } else if (key.equals(Tokens.LABEL)) {
            return this.add(new LabelFilterPipe(predicate, value));
        } else {
            final Pipe pipe = new PropertyFilterPipe(key, predicate, value);
            return this.doQueryOptimization ? GremlinFluentUtility.optimizePipelineForQuery(this, pipe) : this.add(pipe);
        }
    }
View Full Code Here

     * @param startValue the start of the interval (inclusive)
     * @param endValue   the end of the interval (exclusive)
     * @return the extended Pipeline
     */
    public GremlinPipeline<S, ? extends Element> interval(final String key, final Comparable startValue, final Comparable endValue) {
        final Pipe pipe = new IntervalFilterPipe<Element>(key, startValue, endValue);
        return this.doQueryOptimization ? GremlinFluentUtility.optimizePipelineForQuery(this, pipe) : this.add(pipe);
    }
View Full Code Here

     * @param low  the low end of the range
     * @param high the high end of the range
     * @return the extended Pipeline
     */
    public GremlinPipeline<S, E> range(final int low, final int high) {
        final Pipe pipe = new RangeFilterPipe<E>(low, high);
        if (!this.doQueryOptimization)
            return this.add(pipe);
        else {
            return GremlinFluentUtility.optimizePipelineForQuery(this, pipe);
        }
View Full Code Here

public class GremlinStartPipeTest extends TestCase {

    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);
    }
View Full Code Here

        this.total = pipes.size();
    }

    public S processNextStart() {
        while (true) {
            final Pipe pipe = this.pipes.get(this.current);
            if (pipe.hasNext()) {
                return (S) pipe.next();
            } else {
                this.current = (this.current + 1) % this.total;
                if (this.current == 0) {
                    throw FastNoSuchElementException.instance();
                }
View Full Code Here

    public S processNextStart() {
        int counter = 0;
        while (true) {
            counter++;
            final Pipe currentPipe = this.pipes.get(this.current);
            if (currentPipe.hasNext()) {
                final S s = (S) currentPipe.next();
                this.current = (this.current + 1) % this.total;
                return s;
            } else if (counter == this.total) {
                throw FastNoSuchElementException.instance();
            } else {
View Full Code Here

     * @return the removed pipes
     */
    public static List<Pipe> removePreviousPipes(final Pipeline pipeline, final String namedStep) {
        final List<Pipe> previousPipes = new ArrayList<Pipe>();
        for (int i = pipeline.size() - 1; i >= 0; i--) {
            final Pipe pipe = pipeline.get(i);
            if (pipe instanceof AsPipe && ((AsPipe) pipe).getName().equals(namedStep)) {
                break;
            } else {
                previousPipes.add(0, pipe);
            }
View Full Code Here

    private Iterable<Edge> getOutEdges(String... labels) {
        if (labels.length == 0) {
            return this.outEdges;
        } else {
            Pipe pipe = new LabelFilterPipe(Compare.EQUAL, labels);
            pipe.setStarts(this.outEdges);
            return pipe;
        }
    }
View Full Code Here

TOP

Related Classes of com.tinkerpop.pipes.Pipe

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.