Search in sources :

Example 66 with ProcessorFunction

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

the class UnfoldTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.UNFOLD, rangeLimit);
    return parseSingleUnaryVertex(vertexIdManager, labelManager, processorFunction, contextManager);
}
Also used : ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager)

Example 67 with ProcessorFunction

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

the class TreeNodeUtils method createSelectOneFunction.

/**
 * Build select function
 *
 * @param selectLabel The given label
 * @param pop The given pop
 * @param labelIndexList The given label index list
 * @return The select function
 */
public static ProcessorFunction createSelectOneFunction(String selectLabel, Pop pop, Map<String, Integer> labelIndexList) {
    boolean labelExist = labelIndexList.containsKey(selectLabel);
    Message.Value.Builder argumentBuilder = Message.Value.newBuilder().setBoolValue(labelExist).setIntValue(null == pop ? Message.PopType.POP_EMPTY.getNumber() : Message.PopType.valueOf(StringUtils.upperCase(pop.name())).getNumber()).addIntValueList(labelExist ? labelIndexList.get(selectLabel) : TreeConstants.MAGIC_LABEL_ID).setStrValue(selectLabel);
    ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.SELECT_ONE, argumentBuilder);
    processorFunction.getUsedLabelList().add(labelExist ? labelIndexList.get(selectLabel) : TreeConstants.MAGIC_LABEL_ID);
    return processorFunction;
}
Also used : ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction)

Example 68 with ProcessorFunction

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

the class TreeNodeUtils method buildSubQueryWithLabel.

/**
 * Build sub query plan, and save the result of sub plan to given label id
 *
 * @param treeNode The given tree node
 * @param sourceVertex The given source vertex
 * @param contextManager The given context manager
 * @return The result query plan and label id
 */
public static Pair<LogicalQueryPlan, Integer> buildSubQueryWithLabel(TreeNode treeNode, LogicalVertex sourceVertex, ContextManager contextManager) {
    boolean joinFlag = checkJoinSourceFlag(treeNode);
    List<TreeNode> treeNodeList = buildTreeNodeListFromLeaf(treeNode);
    LogicalQueryPlan queryPlan = new LogicalQueryPlan(contextManager);
    LogicalVertex originalVertex = null;
    LogicalVertex currentSourceVertex = sourceVertex;
    for (TreeNode currentNode : treeNodeList) {
        if (currentNode instanceof SourceDelegateNode) {
            queryPlan.addLogicalVertex(sourceVertex);
            if (joinFlag) {
                LogicalVertex enterKeyVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.ENTER_KEY, Message.Value.newBuilder().setPayload(QueryFlowOuterClass.EnterKeyArgumentProto.newBuilder().setEnterKeyType(QueryFlowOuterClass.EnterKeyTypeProto.KEY_SELF).setUniqFlag(true).build().toByteString())), false, currentSourceVertex);
                currentNode.setFinishVertex(enterKeyVertex, contextManager.getTreeNodeLabelManager());
                queryPlan.addLogicalVertex(enterKeyVertex);
                queryPlan.addLogicalEdge(sourceVertex, enterKeyVertex, new LogicalEdge());
                currentSourceVertex = enterKeyVertex;
                originalVertex = enterKeyVertex;
            } else {
                currentNode.setFinishVertex(sourceVertex, contextManager.getTreeNodeLabelManager());
                originalVertex = sourceVertex;
            }
        } else {
            queryPlan.mergeLogicalQueryPlan(currentNode.buildLogicalQueryPlan(contextManager));
        }
    }
    checkNotNull(originalVertex, "original vertex can't be null");
    LogicalVertex valueVertex = queryPlan.getOutputVertex();
    String valueLabel = contextManager.getTreeNodeLabelManager().createSysLabelStart("val");
    int valueLabelId = contextManager.getTreeNodeLabelManager().getLabelIndex(valueLabel);
    if (joinFlag) {
        LogicalVertex joinVertex;
        if (treeNode instanceof CountGlobalTreeNode || treeNode instanceof SumTreeNode) {
            joinVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_COUNT_LABEL, Message.Value.newBuilder().setIntValue(valueLabelId)), false, originalVertex, valueVertex);
        } else {
            joinVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_LABEL, Message.Value.newBuilder().setIntValue(valueLabelId)), false, originalVertex, valueVertex);
        }
        queryPlan.addLogicalVertex(joinVertex);
        queryPlan.addLogicalEdge(originalVertex, joinVertex, LogicalEdge.shuffleByKey(0));
        queryPlan.addLogicalEdge(valueVertex, joinVertex, LogicalEdge.forwardEdge());
    } else {
        LogicalVertex originalOutputVertex = queryPlan.getTargetVertex(originalVertex);
        String originalLabel = contextManager.getTreeNodeLabelManager().createBeforeSysLabelStart(originalOutputVertex, "original");
        ProcessorFunction selectFunction = createSelectOneFunction(originalLabel, Pop.first, contextManager.getTreeNodeLabelManager().getLabelIndexList());
        LogicalVertex selectVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), selectFunction, valueVertex);
        selectVertex.getBeforeRequirementList().add(QueryFlowOuterClass.RequirementValue.newBuilder().setReqType(QueryFlowOuterClass.RequirementType.LABEL_START).setReqArgument(Message.Value.newBuilder().addIntValueList(valueLabelId)));
        queryPlan.addLogicalVertex(selectVertex);
        queryPlan.addLogicalEdge(valueVertex, selectVertex, LogicalEdge.forwardEdge());
    }
    return Pair.of(queryPlan, valueLabelId);
}
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) CountGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.CountGlobalTreeNode) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) VertexTreeNode(com.alibaba.maxgraph.compiler.tree.VertexTreeNode) MaxTreeNode(com.alibaba.maxgraph.compiler.tree.MaxTreeNode) RangeGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.RangeGlobalTreeNode) FoldTreeNode(com.alibaba.maxgraph.compiler.tree.FoldTreeNode) TreeNode(com.alibaba.maxgraph.compiler.tree.TreeNode) TokenTreeNode(com.alibaba.maxgraph.compiler.tree.TokenTreeNode) MinTreeNode(com.alibaba.maxgraph.compiler.tree.MinTreeNode) CountGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.CountGlobalTreeNode) HasTreeNode(com.alibaba.maxgraph.compiler.tree.HasTreeNode) SelectOneTreeNode(com.alibaba.maxgraph.compiler.tree.SelectOneTreeNode) PropertyMapTreeNode(com.alibaba.maxgraph.compiler.tree.PropertyMapTreeNode) SumTreeNode(com.alibaba.maxgraph.compiler.tree.SumTreeNode) UnaryTreeNode(com.alibaba.maxgraph.compiler.tree.UnaryTreeNode) LogicalQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan) SumTreeNode(com.alibaba.maxgraph.compiler.tree.SumTreeNode)

