Search in sources :

Example 6 with GraphEdge

use of com.alibaba.maxgraph.compiler.api.schema.GraphEdge 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)

Example 7 with GraphEdge

use of com.alibaba.maxgraph.compiler.api.schema.GraphEdge in project GraphScope by alibaba.

the class SubgraphTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    TreeNodeLabelManager treeNodeLabelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex sourceDelegateVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(sourceDelegateVertex);
    List<Integer> edgeLabelList = Lists.newArrayList();
    if (sourceDelegateVertex.getProcessorFunction().getOperatorType() == QueryFlowOuterClass.OperatorType.E) {
        Message.Value.Builder argumentBuilder = sourceDelegateVertex.getProcessorFunction().getArgumentBuilder();
        edgeLabelList.addAll(argumentBuilder.getIntValueListList());
    }
    Set<Integer> sourceVertexList = Sets.newHashSet();
    Set<Integer> targetVertexList = Sets.newHashSet();
    Message.SubgraphVertexList.Builder subgraphBuilder = Message.SubgraphVertexList.newBuilder();
    for (Integer edgeLabel : edgeLabelList) {
        GraphEdge edgeType = (GraphEdge) schema.getElement(edgeLabel);
        for (EdgeRelation relationShip : edgeType.getRelationList()) {
            sourceVertexList.add(relationShip.getSource().getLabelId());
            targetVertexList.add(relationShip.getTarget().getLabelId());
        }
    }
    if (sourceVertexList.isEmpty()) {
        schema.getVertexList().forEach(v -> {
            sourceVertexList.add(v.getLabelId());
            targetVertexList.add(v.getLabelId());
        });
    }
    subgraphBuilder.addAllSourceVertexList(sourceVertexList).addAllTargetVertexList(targetVertexList);
    ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.SUBGRAPH, Message.Value.newBuilder().setBoolFlag(this.vertexFlag).setPayload(subgraphBuilder.build().toByteString()));
    LogicalVertex graphVertex = new LogicalUnaryVertex(vertexIdManager.getId(), processorFunction, false, sourceDelegateVertex);
    logicalSubQueryPlan.addLogicalVertex(graphVertex);
    logicalSubQueryPlan.addLogicalEdge(sourceDelegateVertex, graphVertex, new LogicalEdge());
    setFinishVertex(graphVertex, treeNodeLabelManager);
    addUsedLabelAndRequirement(graphVertex, treeNodeLabelManager);
    return logicalSubQueryPlan;
}
Also used : LogicalUnaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) EdgeRelation(com.alibaba.maxgraph.compiler.api.schema.EdgeRelation) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) GraphEdge(com.alibaba.maxgraph.compiler.api.schema.GraphEdge) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 8 with GraphEdge

use of com.alibaba.maxgraph.compiler.api.schema.GraphEdge in project GraphScope by alibaba.

the class LpaVertexProgramTreeNode method createOperatorArgument.

private Message.Value.Builder createOperatorArgument() {
    Message.Value.Builder valueBuilder = Message.Value.newBuilder();
    Message.ProgramLPAArg.Builder argBuilder = Message.ProgramLPAArg.newBuilder();
    Traversal.Admin<Vertex, Edge> edgeTraversal = step.getLocalChildren().get(0);
    List<Step> steps = edgeTraversal.getSteps();
    // supports with(PageRank.edges,outE('knows'))
    VertexStep vstep = (VertexStep) steps.get(0);
    String[] labels = vstep.getEdgeLabels();
    for (String edgeLabel : labels) {
        GraphEdge edgeType = (GraphEdge) schema.getElement(edgeLabel);
        argBuilder.addEdgeLabels(edgeType.getLabelId());
    }
    if (Direction.BOTH.equals(vstep.getDirection())) {
        argBuilder.setDirection(Message.EdgeDirection.DIR_NONE);
    } else if (Direction.IN.equals(vstep.getDirection())) {
        argBuilder.setDirection(Message.EdgeDirection.DIR_IN);
    } else if (Direction.OUT.equals(vstep.getDirection())) {
        argBuilder.setDirection(Message.EdgeDirection.DIR_OUT);
    } else {
        checkArgument(false, "direction must be in/out/both for lpa");
    }
    for (int i = 1; i < steps.size(); ++i) {
        Step step = steps.get(i);
        if (step instanceof HasStep) {
            HasContainer hasContainer = (HasContainer) ((HasStep) step).getHasContainers().get(0);
            Object value = hasContainer.getPredicate().getValue();
            GraphEdge edgeType = (GraphEdge) schema.getElement(value.toString());
            argBuilder.addEdgeLabels(edgeType.getLabelId());
        }
    }
    argBuilder.setSeedLabel(SchemaUtils.getPropId(step.getLabel(), schema));
    argBuilder.setTargetLabel(SchemaUtils.getPropId(step.getProperty(), schema));
    checkArgument(step.getMaxIterations() > 0, "iteration must > 0 for LPA");
    argBuilder.setIteration(step.getMaxIterations());
    valueBuilder.setPayload(argBuilder.build().toByteString());
    return valueBuilder;
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) HasStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) HasStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep) Step(org.apache.tinkerpop.gremlin.process.traversal.Step) VertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep) LpaVertexProgramStep(com.alibaba.maxgraph.tinkerpop.steps.LpaVertexProgramStep) 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)

Example 9 with GraphEdge

use of com.alibaba.maxgraph.compiler.api.schema.GraphEdge in project GraphScope by alibaba.

the class GraphSchemaMapper method parseFromSchema.

