use of com.alibaba.maxgraph.compiler.optimizer.QueryFlowManager in project GraphScope by alibaba.
the class TimelyExecutor method prepare.
@Override
public void prepare(String prepareId, TimelyQuery timelyQuery, ExecuteConfig executeConfig) {
QueryFlowManager queryFlowManager = timelyQuery.getQueryFlowManager();
checkArgument(queryFlowManager.checkValidPrepareFlow(), "There's no argument for prepare statement");
try {
if (statementStore.checkExist(prepareId)) {
throw new RuntimeException("PREPARE " + prepareId + " fail for the same name statement has been exist.");
}
QueryFlowOuterClass.QueryFlow queryFlow = queryFlowManager.getQueryFlow().setQueryId(prepareId).build();
rpcConnector.prepare(queryFlow, this.isAsyncGrpc);
OperatorListManager operatorListManager = queryFlowManager.getOperatorListManager();
statementStore.save(prepareId, new PrepareStoreEntity(operatorListManager.getPrepareEntityList(), operatorListManager.getLabelManager(), queryFlowManager.getResultValueType(), queryFlow));
logger.info("PREPARE " + prepareId + " success");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.alibaba.maxgraph.compiler.optimizer.QueryFlowManager in project GraphScope by alibaba.
the class MixedTraversalOpProcessor method doProcessTraversal.
private Long doProcessTraversal(Context context, Object object, Graph graph, long timeout, String queryId, Stopwatch timer) {
Pair<GraphSchema, Long> snapshotSchema;
GraphSchema schema;
Long resultNum = 0L;
if (object instanceof GraphTraversal.Admin || object instanceof DfsTraversal) {
QueryStatus queryStatus;
GraphTraversal.Admin traversal = (object instanceof GraphTraversal.Admin) ? GraphTraversal.Admin.class.cast(object) : (DfsTraversal.class.cast(object)).getTraversal();
String queryString = traversal.toString();
logger.info("Receive traversal query=>" + queryString);
if (!traversal.isLocked()) {
traversal.getStrategies().removeStrategies(ProfileStrategy.class, MxGraphStepStrategy.class, FilterRankingStrategy.class);
}
traversal.applyStrategies();
NettyVertexRpcProcessor nettyVertexRpcProcessor;
QueryFlowManager queryFlowManager;
// 保证一查看到snapshotId就开始维护query_status
synchronized (queryCallbackManager) {
snapshotSchema = schemaFetcher.getSchemaSnapshotPair();
queryStatus = queryCallbackManager.beforeExecution(snapshotSchema.getRight());
}
schema = snapshotSchema.getLeft();
LogicalPlanOptimizer planOptimizer = new LogicalPlanOptimizer(new OptimizeConfig(), this.globalPullGraphFlag, schema, snapshotSchema.getRight(), this.lambdaEnableFlag);
final int resultIterationBatchSize = (Integer) context.getRequestMessage().optionalArgs(Tokens.ARGS_BATCH_SIZE).orElse(this.resultIterationBatchSize);
nettyVertexRpcProcessor = new NettyTraverserVertexProcessor(context, resultIterationBatchSize, false);
try {
queryFlowManager = (object instanceof GraphTraversal.Admin) ? planOptimizer.build(GraphTraversal.class.cast(traversal)) : planOptimizer.build(DfsTraversal.class.cast(object));
} catch (IllegalArgumentException iae) {
if (iae.getMessage().contains("MaxGraphIoStep")) {
logger.info("do maxgraph io step");
while (traversal.hasNext()) {
logger.info("maxgraph io hasNext");
}
nettyVertexRpcProcessor.finish(ResponseStatusCode.SUCCESS);
return 0L;
}
throw iae;
}
try {
boolean isLambdaExisted = TraversalHelper.anyStepRecursively(s -> s instanceof LambdaHolder, (Traversal.Admin<?, ?>) traversal);
queryFlowManager.getQueryFlow().setFrontId(serverId);
if (this.lambdaEnableFlag && isLambdaExisted) {
final ObjectMapper mapper = GraphSONMapper.build().version(GraphSONVersion.V3_0).addCustomModule(GraphSONXModuleV3d0.build().create(false)).create().createMapper();
Bytecode bytecode = (Bytecode) context.getRequestMessage().getArgs().get(Tokens.ARGS_GREMLIN);
byte[] bytecodeByte = mapper.writeValueAsBytes(bytecode);
queryFlowManager.getQueryFlow().setLambdaExisted(isLambdaExisted).setBytecode(ByteString.copyFrom(bytecodeByte));
}
GremlinResultTransform gremlinResultTransform = new GremlinResultTransform(remoteRpcConnector, nettyVertexRpcProcessor, this.graph, queryFlowManager.getResultValueType(), vertexCacheFlag);
NettyResultProcessor nettyResultProcessor = new NettyResultProcessor(queryId, traversal.toString(), context, new ExecuteConfig().getBatchQuerySize(), resultIterationBatchSize, false);
nettyResultProcessor.setSchema(schema);
nettyResultProcessor.setResultTransform(gremlinResultTransform);
nettyResultProcessor.setLabelIndexNameList(queryFlowManager.getTreeNodeLabelManager().getUserIndexLabelList());
TimelyQuery timelyQuery = new TimelyQuery(queryFlowManager, nettyResultProcessor, this.graph);
Logging.query(this.graphName, FRONTEND, this.serverId, queryId, QueryType.EXECUTE, QueryEvent.PLAN_GENERATED, timer.elapsed(TimeUnit.NANOSECONDS), null, null, "");
timelyExecutor.execute(timelyQuery, schema, timeout, queryId);
resultNum = nettyResultProcessor.total();
} catch (JsonProcessingException e) {
e.printStackTrace();
} finally {
queryCallbackManager.afterExecution(queryStatus);
}
} else {
throw new IllegalArgumentException("Not support to process=>" + object);
}
return resultNum;
}
use of com.alibaba.maxgraph.compiler.optimizer.QueryFlowManager in project GraphScope by alibaba.
the class CompilerBaseTest method executeQuery.
protected void executeQuery(DfsTraversal traversal) {
QueryFlowManager queryFlowManager = logicalPlanOptimizer.build(traversal);
System.out.println(TextFormat.printToString(queryFlowManager.getQueryFlow().build()));
assertResultPlan(TextFormat.printToString(queryFlowManager.getQueryFlow().build()));
}
use of com.alibaba.maxgraph.compiler.optimizer.QueryFlowManager in project GraphScope by alibaba.
the class AbstractOperatorTest method executeTreeQuery.
protected void executeTreeQuery(GraphTraversal traversal) {
QueryFlowManager queryFlowManager = logicalPlanOptimizer.build(traversal);
String resultContent = TextFormat.printToString(queryFlowManager.getQueryFlow().build());
System.out.println(resultContent);
if (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);
}
}
use of com.alibaba.maxgraph.compiler.optimizer.QueryFlowManager in project GraphScope by alibaba.
the class CompilerBaseTest method executeQuery.
protected void executeQuery(GraphTraversal traversal) {
QueryFlowManager queryFlowManager = logicalPlanOptimizer.build(traversal);
System.out.println(TextFormat.printToString(queryFlowManager.getQueryFlow().build()));
assertResultPlan(TextFormat.printToString(queryFlowManager.getQueryFlow().build()));
}
Aggregations