Search in sources :

Example 1 with DefaultResultParser

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();
}
Also used : TraversalBuilder(com.alibaba.graphscope.gaia.plan.translator.builder.TraversalBuilder) AbstractBroadcastProcessor(com.alibaba.graphscope.gaia.broadcast.AbstractBroadcastProcessor) TraversalTranslator(com.alibaba.graphscope.gaia.plan.translator.TraversalTranslator) Settings(org.apache.tinkerpop.gremlin.server.Settings) Tokens(org.apache.tinkerpop.gremlin.driver.Tokens) LoggerFactory(org.slf4j.LoggerFactory) DefaultResultParser(com.alibaba.graphscope.gaia.result.DefaultResultParser) Supplier(java.util.function.Supplier) RequestMessage(org.apache.tinkerpop.gremlin.driver.message.RequestMessage) ArrayList(java.util.ArrayList) GremlinResultProcessor(com.alibaba.graphscope.gaia.result.GremlinResultProcessor) Map(java.util.Map) OpProcessorException(org.apache.tinkerpop.gremlin.server.op.OpProcessorException) GraphStoreService(com.alibaba.graphscope.gaia.store.GraphStoreService) Logger(org.slf4j.Logger) GaiaConfig(com.alibaba.graphscope.gaia.config.GaiaConfig) PlanUtils(com.alibaba.graphscope.gaia.plan.PlanUtils) AbstractBuilder(com.alibaba.pegasus.builder.AbstractBuilder) List(java.util.List) TagIdMaker(com.alibaba.graphscope.gaia.idmaker.TagIdMaker) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) PlanConfig(com.alibaba.graphscope.gaia.plan.translator.builder.PlanConfig) ResponseStatusCode(org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode) GraphType(com.alibaba.graphscope.gaia.store.GraphType) Context(org.apache.tinkerpop.gremlin.server.Context) GremlinExecutor(org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor) OpProcessorException(org.apache.tinkerpop.gremlin.server.op.OpProcessorException) AbstractBuilder(com.alibaba.pegasus.builder.AbstractBuilder) TraversalBuilder(com.alibaba.graphscope.gaia.plan.translator.builder.TraversalBuilder) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) GremlinResultProcessor(com.alibaba.graphscope.gaia.result.GremlinResultProcessor) RequestMessage(org.apache.tinkerpop.gremlin.driver.message.RequestMessage) TagIdMaker(com.alibaba.graphscope.gaia.idmaker.TagIdMaker) TraversalTranslator(com.alibaba.graphscope.gaia.plan.translator.TraversalTranslator) ArrayList(java.util.ArrayList) List(java.util.List) Settings(org.apache.tinkerpop.gremlin.server.Settings) DefaultResultParser(com.alibaba.graphscope.gaia.result.DefaultResultParser)

Aggregations

AbstractBroadcastProcessor (com.alibaba.graphscope.gaia.broadcast.AbstractBroadcastProcessor)1 GaiaConfig (com.alibaba.graphscope.gaia.config.GaiaConfig)1 TagIdMaker (com.alibaba.graphscope.gaia.idmaker.TagIdMaker)1 PlanUtils (com.alibaba.graphscope.gaia.plan.PlanUtils)1 TraversalTranslator (com.alibaba.graphscope.gaia.plan.translator.TraversalTranslator)1 PlanConfig (com.alibaba.graphscope.gaia.plan.translator.builder.PlanConfig)1 TraversalBuilder (com.alibaba.graphscope.gaia.plan.translator.builder.TraversalBuilder)1 DefaultResultParser (com.alibaba.graphscope.gaia.result.DefaultResultParser)1 GremlinResultProcessor (com.alibaba.graphscope.gaia.result.GremlinResultProcessor)1 GraphStoreService (com.alibaba.graphscope.gaia.store.GraphStoreService)1 GraphType (com.alibaba.graphscope.gaia.store.GraphType)1 AbstractBuilder (com.alibaba.pegasus.builder.AbstractBuilder)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Supplier (java.util.function.Supplier)1 Tokens (org.apache.tinkerpop.gremlin.driver.Tokens)1 RequestMessage (org.apache.tinkerpop.gremlin.driver.message.RequestMessage)1 ResponseStatusCode (org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode)1 GremlinExecutor (org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor)1