Search in sources :

Example 1 with ProcessorFunction

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

the class LogicalQueryPlan method checkVertexChain.

private boolean checkVertexChain(LogicalVertex sourceVertex, LogicalVertex targetVertex) {
    ProcessorFunction targetFunction = targetVertex.getProcessorFunction();
    QueryFlowOuterClass.OperatorType targetOperatorType = targetFunction.getOperatorType();
    if (sourceVertex instanceof LogicalSourceVertex) {
        if ((targetOperatorType == QueryFlowOuterClass.OperatorType.OUT || targetOperatorType == QueryFlowOuterClass.OperatorType.OUT_E) && targetVertex.getAfterRequirementList().isEmpty() && targetVertex.getBeforeRequirementList().isEmpty() && targetVertex.getProcessorFunction().getRangeLimit() == null && sourceVertex.getAfterRequirementList().isEmpty() && sourceVertex.getBeforeRequirementList().isEmpty() && sourceVertex.getProcessorFunction().getRangeLimit() == null && ((ProcessorSourceFunction) sourceVertex.getProcessorFunction()).getOdpsQueryInput() == null) {
            return true;
        }
    } else if (sourceVertex instanceof LogicalChainSourceVertex) {
        if ((targetOperatorType == QueryFlowOuterClass.OperatorType.IN_V || targetOperatorType == QueryFlowOuterClass.OperatorType.OUT_V || targetOperatorType == QueryFlowOuterClass.OperatorType.BOTH_V || targetOperatorType == QueryFlowOuterClass.OperatorType.OTHER_V) && targetVertex.getBeforeRequirementList().isEmpty() && targetVertex.getAfterRequirementList().isEmpty() && targetVertex.getProcessorFunction().getRangeLimit() == null) {
            return true;
        }
    }
    return false;
}
Also used : ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) LogicalChainSourceVertex(com.alibaba.maxgraph.compiler.logical.chain.LogicalChainSourceVertex) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) ProcessorSourceFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorSourceFunction)

Example 2 with ProcessorFunction

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

the class LogicalQueryPlan method optimizeKeyDelete.

private void optimizeKeyDelete() {
    List<LogicalVertex> logicalVertexList = this.getLogicalVertexList();
    for (int i = 0; i < logicalVertexList.size(); i++) {
        LogicalVertex logicalVertex = logicalVertexList.get(i);
        ProcessorFunction processorFunction = logicalVertex.getProcessorFunction();
        if (null != processorFunction) {
            if (logicalVertex instanceof LogicalBinaryVertex) {
                LogicalBinaryVertex binaryVertex = (LogicalBinaryVertex) logicalVertex;
                LogicalVertex leftVertex = binaryVertex.getLeftInput();
                if (leftVertex.getProcessorFunction().getOperatorType() == QueryFlowOuterClass.OperatorType.ENTER_KEY) {
                    if (((LogicalBinaryVertex) logicalVertex).containsAfterKeyDelete()) {
                        for (int k = i - 1; k >= 0; k--) {
                            LogicalVertex currentBinaryVertex = logicalVertexList.get(k);
                            if (currentBinaryVertex.getProcessorFunction().getOperatorType() == QueryFlowOuterClass.OperatorType.ENTER_KEY) {
                                if (currentBinaryVertex != leftVertex) {
                                    throw new IllegalArgumentException("Not support nest enter key");
                                }
                                break;
                            }
                            if (currentBinaryVertex instanceof LogicalBinaryVertex) {
                                ((LogicalBinaryVertex) currentBinaryVertex).removeAfterKeyDelete();
                            }
                        }
                    }
                } else {
                    binaryVertex.removeAfterKeyDelete();
                }
            } else {
                QueryFlowOuterClass.OperatorType operatorType = logicalVertex.getProcessorFunction().getOperatorType();
                if (operatorType == QueryFlowOuterClass.OperatorType.KEY_MESSAGE || operatorType == QueryFlowOuterClass.OperatorType.BYKEY_ENTRY) {
                    LogicalVertex currentKeyVertex = logicalVertex;
                    while (true) {
                        LogicalVertex currentSourceVertex = getSourceVertex(currentKeyVertex);
                        if (currentSourceVertex instanceof LogicalSourceVertex) {
                            break;
                        } else if (currentSourceVertex instanceof LogicalBinaryVertex) {
                            ((LogicalBinaryVertex) currentSourceVertex).removeAfterKeyDelete();
                            break;
                        } else {
                            currentKeyVertex = currentSourceVertex;
                        }
                    }
                }
            }
        }
    }
}
Also used : ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass)

