Search in sources :

Example 6 with LogicalBinaryVertex

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

the class UnionTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    if (unionTreeNodeList.isEmpty()) {
        throw new IllegalArgumentException("union tree node list is empty");
    } else {
        LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
        LogicalVertex delegateSourceVertex = getInputNode().getOutputVertex();
        logicalSubQueryPlan.addLogicalVertex(delegateSourceVertex);
        LogicalVertex unionVertex = null;
        for (TreeNode treeNode : unionTreeNodeList) {
            LogicalSubQueryPlan unionPlan = TreeNodeUtils.buildQueryPlan(treeNode, labelManager, contextManager, vertexIdManager);
            LogicalVertex currentUnionVertex = unionPlan.getOutputVertex();
            logicalSubQueryPlan.mergeLogicalQueryPlan(unionPlan);
            if (null == unionVertex) {
                unionVertex = currentUnionVertex;
            } else {
                LogicalBinaryVertex binaryVertex = new LogicalBinaryVertex(vertexIdManager.getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.UNION), false, unionVertex, currentUnionVertex);
                logicalSubQueryPlan.addLogicalVertex(binaryVertex);
                logicalSubQueryPlan.addLogicalEdge(unionVertex, binaryVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
                logicalSubQueryPlan.addLogicalEdge(currentUnionVertex, binaryVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
                unionVertex = binaryVertex;
            }
        }
        LogicalVertex outputVertex = logicalSubQueryPlan.getOutputVertex();
        addUsedLabelAndRequirement(outputVertex, labelManager);
        setFinishVertex(outputVertex, labelManager);
        return logicalSubQueryPlan;
    }
}
Also used : 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) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 7 with LogicalBinaryVertex

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

the class WherePredicateTreeNode method processComplexNode.

private int processComplexNode(ContextManager contextManager, VertexIdManager vertexIdManager, TreeNodeLabelManager labelManager, LogicalSubQueryPlan logicalSubQueryPlan, LogicalVertex sourceVertex, TreeNode ringNode) {
    if (ringNode instanceof JoinZeroNode) {
        ((JoinZeroNode) ringNode).disableJoinZero();
    }
    LogicalSubQueryPlan subQueryPlan = TreeNodeUtils.buildSubQueryPlan(ringNode, sourceVertex, contextManager);
    LogicalVertex secondValueVertex = subQueryPlan.getOutputVertex();
    logicalSubQueryPlan.mergeLogicalQueryPlan(subQueryPlan);
    String secondValueLabel = labelManager.createSysLabelStart("val");
    int labelId = labelManager.getLabelIndex(secondValueLabel);
    QueryFlowOuterClass.OperatorType joinType = CompilerUtils.parseJoinOperatorType(ringNode);
    LogicalBinaryVertex joinVertex = new LogicalBinaryVertex(vertexIdManager.getId(), new ProcessorFunction(joinType, Message.Value.newBuilder().setIntValue(labelId)), false, sourceVertex, secondValueVertex);
    logicalSubQueryPlan.addLogicalVertex(joinVertex);
    logicalSubQueryPlan.addLogicalEdge(sourceVertex, joinVertex, new LogicalEdge());
    logicalSubQueryPlan.addLogicalEdge(secondValueVertex, joinVertex, new LogicalEdge());
    return labelId;
}
Also used : 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) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 8 with LogicalBinaryVertex

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

