Search in sources :

Example 36 with LogicalVertex

use of com.alibaba.maxgraph.compiler.logical.LogicalVertex in project GraphScope by alibaba.

the class RepeatTreeNode method unionVertexList.

private LogicalVertex unionVertexList(VertexIdManager vertexIdManager, LogicalSubQueryPlan repeatBodyPlan, List<LogicalVertex> leaveVertexList) {
    LogicalVertex unionVertex = leaveVertexList.get(0);
    for (int i = 1; i < leaveVertexList.size(); i++) {
        LogicalVertex currentUnionVertex = new LogicalBinaryVertex(vertexIdManager.getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.UNION), false, unionVertex, leaveVertexList.get(i));
        repeatBodyPlan.addLogicalVertex(currentUnionVertex);
        repeatBodyPlan.addLogicalEdge(unionVertex, currentUnionVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
        repeatBodyPlan.addLogicalEdge(leaveVertexList.get(i), currentUnionVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
        unionVertex = currentUnionVertex;
    }
    return unionVertex;
}
Also used : LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex)

Example 37 with LogicalVertex

use of com.alibaba.maxgraph.compiler.logical.LogicalVertex in project GraphScope by alibaba.

the class RepeatTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex delegateSourceVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(delegateSourceVertex);
    List<LogicalVertex> outputVertexList = Lists.newArrayList();
    LogicalVertex inputVertex = delegateSourceVertex;
    ProcessorRepeatFunction processorRepeatFunction = new ProcessorRepeatFunction();
    if (null != untilFirstTreeNode) {
        Pair<LogicalVertex, Pair<LogicalVertex, LogicalSubQueryPlan>> untilTable = buildUntilQueryPlan(untilTreeNode, delegateSourceVertex, labelManager, contextManager, vertexIdManager);
        outputVertexList.add(untilTable.getLeft());
        inputVertex = untilTable.getRight().getLeft();
        logicalSubQueryPlan.mergeLogicalQueryPlan(untilTable.getRight().getRight());
    }
    if (null != emitFirstTreeNode) {
        LogicalVertex emitVertex;
        if (emitFirstTreeNode instanceof SourceDelegateNode) {
            emitVertex = inputVertex;
        } else {
            emitVertex = buildFilterResultPlan(contextManager, vertexIdManager, labelManager, logicalSubQueryPlan, inputVertex, emitFirstTreeNode);
        }
        outputVertexList.add(emitVertex);
        processorRepeatFunction.enableEmitFlag();
    }
    checkArgument(null != repeatBodyTreeNode, "repeat body tree node can't be null");
    processorRepeatFunction.setMaxLoopTimes(maxLoopTimes);
    LogicalVertex repeatVertex = new LogicalUnaryVertex(vertexIdManager.getId(), processorRepeatFunction, false, inputVertex);
    logicalSubQueryPlan.addLogicalVertex(repeatVertex);
    logicalSubQueryPlan.addLogicalEdge(inputVertex, repeatVertex, new LogicalEdge());
    List<LogicalVertex> leaveVertexList = Lists.newArrayList();
    LogicalSubQueryPlan repeatBodyPlan = new LogicalSubQueryPlan(contextManager);
    LogicalSourceDelegateVertex repeatSourceVertex = new LogicalSourceDelegateVertex(inputVertex);
    repeatBodyPlan.addLogicalVertex(repeatSourceVertex);
    repeatBodyPlan.mergeLogicalQueryPlan(TreeNodeUtils.buildQueryPlanWithSource(repeatBodyTreeNode, labelManager, contextManager, vertexIdManager, repeatSourceVertex));
    LogicalVertex feedbackVertex = repeatBodyPlan.getOutputVertex();
    if (null != untilTreeNode) {
        Pair<LogicalVertex, Pair<LogicalVertex, LogicalSubQueryPlan>> untilTable = buildUntilQueryPlan(untilTreeNode, feedbackVertex, labelManager, contextManager, vertexIdManager);
        feedbackVertex = untilTable.getRight().getLeft();
        LogicalVertex untilVertex = untilTable.getLeft();
        untilVertex.getAfterRequirementList().add(QueryFlowOuterClass.RequirementValue.newBuilder().setReqType(QueryFlowOuterClass.RequirementType.KEY_DEL));
        leaveVertexList.add(untilVertex);
        repeatBodyPlan.mergeLogicalQueryPlan(untilTable.getRight().getRight());
    }
    if (null != emitTreeNode) {
        LogicalVertex emitVertex;
        if (emitTreeNode instanceof SourceDelegateNode) {
            emitVertex = feedbackVertex;
        } else {
            emitVertex = buildFilterResultPlan(contextManager, vertexIdManager, labelManager, repeatBodyPlan, feedbackVertex, emitTreeNode);
        }
        if (null != dfsEmitTreeNode) {
            repeatBodyPlan.mergeLogicalQueryPlan(TreeNodeUtils.buildQueryPlanWithSource(dfsEmitTreeNode, labelManager, contextManager, vertexIdManager, emitVertex));
            emitVertex = repeatBodyPlan.getOutputVertex();
        }
        leaveVertexList.add(emitVertex);
        processorRepeatFunction.enableEmitFlag();
    }
    if (null != dfsFeedTreeNode) {
        dfsFeedTreeNode.setRepeatSourceVertex(repeatBodyPlan.getTargetVertex(repeatSourceVertex));
        LogicalSubQueryPlan dfsQueryPlan = TreeNodeUtils.buildQueryPlanWithSource(dfsFeedTreeNode, labelManager, contextManager, vertexIdManager, feedbackVertex);
        feedbackVertex = dfsQueryPlan.getOutputVertex();
        repeatBodyPlan.mergeLogicalQueryPlan(dfsQueryPlan);
    }
    processorRepeatFunction.setEnterVertex(repeatBodyPlan.getTargetVertex(repeatSourceVertex));
    processorRepeatFunction.setFeedbackVertex(feedbackVertex);
    processorRepeatFunction.setRepeatPlan(repeatBodyPlan);
    if (!leaveVertexList.isEmpty()) {
        if (leaveVertexList.size() == 1) {
            processorRepeatFunction.setLeaveVertex(leaveVertexList.get(0));
        } else {
            LogicalVertex unionLeaveVertex = unionVertexList(vertexIdManager, repeatBodyPlan, leaveVertexList);
            processorRepeatFunction.setLeaveVertex(unionLeaveVertex);
        }
    }
    LogicalVertex outputVertex = repeatVertex;
    if (!outputVertexList.isEmpty()) {
        List<LogicalVertex> outputUnionVertexList = Lists.newArrayList(outputVertexList);
        outputUnionVertexList.add(repeatVertex);
        outputVertex = unionVertexList(vertexIdManager, logicalSubQueryPlan, outputUnionVertexList);
    }
    addUsedLabelAndRequirement(outputVertex, labelManager);
    setFinishVertex(outputVertex, labelManager);
    return logicalSubQueryPlan;
}
Also used : LogicalUnaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) LogicalSourceDelegateVertex(com.alibaba.maxgraph.compiler.logical.LogicalSourceDelegateVertex) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) ProcessorRepeatFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorRepeatFunction) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan) Pair(org.apache.commons.lang3.tuple.Pair)