public static GraphSchemaMapper parseFromSchema(GraphSchema schema) {
    GraphSchemaMapper schemaMapper = new GraphSchemaMapper();
    schemaMapper.version = schema.getVersion();
    schemaMapper.types = Lists.newArrayList();
    for (GraphVertex graphVertex : schema.getVertexList()) {
        schemaMapper.types.add(VertexTypeMapper.parseFromVertexType(graphVertex));
    }
    for (GraphEdge graphEdge : schema.getEdgeList()) {
        schemaMapper.types.add(EdgeTypeMapper.parseFromEdgeType(graphEdge));
    }
    return schemaMapper;
}
Also used : GraphVertex(com.alibaba.maxgraph.compiler.api.schema.GraphVertex) GraphEdge(com.alibaba.maxgraph.compiler.api.schema.GraphEdge)

Example 10 with GraphEdge

use of com.alibaba.maxgraph.compiler.api.schema.GraphEdge in project GraphScope by alibaba.

the class CostDataStatistics method getOutERatio.

/**
 * Compute outE scale ratio with start vertex label list and edge list
 *
 * @param input The given start vertex label list
 * @param edgeList The given edge label list
 * @return The result ratio
 */
public NodeStatistics getOutERatio(NodeStatistics input, Set<String> edgeList) {
    GraphSchema schema = schemaFetcher.getSchemaSnapshotPair().getLeft();
    NodeStatistics nodeStatistics = new NodeStatistics(schema);
    Map<String, Double> inputVertexCountList = input.getVertexCountList();
    for (String edgeLabel : edgeList) {
        try {
            GraphEdge edge = (GraphEdge) schema.getElement(edgeLabel);
            List<EdgeRelation> relationList = edge.getRelationList();
            if (relationList.size() > 0) {
                double avgRelationRatio = 1.0 / edge.getRelationList().size();
                relationList.stream().filter(v -> inputVertexCountList.containsKey(v.getSource().getLabel())).forEach(v -> {
                    double sourceVertexCount = inputVertexCountList.getOrDefault(v.getSource().getLabel(), INIT_VERTEX_COUNT);
                    double currEdgeCount = (this.edgeCountList.getOrDefault(edge.getLabel(), INIT_EDGE_COUNT) * avgRelationRatio / this.vertexCountList.getOrDefault(v.getSource().getLabel(), INIT_VERTEX_COUNT)) * sourceVertexCount;
                    nodeStatistics.addEdgeCount(edgeLabel, currEdgeCount);
                });
            }
        } catch (Exception ignored) {
        }
    }
    return nodeStatistics;
}
Also used : GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) SchemaFetcher(com.alibaba.maxgraph.compiler.api.schema.SchemaFetcher) EdgeVertexTreeNode(com.alibaba.maxgraph.compiler.tree.EdgeVertexTreeNode) VertexTreeNode(com.alibaba.maxgraph.compiler.tree.VertexTreeNode) Set(java.util.Set) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EdgeTreeNode(com.alibaba.maxgraph.compiler.tree.EdgeTreeNode) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) NodeType(com.alibaba.maxgraph.compiler.tree.NodeType) Sets(com.google.common.collect.Sets) GraphEdge(com.alibaba.maxgraph.compiler.api.schema.GraphEdge) Direction(org.apache.tinkerpop.gremlin.structure.Direction) List(java.util.List) Lists(com.google.common.collect.Lists) EdgeRelation(com.alibaba.maxgraph.compiler.api.schema.EdgeRelation) EdgeOtherVertexTreeNode(com.alibaba.maxgraph.compiler.tree.EdgeOtherVertexTreeNode) Map(java.util.Map) JSONObject(com.alibaba.fastjson.JSONObject) TreeNode(com.alibaba.maxgraph.compiler.tree.TreeNode) GraphElement(com.alibaba.maxgraph.compiler.api.schema.GraphElement) EdgeRelation(com.alibaba.maxgraph.compiler.api.schema.EdgeRelation) GraphEdge(com.alibaba.maxgraph.compiler.api.schema.GraphEdge) GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema)

Aggregations

GraphEdge (com.alibaba.maxgraph.compiler.api.schema.GraphEdge)17 EdgeRelation (com.alibaba.maxgraph.compiler.api.schema.EdgeRelation)6 GraphElement (com.alibaba.maxgraph.compiler.api.schema.GraphElement)6 JSONObject (com.alibaba.fastjson.JSONObject)5 GraphSchema (com.alibaba.maxgraph.compiler.api.schema.GraphSchema)5 GraphVertex (com.alibaba.maxgraph.compiler.api.schema.GraphVertex)5 Step (org.apache.tinkerpop.gremlin.process.traversal.Step)5 HasStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep)5 VertexStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep)5 HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)5 SchemaFetcher (com.alibaba.maxgraph.compiler.api.schema.SchemaFetcher)4 EdgeOtherVertexTreeNode (com.alibaba.maxgraph.compiler.tree.EdgeOtherVertexTreeNode)4 EdgeTreeNode (com.alibaba.maxgraph.compiler.tree.EdgeTreeNode)4 EdgeVertexTreeNode (com.alibaba.maxgraph.compiler.tree.EdgeVertexTreeNode)4 NodeType (com.alibaba.maxgraph.compiler.tree.NodeType)4 TreeNode (com.alibaba.maxgraph.compiler.tree.TreeNode)4 VertexTreeNode (com.alibaba.maxgraph.compiler.tree.VertexTreeNode)4 SourceTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode)4 Lists (com.google.common.collect.Lists)4 Maps (com.google.common.collect.Maps)4