Search in sources :

Example 1 with Parameters

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;
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Parameters(org.apache.tinkerpop.gremlin.process.traversal.step.util.Parameters) HasStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep) ArrayList(java.util.ArrayList) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) HasStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep) ConnectedComponentVertexProgramStep(org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.ConnectedComponentVertexProgramStep) Step(org.apache.tinkerpop.gremlin.process.traversal.Step) VertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep) VertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep) GraphEdge(com.alibaba.maxgraph.compiler.api.schema.GraphEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) GraphEdge(com.alibaba.maxgraph.compiler.api.schema.GraphEdge)

Aggregations

GraphEdge (com.alibaba.maxgraph.compiler.api.schema.GraphEdge)1 ArrayList (java.util.ArrayList)1 ConnectedComponentVertexProgramStep (org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.ConnectedComponentVertexProgramStep)1 Step (org.apache.tinkerpop.gremlin.process.traversal.Step)1 HasStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep)1 VertexStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep)1 HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)1 Parameters (org.apache.tinkerpop.gremlin.process.traversal.step.util.Parameters)1 Edge (org.apache.tinkerpop.gremlin.structure.Edge)1 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)1