use of com.alibaba.maxgraph.compiler.prepare.PreparedTraversal in project GraphScope by alibaba.
the class MixedOpProcessor method processGraphTraversal.
@Override
protected void processGraphTraversal(String script, Context context, Object traversal, long timeout) {
String queryId = String.valueOf(ThreadLocalRandom.current().nextLong());
Stopwatch timer = Stopwatch.createStarted();
QueryType queryType = QueryType.EXECUTE;
if (traversal instanceof PreparedTraversal) {
queryType = QueryType.PREPARE;
} else if (traversal instanceof PreparedExecuteParam) {
queryType = QueryType.QUERY;
}
Logging.query(this.graphName, com.alibaba.maxgraph.proto.RoleType.FRONTEND, this.serverId, queryId, queryType, QueryEvent.FRONT_RECEIVED, null, null, null, script);
try {
Long totalResultNum = doProcessGraphTraversal(script, context, traversal, timeout, queryId, timer);
Logging.query(this.graphName, com.alibaba.maxgraph.proto.RoleType.FRONTEND, this.serverId, queryId, QueryType.EXECUTE, QueryEvent.FRONT_FINISH, timer.elapsed(TimeUnit.NANOSECONDS), totalResultNum, true, script);
} catch (Exception e) {
Logging.query(this.graphName, com.alibaba.maxgraph.proto.RoleType.FRONTEND, this.serverId, queryId, QueryType.EXECUTE, QueryEvent.FRONT_FINISH, timer.elapsed(TimeUnit.NANOSECONDS), null, false, script);
throw new RuntimeException(e);
}
}
use of com.alibaba.maxgraph.compiler.prepare.PreparedTraversal in project GraphScope by alibaba.
the class MixedOpProcessor method doProcessGraphTraversal.
private Long doProcessGraphTraversal(String script, Context context, Object traversal, long timeout, String queryId, Stopwatch timer) throws Exception {
Long totalResultNum = 0L;
Pair<GraphSchema, Long> snapshotSchema;
GraphSchema schema;
if (traversal instanceof GraphTraversal || traversal instanceof DfsTraversal) {
final int resultIterationBatchSize = (Integer) context.getRequestMessage().optionalArgs(Tokens.ARGS_BATCH_SIZE).orElse(this.resultIterationBatchSize);
NettyVertexRpcProcessor nettyVertexRpcProcessor = new NettyVertexRpcProcessor(context, resultIterationBatchSize, false);
AbstractResultProcessor nettyResultProcessor = new NettyResultProcessor(queryId, script, context, executeConfig.getBatchQuerySize(), resultIterationBatchSize, false);
totalResultNum = processQueryTraversal(script, traversal, timeout, queryId, timer, this.remoteRpcConnector, nettyVertexRpcProcessor, nettyResultProcessor);
} else {
snapshotSchema = this.schemaFetcher.getSchemaSnapshotPair();
schema = snapshotSchema.getLeft();
if (traversal instanceof PreparedTraversal) {
throw new UnsupportedOperationException();
} else if (traversal instanceof PreparedExecuteParam) {
throw new UnsupportedOperationException();
} else if (traversal instanceof ShowProcessListQuery) {
TimelyResultProcessor nettyResultProcessor = newNettyResultProcessor(queryId, script, context, graph, schema);
timelyExecutor.showProcessList(nettyResultProcessor);
} else if (traversal instanceof CancelDataflow) {
NettyResultProcessor nettyResultProcessor = newNettyResultProcessor(queryId, script, context, graph, schema);
timelyExecutor.cancelDataflow(nettyResultProcessor, ((CancelDataflow) traversal).queryId);
} else if (traversal instanceof RecordManager) {
Object result = processRecordManager(RecordManager.class.cast(traversal));
writeResultList(context, Lists.newArrayList(result), ResponseStatusCode.SUCCESS);
} else if (traversal instanceof EstimateRequest) {
writeResultList(context, Lists.newArrayList(processEstimateManager((EstimateRequest) traversal, timeout)), ResponseStatusCode.SUCCESS);
} else if (traversal instanceof StatisticsRequest) {
CostDataStatistics costDataStatistics = CostDataStatistics.getInstance();
writeResultList(context, Lists.newArrayList(costDataStatistics.formatJson()), ResponseStatusCode.SUCCESS);
} else if (traversal instanceof ShowPlanPathListRequest) {
ShowPlanPathListRequest showPlanPathListRequest = (ShowPlanPathListRequest) traversal;
writeResultList(context, Lists.newArrayList(buildCostPathList(showPlanPathListRequest.getTraversal())), ResponseStatusCode.SUCCESS);
} else if (traversal instanceof Element) {
writeResultList(context, Lists.newArrayList((Element) traversal), ResponseStatusCode.SUCCESS);
} else if (traversal instanceof List) {
writeResultList(context, (List) traversal, ResponseStatusCode.SUCCESS);
} else if (traversal instanceof GraphSchema) {
writeResultList(context, Lists.newArrayList(((GraphSchema) traversal).formatJson()), ResponseStatusCode.SUCCESS);
} else if (traversal instanceof String) {
writeResultList(context, Lists.newArrayList(traversal), ResponseStatusCode.SUCCESS);
} else if (traversal != null && (!(traversal instanceof String) || !StringUtils.isEmpty(traversal.toString()))) {
throw new IllegalArgumentException(traversal.toString());
}
}
return totalResultNum;
}
Aggregations