Example 38 with LogicalVertex

use of com.alibaba.maxgraph.compiler.logical.LogicalVertex in project GraphScope by alibaba.

the class RepeatTreeNode method buildUntilQueryPlan.

/**
 * Build until query plan with given tree node
 *
 * @param untilTreeNode The given until tree node
 * @param inputVertex   The input vertex of until
 * @return The table of result. The first one is until vertex, the second one is feedback vertex and the third one is result plan
 */
private Pair<LogicalVertex, Pair<LogicalVertex, LogicalSubQueryPlan>> buildUntilQueryPlan(TreeNode untilTreeNode, LogicalVertex inputVertex, TreeNodeLabelManager treeNodeLabelManager, ContextManager contextManager, VertexIdManager vertexIdManager) {
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex untilVertex = null, feedbackVertex = null;
    if (untilTreeNode instanceof NotTreeNode) {
        NotTreeNode notTreeNode = NotTreeNode.class.cast(untilTreeNode);
        TreeNode notFilterNode = notTreeNode.getNotTreeNode();
        TreeNode currentUntilNode = TreeNodeUtils.buildSingleOutputNode(notFilterNode, schema);
        LogicalSubQueryPlan untilPlan = TreeNodeUtils.buildSubQueryPlanWithKey(currentUntilNode, inputVertex, treeNodeLabelManager, contextManager, vertexIdManager);
        LogicalVertex enterKeyVertex = TreeNodeUtils.getSourceTreeNode(currentUntilNode).getOutputVertex();
        logicalSubQueryPlan.mergeLogicalQueryPlan(untilPlan);
        LogicalVertex feedbackKeyVertex = untilPlan.getOutputVertex();
        feedbackVertex = new LogicalUnaryVertex(vertexIdManager.getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.KEY_MESSAGE), true, feedbackKeyVertex);
        logicalSubQueryPlan.addLogicalVertex(feedbackVertex);
        logicalSubQueryPlan.addLogicalEdge(feedbackKeyVertex, feedbackVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
        untilVertex = new LogicalBinaryVertex(vertexIdManager.getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_DIRECT_FILTER_NEGATE), false, enterKeyVertex, feedbackKeyVertex);
        logicalSubQueryPlan.addLogicalVertex(untilVertex);
        logicalSubQueryPlan.addLogicalEdge(enterKeyVertex, untilVertex, new LogicalEdge());
        logicalSubQueryPlan.addLogicalEdge(feedbackKeyVertex, untilVertex, new LogicalEdge());
    } else {
        TreeNode currentUntilNode = TreeNodeUtils.buildSingleOutputNode(untilTreeNode, schema);
        LogicalSubQueryPlan untilPlan = TreeNodeUtils.buildSubQueryPlanWithKey(currentUntilNode, inputVertex, treeNodeLabelManager, contextManager, vertexIdManager);
        LogicalVertex enterKeyVertex = TreeNodeUtils.getSourceTreeNode(currentUntilNode).getOutputVertex();
        LogicalVertex untilOutputVertex = untilPlan.getOutputVertex();
        logicalSubQueryPlan.mergeLogicalQueryPlan(untilPlan);
        feedbackVertex = new LogicalBinaryVertex(vertexIdManager.getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_DIRECT_FILTER_NEGATE), false, enterKeyVertex, untilOutputVertex);
        logicalSubQueryPlan.addLogicalVertex(feedbackVertex);
        logicalSubQueryPlan.addLogicalEdge(enterKeyVertex, feedbackVertex, new LogicalEdge());
        logicalSubQueryPlan.addLogicalEdge(untilOutputVertex, feedbackVertex, new LogicalEdge());
        untilVertex = new LogicalUnaryVertex(vertexIdManager.getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.KEY_MESSAGE), true, untilOutputVertex);
        logicalSubQueryPlan.addLogicalVertex(untilVertex);
        logicalSubQueryPlan.addLogicalEdge(untilOutputVertex, untilVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
    }
    return Pair.of(untilVertex, Pair.of(feedbackVertex, logicalSubQueryPlan));
}
Also used : LogicalUnaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 39 with LogicalVertex

