1 | /* | |
2 | * Copyright OpenSearch Contributors | |
3 | * SPDX-License-Identifier: Apache-2.0 | |
4 | */ | |
5 | ||
6 | ||
7 | package org.opensearch.sql.planner; | |
8 | ||
9 | ||
10 | import java.util.List; | |
11 | import lombok.RequiredArgsConstructor; | |
12 | import org.opensearch.sql.planner.logical.LogicalPlan; | |
13 | import org.opensearch.sql.planner.logical.LogicalPlanNodeVisitor; | |
14 | import org.opensearch.sql.planner.logical.LogicalRelation; | |
15 | import org.opensearch.sql.planner.optimizer.LogicalPlanOptimizer; | |
16 | import org.opensearch.sql.planner.physical.PhysicalPlan; | |
17 | import org.opensearch.sql.storage.Table; | |
18 | ||
19 | /** | |
20 | * Planner that plans and chooses the optimal physical plan. | |
21 | */ | |
22 | @RequiredArgsConstructor | |
23 | public class Planner { | |
24 | ||
25 | private final LogicalPlanOptimizer logicalOptimizer; | |
26 | ||
27 | /** | |
28 | * Generate optimal physical plan for logical plan. If no table involved, | |
29 | * translate logical plan to physical by default implementor. | |
30 | * TODO: for now just delegate entire logical plan to storage engine. | |
31 | * | |
32 | * @param plan logical plan | |
33 | * @return optimal physical plan | |
34 | */ | |
35 | public PhysicalPlan plan(LogicalPlan plan) { | |
36 | Table table = findTable(plan); | |
37 |
1
1. plan : negated conditional → KILLED |
if (table == null) { |
38 |
1
1. plan : replaced return value with null for org/opensearch/sql/planner/Planner::plan → KILLED |
return plan.accept(new DefaultImplementor<>(), null); |
39 | } | |
40 |
1
1. plan : replaced return value with null for org/opensearch/sql/planner/Planner::plan → KILLED |
return table.implement( |
41 | table.optimize(optimize(plan))); | |
42 | } | |
43 | ||
44 | private Table findTable(LogicalPlan plan) { | |
45 |
1
1. findTable : replaced return value with null for org/opensearch/sql/planner/Planner::findTable → KILLED |
return plan.accept(new LogicalPlanNodeVisitor<Table, Object>() { |
46 | ||
47 | @Override | |
48 | public Table visitNode(LogicalPlan node, Object context) { | |
49 | List<LogicalPlan> children = node.getChild(); | |
50 |
1
1. visitNode : negated conditional → KILLED |
if (children.isEmpty()) { |
51 | return null; | |
52 | } | |
53 |
1
1. visitNode : replaced return value with null for org/opensearch/sql/planner/Planner$1::visitNode → KILLED |
return children.get(0).accept(this, context); |
54 | } | |
55 | ||
56 | @Override | |
57 | public Table visitRelation(LogicalRelation node, Object context) { | |
58 |
1
1. visitRelation : replaced return value with null for org/opensearch/sql/planner/Planner$1::visitRelation → KILLED |
return node.getTable(); |
59 | } | |
60 | ||
61 | }, null); | |
62 | } | |
63 | ||
64 | private LogicalPlan optimize(LogicalPlan plan) { | |
65 |
1
1. optimize : replaced return value with null for org/opensearch/sql/planner/Planner::optimize → KILLED |
return logicalOptimizer.optimize(plan); |
66 | } | |
67 | } | |
Mutations | ||
37 |
1.1 |
|
38 |
1.1 |
|
40 |
1.1 |
|
45 |
1.1 |
|
50 |
1.1 |
|
53 |
1.1 |
|
58 |
1.1 |
|
65 |
1.1 |