Search in sources :

Example 11 with ProcessorFunction

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

the class CountGlobalTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex sourceVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(sourceVertex);
    QueryFlowOuterClass.OperatorType operatorType = getUseKeyOperator(QueryFlowOuterClass.OperatorType.COUNT);
    QueryFlowOuterClass.CountArgumentProto countArgument = QueryFlowOuterClass.CountArgumentProto.newBuilder().setLimitFlag(limitFlag).setLimitCount(limitCount).build();
    ProcessorFunction countFunction = new ProcessorFunction(operatorType, Message.Value.newBuilder().setPayload(countArgument.toByteString()));
    LogicalUnaryVertex countVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), countFunction, false, sourceVertex);
    logicalSubQueryPlan.addLogicalVertex(countVertex);
    logicalSubQueryPlan.addLogicalEdge(sourceVertex, countVertex, new LogicalEdge());
    LogicalVertex outputVertex = processJoinZeroVertex(contextManager.getVertexIdManager(), logicalSubQueryPlan, countVertex, isJoinZeroFlag());
    setFinishVertex(outputVertex, 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) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 12 with ProcessorFunction

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

the class DedupGlobalTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex sourceVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(sourceVertex);
    QueryFlowOuterClass.OperatorType dedupType = getUseKeyOperator(QueryFlowOuterClass.OperatorType.DEDUP);
    if (null == dedupTreeNode || dedupTreeNode instanceof SourceDelegateNode) {
        ProcessorFunction dedupFunction = new ProcessorFunction(dedupType);
        LogicalVertex dedupVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), dedupFunction, isPropLocalFlag(), sourceVertex);
        logicalSubQueryPlan.addLogicalVertex(dedupVertex);
        logicalSubQueryPlan.addLogicalEdge(sourceVertex, dedupVertex, new LogicalEdge());
    } else {
        UnaryTreeNode unaryDedupTreeNode = UnaryTreeNode.class.cast(dedupTreeNode);
        if (unaryDedupTreeNode.getInputNode() instanceof SourceDelegateNode && ((unaryDedupTreeNode instanceof ElementValueTreeNode && ElementValueTreeNode.class.cast(unaryDedupTreeNode).getByPassTraversal() == null) || unaryDedupTreeNode instanceof SelectOneTreeNode || unaryDedupTreeNode instanceof TokenTreeNode)) {
            // id()/label() has been converted to select one tree node
            Message.Value.Builder argumentBuilder = Message.Value.newBuilder();
            Set<Integer> usedLabelList = Sets.newHashSet();
            if (unaryDedupTreeNode instanceof ElementValueTreeNode) {
                String propKey = ((ElementValueTreeNode) unaryDedupTreeNode).getPropKeyList().iterator().next();
                int propId = SchemaUtils.getPropId(propKey, schema);
                argumentBuilder.setIntValue(propId);
            } else if (unaryDedupTreeNode instanceof TokenTreeNode) {
                T token = ((TokenTreeNode) unaryDedupTreeNode).getToken();
                argumentBuilder.setIntValue(contextManager.getTreeNodeLabelManager().getLabelIndex(token.getAccessor()));
            } else {
                String label = ((SelectOneTreeNode) unaryDedupTreeNode).getSelectLabel();
                argumentBuilder.setIntValue(contextManager.getTreeNodeLabelManager().getLabelIndex(label));
                usedLabelList.add(contextManager.getTreeNodeLabelManager().getLabelIndex(label));
            }
            ProcessorFunction dedupFunction = new ProcessorFunction(dedupType, argumentBuilder);
            LogicalVertex dedupVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), dedupFunction, isPropLocalFlag(), sourceVertex);
            logicalSubQueryPlan.addLogicalVertex(dedupVertex);
            logicalSubQueryPlan.addLogicalEdge(sourceVertex, dedupVertex, new LogicalEdge());
        } else {
            TreeNode currentDedupNode = TreeNodeUtils.buildSingleOutputNode(dedupTreeNode, schema);
            Pair<LogicalQueryPlan, Integer> planLabelPair = TreeNodeUtils.buildSubQueryWithLabel(currentDedupNode, sourceVertex, contextManager);
            logicalSubQueryPlan.mergeLogicalQueryPlan(planLabelPair.getLeft());
            LogicalVertex dedupInputVertex = logicalSubQueryPlan.getOutputVertex();
            ProcessorFunction dedupFunction = new ProcessorFunction(dedupType, Message.Value.newBuilder().setIntValue(planLabelPair.getRight()));
            dedupFunction.getUsedLabelList().add(planLabelPair.getRight());
            LogicalVertex dedupVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), dedupFunction, isPropLocalFlag(), dedupInputVertex);
            logicalSubQueryPlan.addLogicalVertex(dedupVertex);
            logicalSubQueryPlan.addLogicalEdge(dedupInputVertex, dedupVertex, new LogicalEdge());
        }
    }
    LogicalVertex dedupVertex = logicalSubQueryPlan.getOutputVertex();
    addUsedLabelAndRequirement(dedupVertex, contextManager.getTreeNodeLabelManager());
    setFinishVertex(dedupVertex, 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) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) T(org.apache.tinkerpop.gremlin.structure.T) LogicalQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 13 with ProcessorFunction

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

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

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

Aggregations

ProcessorFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction)71 LogicalVertex (com.alibaba.maxgraph.compiler.logical.LogicalVertex)38 LogicalEdge (com.alibaba.maxgraph.compiler.logical.LogicalEdge)36 LogicalSubQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)34 VertexIdManager (com.alibaba.maxgraph.compiler.logical.VertexIdManager)34 LogicalUnaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex)27 QueryFlowOuterClass (com.alibaba.maxgraph.QueryFlowOuterClass)18 LogicalBinaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex)18 SourceDelegateNode (com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)10 SourceTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode)9 Message (com.alibaba.maxgraph.Message)7 LogicalQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan)7 TreeNode (com.alibaba.maxgraph.compiler.tree.TreeNode)5 List (java.util.List)5 ProcessorSourceFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorSourceFunction)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