Search in sources :

Example 16 with LogicalBinaryVertex

use of com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex 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 17 with LogicalBinaryVertex

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

the class BranchTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex sourceVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(sourceVertex);
    int optionLabelId = 0;
    boolean optionJoinFlag = true;
    UnaryTreeNode branchUnaryNode = UnaryTreeNode.class.cast(branchTreeNode);
    if (branchUnaryNode.getInputNode() instanceof SourceTreeNode) {
        if (branchUnaryNode instanceof PropertyNode) {
            String prop = PropertyNode.class.cast(branchUnaryNode).getPropKeyList().iterator().next();
            optionLabelId = SchemaUtils.getPropId(prop, schema);
            optionJoinFlag = false;
        } else if (branchUnaryNode instanceof SelectOneTreeNode) {
            optionLabelId = contextManager.getTreeNodeLabelManager().getLabelIndex(SelectOneTreeNode.class.cast(branchUnaryNode).getSelectLabel());
            optionJoinFlag = false;
        } else if (branchUnaryNode instanceof TokenTreeNode) {
            optionLabelId = contextManager.getTreeNodeLabelManager().getLabelIndex(TokenTreeNode.class.cast(branchUnaryNode).getToken().getAccessor());
            optionJoinFlag = false;
        }
    }
    if (optionJoinFlag) {
        // join the value stream to get value and set it to label
        if (branchUnaryNode instanceof JoinZeroNode) {
            ((JoinZeroNode) branchUnaryNode).disableJoinZero();
        }
        TreeNode currentBranchTreeNode = TreeNodeUtils.buildSingleOutputNode(branchTreeNode, schema);
        LogicalQueryPlan branchValuePlan = TreeNodeUtils.buildSubQueryPlan(currentBranchTreeNode, sourceVertex, contextManager);
        TreeNode branchSourceNode = TreeNodeUtils.getSourceTreeNode(currentBranchTreeNode);
        sourceVertex = branchSourceNode.getOutputVertex();
        LogicalVertex branchValueVertex = branchValuePlan.getOutputVertex();
        logicalSubQueryPlan.mergeLogicalQueryPlan(branchValuePlan);
        String valueLabel = contextManager.getTreeNodeLabelManager().createSysLabelStart("val");
        optionLabelId = contextManager.getTreeNodeLabelManager().getLabelIndex(valueLabel);
        QueryFlowOuterClass.OperatorType joinOperatorType = CompilerUtils.parseJoinOperatorType(branchTreeNode);
        ProcessorFunction joinFunction = new ProcessorFunction(joinOperatorType, Message.Value.newBuilder().setIntValue(optionLabelId));
        LogicalBinaryVertex joinVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), joinFunction, false, sourceVertex, branchValueVertex);
        logicalSubQueryPlan.addLogicalVertex(joinVertex);
        logicalSubQueryPlan.addLogicalEdge(sourceVertex, joinVertex, new LogicalEdge());
        logicalSubQueryPlan.addLogicalEdge(branchValueVertex, joinVertex, new LogicalEdge());
    }
    LogicalVertex outputVertex = logicalSubQueryPlan.getOutputVertex();
    if (optionLabelId > 0) {
        ProcessorFunction fillFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.PROP_FILL, Message.Value.newBuilder().addIntValueList(optionLabelId));
        LogicalVertex fillPropVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), fillFunction, true, outputVertex);
        logicalSubQueryPlan.addLogicalVertex(fillPropVertex);
        logicalSubQueryPlan.addLogicalEdge(outputVertex, fillPropVertex, outputVertex.isPropLocalFlag() ? new LogicalEdge(EdgeShuffleType.FORWARD) : new LogicalEdge());
        outputVertex = fillPropVertex;
    }
    Map<Object, Message.LogicalCompare> pickCompareList = Maps.newHashMap();
    List<Message.LogicalCompare> noneCompareList = Lists.newArrayList();
    for (Map.Entry<Object, List<TreeNode>> pickEntry : optionPickList.entrySet()) {
        Object pick = pickEntry.getKey();
        Object pickValue = pick;
        if (optionLabelId == TreeConstants.LABEL_INDEX) {
            final String pickString = pick.toString();
            pickValue = schema.getElement(pickString).getLabelId();
        } else if (optionLabelId == TreeConstants.ID_INDEX) {
            pickValue = Long.parseLong(pick.toString());
        }
        Message.VariantType variantType = CompilerUtils.parseVariantType(pickValue.getClass(), pickValue);
        Message.Value.Builder valueBuilder = Message.Value.newBuilder().setValueType(variantType);
        switch(variantType) {
            case VT_INT:
                {
                    if (pickValue instanceof Integer) {
                        valueBuilder.setIntValue((Integer) pickValue);
                    } else {
                        Class<?> pickTokenKeyClazz = BranchStep.class.getDeclaredClasses()[0];
                        Number number = ReflectionUtils.getFieldValue(pickTokenKeyClazz, pickValue, "number");
                        valueBuilder.setIntValue((int) number);
                    }
                    break;
                }
            case VT_LONG:
                {
                    if (pickValue instanceof Long) {
                        valueBuilder.setLongValue((Long) pickValue);
                    } else {
                        Class<?> pickTokenKeyClazz = BranchStep.class.getDeclaredClasses()[0];
                        Number number = ReflectionUtils.getFieldValue(pickTokenKeyClazz, pickValue, "number");
                        valueBuilder.setLongValue((long) number);
                    }
                    break;
                }
            case VT_STRING:
                {
                    valueBuilder.setStrValue((String) pickValue).build();
                    break;
                }
            default:
                {
                    throw new UnsupportedOperationException(pickValue + " for branch option operator");
                }
        }
        Message.Value value = valueBuilder.build();
        pickCompareList.put(pick, Message.LogicalCompare.newBuilder().setPropId(optionLabelId).setCompare(Message.CompareType.EQ).setValue(value).setType(variantType).build());
        noneCompareList.add(Message.LogicalCompare.newBuilder().setPropId(optionLabelId).setCompare(Message.CompareType.NEQ).setValue(value).setType(variantType).build());
    }
    List<LogicalVertex> unionVertexList = Lists.newArrayList();
    for (Map.Entry<Object, List<TreeNode>> optionEntry : this.optionPickList.entrySet()) {
        List<TreeNode> optionTreeNodeList = optionEntry.getValue();
        Message.LogicalCompare logicalCompare = checkNotNull(pickCompareList.get(optionEntry.getKey()));
        ProcessorFilterFunction filterFunction = new ProcessorFilterFunction(QueryFlowOuterClass.OperatorType.FILTER, createArgumentBuilder().setBoolValue(true));
        filterFunction.getLogicalCompareList().add(logicalCompare);
        LogicalVertex filterVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), filterFunction, outputVertex);
        logicalSubQueryPlan.addLogicalVertex(filterVertex);
        logicalSubQueryPlan.addLogicalEdge(outputVertex, filterVertex, LogicalEdge.forwardEdge());
        for (TreeNode treeNode : optionTreeNodeList) {
            LogicalQueryPlan subQueryPlan = TreeNodeUtils.buildQueryPlanWithSource(treeNode, contextManager.getTreeNodeLabelManager(), contextManager, contextManager.getVertexIdManager(), filterVertex);
            unionVertexList.add(subQueryPlan.getOutputVertex());
            logicalSubQueryPlan.mergeLogicalQueryPlan(subQueryPlan);
        }
    }
    if (null != noneTreeNode) {
        ProcessorFilterFunction filterFunction = new ProcessorFilterFunction(QueryFlowOuterClass.OperatorType.FILTER, createArgumentBuilder().setBoolValue(true));
        filterFunction.getLogicalCompareList().addAll(noneCompareList);
        LogicalVertex filterVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), filterFunction, outputVertex);
        logicalSubQueryPlan.addLogicalVertex(filterVertex);
        logicalSubQueryPlan.addLogicalEdge(outputVertex, filterVertex, LogicalEdge.forwardEdge());
        LogicalQueryPlan subQueryPlan = TreeNodeUtils.buildQueryPlanWithSource(noneTreeNode, contextManager.getTreeNodeLabelManager(), contextManager, contextManager.getVertexIdManager(), filterVertex);
        unionVertexList.add(subQueryPlan.getOutputVertex());
        logicalSubQueryPlan.mergeLogicalQueryPlan(subQueryPlan);
    }
    if (null != anyTreeNode) {
        LogicalQueryPlan subQueryPlan = TreeNodeUtils.buildQueryPlanWithSource(anyTreeNode, contextManager.getTreeNodeLabelManager(), contextManager, contextManager.getVertexIdManager(), outputVertex);
        unionVertexList.add(subQueryPlan.getOutputVertex());
        logicalSubQueryPlan.mergeLogicalQueryPlan(subQueryPlan);
    }
    LogicalVertex currentUnionVertex = unionVertexList.remove(0);
    for (LogicalVertex logicalVertex : unionVertexList) {
        LogicalVertex unionVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.UNION), false, currentUnionVertex, logicalVertex);
        logicalSubQueryPlan.addLogicalVertex(unionVertex);
        logicalSubQueryPlan.addLogicalEdge(currentUnionVertex, unionVertex, LogicalEdge.forwardEdge());
        logicalSubQueryPlan.addLogicalEdge(logicalVertex, unionVertex, LogicalEdge.forwardEdge());
        currentUnionVertex = unionVertex;
    }
    addUsedLabelAndRequirement(currentUnionVertex, contextManager.getTreeNodeLabelManager());
    setFinishVertex(currentUnionVertex, contextManager.getTreeNodeLabelManager());
    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) Message(com.alibaba.maxgraph.Message) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) ProcessorFilterFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFilterFunction) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) PropertyNode(com.alibaba.maxgraph.compiler.tree.addition.PropertyNode) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) LogicalQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan) List(java.util.List) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan) JoinZeroNode(com.alibaba.maxgraph.compiler.tree.addition.JoinZeroNode) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) Map(java.util.Map)

