Search in sources :

Example 1 with RowFieldManager

use of com.alibaba.maxgraph.compiler.cost.RowFieldManager in project GraphScope by alibaba.

the class LogicalPlanBuilder method processCostModel.

private void processCostModel(TreeNode currentNode, LogicalQueryPlan queryPlan, ContextManager contextManager, GraphSchema schema, Set<Integer> labelIdList) {
    CostModelManager costModelManager = contextManager.getCostModelManager();
    TreeNodeLabelManager treeNodeLabelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    if (costModelManager.hasBestPath()) {
        CostMappingManager costMappingManager = costModelManager.getCostMappingManager();
        RowFieldManager rowFieldManager = costModelManager.getPathFieldManager();
        if (null == rowFieldManager) {
            return;
        }
        RowField rowField = rowFieldManager.getRowField();
        Set<String> birthFieldList = rowFieldManager.getBirthFieldList();
        Set<String> fieldList = rowField.getFieldList();
        for (String field : fieldList) {
            LogicalVertex outputVertex = queryPlan.getOutputVertex();
            if (birthFieldList.contains(field)) {
                buildLabelValuePlan(queryPlan, contextManager, schema, outputVertex, treeNodeLabelManager, vertexIdManager, costMappingManager, field, currentNode);
            } else {
                RowFieldManager parentFieldManager = rowFieldManager.getParent();
                if (!parentFieldManager.getRowField().getFieldList().contains(field)) {
                    buildLabelValuePlan(queryPlan, contextManager, schema, outputVertex, treeNodeLabelManager, vertexIdManager, costMappingManager, field, currentNode);
                }
            }
        }
        currentNode.setFinishVertex(queryPlan.getOutputVertex(), null);
    }
    List<LogicalVertex> logicalVertexList = queryPlan.getLogicalVertexList();
    for (LogicalVertex vertex : logicalVertexList) {
        if (vertex.getProcessorFunction() != null && vertex.getProcessorFunction().getOperatorType() == QueryFlowOuterClass.OperatorType.LABEL_VALUE) {
            if (vertex.getProcessorFunction().getArgumentBuilder().getIntValue() != 0) {
                labelIdList.add(vertex.getProcessorFunction().getArgumentBuilder().getIntValue());
            }
        } else {
            vertex.getBeforeRequirementList().removeIf(vv -> {
                if (vv.getReqType() == QueryFlowOuterClass.RequirementType.LABEL_START) {
                    List<Integer> intValueList = Lists.newArrayList(vv.getReqArgument().getIntValueListList());
                    intValueList.removeIf(labelIdList::contains);
                    if (intValueList.isEmpty()) {
                        return true;
                    }
                    vv.getReqArgumentBuilder().clearIntValueList().addAllIntValueList(intValueList);
                }
                return false;
            });
        }
    }
}
Also used : TreeNodeLabelManager(com.alibaba.maxgraph.compiler.tree.TreeNodeLabelManager) CostMappingManager(com.alibaba.maxgraph.compiler.cost.CostMappingManager) RowFieldManager(com.alibaba.maxgraph.compiler.cost.RowFieldManager) CostModelManager(com.alibaba.maxgraph.compiler.cost.CostModelManager) RowField(com.alibaba.maxgraph.compiler.cost.RowField)

Aggregations

CostMappingManager (com.alibaba.maxgraph.compiler.cost.CostMappingManager)1 CostModelManager (com.alibaba.maxgraph.compiler.cost.CostModelManager)1 RowField (com.alibaba.maxgraph.compiler.cost.RowField)1 RowFieldManager (com.alibaba.maxgraph.compiler.cost.RowFieldManager)1 TreeNodeLabelManager (com.alibaba.maxgraph.compiler.tree.TreeNodeLabelManager)1