Search in sources :

Example 21 with SourceDelegateNode

use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.

the class GroupTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex sourceVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(sourceVertex);
    QueryFlowOuterClass.EnterKeyArgumentProto enterKeyArgumentProto = null;
    if (keyTreeNode == null || keyTreeNode instanceof SourceDelegateNode) {
        enterKeyArgumentProto = QueryFlowOuterClass.EnterKeyArgumentProto.newBuilder().setEnterKeyType(QueryFlowOuterClass.EnterKeyTypeProto.KEY_SELF).build();
    } else if (UnaryTreeNode.class.cast(keyTreeNode).getInputNode() instanceof SourceDelegateNode) {
        Optional<QueryFlowOuterClass.EnterKeyArgumentProto> propLabelId = TreeNodeUtils.parseEnterKeyArgument(keyTreeNode, schema, contextManager.getTreeNodeLabelManager());
        if (propLabelId.isPresent()) {
            enterKeyArgumentProto = propLabelId.get();
        }
    }
    if (null != enterKeyArgumentProto) {
        // use enter key operator to generate key data
        ProcessorFunction enterKeyFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.ENTER_KEY, Message.Value.newBuilder().setPayload(enterKeyArgumentProto.toByteString()));
        LogicalVertex enterKeyVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), enterKeyFunction, false, sourceVertex);
        enterKeyArgumentProto.getPropIdListList().forEach(v -> {
            if (v < 0) {
                enterKeyFunction.getUsedLabelList().add(v);
            }
        });
        if (enterKeyArgumentProto.getPropLabelId() < 0) {
            enterKeyFunction.getUsedLabelList().add(enterKeyArgumentProto.getPropLabelId());
        }
        logicalSubQueryPlan.addLogicalVertex(enterKeyVertex);
        logicalSubQueryPlan.addLogicalEdge(sourceVertex, enterKeyVertex, new LogicalEdge());
    } else {
        TreeNode currentKeyNode = TreeNodeUtils.buildSingleOutputNode(keyTreeNode, schema);
        LogicalSubQueryPlan keyQueryPlan = TreeNodeUtils.buildSubQueryPlan(currentKeyNode, sourceVertex, contextManager, true);
        LogicalVertex keyValueVertex = keyQueryPlan.getOutputVertex();
        logicalSubQueryPlan.mergeLogicalQueryPlan(keyQueryPlan);
        sourceVertex = TreeNodeUtils.getSourceTreeNode(keyTreeNode).getOutputVertex();
        if (sourceVertex.getProcessorFunction().getOperatorType() == QueryFlowOuterClass.OperatorType.ENTER_KEY) {
            ProcessorFunction joinKeyFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_RIGHT_VALUE_KEY);
            LogicalBinaryVertex joinKeyVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), joinKeyFunction, false, sourceVertex, keyValueVertex);
            logicalSubQueryPlan.addLogicalVertex(joinKeyVertex);
            logicalSubQueryPlan.addLogicalEdge(sourceVertex, joinKeyVertex, new LogicalEdge());
            logicalSubQueryPlan.addLogicalEdge(keyValueVertex, joinKeyVertex, new LogicalEdge());
        } else {
            String keyValueLabel = contextManager.getTreeNodeLabelManager().createSysLabelStart(keyValueVertex, "val");
            String sourceLabel = contextManager.getTreeNodeLabelManager().createSysLabelStart(sourceVertex, "source");
            ProcessorFunction selectSourceFunction = TreeNodeUtils.createSelectOneFunction(sourceLabel, Pop.first, contextManager.getTreeNodeLabelManager().getLabelIndexList());
            LogicalVertex selectVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), selectSourceFunction, false, keyValueVertex);
            logicalSubQueryPlan.addLogicalVertex(selectVertex);
            logicalSubQueryPlan.addLogicalEdge(keyValueVertex, selectVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
            int keyValueLabelId = contextManager.getTreeNodeLabelManager().getLabelIndex(keyValueLabel);
            ProcessorFunction enterKeyFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.ENTER_KEY, Message.Value.newBuilder().setPayload(QueryFlowOuterClass.EnterKeyArgumentProto.newBuilder().setEnterKeyType(QueryFlowOuterClass.EnterKeyTypeProto.KEY_PROP_LABEL).setUniqFlag(false).setPropLabelId(keyValueLabelId).build().toByteString()));
            enterKeyFunction.getUsedLabelList().add(keyValueLabelId);
            LogicalVertex enterKeyVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), enterKeyFunction, false, selectVertex);
            logicalSubQueryPlan.addLogicalVertex(enterKeyVertex);
            logicalSubQueryPlan.addLogicalEdge(selectVertex, enterKeyVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
        }
    }
    LogicalVertex outputVertex = logicalSubQueryPlan.getOutputVertex();
    LogicalSubQueryPlan aggregateQueryPlan = TreeNodeUtils.buildSubQueryPlan(valueTreeNode, outputVertex, contextManager, false);
    LogicalVertex aggregateVertex = aggregateQueryPlan.getOutputVertex();
    logicalSubQueryPlan.mergeLogicalQueryPlan(aggregateQueryPlan);
    // convert by key value to entry
    ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.BYKEY_ENTRY);
    LogicalVertex bykeyEntryVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), processorFunction, false, aggregateVertex);
    logicalSubQueryPlan.addLogicalVertex(bykeyEntryVertex);
    logicalSubQueryPlan.addLogicalEdge(aggregateVertex, bykeyEntryVertex, new LogicalEdge());
    outputVertex = logicalSubQueryPlan.getOutputVertex();
    ProcessorFunction foldMapFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.FOLDMAP);
    LogicalVertex foldMapVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), foldMapFunction, false, outputVertex);
    logicalSubQueryPlan.addLogicalVertex(foldMapVertex);
    logicalSubQueryPlan.addLogicalEdge(outputVertex, foldMapVertex, new LogicalEdge());
    addUsedLabelAndRequirement(foldMapVertex, contextManager.getTreeNodeLabelManager());
    setFinishVertex(foldMapVertex, contextManager.getTreeNodeLabelManager());
    return logicalSubQueryPlan;
}
Also used : LogicalUnaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) Optional(java.util.Optional) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 22 with SourceDelegateNode