Example 18 with LogicalBinaryVertex

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

the class GroupCountTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex sourceVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(sourceVertex);
    LogicalVertex outputVertex;
    if (null == keyTreeNode || keyTreeNode instanceof SourceDelegateNode) {
        ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.GROUP_COUNT);
        outputVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), processorFunction, false, sourceVertex);
        logicalSubQueryPlan.addLogicalVertex(outputVertex);
        logicalSubQueryPlan.addLogicalEdge(sourceVertex, outputVertex, new LogicalEdge());
    } else {
        TreeNode currentKeyNode = TreeNodeUtils.buildSingleOutputNode(keyTreeNode, schema);
        if (currentKeyNode instanceof JoinZeroNode) {
            ((JoinZeroNode) currentKeyNode).disableJoinZero();
        }
        LogicalSubQueryPlan keyValuePlan = TreeNodeUtils.buildSubQueryPlan(currentKeyNode, sourceVertex, contextManager);
        LogicalVertex groupValueVertex = keyValuePlan.getOutputVertex();
        LogicalVertex enterKeyVertex = TreeNodeUtils.getSourceTreeNode(currentKeyNode).getOutputVertex();
        logicalSubQueryPlan.mergeLogicalQueryPlan(keyValuePlan);
        if (TreeNodeUtils.checkJoinSourceFlag(currentKeyNode)) {
            String valueLabel = contextManager.getTreeNodeLabelManager().createSysLabelStart("val");
            getUsedLabelList().add(valueLabel);
            int valueLabelId = contextManager.getTreeNodeLabelManager().getLabelIndex(valueLabel);
            LogicalBinaryVertex logicalBinaryVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(CompilerUtils.parseJoinOperatorType(currentKeyNode), Message.Value.newBuilder().setIntValue(valueLabelId)), false, enterKeyVertex, groupValueVertex);
            logicalSubQueryPlan.addLogicalVertex(logicalBinaryVertex);
            logicalSubQueryPlan.addLogicalEdge(enterKeyVertex, logicalBinaryVertex, new LogicalEdge());
            logicalSubQueryPlan.addLogicalEdge(groupValueVertex, logicalBinaryVertex, new LogicalEdge());
            ProcessorFunction selectValueFunction = TreeNodeUtils.createSelectOneFunction(valueLabel, Pop.first, contextManager.getTreeNodeLabelManager().getLabelIndexList());
            LogicalVertex selectLabelVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), selectValueFunction, false, logicalBinaryVertex);
            logicalSubQueryPlan.addLogicalVertex(selectLabelVertex);
            logicalSubQueryPlan.addLogicalEdge(logicalBinaryVertex, selectLabelVertex, LogicalEdge.forwardEdge());
        }
        groupValueVertex = logicalSubQueryPlan.getOutputVertex();
        ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.GROUP_COUNT, Message.Value.newBuilder());
        outputVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), processorFunction, false, groupValueVertex);
        logicalSubQueryPlan.addLogicalVertex(outputVertex);
        logicalSubQueryPlan.addLogicalEdge(groupValueVertex, outputVertex, new LogicalEdge());
    }
    ProcessorFunction foldMapFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.FOLDMAP);
    LogicalVertex foldMapVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), foldMapFunction, false, outputVertex);
    logicalSubQueryPlan.addLogicalVertex(foldMapVertex);
    logicalSubQueryPlan.addLogicalEdge(outputVertex, foldMapVertex, new LogicalEdge());
    addUsedLabelAndRequirement(foldMapVertex, contextManager.getTreeNodeLabelManager());
    setFinishVertex(foldMapVertex, contextManager.getTreeNodeLabelManager());
    return 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) JoinZeroNode(com.alibaba.maxgraph.compiler.tree.addition.JoinZeroNode) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 19 with LogicalBinaryVertex

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

