use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class ServerInfoManager method serverInfos.
private Iterator<HugeServerInfo> serverInfos(Map<String, Object> conditions, long limit, String page) {
return this.call(() -> {
ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
if (page != null) {
query.page(page);
}
HugeGraph graph = this.graph.graph();
VertexLabel vl = graph.vertexLabel(HugeServerInfo.P.SERVER);
query.eq(HugeKeys.LABEL, vl.id());
for (Map.Entry<String, Object> entry : conditions.entrySet()) {
PropertyKey pk = graph.propertyKey(entry.getKey());
query.query(Condition.eq(pk.id(), entry.getValue()));
}
query.showHidden(true);
if (limit != NO_LIMIT) {
query.limit(limit);
}
Iterator<Vertex> vertices = this.tx().queryVertices(query);
Iterator<HugeServerInfo> servers = new MapperIterator<>(vertices, HugeServerInfo::fromVertex);
// Convert iterator to list to avoid across thread tx accessed
return QueryResults.toList(servers);
});
}
use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class StandardTaskScheduler method queryTask.
private <V> Iterator<HugeTask<V>> queryTask(Map<String, Object> conditions, long limit, String page) {
return this.call(() -> {
ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
if (page != null) {
query.page(page);
}
VertexLabel vl = this.graph().vertexLabel(P.TASK);
query.eq(HugeKeys.LABEL, vl.id());
for (Map.Entry<String, Object> entry : conditions.entrySet()) {
PropertyKey pk = this.graph().propertyKey(entry.getKey());
query.query(Condition.eq(pk.id(), entry.getValue()));
}
query.showHidden(true);
if (limit != NO_LIMIT) {
query.limit(limit);
}
Iterator<Vertex> vertices = this.tx().queryVertices(query);
Iterator<HugeTask<V>> tasks = new MapperIterator<>(vertices, HugeTask::fromVertex);
// Convert iterator to list to avoid across thread tx accessed
return QueryResults.toList(tasks);
});
}
use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class VertexCoreTest method testQueryFilterByPropName.
@Test
public void testQueryFilterByPropName() {
HugeGraph graph = graph();
Assume.assumeTrue("Not support CONTAINS_KEY query", storeFeatures().supportsQueryWithContainsKey());
init10Vertices();
VertexLabel language = graph.vertexLabel("language");
PropertyKey dynamic = graph.propertyKey("dynamic");
// Query vertex by condition (does contain the property name?)
ConditionQuery q = new ConditionQuery(HugeType.VERTEX);
q.eq(HugeKeys.LABEL, language.id());
q.key(HugeKeys.PROPERTIES, dynamic.id());
List<Vertex> vertices = ImmutableList.copyOf(graph.vertices(q));
Assert.assertEquals(1, vertices.size());
assertContains(vertices, T.label, "language", "name", "python", "dynamic", true);
// Query vertex by condition (does contain the property name?)
q = new ConditionQuery(HugeType.VERTEX);
q.key(HugeKeys.PROPERTIES, dynamic.id());
vertices = ImmutableList.copyOf(graph.vertices(q));
Assert.assertEquals(1, vertices.size());
assertContains(vertices, T.label, "language", "name", "python", "dynamic", true);
}
use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class VertexCoreTest method testScanVertex.
@Test
public void testScanVertex() {
HugeGraph graph = graph();
// TODO: also support test scan by range
Assume.assumeTrue("Not support scan", storeFeatures().supportsScanToken() || storeFeatures().supportsScanKeyRange());
this.init10VerticesAndCommit();
List<Vertex> vertices = new LinkedList<>();
long splitSize = 1 * 1024 * 1024;
List<Shard> splits = graph.metadata(HugeType.VERTEX, "splits", splitSize);
for (Shard split : splits) {
ConditionQuery q = new ConditionQuery(HugeType.VERTEX);
q.scan(split.start(), split.end());
vertices.addAll(ImmutableList.copyOf(graph.vertices(q)));
}
Assert.assertEquals(10, vertices.size());
}
use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class Vertices method vertices.
public Iterator<Vertex> vertices(HugeGraph g) {
Map<String, Object> props = this.properties;
E.checkArgument(!((this.ids == null || this.ids.isEmpty()) && (props == null || props.isEmpty()) && this.label == null), "No source vertices provided");
Iterator<Vertex> iterator;
if (this.ids != null && !this.ids.isEmpty()) {
List<Id> sourceIds = new ArrayList<>(this.ids.size());
for (Object id : this.ids) {
sourceIds.add(HugeVertex.getIdValue(id));
}
iterator = g.vertices(sourceIds.toArray());
E.checkArgument(iterator.hasNext(), "Not exist source vertices with ids %s", this.ids);
} else {
ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
if (this.label != null) {
Id label = g.vertexLabel(this.label).id();
query.eq(HugeKeys.LABEL, label);
}
if (props != null && !props.isEmpty()) {
Map<Id, Object> pks = TraversalUtil.transProperties(g, props);
TraversalUtil.fillConditionQuery(query, pks, g);
}
assert !query.empty();
iterator = g.vertices(query);
E.checkArgument(iterator.hasNext(), "Not exist source vertex " + "with label '%s' and properties '%s'", this.label, props);
}
return iterator;
}
Aggregations