use of com.baidu.hugegraph.backend.query.Query in project incubator-hugegraph by apache.
the class HugeGraphStep method edgesCount.
private long edgesCount() {
if (!this.hasIds()) {
HugeGraph graph = TraversalUtil.getGraph(this);
Query query = this.makeQuery(graph, HugeType.EDGE);
return graph.queryNumber(query).longValue();
}
return IteratorUtils.count(this.edges());
}
use of com.baidu.hugegraph.backend.query.Query in project incubator-hugegraph by apache.
the class HugeVariables method queryVariableVertex.
private HugeVertex queryVariableVertex(String key) {
GraphTransaction tx = this.params.graphTransaction();
Query query = this.createVariableQuery(key);
Iterator<Vertex> vertices = tx.queryVertices(query);
return (HugeVertex) QueryResults.one(vertices);
}
use of com.baidu.hugegraph.backend.query.Query in project incubator-hugegraph by apache.
the class RocksDBStore method query.
@Override
public Iterator<BackendEntry> query(Query query) {
Lock readLock = this.storeLock.readLock();
readLock.lock();
try {
this.checkOpened();
HugeType tableType = RocksDBTable.tableType(query);
RocksDBTable table;
RocksDBSessions.Session session;
if (query.olap()) {
table = this.table(this.olapTableName(tableType));
session = this.session(HugeType.OLAP);
} else {
table = this.table(tableType);
session = this.session(tableType);
}
Iterator<BackendEntry> entries = table.query(session, query);
// Merge olap results as needed
Set<Id> olapPks = query.olapPks();
if (this.isGraphStore && !olapPks.isEmpty()) {
List<Iterator<BackendEntry>> iterators = new ArrayList<>();
for (Id pk : olapPks) {
Query q = query.copy();
table = this.table(this.olapTableName(pk));
iterators.add(table.query(this.session(HugeType.OLAP), q));
}
entries = new MergeIterator<>(entries, iterators, BackendEntry::mergeable);
}
return entries;
} finally {
readLock.unlock();
}
}
use of com.baidu.hugegraph.backend.query.Query in project incubator-hugegraph by apache.
the class EdgeCoreTest method testQueryOutEdgesOfVertexBySortkeyWithMoreFieldsInPage.
@Test
public void testQueryOutEdgesOfVertexBySortkeyWithMoreFieldsInPage() {
Assume.assumeTrue("Not support paging", storeFeatures().supportsQueryByPage());
HugeGraph graph = graph();
SchemaManager schema = graph.schema();
schema.propertyKey("no").asText().create();
schema.propertyKey("location").asText().create();
schema.propertyKey("callType").asText().create();
schema.propertyKey("calltime").asDate().create();
schema.propertyKey("duration").asInt().create();
schema.vertexLabel("phone").properties("no").primaryKeys("no").enableLabelIndex(false).create();
schema.edgeLabel("call").multiTimes().properties("location", "callType", "duration", "calltime").sourceLabel("phone").targetLabel("phone").sortKeys("location", "callType", "duration", "calltime").create();
Vertex v1 = graph.addVertex(T.label, "phone", "no", "13812345678");
Vertex v2 = graph.addVertex(T.label, "phone", "no", "13866668888");
Vertex v10086 = graph.addVertex(T.label, "phone", "no", "10086");
v1.addEdge("call", v2, "location", "Beijing", "callType", "work", "duration", 3, "calltime", "2017-5-1 23:00:00");
v1.addEdge("call", v2, "location", "Beijing", "callType", "work", "duration", 3, "calltime", "2017-5-2 12:00:01");
v1.addEdge("call", v2, "location", "Beijing", "callType", "work", "duration", 3, "calltime", "2017-5-3 12:08:02");
v1.addEdge("call", v2, "location", "Beijing", "callType", "work", "duration", 8, "calltime", "2017-5-3 22:22:03");
v1.addEdge("call", v2, "location", "Beijing", "callType", "fun", "duration", 10, "calltime", "2017-5-4 20:33:04");
v1.addEdge("call", v10086, "location", "Nanjing", "callType", "work", "duration", 12, "calltime", "2017-5-2 15:30:05");
v1.addEdge("call", v10086, "location", "Nanjing", "callType", "work", "duration", 14, "calltime", "2017-5-3 14:56:06");
v2.addEdge("call", v10086, "location", "Nanjing", "callType", "fun", "duration", 15, "calltime", "2017-5-3 17:28:07");
graph.tx().commit();
Assert.assertEquals(8, graph.traversal().E().toList().size());
// Query by sortkey prefix "location"
List<Edge> edges = graph.traversal().V(v1).outE("call").has("location", "Beijing").toList();
Assert.assertEquals(5, edges.size());
Assert.assertEquals(5, traverseInPage(page -> {
return graph.traversal().V(v1).outE("call").has("location", "Beijing").has("~page", page).limit(1);
}));
edges = graph.traversal().V(v1).outE("call").has("location", "Nanjing").toList();
Assert.assertEquals(2, edges.size());
Assert.assertEquals(2, traverseInPage(page -> {
return graph.traversal().V(v1).outE("call").has("location", "Nanjing").has("~page", page).limit(1);
}));
// Query by sortkey prefix "location", "callType"
edges = graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").toList();
Assert.assertEquals(4, edges.size());
Assert.assertEquals(4, traverseInPage(page -> {
return graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("~page", page).limit(1);
}));
edges = graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "fun").toList();
Assert.assertEquals(1, edges.size());
Assert.assertEquals(1, traverseInPage(page -> {
return graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "fun").has("~page", page).limit(1);
}));
edges = graph.traversal().V(v1).outE("call").has("location", "Nanjing").has("callType", "work").toList();
Assert.assertEquals(2, edges.size());
Assert.assertEquals(2, traverseInPage(page -> {
return graph.traversal().V(v1).outE("call").has("location", "Nanjing").has("callType", "work").has("~page", page).limit(1);
}));
// Query by sortkey prefix "location", "callType", "duration"
edges = graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", 3).toList();
Assert.assertEquals(3, edges.size());
Assert.assertEquals(3, traverseInPage(page -> {
return graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", 3).has("~page", page).limit(1);
}));
edges = graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", 8).toList();
Assert.assertEquals(1, edges.size());
Assert.assertEquals(1, traverseInPage(page -> {
return graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", 8).has("~page", page).limit(1);
}));
edges = graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "fun").has("duration", 10).toList();
Assert.assertEquals(1, edges.size());
Assert.assertEquals(1, traverseInPage(page -> {
return graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "fun").has("duration", 10).has("~page", page).limit(1);
}));
edges = graph.traversal().V(v1).outE("call").has("location", "Nanjing").has("callType", "work").has("duration", 12).toList();
Assert.assertEquals(1, edges.size());
Assert.assertEquals(1, traverseInPage(page -> {
return graph.traversal().V(v1).outE("call").has("location", "Nanjing").has("callType", "work").has("duration", 12).has("~page", page).limit(1);
}));
edges = graph.traversal().V(v1).outE("call").has("location", "Nanjing").has("callType", "work").has("duration", 14).toList();
Assert.assertEquals(1, edges.size());
Assert.assertEquals(1, traverseInPage(page -> {
return graph.traversal().V(v1).outE("call").has("location", "Nanjing").has("callType", "work").has("duration", 14).has("~page", page).limit(1);
}));
// Query by sortkey prefix "location", "callType" and range "duration"
edges = graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", P.lt(8)).toList();
Assert.assertEquals(3, edges.size());
Assert.assertEquals(3, traverseInPage(page -> {
return graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", P.lt(8)).has("~page", page).limit(1);
}));
edges = graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", P.lte(8)).toList();
Assert.assertEquals(4, edges.size());
Assert.assertEquals(4, traverseInPage(page -> {
return graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", P.lte(8)).has("~page", page).limit(1);
}));
edges = graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", P.gt(3)).toList();
Assert.assertEquals(1, edges.size());
Assert.assertEquals(1, traverseInPage(page -> {
return graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", P.gt(3)).has("~page", page).limit(1);
}));
edges = graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", P.gte(3)).toList();
Assert.assertEquals(4, edges.size());
Assert.assertEquals(4, traverseInPage(page -> {
return graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", P.gte(3)).has("~page", page).limit(1);
}));
edges = graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", P.between(3, 9)).toList();
Assert.assertEquals(4, edges.size());
Assert.assertEquals(4, traverseInPage(page -> {
return graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", P.between(3, 9)).has("~page", page).limit(1);
}));
// Query by sortkey prefix "location", "callType", "duration",
// "callTime"
edges = graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", 3).has("calltime", "2017-5-1 23:00:00").toList();
Assert.assertEquals(1, edges.size());
Assert.assertEquals(1, traverseInPage(page -> {
return graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", 3).has("calltime", "2017-5-1 23:00:00").has("~page", page).limit(1);
}));
edges = graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", 3).has("calltime", "2017-5-2 12:00:01").toList();
Assert.assertEquals(1, edges.size());
Assert.assertEquals(1, traverseInPage(page -> {
return graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", 3).has("calltime", "2017-5-2 12:00:01").has("~page", page).limit(1);
}));
edges = graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", 3).has("calltime", "2017-5-3 12:08:02").toList();
Assert.assertEquals(1, edges.size());
Assert.assertEquals(1, traverseInPage(page -> {
return graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", 3).has("calltime", "2017-5-3 12:08:02").has("~page", page).limit(1);
}));
// Query by sortkey prefix "location", "callType", "duration" and
// range "callTime"
edges = graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", 3).has("calltime", P.lt("2017-5-2 12:00:01")).toList();
Assert.assertEquals(1, edges.size());
Assert.assertEquals(1, traverseInPage(page -> {
return graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", 3).has("calltime", P.lt("2017-5-2 12:00:01")).has("~page", page).limit(1);
}));
edges = graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", 3).has("calltime", P.lte("2017-5-2 12:00:01")).toList();
Assert.assertEquals(2, edges.size());
Assert.assertEquals(2, traverseInPage(page -> {
return graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", 3).has("calltime", P.lte("2017-5-2 12:00:01")).has("~page", page).limit(1);
}));
edges = graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", 3).has("calltime", P.gt("2017-5-2 12:00:01")).toList();
Assert.assertEquals(1, edges.size());
Assert.assertEquals(1, traverseInPage(page -> {
return graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", 3).has("calltime", P.gt("2017-5-2 12:00:01")).has("~page", page).limit(1);
}));
edges = graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", 3).has("calltime", P.gte("2017-5-2 12:00:01")).toList();
Assert.assertEquals(2, edges.size());
Assert.assertEquals(2, traverseInPage(page -> {
return graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", 3).has("calltime", P.gte("2017-5-2 12:00:01")).has("~page", page).limit(1);
}));
edges = graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", 3).has("calltime", P.between("2017-5-2", "2017-5-4")).toList();
Assert.assertEquals(2, edges.size());
Assert.assertEquals(2, traverseInPage(page -> {
return graph.traversal().V(v1).outE("call").has("location", "Beijing").has("callType", "work").has("duration", 3).has("calltime", P.between("2017-5-2", "2017-5-4")).has("~page", page).limit(1);
}));
Assert.assertThrows(IllegalArgumentException.class, () -> {
traverseInPage(page -> {
// no location
return graph.traversal().V(v1).outE("call").has("callType", "work").has("duration", 3).has("calltime", P.between("2017-5-2", "2017-5-4")).has("~page", page).limit(1);
});
}, e -> {
Assert.assertContains("Can't query by paging and filtering", e.getMessage());
});
}
use of com.baidu.hugegraph.backend.query.Query in project incubator-hugegraph by apache.
the class RamTableTest method edgesOfVertex.
private Iterator<Edge> edgesOfVertex(Id source, Directions dir, Id label) {
Id[] labels = {};
if (label != null) {
labels = new Id[] { label };
}
Query query = GraphTransaction.constructEdgesQuery(source, dir, labels);
return this.graph().edges(query);
}
Aggregations