Example 3 with ProcessorFunction

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

the class LogicalQueryPlan method optimizeFoldVertex.

private void optimizeFoldVertex() {
    List<LogicalVertex> logicalVertexList = getLogicalVertexList();
    Set<LogicalVertex> removeVertexList = Sets.newHashSet();
    for (LogicalVertex logicalVertex : logicalVertexList) {
        if (logicalVertex instanceof LogicalSourceDelegateVertex) {
            continue;
        }
        if (logicalVertex.getProcessorFunction().getOperatorType() == QueryFlowOuterClass.OperatorType.FOLD || logicalVertex.getProcessorFunction().getOperatorType() == QueryFlowOuterClass.OperatorType.FOLD_BY_KEY || logicalVertex.getProcessorFunction().getOperatorType() == QueryFlowOuterClass.OperatorType.FOLDMAP) {
            if (logicalVertex.getAfterRequirementList().isEmpty()) {
                List<LogicalVertex> targetVertexList = getTargetVertexList(logicalVertex);
                if (targetVertexList.size() == 1) {
                    LogicalVertex targetVertex = targetVertexList.get(0);
                    if (targetVertex.getBeforeRequirementList().isEmpty()) {
                        ProcessorFunction targetFunction = targetVertex.getProcessorFunction();
                        if (targetFunction.getOperatorType() == QueryFlowOuterClass.OperatorType.UNFOLD) {
                            LogicalVertex inputVertex = getSourceVertex(logicalVertex);
                            List<LogicalVertex> targetOutputList = getTargetVertexList(targetVertex);
                            if (targetOutputList.size() <= 1) {
                                inputVertex.getAfterRequirementList().addAll(logicalVertex.getBeforeRequirementList());
                                if (targetOutputList.size() == 1) {
                                    LogicalVertex targetOutputVertex = targetOutputList.get(0);
                                    targetOutputVertex.getBeforeRequirementList().addAll(targetVertex.getAfterRequirementList());
                                }
                                removeVertexList.add(logicalVertex);
                                removeVertexList.add(targetVertex);
                            }
                        }
                    }
                }
            }
        }
    }
    for (LogicalVertex removeVertex : removeVertexList) {
        removeVertex(removeVertex);
    }
}
Also used : ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction)

Example 4 with ProcessorFunction

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

the class OptionalTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex sourceVertex = getInputNode().getOutputVertex();
    logicalQueryPlan.addLogicalVertex(sourceVertex);
    LogicalVertex trueVertex = TreeNodeUtils.buildFilterTreeNode(this.branchTreeNode, contextManager, logicalQueryPlan, sourceVertex, schema);
    ProcessorFunction joinFilterRightFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_DIRECT_FILTER_NEGATE);
    LogicalEdge leftEdge = getInputNode().isPropLocalFlag() ? new LogicalEdge(EdgeShuffleType.FORWARD) : new LogicalEdge(EdgeShuffleType.SHUFFLE_BY_KEY);
    LogicalBinaryVertex falseVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), joinFilterRightFunction, getInputNode().isPropLocalFlag(), sourceVertex, trueVertex);
    logicalQueryPlan.addLogicalVertex(falseVertex);
    logicalQueryPlan.addLogicalEdge(sourceVertex, falseVertex, leftEdge);
    logicalQueryPlan.addLogicalEdge(trueVertex, falseVertex, new LogicalEdge(EdgeShuffleType.SHUFFLE_BY_KEY));
    LogicalQueryPlan truePlan = TreeNodeUtils.buildSubQueryPlan(this.trueNode, trueVertex, contextManager);
    LogicalVertex trueOutputVertex = truePlan.getOutputVertex();
    LogicalQueryPlan falsePlan = TreeNodeUtils.buildSubQueryPlan(this.falseNode, falseVertex, contextManager);
    LogicalVertex falseOutputVertex = falsePlan.getOutputVertex();
    logicalQueryPlan.mergeLogicalQueryPlan(truePlan);
    logicalQueryPlan.mergeLogicalQueryPlan(falsePlan);
    LogicalBinaryVertex unionVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.UNION), false, trueOutputVertex, falseOutputVertex);
    logicalQueryPlan.addLogicalVertex(unionVertex);
    logicalQueryPlan.addLogicalEdge(trueOutputVertex, unionVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
    logicalQueryPlan.addLogicalEdge(falseOutputVertex, unionVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
    setFinishVertex(unionVertex, contextManager.getTreeNodeLabelManager());
    addUsedLabelAndRequirement(unionVertex, contextManager.getTreeNodeLabelManager());
    return logicalQueryPlan;
}
Also used : LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) LogicalQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 5 with ProcessorFunction

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