Example 69 with ProcessorFunction

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

the class TreeNodeUtils method buildSubQueryPlan.

/**
 * Build sub query plan from given leaf tree node
 *
 * @param treeNode The given leaf tree node
 * @param sourceVertex The source vertex
 * @param contextManager The context manager
 * @param generateUseKey The flag of generated use key, it may be generated outside such as
 *     group
 * @return The query plan of sub query
 */
public static LogicalSubQueryPlan buildSubQueryPlan(TreeNode treeNode, LogicalVertex sourceVertex, ContextManager contextManager, boolean generateUseKey) {
    TreeNodeLabelManager treeNodeLabelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    List<TreeNode> treeNodeList = buildTreeNodeListFromLeaf(treeNode);
    boolean useKeyFlag = checkNodeListUseKey(treeNodeList);
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex currentSourceVertex = sourceVertex;
    for (TreeNode currentNode : treeNodeList) {
        if (currentNode instanceof AbstractUseKeyNode) {
            ((AbstractUseKeyNode) currentNode).enableUseKeyFlag(currentSourceVertex);
        }
        if (currentNode instanceof SourceDelegateNode) {
            if (useKeyFlag && generateUseKey) {
                LogicalVertex enterKeyVertex = new LogicalUnaryVertex(vertexIdManager.getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.ENTER_KEY, Message.Value.newBuilder().setPayload(QueryFlowOuterClass.EnterKeyArgumentProto.newBuilder().setEnterKeyType(QueryFlowOuterClass.EnterKeyTypeProto.KEY_SELF).setUniqFlag(true).build().toByteString())), false, currentSourceVertex);
                currentNode.setFinishVertex(enterKeyVertex, treeNodeLabelManager);
                logicalSubQueryPlan.addLogicalVertex(currentSourceVertex);
                logicalSubQueryPlan.addLogicalVertex(enterKeyVertex);
                logicalSubQueryPlan.addLogicalEdge(currentSourceVertex, enterKeyVertex, new LogicalEdge());
                currentSourceVertex = enterKeyVertex;
            } else {
                currentNode.setFinishVertex(currentSourceVertex, treeNodeLabelManager);
                logicalSubQueryPlan.addLogicalVertex(currentSourceVertex);
            }
        }
        logicalSubQueryPlan.mergeLogicalQueryPlan(currentNode.buildLogicalQueryPlan(contextManager));
    }
    return logicalSubQueryPlan;
}
Also used : TreeNodeLabelManager(com.alibaba.maxgraph.compiler.tree.TreeNodeLabelManager) 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) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) VertexTreeNode(com.alibaba.maxgraph.compiler.tree.VertexTreeNode) MaxTreeNode(com.alibaba.maxgraph.compiler.tree.MaxTreeNode) RangeGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.RangeGlobalTreeNode) FoldTreeNode(com.alibaba.maxgraph.compiler.tree.FoldTreeNode) TreeNode(com.alibaba.maxgraph.compiler.tree.TreeNode) TokenTreeNode(com.alibaba.maxgraph.compiler.tree.TokenTreeNode) MinTreeNode(com.alibaba.maxgraph.compiler.tree.MinTreeNode) CountGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.CountGlobalTreeNode) HasTreeNode(com.alibaba.maxgraph.compiler.tree.HasTreeNode) SelectOneTreeNode(com.alibaba.maxgraph.compiler.tree.SelectOneTreeNode) PropertyMapTreeNode(com.alibaba.maxgraph.compiler.tree.PropertyMapTreeNode) SumTreeNode(com.alibaba.maxgraph.compiler.tree.SumTreeNode) UnaryTreeNode(com.alibaba.maxgraph.compiler.tree.UnaryTreeNode) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan) AbstractUseKeyNode(com.alibaba.maxgraph.compiler.tree.addition.AbstractUseKeyNode)

