Search in sources :

Example 41 with LogicalVertex

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

the class StoreTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    TreeNodeLabelManager treeNodeLabelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    LogicalVertex storeVertex;
    LogicalSubQueryPlan logicalSubQueryPlan;
    if (null == storeTreeNode) {
        ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.FOLD_STORE);
        logicalSubQueryPlan = parseSingleUnaryVertex(vertexIdManager, treeNodeLabelManager, processorFunction, contextManager);
        storeVertex = logicalSubQueryPlan.getOutputVertex();
    } else {
        logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
        LogicalVertex sourceVertex = getInputNode().getOutputVertex();
        logicalSubQueryPlan.addLogicalVertex(sourceVertex);
        LogicalSubQueryPlan storeQueryPlan = TreeNodeUtils.buildQueryPlanWithSource(storeTreeNode, treeNodeLabelManager, contextManager, vertexIdManager, sourceVertex);
        logicalSubQueryPlan.mergeLogicalQueryPlan(storeQueryPlan);
        LogicalVertex valueVertex = logicalSubQueryPlan.getOutputVertex();
        ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.FOLD_STORE);
        LogicalVertex foldVertex = new LogicalUnaryVertex(vertexIdManager.getId(), processorFunction, false, valueVertex);
        logicalSubQueryPlan.addLogicalVertex(foldVertex);
        logicalSubQueryPlan.addLogicalEdge(valueVertex, foldVertex, new LogicalEdge(EdgeShuffleType.SHUFFLE_BY_CONST));
        storeVertex = logicalSubQueryPlan.getOutputVertex();
    }
    storeVertex.enableStoreFlag();
    setFinishVertex(getInputNode().getOutputVertex(), treeNodeLabelManager);
    contextManager.addStoreVertex(sideEffectKey, storeVertex);
    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) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 42 with LogicalVertex

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

the class TraversalMapTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex delegateSourceVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(delegateSourceVertex);
    TreeNode currTraversalNode = TreeNodeUtils.buildSingleOutputNode(traversalNode, schema);
    LogicalSubQueryPlan traversalPlan = TreeNodeUtils.buildQueryPlanWithSource(currTraversalNode, labelManager, contextManager, vertexIdManager, delegateSourceVertex);
    logicalSubQueryPlan.mergeLogicalQueryPlan(traversalPlan);
    LogicalVertex outputVertex = logicalSubQueryPlan.getOutputVertex();
    addUsedLabelAndRequirement(outputVertex, labelManager);
    setFinishVertex(outputVertex, labelManager);
    return logicalSubQueryPlan;
}
Also used : LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 43 with LogicalVertex

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

the class AndTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex delegateSourceVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(delegateSourceVertex);
    LogicalVertex filterVertex = delegateSourceVertex;
    for (TreeNode andTreeNode : andTreeNodeList) {
        LogicalQueryPlan logicalQueryPlan = new LogicalQueryPlan(contextManager);
        logicalQueryPlan.addLogicalVertex(filterVertex);
        filterVertex = TreeNodeUtils.buildFilterTreeNode(andTreeNode, contextManager, logicalQueryPlan, filterVertex, schema);
        logicalSubQueryPlan.mergeLogicalQueryPlan(logicalQueryPlan);
    }
    LogicalVertex outputVertex = logicalSubQueryPlan.getOutputVertex();
    addUsedLabelAndRequirement(outputVertex, contextManager.getTreeNodeLabelManager());
    setFinishVertex(outputVertex, contextManager.getTreeNodeLabelManager());
    return logicalSubQueryPlan;
}
Also used : LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) LogicalQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 44 with LogicalVertex

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

the class BranchTreeNode method buildLogicalQueryPlan.

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

Example 45 with LogicalVertex

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

the class OutputVineyardTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    TreeNode inputNode = this.getInputNode();
    LogicalVertex inputVertex = inputNode.getOutputVertex();
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    logicalSubQueryPlan.addLogicalVertex(inputVertex);
    LogicalVertex vineyardVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.OUTPUT_VINEYARD_VERTEX, Message.Value.newBuilder().setStrValue(this.graphName)), inputVertex);
    logicalSubQueryPlan.addLogicalVertex(vineyardVertex);
    logicalSubQueryPlan.addLogicalEdge(inputVertex, vineyardVertex, LogicalEdge.shuffleByKey(0));
    LogicalVertex vineyardEdge = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.OUTPUT_VINEYARD_EDGE, Message.Value.newBuilder().setStrValue(this.graphName)), inputVertex);
    logicalSubQueryPlan.addLogicalVertex(vineyardEdge);
    logicalSubQueryPlan.addLogicalEdge(vineyardVertex, vineyardEdge, LogicalEdge.forwardEdge());
    LogicalVertex sumVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.SUM, Message.Value.newBuilder().setValueType(Message.VariantType.VT_LONG)), vineyardEdge);
    logicalSubQueryPlan.addLogicalVertex(sumVertex);
    logicalSubQueryPlan.addLogicalEdge(vineyardEdge, sumVertex, LogicalEdge.shuffleConstant());
    setFinishVertex(sumVertex, contextManager.getTreeNodeLabelManager());
    addUsedLabelAndRequirement(sumVertex, 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) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Aggregations

LogicalVertex (com.alibaba.maxgraph.compiler.logical.LogicalVertex)53 LogicalSubQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)41 ProcessorFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction)38 LogicalEdge (com.alibaba.maxgraph.compiler.logical.LogicalEdge)34 LogicalUnaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex)29 LogicalBinaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex)20 VertexIdManager (com.alibaba.maxgraph.compiler.logical.VertexIdManager)18 QueryFlowOuterClass (com.alibaba.maxgraph.QueryFlowOuterClass)13 SourceDelegateNode (com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)11 LogicalQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan)9 SourceTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode)9 Message (com.alibaba.maxgraph.Message)6 LogicalSourceDelegateVertex (com.alibaba.maxgraph.compiler.logical.LogicalSourceDelegateVertex)4 CountGlobalTreeNode (com.alibaba.maxgraph.compiler.tree.CountGlobalTreeNode)4 FoldTreeNode (com.alibaba.maxgraph.compiler.tree.FoldTreeNode)4 HasTreeNode (com.alibaba.maxgraph.compiler.tree.HasTreeNode)4 MaxTreeNode (com.alibaba.maxgraph.compiler.tree.MaxTreeNode)4 MinTreeNode (com.alibaba.maxgraph.compiler.tree.MinTreeNode)4 PropertyMapTreeNode (com.alibaba.maxgraph.compiler.tree.PropertyMapTreeNode)4 RangeGlobalTreeNode (com.alibaba.maxgraph.compiler.tree.RangeGlobalTreeNode)4