the class OrderGlobalTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex delegateSourceVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(delegateSourceVertex);
    TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    Message.OrderComparatorList.Builder comparatorList = Message.OrderComparatorList.newBuilder();
    Set<String> propFillList = Sets.newHashSet();
    Set<Integer> usedLabelIdList = Sets.newHashSet();
    LogicalVertex lastJoinVertex = null;
    LogicalVertex inputVertex = delegateSourceVertex;
    for (int i = 0; i < treeNodeOrderList.size(); i++) {
        Pair<TreeNode, Order> orderPair = treeNodeOrderList.get(i);
        if (orderPair.getLeft() instanceof SourceDelegateNode) {
            comparatorList.addOrderComparator(Message.OrderComparator.newBuilder().setPropId(0).setOrderType(Message.OrderType.valueOf(StringUtils.upperCase(orderPair.getRight().name()))).build());
        } else {
            UnaryTreeNode unaryTreeNode = UnaryTreeNode.class.cast(orderPair.getLeft());
            if (unaryTreeNode.getInputNode() instanceof SourceDelegateNode && ((unaryTreeNode instanceof SelectOneTreeNode && SelectOneTreeNode.class.cast(unaryTreeNode).getTraversalTreeNode() == null) || (unaryTreeNode instanceof ElementValueTreeNode && ElementValueTreeNode.class.cast(unaryTreeNode).getByPassTraversal() == null) || unaryTreeNode instanceof TokenTreeNode || (unaryTreeNode instanceof TraversalMapTreeNode && ((TraversalMapTreeNode) unaryTreeNode).getTraversalNode() instanceof ColumnTreeNode && ((ColumnTreeNode) ((TraversalMapTreeNode) unaryTreeNode).getTraversalNode()).getInputNode() instanceof SourceDelegateNode))) {
                if (unaryTreeNode instanceof SelectOneTreeNode) {
                    int labelId = labelManager.getLabelIndex(SelectOneTreeNode.class.cast(unaryTreeNode).getSelectLabel());
                    comparatorList.addOrderComparator(Message.OrderComparator.newBuilder().setPropId(labelId).setOrderType(Message.OrderType.valueOf(StringUtils.upperCase(orderPair.getRight().name()))).build());
                    usedLabelIdList.add(labelId);
                } else if (unaryTreeNode instanceof TokenTreeNode) {
                    int labelId = labelManager.getLabelIndex(TokenTreeNode.class.cast(unaryTreeNode).getToken().getAccessor());
                    comparatorList.addOrderComparator(Message.OrderComparator.newBuilder().setPropId(labelId).setOrderType(Message.OrderType.valueOf(StringUtils.upperCase(orderPair.getRight().name()))).build());
                } else if (unaryTreeNode instanceof ElementValueTreeNode) {
                    String propKey = ElementValueTreeNode.class.cast(unaryTreeNode).getPropKeyList().iterator().next();
                    propFillList.add(propKey);
                    comparatorList.addOrderComparator(Message.OrderComparator.newBuilder().setPropId(CompilerUtils.getPropertyId(schema, propKey)).setOrderType(Message.OrderType.valueOf(StringUtils.upperCase(orderPair.getRight().name()))).build());
                } else {
                    TraversalMapTreeNode traversalMapTreeNode = TraversalMapTreeNode.class.cast(unaryTreeNode);
                    ColumnTreeNode columnTreeNode = (ColumnTreeNode) traversalMapTreeNode.getTraversalNode();
                    comparatorList.addOrderComparator(Message.OrderComparator.newBuilder().setPropId(labelManager.getLabelIndex(columnTreeNode.getColumn().name())).setOrderType(Message.OrderType.valueOf(StringUtils.upperCase(orderPair.getRight().name()))).build());
                }
            } else {
                TreeNode compareTreeNode = TreeNodeUtils.buildSingleOutputNode(orderPair.getLeft(), schema);
                Pair<LogicalQueryPlan, Integer> planLabelPair = TreeNodeUtils.buildSubQueryWithLabel(compareTreeNode, inputVertex, contextManager);
                inputVertex = planLabelPair.getLeft().getOutputVertex();
                logicalSubQueryPlan.mergeLogicalQueryPlan(planLabelPair.getLeft());
                comparatorList.addOrderComparator(Message.OrderComparator.newBuilder().setPropId(planLabelPair.getRight()).setOrderType(Message.OrderType.valueOf(StringUtils.upperCase(orderPair.getRight().name()))).build());
                usedLabelIdList.add(planLabelPair.getRight());
            }
        }
    }
    if (!propFillList.isEmpty() && getInputNode().getOutputValueType() instanceof VertexValueType) {
        LogicalVertex propFillInputVertex = logicalSubQueryPlan.getOutputVertex();
        ProcessorFunction propFillFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.PROP_FILL, Message.Value.newBuilder().addAllIntValueList(propFillList.stream().map(v -> CompilerUtils.getPropertyId(schema, v)).collect(Collectors.toSet())));
        LogicalVertex propFillVertex = new LogicalUnaryVertex(vertexIdManager.getId(), propFillFunction, true, propFillInputVertex);
        LogicalEdge logicalEdge;
        if (propFillInputVertex.isPropLocalFlag()) {
            logicalEdge = new LogicalEdge(EdgeShuffleType.FORWARD);
        } else {
            logicalEdge = new LogicalEdge(EdgeShuffleType.SHUFFLE_BY_KEY);
        }
        logicalSubQueryPlan.addLogicalVertex(propFillVertex);
        logicalSubQueryPlan.addLogicalEdge(propFillInputVertex, propFillVertex, logicalEdge);
    }
    Message.Value.Builder argumentBuilder = Message.Value.newBuilder().setPayload(comparatorList.build().toByteString());
    if (orderFlag) {
        argumentBuilder.setBoolValue(true).setIntValue(labelManager.getLabelIndex(orderFlagLabel));
    }
    argumentBuilder.setBoolFlag(partitionIdFlag).setLongValue(SHUFFLE_THRESHOLD).setOrderFlag(orderKeyFlag);
    ProcessorFunction orderFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.ORDER, argumentBuilder, rangeLimit);
    orderFunction.getUsedLabelList().addAll(usedLabelIdList);
    LogicalVertex outputVertex = logicalSubQueryPlan.getOutputVertex();
    LogicalVertex orderVertex = new LogicalUnaryVertex(vertexIdManager.getId(), orderFunction, false, outputVertex);
    logicalSubQueryPlan.addLogicalVertex(orderVertex);
    logicalSubQueryPlan.addLogicalEdge(outputVertex, orderVertex, new LogicalEdge());
    addUsedLabelAndRequirement(orderVertex, labelManager);
    setFinishVertex(orderVertex, labelManager);
    return logicalSubQueryPlan;
}
Also used : GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) LogicalQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan) EdgeShuffleType(com.alibaba.maxgraph.compiler.logical.edge.EdgeShuffleType) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) TreeNodeUtils(com.alibaba.maxgraph.compiler.utils.TreeNodeUtils) VertexValueType(com.alibaba.maxgraph.compiler.tree.value.VertexValueType) StringUtils(org.apache.commons.lang3.StringUtils) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) LogicalUnaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex) Pair(org.apache.commons.lang3.tuple.Pair) Order(org.apache.tinkerpop.gremlin.process.traversal.Order) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) CompilerUtils(com.alibaba.maxgraph.compiler.utils.CompilerUtils) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan) Set(java.util.Set) ContextManager(com.alibaba.maxgraph.compiler.optimizer.ContextManager) Message(com.alibaba.maxgraph.Message) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) ValueType(com.alibaba.maxgraph.compiler.tree.value.ValueType) AbstractUseKeyNode(com.alibaba.maxgraph.compiler.tree.addition.AbstractUseKeyNode) LogicalUnaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) LogicalQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan) Order(org.apache.tinkerpop.gremlin.process.traversal.Order) VertexValueType(com.alibaba.maxgraph.compiler.tree.value.VertexValueType) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)

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