Example 70 with ProcessorFunction

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

the class SourceCreateGraphTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalQueryPlan = new LogicalSubQueryPlan(contextManager);
    logicalQueryPlan.setDelegateSourceFlag(false);
    String graphType = configuration.getString(QUERY_CREATE_GRAPH_TYPE, null);
    if (StringUtils.isEmpty(graphType)) {
        throw new IllegalArgumentException("Graph type must be setted by g.createGraph(graphName).with('graphType'," + " '...')");
    }
    QueryFlowOuterClass.CreateGraphTypeProto createGraphType = QueryFlowOuterClass.CreateGraphTypeProto.valueOf(StringUtils.upperCase(graphType));
    if (createGraphType == QueryFlowOuterClass.CreateGraphTypeProto.VINEYARD) {
        QueryFlowOuterClass.RuntimeGraphSchemaProto schemaProto = CompilerUtils.buildRuntimeGraphSchema(schema);
        ProcessorSourceFunction createGraphFunction = new ProcessorSourceFunction(QueryFlowOuterClass.OperatorType.GRAPH_VINEYARD_BUILDER, Message.Value.newBuilder().setStrValue(graphName).setPayload(schemaProto.toByteString()), null);
        LogicalSourceVertex logicalSourceVertex = new LogicalSourceVertex(contextManager.getVertexIdManager().getId(), createGraphFunction);
        logicalQueryPlan.addLogicalVertex(logicalSourceVertex);
        ProcessorFunction streamFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.GRAPH_VINEYARD_STREAM, Message.Value.newBuilder().setStrValue(graphName));
        LogicalUnaryVertex vineyardStreamVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), streamFunction, logicalSourceVertex);
        logicalQueryPlan.addLogicalVertex(vineyardStreamVertex);
        logicalQueryPlan.addLogicalEdge(logicalSourceVertex, vineyardStreamVertex, LogicalEdge.shuffleConstant());
        setFinishVertex(logicalQueryPlan.getOutputVertex(), contextManager.getTreeNodeLabelManager());
        return logicalQueryPlan;
    } else {
        throw new IllegalArgumentException("Only support create vineyard graph yet");
    }
}
Also used : LogicalSourceVertex(com.alibaba.maxgraph.compiler.logical.LogicalSourceVertex) LogicalUnaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan) ProcessorSourceFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorSourceFunction)

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