Search in sources :

Example 6 with QueryFlowManager

use of com.alibaba.maxgraph.compiler.optimizer.QueryFlowManager in project GraphScope by alibaba.

the class DfsOperatorTest method testDfsSimpleCase.

@Test
public void testDfsSimpleCase() {
    Object obj = tinkerMaxGraph.dfs(g.enableDebugLog().V().out().out(), 10, 20, 1);
    QueryFlowManager queryFlowManager = super.logicalPlanOptimizer.build((DfsTraversal) obj);
    String resultContent = TextFormat.printToString(queryFlowManager.getQueryFlow().build());
    System.out.println(resultContent);
    if (super.writeFlag) {
        try {
            IOUtils.write(resultContent, new FileOutputStream(new File(getWriteDirectory() + "/" + name.getMethodName())), "utf-8");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } else {
        assertResultPlan(name.getMethodName(), resultContent);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) QueryFlowManager(com.alibaba.maxgraph.compiler.optimizer.QueryFlowManager) IOException(java.io.IOException) File(java.io.File) Test(org.junit.Test)

Example 7 with QueryFlowManager

use of com.alibaba.maxgraph.compiler.optimizer.QueryFlowManager in project GraphScope by alibaba.

the class MixedOpProcessor method processQueryTraversal.

private Long processQueryTraversal(String script, Object traversal, long timeout, String queryId, Stopwatch timer, RemoteRpcConnector remoteRpcConnector, RemoteRpcProcessor remoteRpcProcessor, AbstractResultProcessor nettyResultProcessor) throws RetryGremlinException {
    Pair<GraphSchema, Long> snapshotSchema;
    GraphSchema schema;
    Long totalResultNum;
    QueryStatus queryStatus;
    QueryFlowManager queryFlowManager;
    // 保证一查看到snapshotId就开始维护query_status
    synchronized (queryCallbackManager) {
        snapshotSchema = this.schemaFetcher.getSchemaSnapshotPair();
        queryStatus = queryCallbackManager.beforeExecution(snapshotSchema.getRight());
    }
    schema = snapshotSchema.getLeft();
    LogicalPlanOptimizer logicalPlanOptimizer = new LogicalPlanOptimizer(new OptimizeConfig(), this.globalPullGraphFlag, schema, snapshotSchema.getRight(), this.lambdaEnableFlag);
    queryFlowManager = (traversal instanceof GraphTraversal) ? logicalPlanOptimizer.build(GraphTraversal.class.cast(traversal)) : logicalPlanOptimizer.build(DfsTraversal.class.cast(traversal));
    boolean isLambdaExisted = TraversalHelper.anyStepRecursively(s -> s instanceof LambdaHolder, (Traversal.Admin<?, ?>) traversal);
    queryFlowManager.getQueryFlow().setScript(script).setFrontId(serverId);
    if (this.lambdaEnableFlag && isLambdaExisted) {
        queryFlowManager.getQueryFlow().setLambdaExisted(isLambdaExisted);
    }
    nettyResultProcessor.setResultTransform(new GremlinResultTransform(remoteRpcConnector, remoteRpcProcessor, this.graph, queryFlowManager.getResultValueType(), vertexCacheFlag));
    nettyResultProcessor.setLabelIndexNameList(queryFlowManager.getTreeNodeLabelManager().getUserIndexLabelList());
    nettyResultProcessor.setSchema(schema);
    try {
        TimelyQuery timelyQuery = new TimelyQuery(queryFlowManager, nettyResultProcessor, this.graph);
        Logging.query(this.graphName, com.alibaba.maxgraph.proto.RoleType.FRONTEND, this.serverId, queryId, QueryType.EXECUTE, QueryEvent.PLAN_GENERATED, timer.elapsed(TimeUnit.NANOSECONDS), null, null, script);
        timelyExecutor.execute(timelyQuery, schema, timeout, queryId);
        totalResultNum = nettyResultProcessor.total();
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        queryCallbackManager.afterExecution(queryStatus);
    }
    return totalResultNum;
}
Also used : TimelyQuery(com.alibaba.maxgraph.compiler.query.TimelyQuery) DfsTraversal(com.alibaba.maxgraph.compiler.dfs.DfsTraversal) LambdaHolder(org.apache.tinkerpop.gremlin.process.traversal.step.LambdaHolder) DfsTraversal(com.alibaba.maxgraph.compiler.dfs.DfsTraversal) PreparedTraversal(com.alibaba.maxgraph.compiler.prepare.PreparedTraversal) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) QueryFlowManager(com.alibaba.maxgraph.compiler.optimizer.QueryFlowManager) QueryStatus(com.alibaba.maxgraph.api.query.QueryStatus) GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema) RetryGremlinException(com.alibaba.maxgraph.compiler.exception.RetryGremlinException) OptimizeConfig(com.alibaba.maxgraph.compiler.optimizer.OptimizeConfig) LogicalPlanOptimizer(com.alibaba.maxgraph.compiler.optimizer.LogicalPlanOptimizer) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)

Aggregations

QueryFlowManager (com.alibaba.maxgraph.compiler.optimizer.QueryFlowManager)7 IOException (java.io.IOException)3 QueryStatus (com.alibaba.maxgraph.api.query.QueryStatus)2 GraphSchema (com.alibaba.maxgraph.compiler.api.schema.GraphSchema)2 DfsTraversal (com.alibaba.maxgraph.compiler.dfs.DfsTraversal)2 LogicalPlanOptimizer (com.alibaba.maxgraph.compiler.optimizer.LogicalPlanOptimizer)2 OptimizeConfig (com.alibaba.maxgraph.compiler.optimizer.OptimizeConfig)2 TimelyQuery (com.alibaba.maxgraph.compiler.query.TimelyQuery)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)2 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)2 LambdaHolder (org.apache.tinkerpop.gremlin.process.traversal.step.LambdaHolder)2 QueryFlowOuterClass (com.alibaba.maxgraph.QueryFlowOuterClass)1 RetryGremlinException (com.alibaba.maxgraph.compiler.exception.RetryGremlinException)1 ExecuteConfig (com.alibaba.maxgraph.compiler.executor.ExecuteConfig)1 OperatorListManager (com.alibaba.maxgraph.compiler.optimizer.OperatorListManager)1 PreparedTraversal (com.alibaba.maxgraph.compiler.prepare.PreparedTraversal)1 PrepareStoreEntity (com.alibaba.maxgraph.compiler.prepare.store.PrepareStoreEntity)1 ByteString (com.google.protobuf.ByteString)1