Search in sources :

Example 36 with LogicalSubQueryPlan

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

the class SelectOneTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    Map<String, Integer> labelIndexList = labelManager.getLabelIndexList();
    ProcessorFunction selectOneFunction = TreeNodeUtils.createSelectOneFunction(selectLabel, pop, labelIndexList);
    LogicalSubQueryPlan logicalSubQueryPlan = parseSingleUnaryVertex(vertexIdManager, labelManager, selectOneFunction, contextManager, LogicalEdge.shuffleByKey(0), null == traversalTreeNode);
    if (null != traversalTreeNode && !contextManager.getCostModelManager().processFieldValue(selectLabel)) {
        LogicalSubQueryPlan traversalValuePlan = TreeNodeUtils.buildSubQueryPlan(traversalTreeNode, logicalSubQueryPlan.getOutputVertex(), contextManager);
        logicalSubQueryPlan.mergeLogicalQueryPlan(traversalValuePlan);
        LogicalVertex outputVertex = logicalSubQueryPlan.getOutputVertex();
        addUsedLabelAndRequirement(outputVertex, labelManager);
        setFinishVertex(outputVertex, labelManager);
    }
    return logicalSubQueryPlan;
}
Also used : ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 37 with LogicalSubQueryPlan

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

the class SelectTreeNode method parseJoinQueryPlan.

private LogicalSubQueryPlan parseJoinQueryPlan(ContextManager contextManager, VertexIdManager vertexIdManager, TreeNodeLabelManager labelManager, Map<String, Integer> labelIndexList) {
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex delegateSourceVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(delegateSourceVertex);
    Set<String> selectKeySet = Sets.newHashSet();
    List<Integer> keyIdList = Lists.newArrayList();
    List<Integer> valueIdList = Lists.newArrayList();
    for (int i = 0; i < selectKeyList.size(); i++) {
        String selectKey = selectKeyList.get(i);
        if (selectKeySet.contains(selectKey)) {
            continue;
        }
        selectKeySet.add(selectKey);
        TreeNode traversalTreeNode = traversalTreeNodeList.get(i % traversalTreeNodeList.size());
        int labelIndex = labelIndexList.get(selectKey);
        keyIdList.add(labelIndex);
        valueIdList.add(labelIndexList.get(selectKey));
        if (!(traversalTreeNode instanceof SourceDelegateNode)) {
            TreeNode currentTraversalNode = TreeNodeUtils.buildSingleOutputNode(traversalTreeNode, schema);
            LogicalVertex outputVertex = logicalSubQueryPlan.getOutputVertex();
            LogicalSubQueryPlan traversalPlan = TreeNodeUtils.buildSubQueryPlan(currentTraversalNode, outputVertex, contextManager);
            List<LogicalVertex> resultVertexList = traversalPlan.getLogicalVertexList();
            if (resultVertexList.size() == 2) {
                LogicalVertex fieldValueVertex = resultVertexList.get(1);
                ProcessorLabelValueFunction labelValueFunction = new ProcessorLabelValueFunction(labelIndex, fieldValueVertex);
                labelValueFunction.setRequireLabelFlag(true);
                LogicalVertex labelValueVertex = new LogicalUnaryVertex(vertexIdManager.getId(), labelValueFunction, outputVertex);
                logicalSubQueryPlan.addLogicalVertex(labelValueVertex);
                logicalSubQueryPlan.addLogicalEdge(outputVertex, labelValueVertex, LogicalEdge.shuffleByKey(labelIndex));
            } else {
                LogicalVertex fieldValueVertex = traversalPlan.getOutputVertex();
                fieldValueVertex.getAfterRequirementList().add(QueryFlowOuterClass.RequirementValue.newBuilder().setReqType(QueryFlowOuterClass.RequirementType.LABEL_START).setReqArgument(Message.Value.newBuilder().addIntValueList(labelIndex)));
                logicalSubQueryPlan.mergeLogicalQueryPlan(traversalPlan);
                LogicalVertex outputKeyVertex = new LogicalUnaryVertex(vertexIdManager.getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.KEY_MESSAGE), fieldValueVertex);
                logicalSubQueryPlan.addLogicalVertex(outputKeyVertex);
                logicalSubQueryPlan.addLogicalEdge(fieldValueVertex, outputKeyVertex, LogicalEdge.forwardEdge());
            }
        }
    }
    LogicalVertex selectInputVertex = logicalSubQueryPlan.getOutputVertex();
    Message.Value.Builder argumentBuilder = Message.Value.newBuilder().setBoolValue(true).setIntValue(pop == null ? Message.PopType.POP_EMPTY.getNumber() : Message.PopType.valueOf(StringUtils.upperCase(pop.name())).getNumber()).addAllIntValueList(valueIdList).addAllStrValueList(keyIdList.stream().map(labelManager::getLabelName).collect(Collectors.toList()));
    ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.SELECT, argumentBuilder);
    processorFunction.getUsedLabelList().addAll(valueIdList);
    LogicalVertex selectVertex = new LogicalUnaryVertex(vertexIdManager.getId(), processorFunction, false, selectInputVertex);
    logicalSubQueryPlan.addLogicalVertex(selectVertex);
    logicalSubQueryPlan.addLogicalEdge(selectInputVertex, selectVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
    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) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) ProcessorLabelValueFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorLabelValueFunction) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 38 with LogicalSubQueryPlan

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

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

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

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