use of com.baidu.hugegraph.entity.query.GremlinResult in project incubator-hugegraph-toolchain by apache.
the class GremlinQueryService method expandVertex.
public GremlinResult expandVertex(int connId, AdjacentQuery query) {
HugeClient client = this.getClient(connId);
// Build gremlin query
String gremlin = this.buildGremlinQuery(connId, query);
log.debug("expand vertex gremlin ==> {}", gremlin);
// Execute gremlin query
ResultSet resultSet = this.executeGremlin(gremlin, client);
List<Vertex> vertices = new ArrayList<>(resultSet.size());
List<Edge> edges = new ArrayList<>(resultSet.size());
for (Iterator<Result> iter = resultSet.iterator(); iter.hasNext(); ) {
Path path = iter.next().getPath();
List<Object> objects = path.objects();
assert objects.size() == 3;
Edge edge = (Edge) objects.get(1);
Vertex vertex = (Vertex) objects.get(2);
// Filter vertices and edges that existed in query
if (query.retainEdge(edge)) {
edges.add(edge);
}
if (query.retainVertex(vertex)) {
vertices.add(vertex);
}
}
// Build graph view
GraphView graphView = new GraphView(vertices, edges);
return GremlinResult.builder().type(Type.PATH).graphView(graphView).build();
}
use of com.baidu.hugegraph.entity.query.GremlinResult in project incubator-hugegraph-toolchain by apache.
the class GremlinQueryController method execute.
@PostMapping
public GremlinResult execute(@PathVariable("connId") int connId, @RequestBody GremlinQuery query) {
this.checkParamsValid(query);
Date createTime = HubbleUtil.nowDate();
// Insert execute history
ExecuteStatus status = ExecuteStatus.RUNNING;
ExecuteHistory history;
history = new ExecuteHistory(null, connId, 0L, ExecuteType.GREMLIN, query.getContent(), status, AsyncTaskStatus.UNKNOWN, -1L, createTime);
this.historyService.save(history);
StopWatch timer = StopWatch.createStarted();
try {
GremlinResult result = this.queryService.executeQuery(connId, query);
status = ExecuteStatus.SUCCESS;
return result;
} catch (Throwable e) {
status = ExecuteStatus.FAILED;
throw e;
} finally {
timer.stop();
long duration = timer.getTime(TimeUnit.MILLISECONDS);
history.setStatus(status);
history.setDuration(duration);
this.historyService.update(history);
}
}
Aggregations