• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

georgia-tech-db / eva / #844

31 Oct 2023 05:42AM UTC coverage: 0.0%. Remained the same
#844

push

circle-ci

Andy Xu
Fix typo

0 of 12389 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/evadb/optimizer/optimizer_context.py
1
# coding=utf-8
2
# Copyright 2018-2023 EvaDB
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
import copy
×
16

17
from evadb.constants import UNDEFINED_GROUP_ID
×
18
from evadb.database import EvaDBDatabase
×
19
from evadb.optimizer.cost_model import CostModel
×
20
from evadb.optimizer.group_expression import GroupExpression
×
21
from evadb.optimizer.memo import Memo
×
22
from evadb.optimizer.operators import Dummy, Operator
×
23
from evadb.optimizer.optimizer_task_stack import OptimizerTaskStack
×
24
from evadb.optimizer.rules.rules_manager import RulesManager
×
25

26

27
class OptimizerContext:
×
28
    """
29
    Maintain context information for the optimizer
30

31
    Arguments:
32
        _task_queue(OptimizerTaskStack):
33
            stack to keep track outstanding tasks
34
    """
35

36
    def __init__(
×
37
        self,
38
        db: EvaDBDatabase,
39
        cost_model: CostModel,
40
        rules_manager: RulesManager = None,
41
    ):
42
        self._db = db
×
43
        self._task_stack = OptimizerTaskStack()
×
44
        self._memo = Memo()
×
45
        self._cost_model = cost_model
×
46
        # check if ray is enabled
47
        is_ray_enabled = self.db.catalog().get_configuration_catalog_value("ray")
×
48
        self._rules_manager = rules_manager or RulesManager({"ray": is_ray_enabled})
×
49

50
    @property
×
51
    def db(self):
×
52
        return self._db
×
53

54
    @property
×
55
    def rules_manager(self):
×
56
        return self._rules_manager
×
57

58
    @property
×
59
    def cost_model(self):
×
60
        return self._cost_model
×
61

62
    @property
×
63
    def task_stack(self):
×
64
        return self._task_stack
×
65

66
    @property
×
67
    def memo(self):
×
68
        return self._memo
×
69

70
    def _xform_opr_to_group_expr(self, opr: Operator) -> GroupExpression:
×
71
        """
72
        Note: Internal function Generate a group expressions from a
73
        logical operator tree. Caller is responsible for assigning
74
        the group to the returned GroupExpression.
75
        """
76
        # Go through the children first.
77
        child_ids = []
×
78
        for child_opr in opr.children:
×
79
            if isinstance(child_opr, Dummy):
×
80
                child_ids.append(child_opr.group_id)
×
81
            else:
82
                child_expr = self._xform_opr_to_group_expr(opr=child_opr)
×
83
                # add the expr to memo
84
                # handles duplicates and assigns group id
85
                memo_expr = self.memo.add_group_expr(child_expr)
×
86
                child_ids.append(memo_expr.group_id)
×
87

88
        # Group Expression only needs the operator content. Remove
89
        # the opr children as parent-child relationship is captured
90
        # by the group expressions.
91
        # Hack: Shallow copy all the content except children and
92
        # manually clearing the children as we don't need the
93
        # dependency. Better fix is to rewrite the operator class to
94
        # support  exposing only the content
95
        opr_copy = copy.copy(opr)
×
96
        opr_copy.clear_children()
×
97
        expr = GroupExpression(opr=opr_copy, children=child_ids)
×
98
        return expr
×
99

100
    def replace_expression(self, opr: Operator, group_id: int):
×
101
        """
102
        Removes all the expressions from the specified group and
103
        create a new expression. This is called by rewrite rules. The
104
        new expr gets assigned a new group id
105
        """
106
        self.memo.erase_group(group_id)
×
107
        new_expr = self._xform_opr_to_group_expr(opr)
×
108
        new_expr = self.memo.add_group_expr(new_expr, group_id)
×
109
        return new_expr
×
110

111
    def add_opr_to_group(self, opr: Operator, group_id: int = UNDEFINED_GROUP_ID):
×
112
        """
113
        Convert operator to group_expression and add to the group
114
        """
115
        grp_expr = self._xform_opr_to_group_expr(opr)
×
116
        grp_expr = self.memo.add_group_expr(grp_expr, group_id)
×
117
        return grp_expr
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc