use of org.apache.tinkerpop.gremlin.process.traversal.step.util.Parameters in project GraphScope by alibaba.
the class ConnectComponetsVertexProgramTreeNode method createOperatorArgument.
private Message.Value.Builder createOperatorArgument() {
Message.Value.Builder valueBuilder = Message.Value.newBuilder();
Message.ProgramCCArg.Builder ccArgumentBuilder = Message.ProgramCCArg.newBuilder();
String clusterProperty = ReflectionUtils.getFieldValue(ConnectedComponentVertexProgramStep.class, step, "clusterProperty");
PureTraversal<Vertex, Edge> edgeTraversal = ReflectionUtils.getFieldValue(ConnectedComponentVertexProgramStep.class, step, "edgeTraversal");
Parameters parameters = ReflectionUtils.getFieldValue(ConnectedComponentVertexProgramStep.class, step, "parameters");
if (parameters.contains(TIMES)) {
ArrayList<Object> times = (ArrayList<Object>) parameters.remove(TIMES);
ccArgumentBuilder.setLoopLimit((int) times.get(0));
} else {
ccArgumentBuilder.setLoopLimit(20);
}
if (clusterProperty.equals(ConnectedComponentVertexProgram.COMPONENT)) {
clusterProperty = COMPONENT;
}
ccArgumentBuilder.setPropertyCcId(SchemaUtils.getPropId(clusterProperty, schema));
List<Step> edgeTraversalSteps = edgeTraversal.getPure().getSteps();
VertexStep vstep = (VertexStep) edgeTraversalSteps.get(0);
for (String edgeLabel : vstep.getEdgeLabels()) {
GraphEdge edgeType = (GraphEdge) schema.getElement(edgeLabel);
ccArgumentBuilder.addEdgeLabels(edgeType.getLabelId());
}
if (Direction.BOTH.equals(vstep.getDirection())) {
ccArgumentBuilder.setDirection(Message.EdgeDirection.DIR_NONE);
} else if (Direction.IN.equals(vstep.getDirection())) {
ccArgumentBuilder.setDirection(Message.EdgeDirection.DIR_IN);
} else if (Direction.OUT.equals(vstep.getDirection())) {
ccArgumentBuilder.setDirection(Message.EdgeDirection.DIR_OUT);
} else {
checkArgument(false, "direction must be in/out/both for shortest path");
}
for (int i = 1; i < edgeTraversalSteps.size(); ++i) {
Step hasStep = edgeTraversalSteps.get(i);
if (hasStep instanceof HasStep) {
HasContainer hasContainer = (HasContainer) ((HasStep) hasStep).getHasContainers().get(0);
Object value = hasContainer.getPredicate().getValue();
GraphEdge edgeType = (GraphEdge) schema.getElement(value.toString());
ccArgumentBuilder.addEdgeLabels(edgeType.getLabelId());
}
}
valueBuilder.setPayload(ccArgumentBuilder.build().toByteString());
return valueBuilder;
}
Aggregations