Search in sources :

Example 1 with CostModelManager

use of com.alibaba.maxgraph.compiler.cost.CostModelManager 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)

Example 2 with CostModelManager

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

the class MixedOpProcessor method buildCostPathList.

private List<String> buildCostPathList(GraphTraversal traversal) {
    TreeBuilder treeBuilder = TreeBuilder.newTreeBuilder(this.schemaFetcher.getSchemaSnapshotPair().getLeft(), new OptimizeConfig(), true);
    TreeManager treeManager = treeBuilder.build(traversal);
    treeManager.optimizeTree();
    CostModelManager costModelManager = treeManager.optimizeCostModel();
    List<CostPath> pathList = costModelManager.getPathList();
    if (pathList == null || pathList.isEmpty()) {
        return Lists.newArrayList();
    }
    return pathList.stream().map(CostPath::toString).collect(Collectors.toList());
}
Also used : TreeManager(com.alibaba.maxgraph.compiler.tree.TreeManager) CostModelManager(com.alibaba.maxgraph.compiler.cost.CostModelManager) CostPath(com.alibaba.maxgraph.compiler.cost.CostPath) TreeBuilder(com.alibaba.maxgraph.compiler.tree.TreeBuilder) OptimizeConfig(com.alibaba.maxgraph.compiler.optimizer.OptimizeConfig)

Example 3 with CostModelManager

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

the class LogicalPlanBuilder method build.

/**
 * Build logical plan from tree manager
 *
 * @param treeManager The given tree manager
 * @return The result logical plan
 */
public LogicalQueryPlan build(TreeManager treeManager) {
    CostModelManager costModelManager = treeManager.optimizeCostModel();
    TreeNodeLabelManager labelManager = treeManager.getLabelManager();
    VertexIdManager vertexIdManager = VertexIdManager.createVertexIdManager();
    ContextManager contextManager = new ContextManager(costModelManager, treeManager.getQueryConfig(), vertexIdManager, labelManager);
    TreeNode leafNode = treeManager.getTreeLeaf();
    return buildPlan(leafNode, contextManager, treeManager.getSchema());
}
Also used : TreeNodeLabelManager(com.alibaba.maxgraph.compiler.tree.TreeNodeLabelManager) BaseTreeNode(com.alibaba.maxgraph.compiler.tree.BaseTreeNode) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) TreeNode(com.alibaba.maxgraph.compiler.tree.TreeNode) ContextManager(com.alibaba.maxgraph.compiler.optimizer.ContextManager) CostModelManager(com.alibaba.maxgraph.compiler.cost.CostModelManager)

Example 4 with CostModelManager

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

the class TreeManager method optimizeCostModel.

public CostModelManager optimizeCostModel() {
    List<TreeNode> treeNodeList = TreeNodeUtils.buildTreeNodeListFromLeaf(this.getTreeLeaf());
    CostGraph costGraph = CostUtils.buildCostGraph(this.getTreeLeaf(), this.labelManager);
    NodeLabelManager nodeLabelManager = new NodeLabelManager();
    NodeLabelList previousNodeLabel = null;
    for (TreeNode treeNode : treeNodeList) {
        NodeLabelList nodeLabelList = NodeLabelList.buildNodeLabel(previousNodeLabel, treeNode, schema);
        nodeLabelManager.addNodeLabelList(nodeLabelList);
        previousNodeLabel = nodeLabelList;
    }
    int pathIndex = this.getQueryConfig().getInt(CompilerConstant.QUERY_COSTMODEL_PLAN_PATH, -1);
    List<CostPath> costPathList = costGraph.getCostPathList();
    CostPath useCostPath;
    if (pathIndex < 0 || pathIndex >= costPathList.size()) {
        CostDataStatistics costDataStatistics = CostDataStatistics.getInstance();
        List<Double> stepCountList = costDataStatistics.computeStepCountList(nodeLabelManager, treeNodeList);
        List<Double> shuffleThresholdList = Lists.newArrayList(1.0);
        for (int i = 1; i < stepCountList.size(); i++) {
            shuffleThresholdList.add(1.5);
        }
        useCostPath = costGraph.computePath(stepCountList, shuffleThresholdList);
    } else {
        useCostPath = costPathList.get(pathIndex);
        logger.info("Use specify cost path " + useCostPath.toString());
    }
    return new CostModelManager(costGraph, useCostPath);
}
Also used : NodeLabelManager(com.alibaba.maxgraph.compiler.cost.statistics.NodeLabelManager) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) SourceVertexTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceVertexTreeNode) CostDataStatistics(com.alibaba.maxgraph.compiler.cost.statistics.CostDataStatistics) NodeLabelList(com.alibaba.maxgraph.compiler.cost.statistics.NodeLabelList) CostModelManager(com.alibaba.maxgraph.compiler.cost.CostModelManager) CostGraph(com.alibaba.maxgraph.compiler.cost.CostGraph) CostPath(com.alibaba.maxgraph.compiler.cost.CostPath)

Aggregations

CostModelManager (com.alibaba.maxgraph.compiler.cost.CostModelManager)4 CostPath (com.alibaba.maxgraph.compiler.cost.CostPath)2 TreeNodeLabelManager (com.alibaba.maxgraph.compiler.tree.TreeNodeLabelManager)2 SourceTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode)2 CostGraph (com.alibaba.maxgraph.compiler.cost.CostGraph)1 CostMappingManager (com.alibaba.maxgraph.compiler.cost.CostMappingManager)1 RowField (com.alibaba.maxgraph.compiler.cost.RowField)1 RowFieldManager (com.alibaba.maxgraph.compiler.cost.RowFieldManager)1 CostDataStatistics (com.alibaba.maxgraph.compiler.cost.statistics.CostDataStatistics)1 NodeLabelList (com.alibaba.maxgraph.compiler.cost.statistics.NodeLabelList)1 NodeLabelManager (com.alibaba.maxgraph.compiler.cost.statistics.NodeLabelManager)1 ContextManager (com.alibaba.maxgraph.compiler.optimizer.ContextManager)1 OptimizeConfig (com.alibaba.maxgraph.compiler.optimizer.OptimizeConfig)1 BaseTreeNode (com.alibaba.maxgraph.compiler.tree.BaseTreeNode)1 TreeBuilder (com.alibaba.maxgraph.compiler.tree.TreeBuilder)1 TreeManager (com.alibaba.maxgraph.compiler.tree.TreeManager)1 TreeNode (com.alibaba.maxgraph.compiler.tree.TreeNode)1 SourceVertexTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceVertexTreeNode)1