Search in sources :

Example 21 with LogicalSubQueryPlan

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

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

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

the class EstimateCountTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalQueryPlan = new LogicalSubQueryPlan(contextManager);
    logicalQueryPlan.setDelegateSourceFlag(false);
    Message.Value.Builder argumentBuilder = super.createArgumentBuilder().setBoolValue(this.vertexFlag);
    if (null != labelList) {
        argumentBuilder.addAllIntValueList(labelList.stream().map(v -> schema.getElement(v).getLabelId()).collect(Collectors.toList()));
    }
    ProcessorSourceFunction processorSourceFunction = new ProcessorSourceFunction(QueryFlowOuterClass.OperatorType.ESTIMATE_COUNT, argumentBuilder, null);
    return processSourceVertex(contextManager.getVertexIdManager(), contextManager.getTreeNodeLabelManager(), logicalQueryPlan, processorSourceFunction);
}
Also used : LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan) ProcessorSourceFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorSourceFunction)

Example 24 with LogicalSubQueryPlan

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

the class ElementValueTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    if (null == bypassTreeNode) {
        Message.Value.Builder argumentBuilder = Message.Value.newBuilder().addIntValueList(SchemaUtils.getPropId(propKey, schema)).setBoolFlag(edgePropFlag());
        ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.PROP_VALUE, argumentBuilder);
        return parseSingleUnaryVertex(contextManager.getVertexIdManager(), contextManager.getTreeNodeLabelManager(), processorFunction, contextManager);
    } else {
        LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
        LogicalVertex delegateSourceVertex = getInputNode().getOutputVertex();
        logicalSubQueryPlan.addLogicalVertex(delegateSourceVertex);
        LogicalSubQueryPlan bypassPlan = TreeNodeUtils.buildQueryPlanWithSource(bypassTreeNode, contextManager.getTreeNodeLabelManager(), contextManager, contextManager.getVertexIdManager(), delegateSourceVertex);
        logicalSubQueryPlan.mergeLogicalQueryPlan(bypassPlan);
        LogicalVertex outputVertex = bypassPlan.getOutputVertex();
        setFinishVertex(outputVertex, contextManager.getTreeNodeLabelManager());
        addUsedLabelAndRequirement(outputVertex, contextManager.getTreeNodeLabelManager());
        return logicalSubQueryPlan;
    }
}
Also used : ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 25 with LogicalSubQueryPlan

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

the class FoldTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex sourceVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(sourceVertex);
    QueryFlowOuterClass.OperatorType foldType = getUseKeyOperator(QueryFlowOuterClass.OperatorType.FOLD);
    LogicalVertex foldVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(foldType, Message.Value.newBuilder()), false, sourceVertex);
    logicalSubQueryPlan.addLogicalVertex(foldVertex);
    logicalSubQueryPlan.addLogicalEdge(sourceVertex, foldVertex, new LogicalEdge(EdgeShuffleType.SHUFFLE_BY_CONST));
    setFinishVertex(foldVertex, contextManager.getTreeNodeLabelManager());
    addUsedLabelAndRequirement(foldVertex, 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) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Aggregations

LogicalSubQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)49 LogicalVertex (com.alibaba.maxgraph.compiler.logical.LogicalVertex)41 ProcessorFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction)34 LogicalEdge (com.alibaba.maxgraph.compiler.logical.LogicalEdge)29 LogicalUnaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex)27 VertexIdManager (com.alibaba.maxgraph.compiler.logical.VertexIdManager)18 LogicalBinaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex)15 QueryFlowOuterClass (com.alibaba.maxgraph.QueryFlowOuterClass)13 SourceDelegateNode (com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)11 SourceTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode)10 LogicalQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan)6 Message (com.alibaba.maxgraph.Message)5 ProcessorSourceFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorSourceFunction)5 CountGlobalTreeNode (com.alibaba.maxgraph.compiler.tree.CountGlobalTreeNode)5 FoldTreeNode (com.alibaba.maxgraph.compiler.tree.FoldTreeNode)5 HasTreeNode (com.alibaba.maxgraph.compiler.tree.HasTreeNode)5 MaxTreeNode (com.alibaba.maxgraph.compiler.tree.MaxTreeNode)5 MinTreeNode (com.alibaba.maxgraph.compiler.tree.MinTreeNode)5 PropertyMapTreeNode (com.alibaba.maxgraph.compiler.tree.PropertyMapTreeNode)5 RangeGlobalTreeNode (com.alibaba.maxgraph.compiler.tree.RangeGlobalTreeNode)5