• 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/rules/rules_manager.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
from __future__ import annotations
×
16

17
from contextlib import contextmanager
×
18
from typing import List
×
19

20
from evadb.configuration.configuration_manager import ConfigurationManager
×
21
from evadb.optimizer.rules.rules import (
×
22
    CacheFunctionExpressionInApply,
23
    CacheFunctionExpressionInFilter,
24
    CacheFunctionExpressionInProject,
25
    CombineSimilarityOrderByAndLimitToVectorIndexScan,
26
    EmbedFilterIntoGet,
27
    EmbedSampleIntoGet,
28
    LogicalApplyAndMergeToPhysical,
29
    LogicalApplyAndMergeToRayPhysical,
30
    LogicalCreateFromSelectToPhysical,
31
    LogicalCreateIndexToVectorIndex,
32
    LogicalCreateToPhysical,
33
    LogicalCreateUDFFromSelectToPhysical,
34
    LogicalCreateUDFToPhysical,
35
    LogicalDeleteToPhysical,
36
    LogicalDerivedGetToPhysical,
37
    LogicalDropObjectToPhysical,
38
    LogicalExchangeToPhysical,
39
    LogicalExplainToPhysical,
40
    LogicalFilterToPhysical,
41
    LogicalFunctionScanToPhysical,
42
    LogicalGetToSeqScan,
43
    LogicalGroupByToPhysical,
44
    LogicalInnerJoinCommutativity,
45
    LogicalInsertToPhysical,
46
    LogicalJoinToPhysicalHashJoin,
47
    LogicalJoinToPhysicalNestedLoopJoin,
48
    LogicalLateralJoinToPhysical,
49
    LogicalLimitToPhysical,
50
    LogicalLoadToPhysical,
51
    LogicalOrderByToPhysical,
52
    LogicalProjectToPhysical,
53
    LogicalProjectToRayPhysical,
54
    LogicalRenameToPhysical,
55
    LogicalShowToPhysical,
56
    LogicalUnionToPhysical,
57
    LogicalVectorIndexScanToPhysical,
58
    PushDownFilterThroughApplyAndMerge,
59
    PushDownFilterThroughJoin,
60
    ReorderPredicates,
61
    XformExtractObjectToLinearFlow,
62
    XformLateralJoinToLinearFlow,
63
)
64
from evadb.optimizer.rules.rules_base import Rule
×
65
from evadb.utils.generic_utils import is_ray_enabled_and_installed
×
66

67

68
class RulesManager:
×
69
    def __init__(self, config: ConfigurationManager):
×
70
        self._logical_rules = [
×
71
            LogicalInnerJoinCommutativity(),
72
            CacheFunctionExpressionInApply(),
73
            CacheFunctionExpressionInFilter(),
74
            CacheFunctionExpressionInProject(),
75
        ]
76

77
        self._stage_one_rewrite_rules = [
×
78
            XformLateralJoinToLinearFlow(),
79
            XformExtractObjectToLinearFlow(),
80
        ]
81

82
        self._stage_two_rewrite_rules = [
×
83
            EmbedFilterIntoGet(),
84
            # EmbedFilterIntoDerivedGet(),
85
            EmbedSampleIntoGet(),
86
            PushDownFilterThroughJoin(),
87
            PushDownFilterThroughApplyAndMerge(),
88
            CombineSimilarityOrderByAndLimitToVectorIndexScan(),
89
            ReorderPredicates(),
90
        ]
91

92
        self._implementation_rules = [
×
93
            LogicalCreateToPhysical(),
94
            LogicalCreateFromSelectToPhysical(),
95
            LogicalRenameToPhysical(),
96
            LogicalCreateUDFToPhysical(),
97
            LogicalCreateUDFFromSelectToPhysical(),
98
            LogicalDropObjectToPhysical(),
99
            LogicalInsertToPhysical(),
100
            LogicalDeleteToPhysical(),
101
            LogicalLoadToPhysical(),
102
            LogicalGetToSeqScan(),
103
            LogicalDerivedGetToPhysical(),
104
            LogicalUnionToPhysical(),
105
            LogicalGroupByToPhysical(),
106
            LogicalOrderByToPhysical(),
107
            LogicalLimitToPhysical(),
108
            LogicalJoinToPhysicalNestedLoopJoin(),
109
            LogicalLateralJoinToPhysical(),
110
            LogicalJoinToPhysicalHashJoin(),
111
            LogicalFunctionScanToPhysical(),
112
            LogicalFilterToPhysical(),
113
            LogicalShowToPhysical(),
114
            LogicalExplainToPhysical(),
115
            LogicalCreateIndexToVectorIndex(),
116
            LogicalVectorIndexScanToPhysical(),
117
        ]
