Search in sources :

Example 6 with LogicalSubQueryPlan

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

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

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

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

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

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