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());
}
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();
}
}
}
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();
}
}
}
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));
}
Aggregations