Search in sources :

Example 6 with VertexIdManager

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

the class SelectTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    Set<String> labelStartList = (Set<String>) this.beforeRequirementList.get(QueryFlowOuterClass.RequirementType.LABEL_START);
    if (!traversalTreeNodeList.isEmpty() && null != labelStartList && !labelStartList.isEmpty()) {
        for (int i = 0; i < selectKeyList.size(); i++) {
            String selectKey = selectKeyList.get(i);
            TreeNode selectTreeNode = traversalTreeNodeList.get(i % traversalTreeNodeList.size());
            if (!(selectTreeNode instanceof SourceDelegateNode)) {
                labelStartList.remove(selectKey);
            }
        }
    }
    if (null == labelStartList || labelStartList.isEmpty()) {
        this.beforeRequirementList.remove(QueryFlowOuterClass.RequirementType.LABEL_START);
    }
    if (!contextManager.getCostModelManager().hasBestPath()) {
        Map<String, Integer> labelIndexList = labelManager.getLabelIndexList();
        if (traversalTreeNodeList.isEmpty()) {
            Set<String> selectKeySet = Sets.newHashSet();
            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());
            List<Integer> selectKeyIdList = Lists.newArrayList();
            for (String selectKey : selectKeyList) {
                if (selectKeySet.contains(selectKey)) {
                    continue;
                }
                selectKeySet.add(selectKey);
                if (!labelIndexList.containsKey(selectKey)) {
                    argumentBuilder.setBoolValue(false);
                    break;
                }
                selectKeyIdList.add(labelIndexList.get(selectKey));
            }
            argumentBuilder.addAllIntValueList(selectKeyIdList).addAllStrValueList(selectKeyIdList.stream().map(v -> labelManager.getLabelName(v)).collect(Collectors.toList()));
            ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.SELECT, argumentBuilder);
            return parseSingleUnaryVertex(vertexIdManager, labelManager, processorFunction, contextManager);
        } else {
            LogicalSubQueryPlan logicalSubQueryPlan = parseJoinQueryPlan(contextManager, vertexIdManager, labelManager, labelIndexList);
            LogicalVertex outputVertex = logicalSubQueryPlan.getOutputVertex();
            addUsedLabelAndRequirement(outputVertex, labelManager);
            setFinishVertex(outputVertex, labelManager);
            return logicalSubQueryPlan;
        }
    } else {
        Map<String, Integer> labelIndexList = labelManager.getLabelIndexList();
        Set<String> selectKeySet = Sets.newHashSet();
        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());
        List<Integer> selectKeyIdList = Lists.newArrayList();
        for (String selectKey : selectKeyList) {
            if (selectKeySet.contains(selectKey)) {
                continue;
            }
            selectKeySet.add(selectKey);
            if (!labelIndexList.containsKey(selectKey)) {
                argumentBuilder.setBoolValue(false);
                break;
            }
            selectKeyIdList.add(labelIndexList.get(selectKey));
        }
        argumentBuilder.addAllIntValueList(selectKeyIdList).addAllStrValueList(selectKeyIdList.stream().map(v -> contextManager.getTreeNodeLabelManager().getLabelName(v)).collect(Collectors.toList()));
        ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.SELECT, argumentBuilder);
        return parseSingleUnaryVertex(contextManager.getVertexIdManager(), contextManager.getTreeNodeLabelManager(), processorFunction, contextManager);
    }
}
Also used : ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) Set(java.util.Set) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 7 with VertexIdManager

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

the class SimplePathTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    Message.Value.Builder argument = super.createArgumentBuilder();
    argument.setBoolValue(this.isSimple);
    ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.SIMPLE_PATH, argument);
    return parseSingleUnaryVertex(vertexIdManager, labelManager, processorFunction, contextManager);
}
Also used : ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager)

Example 8 with VertexIdManager

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