use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.

the class DfsTraversal method buildDfsTree.

/**
 * Build bfs tree manager
 *
 * @param treeBuilder The tree builder
 * @param schema      The schema
 * @return The result tree managet
 */
public TreeManager buildDfsTree(TreeBuilder treeBuilder, GraphSchema schema) {
    TreeManager treeManager = treeBuilder.build(traversal);
    treeManager.optimizeTree();
    TreeNode currentNode = treeManager.getTreeLeaf();
    while (!(currentNode instanceof SourceTreeNode)) {
        if (currentNode.getNodeType() == NodeType.AGGREGATE) {
            throw new IllegalArgumentException("There's aggregate in the query and can'e be executed in bfs mode");
        }
        currentNode = UnaryTreeNode.class.cast(currentNode).getInputNode();
    }
    SourceDfsTreeNode sourceBfsTreeNode = new SourceDfsTreeNode(schema, batchSize);
    RepeatTreeNode repeatTreeNode = new RepeatTreeNode(sourceBfsTreeNode, schema, Maps.newHashMap());
    TreeNode sourceOutputNode = currentNode.getOutputNode();
    SourceDelegateNode repeatSourceTreeNode = new SourceDelegateNode(sourceBfsTreeNode, schema);
    DfsRepeatGraphTreeNode dfsRepeatGraphTreeNode = new DfsRepeatGraphTreeNode(repeatSourceTreeNode, SourceTreeNode.class.cast(currentNode), schema);
    if (null != sourceOutputNode) {
        UnaryTreeNode.class.cast(sourceOutputNode).setInputNode(dfsRepeatGraphTreeNode);
    } else {
        treeManager.setLeafNode(dfsRepeatGraphTreeNode);
    }
    TreeNode bodyLeafTreeNode = treeManager.getTreeLeaf();
    repeatTreeNode.setRepeatBodyTreeNode(bodyLeafTreeNode);
    repeatTreeNode.setEmitTreeNode(new SourceDelegateNode(bodyLeafTreeNode, schema));
    if (order) {
        OrderGlobalTreeNode orderTreeNode = new OrderGlobalTreeNode(new SourceDelegateNode(bodyLeafTreeNode, schema), schema, Lists.newArrayList(Pair.of(new SourceDelegateNode(bodyLeafTreeNode, schema), Order.asc)));
        repeatTreeNode.setDfsEmitTreeNode(orderTreeNode);
    }
    repeatTreeNode.setDfsFeedTreeNode(new DfsFinishTreeNode(new SourceDelegateNode(bodyLeafTreeNode, schema), schema, high));
    repeatTreeNode.setMaxLoopTimes(MAX_BFS_ITERATION_TIMES);
    RangeGlobalTreeNode rangeGlobalTreeNode = new RangeGlobalTreeNode(repeatTreeNode, schema, low, high);
    return new TreeManager(rangeGlobalTreeNode, schema, treeManager.getLabelManager(), treeManager.getQueryConfig());
}
Also used : SourceDfsTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceDfsTreeNode) DfsFinishTreeNode(com.alibaba.maxgraph.compiler.tree.DfsFinishTreeNode) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) SourceDfsTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceDfsTreeNode) DfsFinishTreeNode(com.alibaba.maxgraph.compiler.tree.DfsFinishTreeNode) RepeatTreeNode(com.alibaba.maxgraph.compiler.tree.RepeatTreeNode) OrderGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.OrderGlobalTreeNode) RangeGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.RangeGlobalTreeNode) UnaryTreeNode(com.alibaba.maxgraph.compiler.tree.UnaryTreeNode) DfsRepeatGraphTreeNode(com.alibaba.maxgraph.compiler.tree.DfsRepeatGraphTreeNode) TreeNode(com.alibaba.maxgraph.compiler.tree.TreeNode) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) RepeatTreeNode(com.alibaba.maxgraph.compiler.tree.RepeatTreeNode) TreeManager(com.alibaba.maxgraph.compiler.tree.TreeManager) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) OrderGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.OrderGlobalTreeNode) DfsRepeatGraphTreeNode(com.alibaba.maxgraph.compiler.tree.DfsRepeatGraphTreeNode) UnaryTreeNode(com.alibaba.maxgraph.compiler.tree.UnaryTreeNode) RangeGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.RangeGlobalTreeNode)

