Search in sources :

Example 46 with GremlinPipeline

use of com.tinkerpop.gremlin.java.GremlinPipeline in project incubator-atlas by apache.

the class AtlasEntityQueryTest method testExecute_Collection_rollbackOnException.

@Test
public void testExecute_Collection_rollbackOnException() 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);
    // 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()).andThrow(new RuntimeException("something bad happened"));
    graph.rollback();
    replay(graph, expression, resourceDefinition, request, initialPipeline, queryPipe, expressionPipe, notDeletedPipe, rootPipeline, queryPipeline, expressionPipeline, notDeletedPipeline);
    // end mock expectations
    AtlasEntityQuery query = new TestAtlasEntityQuery(expression, resourceDefinition, request, initialPipeline, queryPipe, notDeletedPipe, graph, null);
    try {
        // invoke method being tested
        query.execute();
        fail("expected exception");
    } catch (RuntimeException e) {
        assertEquals(e.getMessage(), "something bad happened");
    }
    verify(graph, expression, resourceDefinition, request, initialPipeline, queryPipe, expressionPipe, notDeletedPipe, rootPipeline, queryPipeline, expressionPipeline, notDeletedPipeline);
}
Also used : GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) ResourceDefinition(org.apache.atlas.catalog.definition.ResourceDefinition) Request(org.apache.atlas.catalog.Request) Pipe(com.tinkerpop.pipes.Pipe) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph) Test(org.testng.annotations.Test)

Example 47 with GremlinPipeline

use of com.tinkerpop.gremlin.java.GremlinPipeline in project incubator-atlas by apache.

the class AtlasEntityTagQuery method getQueryPipe.

@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();
}
Also used : GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) TermVertexWrapper(org.apache.atlas.catalog.TermVertexWrapper) TermVertexWrapper(org.apache.atlas.catalog.TermVertexWrapper) VertexWrapper(org.apache.atlas.catalog.VertexWrapper) PipeFunction(com.tinkerpop.pipes.PipeFunction) Edge(com.tinkerpop.blueprints.Edge)

Example 48 with GremlinPipeline

use of com.tinkerpop.gremlin.java.GremlinPipeline in project incubator-atlas by apache.

the class ProjectionQueryExpression method asPipe.

@Override
public Pipe asPipe() {
    //todo: encapsulate all of this path logic including path sep escaping and normalizing
    final int sepIdx = getField().indexOf(QueryFactory.PATH_SEP_TOKEN);
    final String edgeToken = getField().substring(0, sepIdx);
    GremlinPipeline pipeline = new GremlinPipeline();
    Relation relation = resourceDefinition.getRelations().get(fieldSegments[0]);
    if (relation != null) {
        pipeline = pipeline.outE();
        pipeline.add(relation.asPipe()).inV();
    } else {
        if (resourceDefinition.getProjections().get(fieldSegments[0]) != null) {
            return super.asPipe();
        } else {
            //todo: default Relation implementation
            pipeline = pipeline.outE().has("label", Text.REGEX, String.format(".*\\.%s", edgeToken)).inV();
        }
    }
    //todo: set resource definition from relation on underlying expression where appropriate
    String childFieldName = getField().substring(sepIdx + QueryFactory.PATH_SEP_TOKEN.length());
    underlyingExpression.setField(childFieldName);
    Pipe childPipe;
    if (childFieldName.contains(QueryFactory.PATH_SEP_TOKEN)) {
        childPipe = new ProjectionQueryExpression(underlyingExpression, resourceDefinition).asPipe();
    } else {
        childPipe = underlyingExpression.asPipe();
    }
    pipeline.add(childPipe);
    return negate ? new FilterFunctionPipe(new ExcludePipeFunction(pipeline)) : pipeline;
}
Also used : GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) Relation(org.apache.atlas.catalog.projection.Relation) Pipe(com.tinkerpop.pipes.Pipe) FilterFunctionPipe(com.tinkerpop.pipes.filter.FilterFunctionPipe) FilterFunctionPipe(com.tinkerpop.pipes.filter.FilterFunctionPipe)

Example 49 with GremlinPipeline

use of com.tinkerpop.gremlin.java.GremlinPipeline in project incubator-atlas by apache.

the class BaseQuery method executeQuery.

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();
}
Also used : GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) Pipe(com.tinkerpop.pipes.Pipe) PropertyFilterPipe(com.tinkerpop.pipes.filter.PropertyFilterPipe)

Example 50 with GremlinPipeline

use of com.tinkerpop.gremlin.java.GremlinPipeline in project gremlin by tinkerpop.

the class SideEffectStepTest method test_g_v1_sideEffectXstore_aX_propertyXnameX.

public void test_g_v1_sideEffectXstore_aX_propertyXnameX() {
    final List<Vertex> a = new ArrayList<Vertex>();
    super.test_g_v1_sideEffectXstore_aX_propertyXnameX(new GremlinPipeline(g.getVertex(1)).sideEffect(new PipeFunction<Vertex, Object>() {

        public Object compute(Vertex vertex) {
            a.clear();
            a.add(vertex);
            return null;
        }
    }).property("name"));
    assertEquals(a.get(0), g.getVertex(1));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) ArrayList(java.util.ArrayList)

Aggregations

GremlinPipeline (com.tinkerpop.gremlin.java.GremlinPipeline)93 Vertex (com.tinkerpop.blueprints.Vertex)28 PipeFunction (com.tinkerpop.pipes.PipeFunction)13 Pipe (com.tinkerpop.pipes.Pipe)6 HashMap (java.util.HashMap)4 Request (org.apache.atlas.catalog.Request)3 VertexWrapper (org.apache.atlas.catalog.VertexWrapper)3 ResourceDefinition (org.apache.atlas.catalog.definition.ResourceDefinition)3 AtlasGraph (org.apache.atlas.repository.graphdb.AtlasGraph)3 Test (org.testng.annotations.Test)3 LoopPipe (com.tinkerpop.pipes.branch.LoopPipe)2 PropertyFilterPipe (com.tinkerpop.pipes.filter.PropertyFilterPipe)2 Table (com.tinkerpop.pipes.util.structures.Table)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Test (org.junit.Test)2 OException (com.orientechnologies.common.exception.OException)1 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)1 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)1