Search in sources :

Example 11 with Pipe

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

the class BooleanQueryExpression method asPipe.

@Override
public Pipe asPipe() {
    Map<BooleanClause.Occur, Collection<BooleanClause>> groupedClauses = groupClauses();
    Pipe andPipe = null;
    Collection<Pipe> andPipes = processAndClauses(groupedClauses);
    andPipes.addAll(processNotClauses(groupedClauses));
    if (!andPipes.isEmpty()) {
        andPipe = new AndFilterPipe(andPipes.toArray(new Pipe[andPipes.size()]));
    }
    Collection<Pipe> orPipes = processOrClauses(groupedClauses);
    if (!orPipes.isEmpty()) {
        if (andPipe != null) {
            orPipes.add(andPipe);
        }
        return new OrFilterPipe(orPipes.toArray(new Pipe[orPipes.size()]));
    } else {
        return andPipe;
    }
}
Also used : AndFilterPipe(com.tinkerpop.pipes.filter.AndFilterPipe) Pipe(com.tinkerpop.pipes.Pipe) OrFilterPipe(com.tinkerpop.pipes.filter.OrFilterPipe) AndFilterPipe(com.tinkerpop.pipes.filter.AndFilterPipe) OrFilterPipe(com.tinkerpop.pipes.filter.OrFilterPipe)

Example 12 with Pipe

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

the class BooleanQueryExpression method processOrClauses.

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;
}
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 13 with Pipe

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

the class BaseQuery method buildPipeline.

protected GremlinPipeline buildPipeline() {
    GremlinPipeline pipeline = getRootVertexPipeline();
    Pipe queryPipe = getQueryPipe();
    if (queryPipe != null) {
        pipeline.add(queryPipe);
    }
    pipeline.add(getNotDeletedPipe());
    return pipeline;
}
Also used : GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) Pipe(com.tinkerpop.pipes.Pipe) PropertyFilterPipe(com.tinkerpop.pipes.filter.PropertyFilterPipe)

Example 14 with Pipe

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

the class AtlasEntityQueryTest method testExecute_Collection.

//todo: add tests for instance query and getInitialPipeline()
@Test
public void testExecute_Collection() throws Exception {
    AtlasGraph graph = createStrictMock(AtlasGraph.class);
    QueryExpression expression = createStrictMock(QueryExpression.class);
    ResourceDefinition resourceDefinition = createStrictMock(ResourceDefinition.class);
    Request request = createStrictMock(Request.class);
    GremlinPipeline initialPipeline = createStrictMock(GremlinPipeline.class);
    Pipe queryPipe = createStrictMock(Pipe.class);
    Pipe expressionPipe = createStrictMock(Pipe.class);
    Pipe notDeletedPipe = createStrictMock(Pipe.class);
    GremlinPipeline rootPipeline = createStrictMock(GremlinPipeline.class);
    GremlinPipeline queryPipeline = createStrictMock(GremlinPipeline.class);
    GremlinPipeline expressionPipeline = createStrictMock(GremlinPipeline.class);
    GremlinPipeline notDeletedPipeline = createStrictMock(GremlinPipeline.class);
    Vertex vertex1 = createStrictMock(Vertex.class);
    VertexWrapper vertex1Wrapper = createStrictMock(VertexWrapper.class);
    List<Vertex> results = new ArrayList<>();
    results.add(vertex1);
    Map<String, Object> vertex1PropertyMap = new HashMap<>();
    vertex1PropertyMap.put("prop1", "prop1.value1");
    vertex1PropertyMap.put("prop2", "prop2.value1");
    Map<String, Object> filteredVertex1PropertyMap = new HashMap<>();
    filteredVertex1PropertyMap.put("prop1", "prop1.value1");
    // mock expectations
    expect(initialPipeline.add(queryPipe)).andReturn(queryPipeline);
    expect(initialPipeline.add(notDeletedPipe)).andReturn(notDeletedPipeline);
    expect(initialPipeline.as("root")).andReturn(rootPipeline);
    expect(expression.asPipe()).andReturn(expressionPipe);
    expect(rootPipeline.add(expressionPipe)).andReturn(expressionPipeline);
    expect(expressionPipeline.back("root")).andReturn(rootPipeline);
    expect(rootPipeline.toList()).andReturn(results);
    graph.commit();
    expect(vertex1Wrapper.getPropertyMap()).andReturn(vertex1PropertyMap);
    expect(resourceDefinition.filterProperties(request, vertex1PropertyMap)).andReturn(filteredVertex1PropertyMap);
    expect(resourceDefinition.resolveHref(filteredVertex1PropertyMap)).andReturn("/foo/bar");
    expect(request.getCardinality()).andReturn(Request.Cardinality.COLLECTION);
    replay(graph, expression, resourceDefinition, request, initialPipeline, queryPipe, expressionPipe, notDeletedPipe, rootPipeline, queryPipeline, expressionPipeline, notDeletedPipeline, vertex1, vertex1Wrapper);
    // end mock expectations
    AtlasEntityQuery query = new TestAtlasEntityQuery(expression, resourceDefinition, request, initialPipeline, queryPipe, notDeletedPipe, graph, vertex1Wrapper);
    // invoke method being tested
    Collection<Map<String, Object>> queryResults = query.execute();
    assertEquals(queryResults.size(), 1);
    Map<String, Object> queryResultMap = queryResults.iterator().next();
    assertEquals(queryResultMap.size(), 2);
    assertEquals(queryResultMap.get("prop1"), "prop1.value1");
    assertEquals(queryResultMap.get("href"), "/foo/bar");
    verify(graph, expression, resourceDefinition, request, initialPipeline, queryPipe, expressionPipe, notDeletedPipe, rootPipeline, queryPipeline, expressionPipeline, notDeletedPipeline, vertex1, vertex1Wrapper);
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) ResourceDefinition(org.apache.atlas.catalog.definition.ResourceDefinition) Request(org.apache.atlas.catalog.Request) Pipe(com.tinkerpop.pipes.Pipe) VertexWrapper(org.apache.atlas.catalog.VertexWrapper) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph) Test(org.testng.annotations.Test)

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