Search in sources :

Example 6 with TraversalTranslator

use of com.alibaba.graphscope.gaia.plan.translator.TraversalTranslator in project GraphScope by alibaba.

the class QueryTest method test_CR_8.

public static void test_CR_8(GaiaConfig config, GraphStoreService storeService, IdMaker queryIdMaker) {
    Traversal testTraversal = CR_8();
    GaiaGraphOpProcessor.applyStrategy(testTraversal, config, storeService);
    long queryId = (long) queryIdMaker.getId(testTraversal.asAdmin());
    AbstractBuilder job = new TraversalTranslator((new TraversalBuilder(testTraversal.asAdmin())).addConfig(PlanConfig.QUERY_ID, queryId).addConfig(PlanConfig.TAG_ID_MAKER, new TagIdMaker(testTraversal.asAdmin())).addConfig(PlanConfig.QUERY_CONFIG, PlanUtils.getDefaultConfig(queryId, config))).translate();
    PlanUtils.print(job);
}
Also used : AbstractBuilder(com.alibaba.pegasus.builder.AbstractBuilder) TraversalBuilder(com.alibaba.graphscope.gaia.plan.translator.builder.TraversalBuilder) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) TagIdMaker(com.alibaba.graphscope.gaia.idmaker.TagIdMaker) TraversalTranslator(com.alibaba.graphscope.gaia.plan.translator.TraversalTranslator)

Example 7 with TraversalTranslator

use of com.alibaba.graphscope.gaia.plan.translator.TraversalTranslator 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)

Example 8 with TraversalTranslator

use of com.alibaba.graphscope.gaia.plan.translator.TraversalTranslator in project GraphScope by alibaba.

the class QueryTest method test_CR_9.

public static void test_CR_9(GaiaConfig config, GraphStoreService storeService, IdMaker queryIdMaker) {
    Traversal testTraversal = CR_9();
    GaiaGraphOpProcessor.applyStrategy(testTraversal, config, storeService);
    long queryId = (long) queryIdMaker.getId(testTraversal.asAdmin());
    AbstractBuilder job = new TraversalTranslator((new TraversalBuilder(testTraversal.asAdmin())).addConfig(PlanConfig.QUERY_ID, queryId).addConfig(PlanConfig.TAG_ID_MAKER, new TagIdMaker(testTraversal.asAdmin())).addConfig(PlanConfig.QUERY_CONFIG, PlanUtils.getDefaultConfig(queryId, config))).translate();
    PlanUtils.print(job);
}
Also used : AbstractBuilder(com.alibaba.pegasus.builder.AbstractBuilder) TraversalBuilder(com.alibaba.graphscope.gaia.plan.translator.builder.TraversalBuilder) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) TagIdMaker(com.alibaba.graphscope.gaia.idmaker.TagIdMaker) TraversalTranslator(com.alibaba.graphscope.gaia.plan.translator.TraversalTranslator)

Example 9 with TraversalTranslator

use of com.alibaba.graphscope.gaia.plan.translator.TraversalTranslator in project GraphScope by alibaba.

the class LogicPlanProcessor 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();
            String content = new String(jobReqBuilder.build().toByteArray(), StandardCharsets.ISO_8859_1);
            AbstractGraphOpProcessor.writeResultList(ctx, Arrays.asList(content), ResponseStatusCode.SUCCESS);
        }
    }).create();
}
Also used : TraversalBuilder(com.alibaba.graphscope.gaia.plan.translator.builder.TraversalBuilder) java.util(java.util) Logger(org.slf4j.Logger) GaiaConfig(com.alibaba.graphscope.gaia.config.GaiaConfig) TraversalTranslator(com.alibaba.graphscope.gaia.plan.translator.TraversalTranslator) Settings(org.apache.tinkerpop.gremlin.server.Settings) PlanUtils(com.alibaba.graphscope.gaia.plan.PlanUtils) Tokens(org.apache.tinkerpop.gremlin.driver.Tokens) LoggerFactory(org.slf4j.LoggerFactory) Supplier(java.util.function.Supplier) RequestMessage(org.apache.tinkerpop.gremlin.driver.message.RequestMessage) StandardCharsets(java.nio.charset.StandardCharsets) AbstractBuilder(com.alibaba.pegasus.builder.AbstractBuilder) 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) OpProcessorException(org.apache.tinkerpop.gremlin.server.op.OpProcessorException) GraphType(com.alibaba.graphscope.gaia.store.GraphType) Context(org.apache.tinkerpop.gremlin.server.Context) GremlinExecutor(org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor) GraphStoreService(com.alibaba.graphscope.gaia.store.GraphStoreService) 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) RequestMessage(org.apache.tinkerpop.gremlin.driver.message.RequestMessage) TagIdMaker(com.alibaba.graphscope.gaia.idmaker.TagIdMaker) TraversalTranslator(com.alibaba.graphscope.gaia.plan.translator.TraversalTranslator) Settings(org.apache.tinkerpop.gremlin.server.Settings)

