use of com.alibaba.graphscope.gaia.result.GremlinResultProcessor 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();
}
use of com.alibaba.graphscope.gaia.result.GremlinResultProcessor in project GraphScope by alibaba.
the class TraversalOpProcessor method select.
@Override
public ThrowingConsumer<Context> select(Context ctx) throws OpProcessorException {
final RequestMessage message = ctx.getRequestMessage();
final ThrowingConsumer<Context> op;
final GremlinExecutor executor = ctx.getGremlinExecutor();
final SimpleBindings b = new SimpleBindings();
final Map<String, String> aliases = (Map<String, String>) message.optionalArgs(Tokens.ARGS_ALIASES).get();
final String traversalSourceName = aliases.entrySet().iterator().next().getValue();
logger.info("tokens ops is {}", message.getOp());
if (config.getGraphType() == GraphType.MAXGRAPH) {
graphStore.updateSnapShotId();
}
switch(message.getOp()) {
case Tokens.OPS_BYTECODE:
op = (context -> {
try {
Object byteCode = message.getArgs().get(Tokens.ARGS_GREMLIN);
Traversal traversal = executor.eval((Bytecode) byteCode, new SimpleBindings(), null, traversalSourceName);
GaiaGraphOpProcessor.applyStrategy(traversal, config, graphStore);
long queryId = (long) queryIdMaker.getId(traversal);
TraversalBuilder traversalBuilder = new TraversalBuilder((Traversal.Admin) traversal).addConfig(PlanConfig.QUERY_ID, queryId).addConfig(PlanConfig.TAG_ID_MAKER, new TagIdMaker((Traversal.Admin) traversal)).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 RemoteTraverserResultParser(traversalBuilder, graphStore, config)));
logger.info("query-{} finish", queryId);
} catch (SchemaNotFoundException e) {
throw new OpProcessorException("schema not found error", ResponseMessage.build(message).code(ResponseStatusCode.SUCCESS).result(Collections.EMPTY_LIST).create());
}
});
return op;
case Tokens.OPS_KEYS:
GaiaGraphOpProcessor.writeResultList(ctx, Collections.EMPTY_LIST, ResponseStatusCode.SUCCESS);
return null;
default:
String errorMsg = "not support " + message.getOp();
GaiaGraphOpProcessor.writeResultList(ctx, Collections.singletonList(errorMsg), ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS);
return null;
}
}
Aggregations