Example 23 with SourceDelegateNode

use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.

the class RepeatTreeNode method buildFilterResultPlan.

private LogicalVertex buildFilterResultPlan(ContextManager contextManager, VertexIdManager vertexIdManager, TreeNodeLabelManager labelManager, LogicalSubQueryPlan logicalSubQueryPlan, LogicalVertex delegateSourceVertex, TreeNode emitTreeNode) {
    TreeNode currentEmitTreeNode = TreeNodeUtils.buildSingleOutputNode(emitTreeNode, schema);
    LogicalSubQueryPlan untilPlan = TreeNodeUtils.buildSubQueryPlan(currentEmitTreeNode, delegateSourceVertex, contextManager);
    LogicalVertex enterKeyVertex = TreeNodeUtils.getSourceTreeNode(currentEmitTreeNode).getOutputVertex();
    LogicalVertex untilResultVertex = untilPlan.getOutputVertex();
    logicalSubQueryPlan.mergeLogicalQueryPlan(untilPlan);
    if (currentEmitTreeNode instanceof HasTreeNode && ((HasTreeNode) currentEmitTreeNode).getInputNode() instanceof SourceDelegateNode) {
        return untilResultVertex;
    } else {
        LogicalVertex currentOutputVertex = new LogicalBinaryVertex(vertexIdManager.getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_DIRECT_FILTER), false, enterKeyVertex, untilResultVertex);
        logicalSubQueryPlan.addLogicalVertex(currentOutputVertex);
        logicalSubQueryPlan.addLogicalEdge(enterKeyVertex, currentOutputVertex, new LogicalEdge());
        logicalSubQueryPlan.addLogicalEdge(untilResultVertex, currentOutputVertex, new LogicalEdge());
        return currentOutputVertex;
    }
}
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) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 24 with SourceDelegateNode