use of com.alibaba.maxgraph.compiler.logical.LogicalVertex in project GraphScope by alibaba.

the class SelectOneTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    Map<String, Integer> labelIndexList = labelManager.getLabelIndexList();
    ProcessorFunction selectOneFunction = TreeNodeUtils.createSelectOneFunction(selectLabel, pop, labelIndexList);
    LogicalSubQueryPlan logicalSubQueryPlan = parseSingleUnaryVertex(vertexIdManager, labelManager, selectOneFunction, contextManager, LogicalEdge.shuffleByKey(0), null == traversalTreeNode);
    if (null != traversalTreeNode && !contextManager.getCostModelManager().processFieldValue(selectLabel)) {
        LogicalSubQueryPlan traversalValuePlan = TreeNodeUtils.buildSubQueryPlan(traversalTreeNode, logicalSubQueryPlan.getOutputVertex(), contextManager);
        logicalSubQueryPlan.mergeLogicalQueryPlan(traversalValuePlan);
        LogicalVertex outputVertex = logicalSubQueryPlan.getOutputVertex();
        addUsedLabelAndRequirement(outputVertex, labelManager);
        setFinishVertex(outputVertex, labelManager);
    }
    return logicalSubQueryPlan;
}
Also used : ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 40 with LogicalVertex

use of com.alibaba.maxgraph.compiler.logical.LogicalVertex in project GraphScope by alibaba.

the class SelectTreeNode method parseJoinQueryPlan.

