Search in sources :

Example 1 with QueryContainer

use of org.janusgraph.graphdb.olap.QueryContainer in project janusgraph by JanusGraph.

the class OLAPTest method scannerShouldSeeAllVertices.

@Test
public void scannerShouldSeeAllVertices() throws Exception {
    GraphTraversalSource g = graph.traversal();
    Vertex v1 = g.addV().next();
    Vertex v2 = g.addV().next();
    g.V(v1).addE("connect").to(v2).iterate();
    g.addV().addV().addV().property("p", "v").iterate();
    g.tx().commit();
    AtomicInteger vertexNum = new AtomicInteger();
    executeScanJob(new VertexScanJob() {

        @Override
        public void process(final JanusGraphVertex vertex, final ScanMetrics metrics) {
            vertexNum.incrementAndGet();
        }

        @Override
        public void getQueries(final QueryContainer queries) {
            queries.addQuery().properties();
            queries.addQuery().edges();
        }

        @Override
        public VertexScanJob clone() {
            return this;
        }
    });
    assertEquals(g.V().count().next(), vertexNum.get());
}
Also used : GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) VertexScanJob(org.janusgraph.graphdb.olap.VertexScanJob) ScanMetrics(org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics) QueryContainer(org.janusgraph.graphdb.olap.QueryContainer) Test(org.junit.jupiter.api.Test) JanusGraphBaseTest(org.janusgraph.graphdb.JanusGraphBaseTest)

Example 2 with QueryContainer

use of org.janusgraph.graphdb.olap.QueryContainer in project janusgraph by JanusGraph.

the class VertexProgramScanJob method getQueries.

@Override
public void getQueries(QueryContainer queries) {
    Set<MessageScope> previousScopes = vertexMemory.getPreviousScopes();
    if (vertexProgram instanceof TraversalVertexProgram || vertexProgram instanceof ShortestPathVertexProgram || vertexProgram instanceof ConnectedComponentVertexProgram || previousScopes.contains(globalScope)) {
        // TraversalVertexProgram currently makes the assumption that the entire star-graph around a vertex
        // is available (in-memory). Hence, this special treatment here.
        // TODO: After TraversalVertexProgram is adjusted, remove this
        // Special handling for ShortestPathVertexProgram necessary until TINKERPOP-2187 is resolved
        // Apparently, ConnectedComponentVertexProgram also needs this special handling
        queries.addQuery().direction(Direction.BOTH).edges();
    }
    for (MessageScope scope : previousScopes) {
        if (scope instanceof MessageScope.Local) {
            JanusGraphVertexStep<Vertex> startStep = FulgoraUtil.getReverseJanusGraphVertexStep((MessageScope.Local) scope, queries.getTransaction());
            QueryContainer.QueryBuilder qb = queries.addQuery();
            startStep.makeQuery(qb);
            qb.edges();
        }
    }
}
Also used : ConnectedComponentVertexProgram(org.apache.tinkerpop.gremlin.process.computer.clustering.connected.ConnectedComponentVertexProgram) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) PreloadedVertex(org.janusgraph.graphdb.vertices.PreloadedVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) ShortestPathVertexProgram(org.apache.tinkerpop.gremlin.process.computer.search.path.ShortestPathVertexProgram) TraversalVertexProgram(org.apache.tinkerpop.gremlin.process.computer.traversal.TraversalVertexProgram) MessageScope(org.apache.tinkerpop.gremlin.process.computer.MessageScope) QueryContainer(org.janusgraph.graphdb.olap.QueryContainer)

Example 3 with QueryContainer

use of org.janusgraph.graphdb.olap.QueryContainer in project janusgraph by JanusGraph.

the class IndexRemoveJob method getQueries.

@Override
public List<SliceQuery> getQueries() {
    if (isGlobalGraphIndex()) {
        // Everything
        return Collections.singletonList(new SliceQuery(BufferUtil.zeroBuffer(1), BufferUtil.oneBuffer(128)));
    } else {
        RelationTypeIndexWrapper wrapper = (RelationTypeIndexWrapper) index;
        InternalRelationType wrappedType = wrapper.getWrappedType();
        Direction direction = null;
        for (Direction dir : Direction.values()) if (wrappedType.isUnidirected(dir))
            direction = dir;
        assert direction != null;
        StandardJanusGraphTx tx = (StandardJanusGraphTx) graph.get().buildTransaction().readOnly().start();
        try {
            QueryContainer qc = new QueryContainer(tx);
            qc.addQuery().type(wrappedType).direction(direction).relations();
            return qc.getSliceQueries();
        } finally {
            tx.rollback();
        }
    }
}
Also used : StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) RelationTypeIndexWrapper(org.janusgraph.graphdb.database.management.RelationTypeIndexWrapper) InternalRelationType(org.janusgraph.graphdb.internal.InternalRelationType) Direction(org.apache.tinkerpop.gremlin.structure.Direction) SliceQuery(org.janusgraph.diskstorage.keycolumnvalue.SliceQuery) QueryContainer(org.janusgraph.graphdb.olap.QueryContainer)