the class TreeNodeUtils method buildSubQueryWithLabel.

/**
 * Build sub query plan, and save the result of sub plan to given label id
 *
 * @param treeNode The given tree node
 * @param sourceVertex The given source vertex
 * @param contextManager The given context manager
 * @return The result query plan and label id
 */
public static Pair<LogicalQueryPlan, Integer> buildSubQueryWithLabel(TreeNode treeNode, LogicalVertex sourceVertex, ContextManager contextManager) {
    boolean joinFlag = checkJoinSourceFlag(treeNode);
    List<TreeNode> treeNodeList = buildTreeNodeListFromLeaf(treeNode);
    LogicalQueryPlan queryPlan = new LogicalQueryPlan(contextManager);
    LogicalVertex originalVertex = null;
    LogicalVertex currentSourceVertex = sourceVertex;
    for (TreeNode currentNode : treeNodeList) {
        if (currentNode instanceof SourceDelegateNode) {
            queryPlan.addLogicalVertex(sourceVertex);
            if (joinFlag) {
                LogicalVertex enterKeyVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.ENTER_KEY, Message.Value.newBuilder().setPayload(QueryFlowOuterClass.EnterKeyArgumentProto.newBuilder().setEnterKeyType(QueryFlowOuterClass.EnterKeyTypeProto.KEY_SELF).setUniqFlag(true).build().toByteString())), false, currentSourceVertex);
                currentNode.setFinishVertex(enterKeyVertex, contextManager.getTreeNodeLabelManager());
                queryPlan.addLogicalVertex(enterKeyVertex);
                queryPlan.addLogicalEdge(sourceVertex, enterKeyVertex, new LogicalEdge());
                currentSourceVertex = enterKeyVertex;
                originalVertex = enterKeyVertex;
            } else {
                currentNode.setFinishVertex(sourceVertex, contextManager.getTreeNodeLabelManager());
                originalVertex = sourceVertex;
            }
        } else {
            queryPlan.mergeLogicalQueryPlan(currentNode.buildLogicalQueryPlan(contextManager));
        }
    }
    checkNotNull(originalVertex, "original vertex can't be null");
    LogicalVertex valueVertex = queryPlan.getOutputVertex();
    String valueLabel = contextManager.getTreeNodeLabelManager().createSysLabelStart("val");
    int valueLabelId = contextManager.getTreeNodeLabelManager().getLabelIndex(valueLabel);
    if (joinFlag) {
        LogicalVertex joinVertex;
        if (treeNode instanceof CountGlobalTreeNode || treeNode instanceof SumTreeNode) {
            joinVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_COUNT_LABEL, Message.Value.newBuilder().setIntValue(valueLabelId)), false, originalVertex, valueVertex);
        } else {
            joinVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_LABEL, Message.Value.newBuilder().setIntValue(valueLabelId)), false, originalVertex, valueVertex);
        }
        queryPlan.addLogicalVertex(joinVertex);
        queryPlan.addLogicalEdge(originalVertex, joinVertex, LogicalEdge.shuffleByKey(0));
        queryPlan.addLogicalEdge(valueVertex, joinVertex, LogicalEdge.forwardEdge());
    } else {
        LogicalVertex originalOutputVertex = queryPlan.getTargetVertex(originalVertex);
        String originalLabel = contextManager.getTreeNodeLabelManager().createBeforeSysLabelStart(originalOutputVertex, "original");
        ProcessorFunction selectFunction = createSelectOneFunction(originalLabel, Pop.first, contextManager.getTreeNodeLabelManager().getLabelIndexList());
        LogicalVertex selectVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), selectFunction, valueVertex);
        selectVertex.getBeforeRequirementList().add(QueryFlowOuterClass.RequirementValue.newBuilder().setReqType(QueryFlowOuterClass.RequirementType.LABEL_START).setReqArgument(Message.Value.newBuilder().addIntValueList(valueLabelId)));
        queryPlan.addLogicalVertex(selectVertex);
        queryPlan.addLogicalEdge(valueVertex, selectVertex, LogicalEdge.forwardEdge());
    }
    return Pair.of(queryPlan, valueLabelId);
}
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) CountGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.CountGlobalTreeNode) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) VertexTreeNode(com.alibaba.maxgraph.compiler.tree.VertexTreeNode) MaxTreeNode(com.alibaba.maxgraph.compiler.tree.MaxTreeNode) RangeGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.RangeGlobalTreeNode) FoldTreeNode(com.alibaba.maxgraph.compiler.tree.FoldTreeNode) TreeNode(com.alibaba.maxgraph.compiler.tree.TreeNode) TokenTreeNode(com.alibaba.maxgraph.compiler.tree.TokenTreeNode) MinTreeNode(com.alibaba.maxgraph.compiler.tree.MinTreeNode) CountGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.CountGlobalTreeNode) HasTreeNode(com.alibaba.maxgraph.compiler.tree.HasTreeNode) SelectOneTreeNode(com.alibaba.maxgraph.compiler.tree.SelectOneTreeNode) PropertyMapTreeNode(com.alibaba.maxgraph.compiler.tree.PropertyMapTreeNode) SumTreeNode(com.alibaba.maxgraph.compiler.tree.SumTreeNode) UnaryTreeNode(com.alibaba.maxgraph.compiler.tree.UnaryTreeNode) LogicalQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan) SumTreeNode(com.alibaba.maxgraph.compiler.tree.SumTreeNode)

