com.tinkerpop.pipes.Pipe Java Examples

The following examples show how to use com.tinkerpop.pipes.Pipe. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IntegrationTestClass.java    From bjoern with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void csvBatchImporterTest() throws java.lang.Exception
{

    CSVBatchImporter importer = new CSVBatchImporter();

    importer.setDbName("__TEST__1");
    try {
        importer.importCSVFiles(
                "test/src/resources/nodes.csv",
                "test/src/resources/edges.csv");
    }
    catch (OSchemaException exception) {
        exception.printStackTrace();
        throw exception;
    }

    OrientGraph graph = new OrientGraph(
            "plocal:" + System.getProperty("ORIENTDB_HOME") + "/databases/" + "__TEST__1");

    Pipe pipe = Gremlin.compile("_().map");
    pipe.setStarts(graph.getVertices());
}
 
Example #2
Source File: AtlasEntityTagQuery.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@Override
protected Pipe getQueryPipe() {
    GremlinPipeline p;
    if (guid.equals("*")) {
        p = new GremlinPipeline().has(Constants.ENTITY_TEXT_PROPERTY_KEY).
                hasNot(Constants.ENTITY_TYPE_PROPERTY_KEY, "Taxonomy").outE();
    } else {
        p = new GremlinPipeline().has(Constants.GUID_PROPERTY_KEY, guid).outE();
    }
    //todo: this is basically the same pipeline used in TagRelation.asPipe()
    p.add(new FilterFunctionPipe<>(new PipeFunction<Edge, Boolean>() {
        @Override
        public Boolean compute(Edge edge) {
            String type = edge.getVertex(Direction.OUT).getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY);
            VertexWrapper v = new TermVertexWrapper(edge.getVertex(Direction.IN));
            return edge.getLabel().startsWith(type) && v.getPropertyKeys().contains("available_as_tag");
        }
    }));

    return p.inV();
}
 
Example #3
Source File: FairMergePipe.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
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 {
            this.current = (this.current + 1) % this.total;
        }
    }
}
 
Example #4
Source File: BooleanQueryExpression.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private Collection<Pipe> processOrClauses(Map<BooleanClause.Occur, Collection<BooleanClause>> groupedClauses) {
    Collection<BooleanClause> shouldClauses = groupedClauses.get(BooleanClause.Occur.SHOULD);
    Collection<Pipe> orPipes = new ArrayList<>();
    if (shouldClauses != null) {
        for (BooleanClause shouldClause : shouldClauses) {
            QueryExpression queryExpression = queryFactory.create(shouldClause.getQuery(), resourceDefinition);
            // don't negate expression if we negated MUST_NOT -> SHOULD
            if (negate && shouldClause.getOccur() != BooleanClause.Occur.MUST_NOT) {
                queryExpression.setNegate();
            }
            properties.addAll(queryExpression.getProperties());
            orPipes.add(queryExpression.asPipe());
        }
    }
    return orPipes;
}
 