use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.

the class RepeatTreeNode 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);
    List<LogicalVertex> outputVertexList = Lists.newArrayList();
    LogicalVertex inputVertex = delegateSourceVertex;
    ProcessorRepeatFunction processorRepeatFunction = new ProcessorRepeatFunction();
    if (null != untilFirstTreeNode) {
        Pair<LogicalVertex, Pair<LogicalVertex, LogicalSubQueryPlan>> untilTable = buildUntilQueryPlan(untilTreeNode, delegateSourceVertex, labelManager, contextManager, vertexIdManager);
        outputVertexList.add(untilTable.getLeft());
        inputVertex = untilTable.getRight().getLeft();
        logicalSubQueryPlan.mergeLogicalQueryPlan(untilTable.getRight().getRight());
    }
    if (null != emitFirstTreeNode) {
        LogicalVertex emitVertex;
        if (emitFirstTreeNode instanceof SourceDelegateNode) {
            emitVertex = inputVertex;
        } else {
            emitVertex = buildFilterResultPlan(contextManager, vertexIdManager, labelManager, logicalSubQueryPlan, inputVertex, emitFirstTreeNode);
        }
        outputVertexList.add(emitVertex);
        processorRepeatFunction.enableEmitFlag();
    }
    checkArgument(null != repeatBodyTreeNode, "repeat body tree node can't be null");
    processorRepeatFunction.setMaxLoopTimes(maxLoopTimes);
    LogicalVertex repeatVertex = new LogicalUnaryVertex(vertexIdManager.getId(), processorRepeatFunction, false, inputVertex);
    logicalSubQueryPlan.addLogicalVertex(repeatVertex);
    logicalSubQueryPlan.addLogicalEdge(inputVertex, repeatVertex, new LogicalEdge());
    List<LogicalVertex> leaveVertexList = Lists.newArrayList();
    LogicalSubQueryPlan repeatBodyPlan = new LogicalSubQueryPlan(contextManager);
    LogicalSourceDelegateVertex repeatSourceVertex = new LogicalSourceDelegateVertex(inputVertex);
    repeatBodyPlan.addLogicalVertex(repeatSourceVertex);
    repeatBodyPlan.mergeLogicalQueryPlan(TreeNodeUtils.buildQueryPlanWithSource(repeatBodyTreeNode, labelManager, contextManager, vertexIdManager, repeatSourceVertex));
    LogicalVertex feedbackVertex = repeatBodyPlan.getOutputVertex();
    if (null != untilTreeNode) {
        Pair<LogicalVertex, Pair<LogicalVertex, LogicalSubQueryPlan>> untilTable = buildUntilQueryPlan(untilTreeNode, feedbackVertex, labelManager, contextManager, vertexIdManager);
        feedbackVertex = untilTable.getRight().getLeft();
        LogicalVertex untilVertex = untilTable.getLeft();
        untilVertex.getAfterRequirementList().add(QueryFlowOuterClass.RequirementValue.newBuilder().setReqType(QueryFlowOuterClass.RequirementType.KEY_DEL));
        leaveVertexList.add(untilVertex);
        repeatBodyPlan.mergeLogicalQueryPlan(untilTable.getRight().getRight());
    }
    if (null != emitTreeNode) {
        LogicalVertex emitVertex;
        if (emitTreeNode instanceof SourceDelegateNode) {
            emitVertex = feedbackVertex;
        } else {
            emitVertex = buildFilterResultPlan(contextManager, vertexIdManager, labelManager, repeatBodyPlan, feedbackVertex, emitTreeNode);
        }
        if (null != dfsEmitTreeNode) {
            repeatBodyPlan.mergeLogicalQueryPlan(TreeNodeUtils.buildQueryPlanWithSource(dfsEmitTreeNode, labelManager, contextManager, vertexIdManager, emitVertex));
            emitVertex = repeatBodyPlan.getOutputVertex();
        }
        leaveVertexList.add(emitVertex);
        processorRepeatFunction.enableEmitFlag();
    }
    if (null != dfsFeedTreeNode) {
        dfsFeedTreeNode.setRepeatSourceVertex(repeatBodyPlan.getTargetVertex(repeatSourceVertex));
        LogicalSubQueryPlan dfsQueryPlan = TreeNodeUtils.buildQueryPlanWithSource(dfsFeedTreeNode, labelManager, contextManager, vertexIdManager, feedbackVertex);
        feedbackVertex = dfsQueryPlan.getOutputVertex();
        repeatBodyPlan.mergeLogicalQueryPlan(dfsQueryPlan);
    }
    processorRepeatFunction.setEnterVertex(repeatBodyPlan.getTargetVertex(repeatSourceVertex));
    processorRepeatFunction.setFeedbackVertex(feedbackVertex);
    processorRepeatFunction.setRepeatPlan(repeatBodyPlan);
    if (!leaveVertexList.isEmpty()) {
        if (leaveVertexList.size() == 1) {
            processorRepeatFunction.setLeaveVertex(leaveVertexList.get(0));
        } else {
            LogicalVertex unionLeaveVertex = unionVertexList(vertexIdManager, repeatBodyPlan, leaveVertexList);
            processorRepeatFunction.setLeaveVertex(unionLeaveVertex);
        }
    }
    LogicalVertex outputVertex = repeatVertex;
    if (!outputVertexList.isEmpty()) {
        List<LogicalVertex> outputUnionVertexList = Lists.newArrayList(outputVertexList);
        outputUnionVertexList.add(repeatVertex);
        outputVertex = unionVertexList(vertexIdManager, logicalSubQueryPlan, outputUnionVertexList);
    }
    addUsedLabelAndRequirement(outputVertex, labelManager);
    setFinishVertex(outputVertex, labelManager);
    return logicalSubQueryPlan;
}
Also used : LogicalUnaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) LogicalSourceDelegateVertex(com.alibaba.maxgraph.compiler.logical.LogicalSourceDelegateVertex) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) ProcessorRepeatFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorRepeatFunction) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan) Pair(org.apache.commons.lang3.tuple.Pair)

