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

georgia-tech-db / eva / #758

04 Sep 2023 08:37PM UTC coverage: 0.0% (-78.3%) from 78.333%
#758

push

circle-ci

hershd23
Increased underline length in at line 75 in text_summarization.rst
	modified:   docs/source/benchmarks/text_summarization.rst

0 of 11303 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
        self._rules_manager = rules_manager or RulesManager(db.config)
×
47

48
    @property
×
49
    def db(self):
×
50
        return self._db
×
51

52
    @property
×
53
    def rules_manager(self):
×
54
        return self._rules_manager
×
55

56
    @property
×
57
    def cost_model(self):
×
58
        return self._cost_model
×
59

60
    @property
×
61
    def task_stack(self):
×
62
        return self._task_stack
×
63

64
    @property
×
65
    def memo(self):
×
66
        return self._memo
×
67

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

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

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

109
    def add_opr_to_group(self, opr: Operator, group_id: int = UNDEFINED_GROUP_ID):
×
110
        """
111
        Convert operator to group_expression and add to the group
112
        """
113
        grp_expr = self._xform_opr_to_group_expr(opr)
×
114
        grp_expr = self.memo.add_group_expr(grp_expr, group_id)
×
115
        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

© 2025 Coveralls, Inc