Example #5
Source File: FluentUtility.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
/**
 * A utility method to remove all the pipes back some partition step and return them as a list.
 *
 * @param namedStep the name of the step previous to remove from the pipeline
 * @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);
        }
    }
    for (int i = 0; i < previousPipes.size(); i++) {
        pipeline.remove(pipeline.size() - 1);
    }

    if (pipeline.size() == 1)
        pipeline.setStarts(pipeline.getStarts());

    return previousPipes;
}
 
Example #6
Source File: AtlasEntityQueryTest.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
public TestAtlasEntityQuery(QueryExpression queryExpression,
                            ResourceDefinition resourceDefinition,
                            Request request,
                            GremlinPipeline initialPipeline,
                            Pipe queryPipe,
                            Pipe notDeletedPipe,
                            AtlasGraph graph,
                            VertexWrapper vWrapper) {

    super(queryExpression, resourceDefinition, request);
    this.initialPipeline = initialPipeline;
    this.queryPipe = queryPipe;
    this.notDeletedPipe = notDeletedPipe;
    this.graph = graph;
    this.vWrapper = vWrapper;
}
 
Example #7
Source File: TreePipe.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
public S processNextStart() {
    final S s = this.starts.next();
    final List path = ((Pipe) this.starts).getCurrentPath();
    Tree<Object> depth = this.tree;
    for (int i = 0; i < path.size(); i++) {
        Object object = path.get(i);
        if (null != this.branchFunctions) {
            object = this.branchFunctions.get(this.currentFunction).compute(object);
            this.currentFunction = (this.currentFunction + 1) % this.branchFunctions.size();
        }

        if (!depth.containsKey(object))
            depth.put(object, new Tree());

        depth = depth.get(object);
    }
    return s;
}
 
Example #8
Source File: CyclicPathFilterPipe.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
public S processNextStart() {
    while (true) {
        final S s = this.starts.next();
        if (this.starts instanceof Pipe) {
            final List path = ((Pipe) this.starts).getCurrentPath();
            this.set.clear();
            this.set.addAll(path);
            if (path.size() == this.set.size()) {
                return s;
            }
        } else {
            return s;
        }
    }

}
 
Example #9
Source File: BooleanQueryExpression.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #10
Source File: TagRelation.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
public Pipe asPipe() {
    return new FilterFunctionPipe<>(new PipeFunction<Edge, Boolean>() {
        @Override
        public Boolean compute(Edge edge) {
            String name = edge.getVertex(Direction.OUT).getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY);
            if (edge.getLabel().startsWith(name)) {
                VertexWrapper v = new TermVertexWrapper(edge.getVertex(Direction.IN));
                return v.getPropertyKeys().contains("available_as_tag") && ! isDeleted(v.getVertex());
            } else {
                return false;
            }
        }
    });
}
 
Example #11
Source File: AbstractMetaPipe.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
public void enablePath(final boolean enable) {
    for (final Pipe pipe : this.getPipes()) {
        pipe.enablePath(enable);
    }
    super.enablePath(enable);

}
 
Example #12
Source File: FairMergePipe.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
public List getCurrentPath() {
    if (this.pathEnabled) {
        int tempCurrent = this.current - 1;
        if (tempCurrent < 0)
            tempCurrent = this.total - 1;
        return this.pipes.get(tempCurrent).getCurrentPath();
    } else
        throw new RuntimeException(Pipe.NO_PATH_MESSAGE);
}
 
Example #13
Source File: OrFilterPipe.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
public S processNextStart() {
    while (true) {
        final S s = this.starts.next();
        for (Pipe<S, Boolean> pipe : this.pipes) {
            pipe.setStarts(new SingleIterator<S>(s));
            if (pipe.next()) {
                return s;
            }
        }
    }
}
 
Example #14
Source File: FluentUtility.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
public static List<Pipe> getPreviousPipes(final Pipeline pipeline, final int numberedStep) {
    final List<Pipe> previousPipes = new ArrayList<Pipe>();
    int pipelineSize = pipeline.size();
    for (int i = 0; i < numberedStep; i++) {
        previousPipes.add(pipeline.get(pipelineSize - i + 1));
    }
    return previousPipes;
}
 
Example #15
Source File: BjoernClientWriter.java    From bjoern with GNU General Public License v3.0 5 votes vote down vote up
public void writeResult(Object result) throws IOException
{
	if (result == null)
	{
		writeMessage("");
	} else if (result instanceof Pipe)
	{
		StringBuilder sBuilder = new StringBuilder();
		Iterable<?> iterable = (Iterable<?>) result;
		for (Object obj : iterable)
		{
			if (obj != null)
			{
				sBuilder.append(obj.toString());
				sBuilder.append("\n");
			}
		}
		if (sBuilder.length() > 0)
		{
			sBuilder.deleteCharAt(sBuilder.length() - 1);
		}
		writeMessage(sBuilder.toString());
	} else
	{
		writeMessage(result.toString());
	}
}
 
Example #16
Source File: GroupByPipe.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
public void addValue(final V value, final Collection values) {
    if (value instanceof Pipe) {
        PipeHelper.fillCollection((Pipe) value, values);
    } else {
        values.add(value);
    }
}
 
Example #17
Source File: BaseQuery.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private List<Vertex> executeQuery() {
    GremlinPipeline pipeline = buildPipeline().as("root");
    Pipe expressionPipe = queryExpression.asPipe();

    // AlwaysQuery returns null for pipe
    return expressionPipe == null ? pipeline.toList() :
            pipeline.add(expressionPipe).back("root").toList();
}
 
Example #18
Source File: SideEffectCapPipe.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
public List getCurrentPath() {
    if (this.pathEnabled) {
        final List list = this.pipeToCap.getCurrentPath();
        list.add(this.currentEnd);
        return list;
    } else {
        throw new RuntimeException(Pipe.NO_PATH_MESSAGE);
    }
}
 
Example #19
Source File: AndFilterPipe.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
public S processNextStart() {
    while (true) {
        final S s = this.starts.next();
        boolean and = true;
        for (final Pipe<S, Boolean> pipe : this.pipes) {
            pipe.setStarts(new SingleIterator<S>(s));
            if (!pipe.next()) {
                and = false;
                break;
            }
        }
        if (and)
            return s;
    }
}
 
Example #20
Source File: AtlasTermQuery.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
protected Pipe getQueryPipe() {
    GremlinPipeline p;
    if (termPath.getTaxonomyName().equals("*")) {
        p = new GremlinPipeline().has("Taxonomy.name").out();
    } else {
        p = new GremlinPipeline().has("Taxonomy.name", termPath.getTaxonomyName()).out().
                has(Constants.ENTITY_TYPE_PROPERTY_KEY, Text.PREFIX, termPath.getFullyQualifiedName());
    }
    return p;
}
 
Example #21
Source File: GremlinPipeline.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
/**
 * Add a RageFilterPipe to the end of the Pipeline.
 * Analogous to a high/low index lookup.
 *
 * @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);
    }
}
 
Example #22
Source File: PipeHelper.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
/**
 * Generate a String representation of a pipe given the pipe and some arguments of the pipe.
 *
 * @param pipe      the pipe's class.getSimpleName() is used
 * @param arguments arguments used in the configuration of the pipe (please avoid objects with massive toString() representations)
 * @return a String representation of the pipe
 */
