Search in sources :

Example 1 with LogicalBinaryVertex

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

the class OptionalTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex sourceVertex = getInputNode().getOutputVertex();
    logicalQueryPlan.addLogicalVertex(sourceVertex);
    LogicalVertex trueVertex = TreeNodeUtils.buildFilterTreeNode(this.branchTreeNode, contextManager, logicalQueryPlan, sourceVertex, schema);
    ProcessorFunction joinFilterRightFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_DIRECT_FILTER_NEGATE);
    LogicalEdge leftEdge = getInputNode().isPropLocalFlag() ? new LogicalEdge(EdgeShuffleType.FORWARD) : new LogicalEdge(EdgeShuffleType.SHUFFLE_BY_KEY);
    LogicalBinaryVertex falseVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), joinFilterRightFunction, getInputNode().isPropLocalFlag(), sourceVertex, trueVertex);
    logicalQueryPlan.addLogicalVertex(falseVertex);
    logicalQueryPlan.addLogicalEdge(sourceVertex, falseVertex, leftEdge);
    logicalQueryPlan.addLogicalEdge(trueVertex, falseVertex, new LogicalEdge(EdgeShuffleType.SHUFFLE_BY_KEY));
    LogicalQueryPlan truePlan = TreeNodeUtils.buildSubQueryPlan(this.trueNode, trueVertex, contextManager);
    LogicalVertex trueOutputVertex = truePlan.getOutputVertex();
    LogicalQueryPlan falsePlan = TreeNodeUtils.buildSubQueryPlan(this.falseNode, falseVertex, contextManager);
    LogicalVertex falseOutputVertex = falsePlan.getOutputVertex();
    logicalQueryPlan.mergeLogicalQueryPlan(truePlan);
    logicalQueryPlan.mergeLogicalQueryPlan(falsePlan);
    LogicalBinaryVertex unionVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.UNION), false, trueOutputVertex, falseOutputVertex);
    logicalQueryPlan.addLogicalVertex(unionVertex);
    logicalQueryPlan.addLogicalEdge(trueOutputVertex, unionVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
    logicalQueryPlan.addLogicalEdge(falseOutputVertex, unionVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
    setFinishVertex(unionVertex, contextManager.getTreeNodeLabelManager());
    addUsedLabelAndRequirement(unionVertex, contextManager.getTreeNodeLabelManager());
    return logicalQueryPlan;
}
Also used : LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) LogicalQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 2 with LogicalBinaryVertex

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

the class DfsFinishTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex delegateSourceVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(delegateSourceVertex);
    LogicalVertex countVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.COUNT), false, delegateSourceVertex);
    logicalSubQueryPlan.addLogicalVertex(countVertex);
    logicalSubQueryPlan.addLogicalEdge(delegateSourceVertex, countVertex, new LogicalEdge());
    Message.Value.Builder argument = Message.Value.newBuilder().setLongValue(maxRecordCount);
    LogicalVertex dfsFinishVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.DFS_FINISH_JOIN, argument), true, repeatSourceVertex, countVertex);
    logicalSubQueryPlan.addLogicalVertex(dfsFinishVertex);
    logicalSubQueryPlan.addLogicalEdge(countVertex, dfsFinishVertex, new LogicalEdge(EdgeShuffleType.SHUFFLE_BY_CONST));
    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) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 3 with LogicalBinaryVertex

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

the class TraversalFlatMapTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    TreeNodeLabelManager treeNodeLabelManager = contextManager.getTreeNodeLabelManager();
    LogicalVertex inputVertex = getInputNode().getOutputVertex();
    LogicalSubQueryPlan logicalQueryPlan = new LogicalSubQueryPlan(contextManager);
    logicalQueryPlan.addLogicalVertex(inputVertex);
    LogicalQueryPlan flatMapPlan = TreeNodeUtils.buildSubQueryPlan(flatMapNode, inputVertex, contextManager);
    logicalQueryPlan.mergeLogicalQueryPlan(flatMapPlan);
    LogicalVertex flatOutputVertex = logicalQueryPlan.getOutputVertex();
    LogicalVertex inputTargetVertex = flatMapPlan.getTargetVertex(inputVertex);
    if (inputTargetVertex.getProcessorFunction().getOperatorType() == QueryFlowOuterClass.OperatorType.ENTER_KEY && !(flatOutputVertex instanceof LogicalBinaryVertex)) {
        flatOutputVertex.getAfterRequirementList().add(QueryFlowOuterClass.RequirementValue.newBuilder().setReqType(QueryFlowOuterClass.RequirementType.KEY_DEL));
    }
    addUsedLabelAndRequirement(flatOutputVertex, treeNodeLabelManager);
    setFinishVertex(flatOutputVertex, treeNodeLabelManager);
    return logicalQueryPlan;
}
Also used : LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) LogicalQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 4 with LogicalBinaryVertex

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

the class NotTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex delegateSourceVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(delegateSourceVertex);
    TreeNode currentNotNode = TreeNodeUtils.buildSingleOutputNode(notTreeNode, schema);
    LogicalSubQueryPlan notQueryPlan = TreeNodeUtils.buildSubQueryPlanWithKey(currentNotNode, delegateSourceVertex, contextManager.getTreeNodeLabelManager(), contextManager, contextManager.getVertexIdManager());
    LogicalVertex notValueVertex = notQueryPlan.getOutputVertex();
    logicalSubQueryPlan.mergeLogicalQueryPlan(notQueryPlan);
    TreeNode sourceNode = TreeNodeUtils.getSourceTreeNode(currentNotNode);
    LogicalVertex enterKeyVertex = sourceNode.getOutputVertex();
    ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_DIRECT_FILTER_NEGATE);
    LogicalBinaryVertex logicalBinaryVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), processorFunction, false, enterKeyVertex, notValueVertex);
    logicalSubQueryPlan.addLogicalVertex(logicalBinaryVertex);
    logicalSubQueryPlan.addLogicalEdge(enterKeyVertex, logicalBinaryVertex, new LogicalEdge());
    logicalSubQueryPlan.addLogicalEdge(notValueVertex, logicalBinaryVertex, new LogicalEdge());
    LogicalVertex outputVertex = logicalSubQueryPlan.getOutputVertex();
    addUsedLabelAndRequirement(outputVertex, contextManager.getTreeNodeLabelManager());
    setFinishVertex(outputVertex, contextManager.getTreeNodeLabelManager());
    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) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 5 with LogicalBinaryVertex

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

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