Example 25 with SourceDelegateNode

use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode 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)

Aggregations

SourceDelegateNode (com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)38 SourceTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode)27 SourceVertexTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceVertexTreeNode)21 EstimateCountTreeNode (com.alibaba.maxgraph.compiler.tree.source.EstimateCountTreeNode)20 SourceCreateGraphTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceCreateGraphTreeNode)20 SourceEdgeTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceEdgeTreeNode)20 CustomAggregationListTraversal (com.alibaba.maxgraph.sdkcommon.compiler.custom.aggregate.CustomAggregationListTraversal)17 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)17 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)17 LogicalSubQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)11 LogicalVertex (com.alibaba.maxgraph.compiler.logical.LogicalVertex)11 LogicalEdge (com.alibaba.maxgraph.compiler.logical.LogicalEdge)10 ProcessorFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction)10 LogicalUnaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex)9 Pair (org.apache.commons.lang3.tuple.Pair)7 ValueType (com.alibaba.maxgraph.compiler.tree.value.ValueType)5 ValueValueType (com.alibaba.maxgraph.compiler.tree.value.ValueValueType)5 VertexValueType (com.alibaba.maxgraph.compiler.tree.value.VertexValueType)5 VertexIdManager (com.alibaba.maxgraph.compiler.logical.VertexIdManager)4 RangeGlobalTreeNode (com.alibaba.maxgraph.compiler.tree.RangeGlobalTreeNode)4