Search in sources :

Example 1 with VertexScanJob

use of org.janusgraph.graphdb.olap.VertexScanJob 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 VertexScanJob

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

the class HadoopVertexScanMapper method setup.

@Override
protected void setup(Context context) throws IOException, InterruptedException {
    /* Don't call super implementation super.setup(context); */
    org.apache.hadoop.conf.Configuration hadoopConf = context.getConfiguration();
    ModifiableHadoopConfiguration scanConf = ModifiableHadoopConfiguration.of(JanusGraphHadoopConfiguration.MAPRED_NS, hadoopConf);
    VertexScanJob vertexScan = getVertexScanJob(scanConf);
    ModifiableConfiguration graphConf = getJanusGraphConfiguration(context);
    graph = JanusGraphFactory.open(graphConf);
    job = VertexJobConverter.convert(graph, vertexScan);
    metrics = new HadoopContextScanMetrics(context);
    finishSetup(scanConf, graphConf);
}
Also used : VertexScanJob(org.janusgraph.graphdb.olap.VertexScanJob) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) ModifiableHadoopConfiguration(org.janusgraph.hadoop.config.ModifiableHadoopConfiguration)

Example 3 with VertexScanJob

use of org.janusgraph.graphdb.olap.VertexScanJob 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

VertexScanJob (org.janusgraph.graphdb.olap.VertexScanJob)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)2 ScanMetrics (org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics)2 JanusGraphBaseTest (org.janusgraph.graphdb.JanusGraphBaseTest)2 QueryContainer (org.janusgraph.graphdb.olap.QueryContainer)2 Test (org.junit.jupiter.api.Test)2 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)1 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)1 ModifiableConfiguration (org.janusgraph.diskstorage.configuration.ModifiableConfiguration)1 ModifiableHadoopConfiguration (org.janusgraph.hadoop.config.ModifiableHadoopConfiguration)1