use of com.alibaba.graphscope.gaia.result.DefaultResultParser in project GraphScope by alibaba.
the class GaiaGraphOpProcessor method createLifeCycle.
@Override
protected GremlinExecutor.LifeCycle createLifeCycle(Context ctx, Supplier<GremlinExecutor> gremlinExecutorSupplier, BindingSupplier bindingsSupplier) {
final RequestMessage msg = ctx.getRequestMessage();
final Settings settings = ctx.getSettings();
final Map<String, Object> args = msg.getArgs();
final long seto = args.containsKey(Tokens.ARGS_SCRIPT_EVAL_TIMEOUT) ? ((Number) args.get(Tokens.ARGS_SCRIPT_EVAL_TIMEOUT)).longValue() : settings.scriptEvaluationTimeout;
if (config.getGraphType() == GraphType.MAXGRAPH) {
graphStore.updateSnapShotId();
}
return GremlinExecutor.LifeCycle.build().scriptEvaluationTimeoutOverride(seto).beforeEval(b -> {
try {
b.putAll(bindingsSupplier.get());
} catch (OpProcessorException ope) {
throw new RuntimeException(ope);
}
}).transformResult(o -> {
if (o != null && o instanceof Traversal) {
applyStrategy((Traversal) o, config, graphStore);
}
return o;
}).withResult(o -> {
if (o != null && o instanceof Traversal) {
long queryId = (long) queryIdMaker.getId(o);
TraversalBuilder traversalBuilder = new TraversalBuilder((Traversal.Admin) o).addConfig(PlanConfig.QUERY_ID, queryId).addConfig(PlanConfig.TAG_ID_MAKER, new TagIdMaker((Traversal.Admin) o)).addConfig(PlanConfig.QUERY_CONFIG, PlanUtils.getDefaultConfig(queryId, config));
if (config.getGraphType() == GraphType.MAXGRAPH) {
traversalBuilder.addConfig(PlanConfig.SNAPSHOT_ID, Long.valueOf(graphStore.getSnapShotId()));
}
AbstractBuilder jobReqBuilder = new TraversalTranslator(traversalBuilder).translate();
PlanUtils.print(jobReqBuilder);
broadcastProcessor.broadcast(jobReqBuilder.build(), new GremlinResultProcessor(ctx, new DefaultResultParser(traversalBuilder, graphStore, config)));
} else {
List<Object> results = new ArrayList<>();
if (o != null) {
results.add(o);
}
writeResultList(ctx, results, ResponseStatusCode.SUCCESS);
}
}).create();
}
Aggregations