public static String makePipeString(final Pipe pipe, final Object... arguments) {
    String result = pipe.getClass().getSimpleName();
    if (arguments.length > 0) {
        result = result + "(";
        for (final Object arg : arguments) {
            result = result + arg + ",";
        }
        result = result.substring(0, result.length() - 1) + ")";
    }
    return result;
}
 
Example #23
Source File: LoopPipe.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
public List getCurrentPath() {
    if (this.pathEnabled) {
        final List path = new ArrayList();
        final List currentPath = this.expando.getCurrentPath();
        if (null != currentPath)
            path.addAll(currentPath);
        path.addAll(this.pipe.getCurrentPath());
        return path;
    } else {
        throw new RuntimeException(Pipe.NO_PATH_MESSAGE);
    }
}
 
Example #24
Source File: GremlinPipeline.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
/**
 * Add an IdFilterPipe, LabelFilterPipe, or PropertyFilterPipe to the end of the Pipeline.
 * If the incoming element has the provided key/value as check with .equals(), then let the element pass.
 * If the key is id or label, then use respect id or label filtering.
 *
 * @param key       the property key to check
 * @param predicate the comparison to use
 * @param value     the object to filter on
 * @return the extended Pipeline
 */
public GremlinPipeline<S, ? extends Element> has(final String key, final Predicate predicate, final Object value) {
    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);
    }
}
 
Example #25
Source File: AndFilterPipe.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
public AndFilterPipe(final Pipe<S, ?>... pipes) {
    for (final Pipe<S, ?> pipe : pipes) {
        this.pipes.add(new HasNextPipe<S>(pipe));
    }
}
 
Example #26
Source File: LoopPipe.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
public LoopPipe(final Pipe<S, S> pipe, final PipeFunction<LoopBundle<S>, Boolean> whileFunction) {
    this(pipe, whileFunction, null);
}
 
Example #27
Source File: MemoizePipe.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
public MemoizePipe(final Pipe<S, E> pipe) {
    this(pipe, new HashMap<S, List<E>>());
}
 
Example #28
Source File: AsPipe.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
public List<Pipe> getPipes() {
    return (List) Arrays.asList(this.pipe);
}
 
Example #29
Source File: Pipeline.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
public void addPipe(final int location, final Pipe pipe) {
    this.pipes.add(location, pipe);
    this.setPipes(this.pipes);
}
 
Example #30
Source File: MemoizePipe.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
public MemoizePipe(final Pipe<S, E> pipe, final Map<S, List<E>> map) {
    this.pipe = pipe;
    this.pipe.setStarts(this.expando);
    this.map = map;
}