Search in sources :

Example 11 with VertexIdManager

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

the class LpaVertexProgramTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    ProcessorFunction processorFunction = new ProcessorFunction(OperatorType.PROGRAM_GRAPH_LPA, createOperatorArgument());
    return parseSingleUnaryVertex(vertexIdManager, labelManager, processorFunction, contextManager);
}
Also used : ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager)

Example 12 with VertexIdManager

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

the class TreeNodeUtils method buildFilterTreeNode.

/**
 * Build logical plan with filter tree node and output the input value
 */
public static LogicalVertex buildFilterTreeNode(TreeNode treeNode, ContextManager contextManager, LogicalQueryPlan logicalQueryPlan, LogicalVertex sourceVertex, GraphSchema schema) {
    TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    TreeNode filterTreeNode = TreeNodeUtils.optimizeSubFilterNode(treeNode);
    UnaryTreeNode unaryTreeNode = UnaryTreeNode.class.cast(filterTreeNode);
    LogicalVertex outputVertex;
    if (unaryTreeNode.getInputNode() instanceof SourceTreeNode && (unaryTreeNode instanceof SelectOneTreeNode || unaryTreeNode instanceof PropertyNode)) {
        // optimize traversal filter to filter operator
        int propId;
        if (unaryTreeNode instanceof SelectOneTreeNode) {
            propId = labelManager.getLabelIndex(SelectOneTreeNode.class.cast(unaryTreeNode).getSelectLabel());
        } else {
            propId = SchemaUtils.getPropId(PropertyNode.class.cast(unaryTreeNode).getPropKeyList().iterator().next(), schema);
        }
        Message.LogicalCompare logicalCompare = Message.LogicalCompare.newBuilder().setCompare(Message.CompareType.EXIST).setPropId(propId).build();
        ProcessorFilterFunction processorFunction = new ProcessorFilterFunction(QueryFlowOuterClass.OperatorType.HAS);
        if (propId < 0) {
            processorFunction.getUsedLabelList().add(propId);
        }
        processorFunction.getLogicalCompareList().add(logicalCompare);
        outputVertex = new LogicalUnaryVertex(vertexIdManager.getId(), processorFunction, false, sourceVertex);
        logicalQueryPlan.addLogicalVertex(outputVertex);
        logicalQueryPlan.addLogicalEdge(sourceVertex, outputVertex, new LogicalEdge());
    } else {
        TreeNode currentFilterTreeNode = TreeNodeUtils.buildSingleOutputNode(filterTreeNode, schema);
        // build filter plan, and use join direct filter vertex to filter left stream
        LogicalSubQueryPlan filterPlan = TreeNodeUtils.buildSubQueryPlan(currentFilterTreeNode, sourceVertex, contextManager);
        TreeNode filterSourceNode = TreeNodeUtils.getSourceTreeNode(currentFilterTreeNode);
        sourceVertex = filterSourceNode.getOutputVertex();
        LogicalVertex rightVertex = filterPlan.getOutputVertex();
        logicalQueryPlan.mergeLogicalQueryPlan(filterPlan);
        if (TreeNodeUtils.checkJoinSourceFlag(currentFilterTreeNode)) {
            LogicalBinaryVertex filterJoinVertex = new LogicalBinaryVertex(vertexIdManager.getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_DIRECT_FILTER), false, sourceVertex, rightVertex);
            logicalQueryPlan.addLogicalVertex(filterJoinVertex);
            logicalQueryPlan.addLogicalEdge(sourceVertex, filterJoinVertex, new LogicalEdge());
            logicalQueryPlan.addLogicalEdge(rightVertex, filterJoinVertex, new LogicalEdge());
            outputVertex = filterJoinVertex;
        } else if (TreeNodeUtils.checkSelectFlag(currentFilterTreeNode)) {
            String inputLabel = labelManager.createSysLabelStart(sourceVertex, "input");
            ProcessorFunction selectFunction = createSelectOneFunction(inputLabel, Pop.last, labelManager.getLabelIndexList());
            LogicalUnaryVertex selectVertex = new LogicalUnaryVertex(vertexIdManager.getId(), selectFunction, false, rightVertex);
            logicalQueryPlan.addLogicalVertex(selectVertex);
            logicalQueryPlan.addLogicalEdge(rightVertex, selectVertex, new LogicalEdge());
            outputVertex = logicalQueryPlan.getOutputVertex();
        } else {
            outputVertex = logicalQueryPlan.getOutputVertex();
        }
    }
    return outputVertex;
}
Also used : TreeNodeLabelManager(com.alibaba.maxgraph.compiler.tree.TreeNodeLabelManager) 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) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) UnaryTreeNode(com.alibaba.maxgraph.compiler.tree.UnaryTreeNode) ProcessorFilterFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFilterFunction) 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) PropertyNode(com.alibaba.maxgraph.compiler.tree.addition.PropertyNode) SelectOneTreeNode(com.alibaba.maxgraph.compiler.tree.SelectOneTreeNode) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 13 with VertexIdManager

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

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

the class VertexTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    Message.Value.Builder argumentBuilder = createArgumentBuilder();
    if (null != edgeLabels) {
        for (String edgeLabel : edgeLabels) {
            argumentBuilder.addIntValueList(schema.getElement(edgeLabel).getLabelId());
        }
    }
    ProcessorFunction processorFunction = new ProcessorFunction(getCountOperator(QueryFlowOuterClass.OperatorType.valueOf(direction.name())), argumentBuilder, rangeLimit);
    if (direction == Direction.OUT && getInputNode().isPropLocalFlag()) {
        return parseSingleUnaryVertex(vertexIdManager, labelManager, processorFunction, contextManager, new LogicalEdge(EdgeShuffleType.FORWARD));
    } else {
        return parseSingleUnaryVertex(vertexIdManager, labelManager, processorFunction, contextManager);
    }
}
Also used : ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager)

Example 15 with VertexIdManager

use of com.alibaba.maxgraph.compiler.logical.VertexIdManager 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)

Aggregations

VertexIdManager (com.alibaba.maxgraph.compiler.logical.VertexIdManager)39 ProcessorFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction)34 LogicalSubQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)18 LogicalVertex (com.alibaba.maxgraph.compiler.logical.LogicalVertex)18 LogicalEdge (com.alibaba.maxgraph.compiler.logical.LogicalEdge)17 LogicalUnaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex)13 QueryFlowOuterClass (com.alibaba.maxgraph.QueryFlowOuterClass)6 LogicalBinaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex)6 Message (com.alibaba.maxgraph.Message)5 SourceTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode)5 SourceDelegateNode (com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)4 TreeNodeLabelManager (com.alibaba.maxgraph.compiler.tree.TreeNodeLabelManager)3 List (java.util.List)3 Pair (org.apache.commons.lang3.tuple.Pair)3 LogicalQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan)2 LogicalSourceDelegateVertex (com.alibaba.maxgraph.compiler.logical.LogicalSourceDelegateVertex)2 LogicalSourceVertex (com.alibaba.maxgraph.compiler.logical.LogicalSourceVertex)2 EdgeShuffleType (com.alibaba.maxgraph.compiler.logical.edge.EdgeShuffleType)2 ProcessorFilterFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorFilterFunction)2 ProcessorRepeatFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorRepeatFunction)2