118

119
        # These rules are enabled only if
120
        # (1) ray is installed and (2) ray is enabled
121
        # Ray must be installed using pip
122
        # It must also be enabled in "evadb.yml"
123
        # NOTE: By default, it is not enabled
124
        ray_enabled = config.get_value("experimental", "ray")
×
125
        if is_ray_enabled_and_installed(ray_enabled):
×
126
            self._implementation_rules.extend(
×
127
                [
128
                    LogicalExchangeToPhysical(),
129
                    LogicalApplyAndMergeToRayPhysical(),
130
                    LogicalProjectToRayPhysical(),
131
                ]
132
            )
133
        else:
134
            self._implementation_rules.extend(
×
135
                [LogicalApplyAndMergeToPhysical(), LogicalProjectToPhysical()]
136
            )
137
        self._all_rules = (
×
138
            self._stage_one_rewrite_rules
139
            + self._stage_two_rewrite_rules
140
            + self._logical_rules
141
            + self._implementation_rules
142
        )
143

144
    @property
×
145
    def stage_one_rewrite_rules(self):
×
146
        return self._stage_one_rewrite_rules
×
147

148
    @property
×
149
    def stage_two_rewrite_rules(self):
×
150
        return self._stage_two_rewrite_rules
×
151

152
    @property
×
153
    def implementation_rules(self):
×
154
        return self._implementation_rules
×
155

156
    @property
×
157
    def logical_rules(self):
×
158
        return self._logical_rules
×
159

160
    def disable_rules(self, rules: List[Rule]):
×
161
        def _remove_from_list(rule_list, rule_to_remove):
×
162
            for rule in rule_list:
×
163
                if rule.rule_type == rule_to_remove.rule_type:
×
164
                    rule_list.remove(rule)
×
165

166
        for rule in rules:
×
167
            assert (
×
168
                rule.is_implementation_rule()
169
                or rule.is_stage_one_rewrite_rules()
170
                or rule.is_stage_two_rewrite_rules()
171
                or rule.is_logical_rule()
172
            ), f"Provided Invalid rule {rule}"
173

174
            if rule.is_implementation_rule():
×
175
                _remove_from_list(self.implementation_rules, rule)
×
176
            elif rule.is_stage_one_rewrite_rules():
×
177
                _remove_from_list(self.stage_one_rewrite_rules, rule)
×
178
            elif rule.is_stage_two_rewrite_rules():
×
179
                _remove_from_list(self.stage_two_rewrite_rules, rule)
×
180
            elif rule.is_logical_rule():
×
181
                _remove_from_list(self.logical_rules, rule)
×
182

183
    def add_rules(self, rules: List[Rule]):
×
184
        def _add_to_list(rule_list, rule_to_remove):
×
185
            if any([rule.rule_type != rule_to_remove.rule_type for rule in rule_list]):
×
186
                rule_list.append(rule)
×
187

188
        for rule in rules:
×
189
            assert (
×
190
                rule.is_implementation_rule()
191
                or rule.is_stage_one_rewrite_rules()
192
                or rule.is_stage_two_rewrite_rules()
193
                or rule.is_logical_rule()
194
            ), f"Provided Invalid rule {rule}"
195

196
            if rule.is_implementation_rule():
×
197
                _add_to_list(self.implementation_rules, rule)
×
198
            elif rule.is_stage_one_rewrite_rules():
×
199
                _add_to_list(self.stage_one_rewrite_rules, rule)
×
200
            elif rule.is_stage_two_rewrite_rules():
×
201
                _add_to_list(self.stage_two_rewrite_rules, rule)
×
202
            elif rule.is_logical_rule():
×
203
                _add_to_list(self.logical_rules, rule)
×
204

205

206
@contextmanager
×
207
def disable_rules(rules_manager: RulesManager, rules: List[Rule]):
×
208
    """Use this function to temporarily drop rules.
209
        Useful for testing and debugging purposes.
210
    Args:
211
        rules_manager (RulesManager)
212
        rules (List[Rule]): List of rules to temporarily drop
213
    """
214
    try:
×
215
        rules_manager.disable_rules(rules)
×
216
        yield
×
217
    finally:
218
        rules_manager.add_rules(rules)
×
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