Example 20 with LogicalBinaryVertex

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

the class AbstractUseKeyNode method processJoinZeroVertex.

/**
 * Process zero for sum and count vertex
 *
 * @param vertexIdManager     The vertex id manager
 * @param logicalSubQueryPlan The logical sub query plan
 * @param valueVertex         The value vertex
 * @param joinZeroFlag        The join zero flag
 * @return The output vertex after deal with join zero flag
 */
protected LogicalVertex processJoinZeroVertex(VertexIdManager vertexIdManager, LogicalSubQueryPlan logicalSubQueryPlan, LogicalVertex valueVertex, boolean joinZeroFlag) {
    LogicalVertex outputVertex = valueVertex;
    LogicalVertex leftVertex = getSourceVertex();
    if (joinZeroFlag && null != leftVertex) {
        ProcessorFunction joinZeroFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_RIGHT_ZERO_JOIN);
        LogicalBinaryVertex logicalBinaryVertex = new LogicalBinaryVertex(vertexIdManager.getId(), joinZeroFunction, false, leftVertex, valueVertex);
        logicalSubQueryPlan.addLogicalVertex(logicalBinaryVertex);
        logicalSubQueryPlan.addLogicalEdge(valueVertex, logicalBinaryVertex, new LogicalEdge());
        outputVertex = logicalBinaryVertex;
    }
    return outputVertex;
}
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)