Example 10 with TraversalTranslator

use of com.alibaba.graphscope.gaia.plan.translator.TraversalTranslator 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;
    }
}
Also used : Context(org.apache.tinkerpop.gremlin.server.Context) TraversalBuilder(com.alibaba.graphscope.gaia.plan.translator.builder.TraversalBuilder) Bytecode(org.apache.tinkerpop.gremlin.process.traversal.Bytecode) AbstractBroadcastProcessor(com.alibaba.graphscope.gaia.broadcast.AbstractBroadcastProcessor) TraversalTranslator(com.alibaba.graphscope.gaia.plan.translator.TraversalTranslator) ThrowingConsumer(org.apache.tinkerpop.gremlin.util.function.ThrowingConsumer) Tokens(org.apache.tinkerpop.gremlin.driver.Tokens) LoggerFactory(org.slf4j.LoggerFactory) IdMaker(com.alibaba.graphscope.gaia.idmaker.IdMaker) RequestMessage(org.apache.tinkerpop.gremlin.driver.message.RequestMessage) ResponseMessage(org.apache.tinkerpop.gremlin.driver.message.ResponseMessage) GremlinResultProcessor(com.alibaba.graphscope.gaia.result.GremlinResultProcessor) Map(java.util.Map) OpProcessorException(org.apache.tinkerpop.gremlin.server.op.OpProcessorException) IncrementalQueryIdMaker(com.alibaba.graphscope.gaia.idmaker.IncrementalQueryIdMaker) GraphStoreService(com.alibaba.graphscope.gaia.store.GraphStoreService) Logger(org.slf4j.Logger) SchemaNotFoundException(com.alibaba.graphscope.gaia.store.SchemaNotFoundException) GaiaConfig(com.alibaba.graphscope.gaia.config.GaiaConfig) PlanUtils(com.alibaba.graphscope.gaia.plan.PlanUtils) RemoteTraverserResultParser(com.alibaba.graphscope.gaia.result.RemoteTraverserResultParser) AbstractBuilder(com.alibaba.pegasus.builder.AbstractBuilder) SimpleBindings(javax.script.SimpleBindings) 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) AbstractOpProcessor(org.apache.tinkerpop.gremlin.server.op.AbstractOpProcessor) Collections(java.util.Collections) OpProcessorException(org.apache.tinkerpop.gremlin.server.op.OpProcessorException) AbstractBuilder(com.alibaba.pegasus.builder.AbstractBuilder) GremlinExecutor(org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor) TraversalBuilder(com.alibaba.graphscope.gaia.plan.translator.builder.TraversalBuilder) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) GremlinResultProcessor(com.alibaba.graphscope.gaia.result.GremlinResultProcessor) SimpleBindings(javax.script.SimpleBindings) RequestMessage(org.apache.tinkerpop.gremlin.driver.message.RequestMessage) TagIdMaker(com.alibaba.graphscope.gaia.idmaker.TagIdMaker) Bytecode(org.apache.tinkerpop.gremlin.process.traversal.Bytecode) TraversalTranslator(com.alibaba.graphscope.gaia.plan.translator.TraversalTranslator) SchemaNotFoundException(com.alibaba.graphscope.gaia.store.SchemaNotFoundException) Map(java.util.Map) RemoteTraverserResultParser(com.alibaba.graphscope.gaia.result.RemoteTraverserResultParser)

Aggregations

TagIdMaker (com.alibaba.graphscope.gaia.idmaker.TagIdMaker)15 TraversalTranslator (com.alibaba.graphscope.gaia.plan.translator.TraversalTranslator)15 TraversalBuilder (com.alibaba.graphscope.gaia.plan.translator.builder.TraversalBuilder)15 AbstractBuilder (com.alibaba.pegasus.builder.AbstractBuilder)15 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)15 GaiaConfig (com.alibaba.graphscope.gaia.config.GaiaConfig)3 PlanUtils (com.alibaba.graphscope.gaia.plan.PlanUtils)3 PlanConfig (com.alibaba.graphscope.gaia.plan.translator.builder.PlanConfig)3 GraphStoreService (com.alibaba.graphscope.gaia.store.GraphStoreService)3 GraphType (com.alibaba.graphscope.gaia.store.GraphType)3 Tokens (org.apache.tinkerpop.gremlin.driver.Tokens)3 RequestMessage (org.apache.tinkerpop.gremlin.driver.message.RequestMessage)3 ResponseStatusCode (org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode)3 GremlinExecutor (org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor)3 Context (org.apache.tinkerpop.gremlin.server.Context)3 OpProcessorException (org.apache.tinkerpop.gremlin.server.op.OpProcessorException)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 AbstractBroadcastProcessor (com.alibaba.graphscope.gaia.broadcast.AbstractBroadcastProcessor)2 GremlinResultProcessor (com.alibaba.graphscope.gaia.result.GremlinResultProcessor)2