private LogicalSubQueryPlan parseJoinQueryPlan(ContextManager contextManager, VertexIdManager vertexIdManager, TreeNodeLabelManager labelManager, Map<String, Integer> labelIndexList) {
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex delegateSourceVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(delegateSourceVertex);
    Set<String> selectKeySet = Sets.newHashSet();
    List<Integer> keyIdList = Lists.newArrayList();
    List<Integer> valueIdList = Lists.newArrayList();
    for (int i = 0; i < selectKeyList.size(); i++) {
        String selectKey = selectKeyList.get(i);
        if (selectKeySet.contains(selectKey)) {
            continue;
        }
        selectKeySet.add(selectKey);
        TreeNode traversalTreeNode = traversalTreeNodeList.get(i % traversalTreeNodeList.size());
        int labelIndex = labelIndexList.get(selectKey);
        keyIdList.add(labelIndex);
        valueIdList.add(labelIndexList.get(selectKey));
        if (!(traversalTreeNode instanceof SourceDelegateNode)) {
            TreeNode currentTraversalNode = TreeNodeUtils.buildSingleOutputNode(traversalTreeNode, schema);
            LogicalVertex outputVertex = logicalSubQueryPlan.getOutputVertex();
            LogicalSubQueryPlan traversalPlan = TreeNodeUtils.buildSubQueryPlan(currentTraversalNode, outputVertex, contextManager);
            List<LogicalVertex> resultVertexList = traversalPlan.getLogicalVertexList();
            if (resultVertexList.size() == 2) {
                LogicalVertex fieldValueVertex = resultVertexList.get(1);
                ProcessorLabelValueFunction labelValueFunction = new ProcessorLabelValueFunction(labelIndex, fieldValueVertex);
                labelValueFunction.setRequireLabelFlag(true);
                LogicalVertex labelValueVertex = new LogicalUnaryVertex(vertexIdManager.getId(), labelValueFunction, outputVertex);
                logicalSubQueryPlan.addLogicalVertex(labelValueVertex);
                logicalSubQueryPlan.addLogicalEdge(outputVertex, labelValueVertex, LogicalEdge.shuffleByKey(labelIndex));
            } else {
                LogicalVertex fieldValueVertex = traversalPlan.getOutputVertex();
                fieldValueVertex.getAfterRequirementList().add(QueryFlowOuterClass.RequirementValue.newBuilder().setReqType(QueryFlowOuterClass.RequirementType.LABEL_START).setReqArgument(Message.Value.newBuilder().addIntValueList(labelIndex)));
                logicalSubQueryPlan.mergeLogicalQueryPlan(traversalPlan);
                LogicalVertex outputKeyVertex = new LogicalUnaryVertex(vertexIdManager.getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.KEY_MESSAGE), fieldValueVertex);
                logicalSubQueryPlan.addLogicalVertex(outputKeyVertex);
                logicalSubQueryPlan.addLogicalEdge(fieldValueVertex, outputKeyVertex, LogicalEdge.forwardEdge());
            }
        }
    }
    LogicalVertex selectInputVertex = logicalSubQueryPlan.getOutputVertex();
    Message.Value.Builder argumentBuilder = Message.Value.newBuilder().setBoolValue(true).setIntValue(pop == null ? Message.PopType.POP_EMPTY.getNumber() : Message.PopType.valueOf(StringUtils.upperCase(pop.name())).getNumber()).addAllIntValueList(valueIdList).addAllStrValueList(keyIdList.stream().map(labelManager::getLabelName).collect(Collectors.toList()));
    ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.SELECT, argumentBuilder);
    processorFunction.getUsedLabelList().addAll(valueIdList);
    LogicalVertex selectVertex = new LogicalUnaryVertex(vertexIdManager.getId(), processorFunction, false, selectInputVertex);
    logicalSubQueryPlan.addLogicalVertex(selectVertex);
    logicalSubQueryPlan.addLogicalEdge(selectInputVertex, selectVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
    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) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) ProcessorLabelValueFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorLabelValueFunction) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Aggregations

LogicalVertex (com.alibaba.maxgraph.compiler.logical.LogicalVertex)53 LogicalSubQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)41 ProcessorFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction)38 LogicalEdge (com.alibaba.maxgraph.compiler.logical.LogicalEdge)34 LogicalUnaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex)29 LogicalBinaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex)20 VertexIdManager (com.alibaba.maxgraph.compiler.logical.VertexIdManager)18 QueryFlowOuterClass (com.alibaba.maxgraph.QueryFlowOuterClass)13 SourceDelegateNode (com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)11 LogicalQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan)9 SourceTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode)9 Message (com.alibaba.maxgraph.Message)6 LogicalSourceDelegateVertex (com.alibaba.maxgraph.compiler.logical.LogicalSourceDelegateVertex)4 CountGlobalTreeNode (com.alibaba.maxgraph.compiler.tree.CountGlobalTreeNode)4 FoldTreeNode (com.alibaba.maxgraph.compiler.tree.FoldTreeNode)4 HasTreeNode (com.alibaba.maxgraph.compiler.tree.HasTreeNode)4 MaxTreeNode (com.alibaba.maxgraph.compiler.tree.MaxTreeNode)4 MinTreeNode (com.alibaba.maxgraph.compiler.tree.MinTreeNode)4 PropertyMapTreeNode (com.alibaba.maxgraph.compiler.tree.PropertyMapTreeNode)4 RangeGlobalTreeNode (com.alibaba.maxgraph.compiler.tree.RangeGlobalTreeNode)4