Aggregations

LogicalBinaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex)20 LogicalVertex (com.alibaba.maxgraph.compiler.logical.LogicalVertex)20 LogicalEdge (com.alibaba.maxgraph.compiler.logical.LogicalEdge)19 ProcessorFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction)18 LogicalSubQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)15 LogicalUnaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex)12 VertexIdManager (com.alibaba.maxgraph.compiler.logical.VertexIdManager)6 SourceTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode)6 QueryFlowOuterClass (com.alibaba.maxgraph.QueryFlowOuterClass)5 LogicalQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan)5 Message (com.alibaba.maxgraph.Message)4 SourceDelegateNode (com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)4 JoinZeroNode (com.alibaba.maxgraph.compiler.tree.addition.JoinZeroNode)3 LogicalSourceDelegateVertex (com.alibaba.maxgraph.compiler.logical.LogicalSourceDelegateVertex)2 LogicalSourceVertex (com.alibaba.maxgraph.compiler.logical.LogicalSourceVertex)2 ProcessorFilterFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorFilterFunction)2 CountGlobalTreeNode (com.alibaba.maxgraph.compiler.tree.CountGlobalTreeNode)2 FoldTreeNode (com.alibaba.maxgraph.compiler.tree.FoldTreeNode)2 HasTreeNode (com.alibaba.maxgraph.compiler.tree.HasTreeNode)2 MaxTreeNode (com.alibaba.maxgraph.compiler.tree.MaxTreeNode)2