the class WherePredicateTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    Map<String, Integer> labelIndexList = labelManager.getLabelIndexList();
    if (ringEmptyFlag) {
        Message.CompareType compareType = CompilerUtils.parseCompareType(predicate, predicate.getBiPredicate());
        if (StringUtils.isEmpty(startKey)) {
            String predicateKey = getPredicateValue();
            if (null != contextManager.getStoreVertex(predicateKey)) {
                LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
                LogicalVertex storeVertex = contextManager.getStoreVertex(predicateKey);
                LogicalVertex sourceVertex = getInputNode().getOutputVertex();
                logicalSubQueryPlan.addLogicalVertex(sourceVertex);
                ProcessorFunction joinStoreFilterFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_STORE_FILTER, Message.Value.newBuilder().setIntValue(CompilerUtils.parseCompareType(predicate, predicate.getBiPredicate()).getNumber()));
                LogicalBinaryVertex logicalBinaryVertex = new LogicalBinaryVertex(vertexIdManager.getId(), joinStoreFilterFunction, getInputNode().isPropLocalFlag(), sourceVertex, storeVertex);
                logicalSubQueryPlan.addLogicalVertex(logicalBinaryVertex);
                logicalSubQueryPlan.addLogicalEdge(sourceVertex, logicalBinaryVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
                setFinishVertex(logicalBinaryVertex, labelManager);
                addUsedLabelAndRequirement(logicalBinaryVertex, labelManager);
                return logicalSubQueryPlan;
            } else {
                int whereLabelId = labelIndexList.getOrDefault(predicateKey, TreeConstants.MAGIC_LABEL_ID);
                ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.WHERE, Message.Value.newBuilder().addIntValueList(compareType.getNumber()).addIntValueList(whereLabelId));
                processorFunction.getUsedLabelList().add(whereLabelId);
                return parseSingleUnaryVertex(vertexIdManager, labelManager, processorFunction, contextManager);
            }
        } else {
            int startLabelId = labelIndexList.getOrDefault(startKey, TreeConstants.MAGIC_LABEL_ID);
            String predicateKey = getPredicateValue();
            if (null != contextManager.getStoreVertex(predicateKey)) {
                LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
                LogicalVertex storeVertex = contextManager.getStoreVertex(predicateKey);
                LogicalVertex sourceVertex = getInputNode().getOutputVertex();
                logicalSubQueryPlan.addLogicalVertex(sourceVertex);
                ProcessorFunction joinStoreFilterFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_STORE_FILTER, Message.Value.newBuilder().setIntValue(startLabelId));
                LogicalBinaryVertex logicalBinaryVertex = new LogicalBinaryVertex(vertexIdManager.getId(), joinStoreFilterFunction, getInputNode().isPropLocalFlag(), sourceVertex, storeVertex);
                logicalSubQueryPlan.addLogicalVertex(logicalBinaryVertex);
                logicalSubQueryPlan.addLogicalEdge(sourceVertex, logicalBinaryVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
                setFinishVertex(logicalBinaryVertex, labelManager);
                addUsedLabelAndRequirement(logicalBinaryVertex, labelManager);
                return logicalSubQueryPlan;
            } else {
                int whereLabelId = labelIndexList.getOrDefault(predicateKey, TreeConstants.MAGIC_LABEL_ID);
                ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.WHERE_LABEL, Message.Value.newBuilder().addIntValueList(compareType.getNumber()).addIntValueList(startLabelId).addIntValueList(whereLabelId));
                processorFunction.getUsedLabelList().addAll(Lists.newArrayList(startLabelId, whereLabelId));
                if ((startLabelId < 0 && whereLabelId < 0) || getInputNode().isPropLocalFlag()) {
                    return parseSingleUnaryVertex(vertexIdManager, labelManager, processorFunction, contextManager);
                } else {
                    return parseSingleUnaryVertex(vertexIdManager, labelManager, processorFunction, contextManager);
                }
            }
        }
    } else {
        LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
        LogicalVertex delegateSourceVertex = getInputNode().getOutputVertex();
        logicalSubQueryPlan.addLogicalVertex(delegateSourceVertex);
        String inputLabel = labelManager.createSysLabelStart(getInputNode().getOutputVertex(), "val");
        TreeNode firstRingNode = sourceNode;
        if (TreeNodeUtils.checkMultipleOutput(firstRingNode)) {
            firstRingNode = new RangeGlobalTreeNode(firstRingNode, schema, 0, 1);
        }
        TreeNode secondRingNode = targetNode;
        if (TreeNodeUtils.checkMultipleOutput(secondRingNode)) {
            secondRingNode = new RangeGlobalTreeNode(secondRingNode, schema, 0, 1);
        }
        int sourceLabelId, targetLabelId;
        boolean selfValueFlag = false;
        if (!TreeNodeUtils.checkJoinSourceFlag(firstRingNode)) {
            // first ring is value node
            if (!TreeNodeUtils.checkJoinSourceFlag(secondRingNode)) {
                // second ring is value node
                sourceLabelId = processFirstValueNode(contextManager, vertexIdManager, labelManager, logicalSubQueryPlan, firstRingNode);
                targetLabelId = processSecondValueNode(contextManager, vertexIdManager, labelManager, logicalSubQueryPlan, secondRingNode);
            } else {
                // second ring is not value node
                targetLabelId = processComplexNode(contextManager, vertexIdManager, labelManager, logicalSubQueryPlan, delegateSourceVertex, secondRingNode);
                sourceLabelId = processFirstValueNode(contextManager, vertexIdManager, labelManager, logicalSubQueryPlan, firstRingNode);
            }
        } else {
            // first ring is not value node
            if (!TreeNodeUtils.checkJoinSourceFlag(secondRingNode)) {
                // second ring is value node
                sourceLabelId = processComplexNode(contextManager, vertexIdManager, labelManager, logicalSubQueryPlan, logicalSubQueryPlan.getOutputVertex(), firstRingNode);
                targetLabelId = processSecondValueNode(contextManager, vertexIdManager, labelManager, logicalSubQueryPlan, secondRingNode);
            } else {
                // second ring is not value node
                sourceLabelId = processComplexNode(contextManager, vertexIdManager, labelManager, logicalSubQueryPlan, logicalSubQueryPlan.getOutputVertex(), firstRingNode);
                targetLabelId = processComplexNode(contextManager, vertexIdManager, labelManager, logicalSubQueryPlan, logicalSubQueryPlan.getOutputVertex(), secondRingNode);
                selfValueFlag = true;
            }
        }
        LogicalVertex currentOutputVertex = logicalSubQueryPlan.getOutputVertex();
        Message.Value.Builder argumentBuilder = Message.Value.newBuilder().addIntValueList(CompilerUtils.parseCompareType(predicate, predicate.getBiPredicate()).getNumber()).addIntValueList(sourceLabelId).addIntValueList(targetLabelId);
        ProcessorFunction whereFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.WHERE_LABEL, argumentBuilder);
        whereFunction.getUsedLabelList().add(sourceLabelId);
        whereFunction.getUsedLabelList().add(targetLabelId);
        LogicalVertex whereVertex = new LogicalUnaryVertex(vertexIdManager.getId(), whereFunction, getInputNode().isPropLocalFlag(), currentOutputVertex);
        logicalSubQueryPlan.addLogicalVertex(whereVertex);
        logicalSubQueryPlan.addLogicalEdge(currentOutputVertex, whereVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
        if (!selfValueFlag) {
            ProcessorFunction inputValueFunction = TreeNodeUtils.createSelectOneFunction(inputLabel, Pop.first, labelIndexList);
            LogicalVertex logicalVertex = new LogicalUnaryVertex(vertexIdManager.getId(), inputValueFunction, false, whereVertex);
            logicalSubQueryPlan.addLogicalVertex(logicalVertex);
            logicalSubQueryPlan.addLogicalEdge(whereVertex, logicalVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
        }
        LogicalVertex outputVertex = logicalSubQueryPlan.getOutputVertex();
        addUsedLabelAndRequirement(outputVertex, labelManager);
        setFinishVertex(outputVertex, labelManager);
        List<LogicalVertex> logicalVertexList = logicalSubQueryPlan.getLogicalVertexList();
        logicalVertexList.remove(delegateSourceVertex);
        return logicalSubQueryPlan;
    }
}
Also used : LogicalUnaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) Message(com.alibaba.maxgraph.Message) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 9 with LogicalBinaryVertex

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