the class SubgraphTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    TreeNodeLabelManager treeNodeLabelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex sourceDelegateVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(sourceDelegateVertex);
    List<Integer> edgeLabelList = Lists.newArrayList();
    if (sourceDelegateVertex.getProcessorFunction().getOperatorType() == QueryFlowOuterClass.OperatorType.E) {
        Message.Value.Builder argumentBuilder = sourceDelegateVertex.getProcessorFunction().getArgumentBuilder();
        edgeLabelList.addAll(argumentBuilder.getIntValueListList());
    }
    Set<Integer> sourceVertexList = Sets.newHashSet();
    Set<Integer> targetVertexList = Sets.newHashSet();
    Message.SubgraphVertexList.Builder subgraphBuilder = Message.SubgraphVertexList.newBuilder();
    for (Integer edgeLabel : edgeLabelList) {
        GraphEdge edgeType = (GraphEdge) schema.getElement(edgeLabel);
        for (EdgeRelation relationShip : edgeType.getRelationList()) {
            sourceVertexList.add(relationShip.getSource().getLabelId());
            targetVertexList.add(relationShip.getTarget().getLabelId());
        }
    }
    if (sourceVertexList.isEmpty()) {
        schema.getVertexList().forEach(v -> {
            sourceVertexList.add(v.getLabelId());
            targetVertexList.add(v.getLabelId());
        });
    }
    subgraphBuilder.addAllSourceVertexList(sourceVertexList).addAllTargetVertexList(targetVertexList);
    ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.SUBGRAPH, Message.Value.newBuilder().setBoolFlag(this.vertexFlag).setPayload(subgraphBuilder.build().toByteString()));
    LogicalVertex graphVertex = new LogicalUnaryVertex(vertexIdManager.getId(), processorFunction, false, sourceDelegateVertex);
    logicalSubQueryPlan.addLogicalVertex(graphVertex);
    logicalSubQueryPlan.addLogicalEdge(sourceDelegateVertex, graphVertex, new LogicalEdge());
    setFinishVertex(graphVertex, treeNodeLabelManager);
    addUsedLabelAndRequirement(graphVertex, treeNodeLabelManager);
    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) EdgeRelation(com.alibaba.maxgraph.compiler.api.schema.EdgeRelation) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) GraphEdge(com.alibaba.maxgraph.compiler.api.schema.GraphEdge) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 9 with VertexIdManager

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

the class SumTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    QueryFlowOuterClass.OperatorType operatorType = getUseKeyOperator(QueryFlowOuterClass.OperatorType.SUM);
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex sourceVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(sourceVertex);
    ValueValueType valueValueType = ValueValueType.class.cast(getInputNode().getOutputValueType());
    ProcessorFunction combinerSumFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.COMBINER_SUM, Message.Value.newBuilder().setValueType(valueValueType.getDataType()));
    LogicalVertex combinerSumVertex = new LogicalUnaryVertex(vertexIdManager.getId(), combinerSumFunction, isPropLocalFlag(), sourceVertex);
    logicalSubQueryPlan.addLogicalVertex(combinerSumVertex);
    logicalSubQueryPlan.addLogicalEdge(sourceVertex, combinerSumVertex, LogicalEdge.forwardEdge());
    ProcessorFunction sumFunction = new ProcessorFunction(operatorType, Message.Value.newBuilder().setValueType(valueValueType.getDataType()));
    LogicalVertex sumVertex = new LogicalUnaryVertex(vertexIdManager.getId(), sumFunction, isPropLocalFlag(), combinerSumVertex);
    logicalSubQueryPlan.addLogicalVertex(sumVertex);
    logicalSubQueryPlan.addLogicalEdge(combinerSumVertex, sumVertex, new LogicalEdge());
    LogicalVertex outputVertex = processJoinZeroVertex(vertexIdManager, logicalSubQueryPlan, sumVertex, isJoinZeroFlag());
    setFinishVertex(outputVertex, labelManager);
    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) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) ValueValueType(com.alibaba.maxgraph.compiler.tree.value.ValueValueType) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 10 with VertexIdManager

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

the class TraversalFilterTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    if (filterTreeNode instanceof SourceTreeNode) {
        throw new IllegalArgumentException();
    } else {
        LogicalVertex sourceVertex = getInputNode().getOutputVertex();
        LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
        logicalSubQueryPlan.addLogicalVertex(sourceVertex);
        LogicalVertex outputVertex = TreeNodeUtils.buildFilterTreeNode(this.filterTreeNode, contextManager, logicalSubQueryPlan, sourceVertex, schema);
        addUsedLabelAndRequirement(outputVertex, labelManager);
        setFinishVertex(outputVertex, labelManager);
        return logicalSubQueryPlan;
    }
}
Also used : LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) 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