Example 4 with QueryContainer

use of org.janusgraph.graphdb.olap.QueryContainer in project janusgraph by JanusGraph.

the class OLAPTest method testVertexScan.

@Test
public void testVertexScan() throws Exception {
    int numV = 100;
    int numE = generateRandomGraph(numV);
    final String DEGREE_COUNT = "degree";
    final String VERTEX_COUNT = "numV";
    clopen();
    ScanMetrics result1 = executeScanJob(new VertexScanJob() {

        @Override
        public void process(JanusGraphVertex vertex, ScanMetrics metrics) {
            long outDegree = vertex.query().labels("knows").direction(Direction.OUT).edgeCount();
            assertEquals(0, vertex.query().labels("knows").direction(Direction.IN).edgeCount());
            assertEquals(1, vertex.query().labels("uid").propertyCount());
            assertTrue(vertex.<Integer>property("uid").orElse(0) > 0);
            metrics.incrementCustom(DEGREE_COUNT, outDegree);
            metrics.incrementCustom(VERTEX_COUNT);
        }

        @Override
        public void getQueries(QueryContainer queries) {
            queries.addQuery().labels("knows").direction(Direction.OUT).edges();
            queries.addQuery().keys("uid").properties();
        }

        @Override
        public VertexScanJob clone() {
            return this;
        }
    });
    assertEquals(numV, result1.getCustom(VERTEX_COUNT));
    assertEquals(numE, result1.getCustom(DEGREE_COUNT));
    ScanMetrics result2 = executeScanJob(new VertexScanJob() {

        @Override
        public void process(JanusGraphVertex vertex, ScanMetrics metrics) {
            metrics.incrementCustom(VERTEX_COUNT);
            assertEquals(1, vertex.query().labels("numvals").propertyCount());
            int numvals = vertex.value("numvals");
            assertEquals(numvals, vertex.query().labels("values").propertyCount());
        }

        @Override
        public void getQueries(QueryContainer queries) {
            queries.addQuery().keys("values").properties();
            queries.addQuery().keys("numvals").properties();
        }

        @Override
        public VertexScanJob clone() {
            return this;
        }
    });
    assertEquals(numV, result2.getCustom(VERTEX_COUNT));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) VertexScanJob(org.janusgraph.graphdb.olap.VertexScanJob) ScanMetrics(org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics) QueryContainer(org.janusgraph.graphdb.olap.QueryContainer) Test(org.junit.jupiter.api.Test) JanusGraphBaseTest(org.janusgraph.graphdb.JanusGraphBaseTest)

Aggregations

QueryContainer (org.janusgraph.graphdb.olap.QueryContainer)4 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)2 ScanMetrics (org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics)2 JanusGraphBaseTest (org.janusgraph.graphdb.JanusGraphBaseTest)2 VertexScanJob (org.janusgraph.graphdb.olap.VertexScanJob)2 Test (org.junit.jupiter.api.Test)2 MessageScope (org.apache.tinkerpop.gremlin.process.computer.MessageScope)1 ConnectedComponentVertexProgram (org.apache.tinkerpop.gremlin.process.computer.clustering.connected.ConnectedComponentVertexProgram)1 ShortestPathVertexProgram (org.apache.tinkerpop.gremlin.process.computer.search.path.ShortestPathVertexProgram)1 TraversalVertexProgram (org.apache.tinkerpop.gremlin.process.computer.traversal.TraversalVertexProgram)1 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)1 Direction (org.apache.tinkerpop.gremlin.structure.Direction)1 SliceQuery (org.janusgraph.diskstorage.keycolumnvalue.SliceQuery)1 RelationTypeIndexWrapper (org.janusgraph.graphdb.database.management.RelationTypeIndexWrapper)1 InternalRelationType (org.janusgraph.graphdb.internal.InternalRelationType)1 StandardJanusGraphTx (org.janusgraph.graphdb.transaction.StandardJanusGraphTx)1 PreloadedVertex (org.janusgraph.graphdb.vertices.PreloadedVertex)1