the class GroupTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex sourceVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(sourceVertex);
    QueryFlowOuterClass.EnterKeyArgumentProto enterKeyArgumentProto = null;
    if (keyTreeNode == null || keyTreeNode instanceof SourceDelegateNode) {
        enterKeyArgumentProto = QueryFlowOuterClass.EnterKeyArgumentProto.newBuilder().setEnterKeyType(QueryFlowOuterClass.EnterKeyTypeProto.KEY_SELF).build();
    } else if (UnaryTreeNode.class.cast(keyTreeNode).getInputNode() instanceof SourceDelegateNode) {
        Optional<QueryFlowOuterClass.EnterKeyArgumentProto> propLabelId = TreeNodeUtils.parseEnterKeyArgument(keyTreeNode, schema, contextManager.getTreeNodeLabelManager());
        if (propLabelId.isPresent()) {
            enterKeyArgumentProto = propLabelId.get();
        }
    }
    if (null != enterKeyArgumentProto) {
        // use enter key operator to generate key data
        ProcessorFunction enterKeyFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.ENTER_KEY, Message.Value.newBuilder().setPayload(enterKeyArgumentProto.toByteString()));
        LogicalVertex enterKeyVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), enterKeyFunction, false, sourceVertex);
        enterKeyArgumentProto.getPropIdListList().forEach(v -> {
            if (v < 0) {
                enterKeyFunction.getUsedLabelList().add(v);
            }
        });
        if (enterKeyArgumentProto.getPropLabelId() < 0) {
            enterKeyFunction.getUsedLabelList().add(enterKeyArgumentProto.getPropLabelId());
        }
        logicalSubQueryPlan.addLogicalVertex(enterKeyVertex);
        logicalSubQueryPlan.addLogicalEdge(sourceVertex, enterKeyVertex, new LogicalEdge());
    } else {
        TreeNode currentKeyNode = TreeNodeUtils.buildSingleOutputNode(keyTreeNode, schema);
        LogicalSubQueryPlan keyQueryPlan = TreeNodeUtils.buildSubQueryPlan(currentKeyNode, sourceVertex, contextManager, true);
        LogicalVertex keyValueVertex = keyQueryPlan.getOutputVertex();
        logicalSubQueryPlan.mergeLogicalQueryPlan(keyQueryPlan);
        sourceVertex = TreeNodeUtils.getSourceTreeNode(keyTreeNode).getOutputVertex();
        if (sourceVertex.getProcessorFunction().getOperatorType() == QueryFlowOuterClass.OperatorType.ENTER_KEY) {
            ProcessorFunction joinKeyFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_RIGHT_VALUE_KEY);
            LogicalBinaryVertex joinKeyVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), joinKeyFunction, false, sourceVertex, keyValueVertex);
            logicalSubQueryPlan.addLogicalVertex(joinKeyVertex);
            logicalSubQueryPlan.addLogicalEdge(sourceVertex, joinKeyVertex, new LogicalEdge());
            logicalSubQueryPlan.addLogicalEdge(keyValueVertex, joinKeyVertex, new LogicalEdge());
        } else {
            String keyValueLabel = contextManager.getTreeNodeLabelManager().createSysLabelStart(keyValueVertex, "val");
            String sourceLabel = contextManager.getTreeNodeLabelManager().createSysLabelStart(sourceVertex, "source");
            ProcessorFunction selectSourceFunction = TreeNodeUtils.createSelectOneFunction(sourceLabel, Pop.first, contextManager.getTreeNodeLabelManager().getLabelIndexList());
            LogicalVertex selectVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), selectSourceFunction, false, keyValueVertex);
            logicalSubQueryPlan.addLogicalVertex(selectVertex);
            logicalSubQueryPlan.addLogicalEdge(keyValueVertex, selectVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
            int keyValueLabelId = contextManager.getTreeNodeLabelManager().getLabelIndex(keyValueLabel);
            ProcessorFunction enterKeyFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.ENTER_KEY, Message.Value.newBuilder().setPayload(QueryFlowOuterClass.EnterKeyArgumentProto.newBuilder().setEnterKeyType(QueryFlowOuterClass.EnterKeyTypeProto.KEY_PROP_LABEL).setUniqFlag(false).setPropLabelId(keyValueLabelId).build().toByteString()));
            enterKeyFunction.getUsedLabelList().add(keyValueLabelId);
            LogicalVertex enterKeyVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), enterKeyFunction, false, selectVertex);
            logicalSubQueryPlan.addLogicalVertex(enterKeyVertex);
            logicalSubQueryPlan.addLogicalEdge(selectVertex, enterKeyVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
        }
    }
    LogicalVertex outputVertex = logicalSubQueryPlan.getOutputVertex();
    LogicalSubQueryPlan aggregateQueryPlan = TreeNodeUtils.buildSubQueryPlan(valueTreeNode, outputVertex, contextManager, false);
    LogicalVertex aggregateVertex = aggregateQueryPlan.getOutputVertex();
    logicalSubQueryPlan.mergeLogicalQueryPlan(aggregateQueryPlan);
    // convert by key value to entry
    ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.BYKEY_ENTRY);
    LogicalVertex bykeyEntryVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), processorFunction, false, aggregateVertex);
    logicalSubQueryPlan.addLogicalVertex(bykeyEntryVertex);
    logicalSubQueryPlan.addLogicalEdge(aggregateVertex, bykeyEntryVertex, new LogicalEdge());
    outputVertex = logicalSubQueryPlan.getOutputVertex();
    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) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) Optional(java.util.Optional) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 10 with LogicalBinaryVertex

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

the class QueryFlowBuilder method buildQueryFlow.

private void buildQueryFlow(QueryPlan.Builder queryPlanBuilder, LogicalQueryPlan queryPlan, long snapshot) {
    List<LogicalVertex> logicalVertexList = queryPlan.getLogicalVertexList();
    Map<Integer, Pair<Integer, Integer>> dfsGraphVertexMapping = Maps.newHashMap();
    for (LogicalVertex logicalVertex : logicalVertexList) {
        ProcessorFunction processorFunction = logicalVertex.getProcessorFunction();
        if (processorFunction instanceof ProcessorRepeatFunction) {
            ProcessorRepeatFunction processorRepeatFunction = ProcessorRepeatFunction.class.cast(processorFunction);
            QueryFlowBuilder repeatBuilder = new QueryFlowBuilder();
            QueryFlow queryFlow = repeatBuilder.buildQueryFlow(processorRepeatFunction.getRepeatPlan(), snapshot).build();
            RepeatArgumentProto.Builder repeatArgument = RepeatArgumentProto.newBuilder().setPlan(queryFlow.getQueryPlan()).setLoopLimit((int) processorRepeatFunction.getMaxLoopTimes()).setFeedbackId(processorRepeatFunction.getFeedbackVertex().getId()).setEmitFlag(processorRepeatFunction.isHasEmitFlag());
            if (processorRepeatFunction.getLeaveVertex() != null) {
                repeatArgument.setLeaveId(processorRepeatFunction.getLeaveVertex().getId());
            } else {
                repeatArgument.setLeaveId(-1);
            }
            logger.info("repeat argument => ");
            logger.info(TextFormat.printToString(repeatArgument));
            OperatorBase.Builder repeatBase = OperatorBase.newBuilder().setId(logicalVertex.getId()).setOperatorType(OperatorType.REPEAT).setArgument(Value.newBuilder().setPayload(repeatArgument.build().toByteString()));
            queryPlanBuilder.addUnaryOp(UnaryOperator.newBuilder().setBase(repeatBase).setInputOperatorId(queryPlan.getSourceVertex(logicalVertex).getId()));
            queryPlanBuilder.addOperatorIdList(logicalVertex.getId());
        } else if (processorFunction instanceof ProcessorChainFunction) {
            OperatorBase.Builder baseBuilder = OperatorBase.newBuilder();
            baseBuilder.setOperatorType(processorFunction.getOperatorType()).setId(logicalVertex.getId());
            if (null != logicalVertex.getEarlyStopArgument()) {
                baseBuilder.setEarlyStopArgument(logicalVertex.getEarlyStopArgument().build());
            }
            ProcessorChainFunction processorChainFunction = ProcessorChainFunction.class.cast(processorFunction);
            processorChainFunction.getChainVertexList().forEach(v -> baseBuilder.addChainedFunction(createChainedFunction(v)));
            if (logicalVertex instanceof LogicalChainSourceVertex) {
                LogicalSourceVertex logicalSourceVertex = ((LogicalChainSourceVertex) logicalVertex).getLogicalSourceVertex();
                baseBuilder.setArgument(logicalSourceVertex.getProcessorFunction().getArgumentBuilder()).addAllLogicalCompare(logicalSourceVertex.getProcessorFunction().getLogicalCompareList());
                SourceOperator.Builder sourceBuilder = SourceOperator.newBuilder().setBase(baseBuilder);
                queryPlanBuilder.setSourceOp(sourceBuilder);
            } else {
                LogicalChainUnaryVertex logicalUnaryVertex = (LogicalChainUnaryVertex) logicalVertex;
                UnaryOperator.Builder unaryOperator = UnaryOperator.newBuilder().setBase(baseBuilder).setInputOperatorId(parseInputOperatorId(queryPlan.getSourceVertex(logicalUnaryVertex).getId(), processorFunction.getOperatorType(), dfsGraphVertexMapping));
                LogicalEdge logicalEdge = queryPlan.getLogicalEdge(queryPlan.getSourceVertex(logicalUnaryVertex), logicalUnaryVertex);
                unaryOperator.setShuffleType(CompilerUtils.parseShuffleTypeFromEdge(logicalEdge)).setInputStreamIndex(logicalEdge.getStreamIndex());
                if (logicalEdge.getShuffleType() == EdgeShuffleType.SHUFFLE_BY_KEY) {
                    InputEdgeShuffle.Builder shuffleBuilder = InputEdgeShuffle.newBuilder().setShuffleType(InputShuffleType.SHUFFLE_BY_ID_TYPE);
                    if (logicalEdge.getShufflePropId() != 0) {
                        shuffleBuilder.setShuffleValue(logicalEdge.getShufflePropId());
                    }
                    unaryOperator.setInputShuffle(shuffleBuilder);
                }
                queryPlanBuilder.addUnaryOp(unaryOperator);
            }
            queryPlanBuilder.addOperatorIdList(logicalVertex.getId());
        } else if (processorFunction instanceof ProcessorLabelValueFunction) {
            ProcessorLabelValueFunction processorLabelValueFunction = (ProcessorLabelValueFunction) processorFunction;
            LogicalVertex labelValueVertex = processorLabelValueFunction.getLabelValueVertex();
            OperatorBase.Builder labelOperatorBuilder = createChainedFunction(labelValueVertex);
            int labelId = processorLabelValueFunction.getLabelId();
            OperatorBase.Builder baseBuilder = OperatorBase.newBuilder().setOperatorType(processorFunction.getOperatorType()).setId(logicalVertex.getId()).setArgument(Value.newBuilder().setIntValue(labelId).setBoolValue(processorLabelValueFunction.getRequireLabelFlag()).setPayload(labelOperatorBuilder.build().toByteString()));
            LogicalVertex inputVertex = queryPlan.getSourceVertex(logicalVertex);
            UnaryOperator.Builder unaryOperator = UnaryOperator.newBuilder().setBase(baseBuilder).setInputOperatorId(parseInputOperatorId(inputVertex.getId(), processorFunction.getOperatorType(), dfsGraphVertexMapping));
            LogicalEdge logicalEdge = queryPlan.getLogicalEdge(inputVertex, logicalVertex);
            unaryOperator.setShuffleType(CompilerUtils.parseShuffleTypeFromEdge(logicalEdge)).setInputStreamIndex(logicalEdge.getStreamIndex());
            queryPlanBuilder.addUnaryOp(unaryOperator).addOperatorIdList(logicalVertex.getId());
        } else {
            if (logicalVertex instanceof LogicalSourceDelegateVertex) {
                continue;
            }
            OperatorBase.Builder baseBuilder = OperatorBase.newBuilder();
            baseBuilder.setOperatorType(processorFunction.getOperatorType()).setId(logicalVertex.getId());
            if (processorFunction.getArgumentBuilder() != null) {
                baseBuilder.setArgument(processorFunction.getArgumentBuilder());
            }
            processorFunction.getLogicalCompareList().forEach(baseBuilder::addLogicalCompare);
            if (processorFunction.getRangeLimit() != null) {
                baseBuilder.setRangeLimit(processorFunction.getRangeLimit());
            }
            baseBuilder.addAllAfterRequirement(logicalVertex.getAfterRequirementList().stream().map(v -> v.build()).collect(Collectors.toList()));
            baseBuilder.addAllBeforeRequirement(logicalVertex.getBeforeRequirementList().stream().map(v -> v.build()).collect(Collectors.toList()));
            if (logicalVertex instanceof LogicalSourceVertex) {
                ProcessorSourceFunction processorSourceFunction = (ProcessorSourceFunction) logicalVertex.getProcessorFunction();
                SourceOperator.Builder sourceBuilder = SourceOperator.newBuilder().setBase(baseBuilder);
                if (null != processorSourceFunction.getOdpsQueryInput()) {
                    sourceBuilder.setOdpsInput(processorSourceFunction.getOdpsQueryInput()).setSourceType(SourceType.ODPS);
                } else {
                    sourceBuilder.setSourceType(SourceType.GRAPH);
                }
                queryPlanBuilder.setSourceOp(sourceBuilder);
            } else if (logicalVertex instanceof LogicalUnaryVertex) {
                EarlyStopArgument.Builder earlyStopArgument = logicalVertex.getEarlyStopArgument();
                if (null != earlyStopArgument && (earlyStopArgument.getGlobalFilterFlag() || earlyStopArgument.getGlobalStopFlag())) {
                    baseBuilder.setEarlyStopArgument(logicalVertex.getEarlyStopArgument().build());
                }
                LogicalUnaryVertex logicalUnaryVertex = LogicalUnaryVertex.class.cast(logicalVertex);
                UnaryOperator.Builder unaryOperator = UnaryOperator.newBuilder().setBase(baseBuilder).setInputOperatorId(parseInputOperatorId(queryPlan.getSourceVertex(logicalUnaryVertex).getId(), processorFunction.getOperatorType(), dfsGraphVertexMapping));
                LogicalEdge logicalEdge = queryPlan.getLogicalEdge(queryPlan.getSourceVertex(logicalUnaryVertex), logicalUnaryVertex);
                unaryOperator.setShuffleType(CompilerUtils.parseShuffleTypeFromEdge(logicalEdge)).setInputStreamIndex(logicalEdge.getStreamIndex());
                queryPlanBuilder.addUnaryOp(unaryOperator);
                if (processorFunction.getOperatorType() == OperatorType.DFS_REPEAT_GRAPH) {
                    VertexIdManager vertexIdManager = queryPlan.getPlanVertexIdManager();
                    int cmdLeftId = vertexIdManager.getId();
                    int dataRightId = vertexIdManager.getId();
                    dfsGraphVertexMapping.put(baseBuilder.getId(), Pair.of(cmdLeftId, dataRightId));
                    UnaryOperator.Builder cmdLeftOp = UnaryOperator.newBuilder().setBase(OperatorBase.newBuilder().setOperatorType(OperatorType.DFS_REPEAT_CMD).setId(cmdLeftId)).setInputOperatorId(baseBuilder.getId()).setShuffleType(InputShuffleType.FORWARD_TYPE);
                    queryPlanBuilder.addUnaryOp(cmdLeftOp);
                    UnaryOperator.Builder dataRightOp = UnaryOperator.newBuilder().setBase(OperatorBase.newBuilder().setOperatorType(OperatorType.DFS_REPEAT_DATA).setId(dataRightId)).setInputOperatorId(baseBuilder.getId()).setShuffleType(InputShuffleType.FORWARD_TYPE);
                    queryPlanBuilder.addUnaryOp(dataRightOp);
                }
            } else if (logicalVertex instanceof LogicalBinaryVertex) {
                LogicalBinaryVertex logicalBinaryVertex = LogicalBinaryVertex.class.cast(logicalVertex);
                BinaryOperator.Builder binaryOperator = BinaryOperator.newBuilder().setBase(baseBuilder).setLeftInputOperatorId(parseInputOperatorId(logicalBinaryVertex.getLeftInput().getId(), processorFunction.getOperatorType(), dfsGraphVertexMapping)).setRightInputOperatorId(parseInputOperatorId(logicalBinaryVertex.getRightInput().getId(), processorFunction.getOperatorType(), dfsGraphVertexMapping));
                LogicalEdge leftEdge = queryPlan.getLogicalEdge(logicalBinaryVertex.getLeftInput(), logicalBinaryVertex);
                LogicalEdge rightEdge = queryPlan.getLogicalEdge(logicalBinaryVertex.getRightInput(), logicalBinaryVertex);
                binaryOperator.setLeftShuffleType(CompilerUtils.parseShuffleTypeFromEdge(leftEdge)).setLeftStreamIndex(leftEdge.getStreamIndex()).setRightShuffleType(CompilerUtils.parseShuffleTypeFromEdge(rightEdge)).setRightStreamIndex(rightEdge.getStreamIndex());
                queryPlanBuilder.addBinaryOp(binaryOperator);
            } else {
                throw new IllegalArgumentException(logicalVertex.toString());
            }
            queryPlanBuilder.addOperatorIdList(logicalVertex.getId());
            Pair<Integer, Integer> dfsCmdPair = dfsGraphVertexMapping.get(logicalVertex.getId());
            if (null != dfsCmdPair) {
                queryPlanBuilder.addOperatorIdList(dfsCmdPair.getLeft());
                queryPlanBuilder.addOperatorIdList(dfsCmdPair.getRight());
            }
        }
    }
}
Also used : ProcessorLabelValueFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorLabelValueFunction) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) LogicalQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan) EdgeShuffleType(com.alibaba.maxgraph.compiler.logical.edge.EdgeShuffleType) LoggerFactory(org.slf4j.LoggerFactory) LogicalSourceVertex(com.alibaba.maxgraph.compiler.logical.LogicalSourceVertex) LogicalSourceDelegateVertex(com.alibaba.maxgraph.compiler.logical.LogicalSourceDelegateVertex) ExecuteParam(com.alibaba.maxgraph.compiler.executor.ExecuteParam) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) LogicalUnaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex) Lists(com.google.common.collect.Lists) Pair(org.apache.commons.lang3.tuple.Pair) ProcessorChainFunction(com.alibaba.maxgraph.compiler.logical.chain.ProcessorChainFunction) ProcessorSourceFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorSourceFunction) Map(java.util.Map) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) LogicalChainSourceVertex(com.alibaba.maxgraph.compiler.logical.chain.LogicalChainSourceVertex) TreeConstants(com.alibaba.maxgraph.compiler.tree.TreeConstants) TextFormat(com.google.protobuf.TextFormat) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) Logger(org.slf4j.Logger) CompilerUtils(com.alibaba.maxgraph.compiler.utils.CompilerUtils) Message(com.alibaba.maxgraph.Message) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) List(java.util.List) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalChainUnaryVertex(com.alibaba.maxgraph.compiler.logical.chain.LogicalChainUnaryVertex) ProcessorRepeatFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorRepeatFunction) LogicalSourceVertex(com.alibaba.maxgraph.compiler.logical.LogicalSourceVertex) LogicalUnaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) LogicalSourceDelegateVertex(com.alibaba.maxgraph.compiler.logical.LogicalSourceDelegateVertex) ProcessorRepeatFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorRepeatFunction) LogicalChainUnaryVertex(com.alibaba.maxgraph.compiler.logical.chain.LogicalChainUnaryVertex) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) LogicalChainSourceVertex(com.alibaba.maxgraph.compiler.logical.chain.LogicalChainSourceVertex) ProcessorLabelValueFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorLabelValueFunction) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) Pair(org.apache.commons.lang3.tuple.Pair) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) ProcessorSourceFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorSourceFunction) ProcessorChainFunction(com.alibaba.maxgraph.compiler.logical.chain.ProcessorChainFunction)

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