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

georgia-tech-db / eva / 20a9a0f9-edcc-437c-815d-bcc1a2d22b17

10 Nov 2023 04:50AM UTC coverage: 66.644% (-10.2%) from 76.812%
20a9a0f9-edcc-437c-815d-bcc1a2d22b17

push

circleci

americast
update docs

0 of 1 new or added line in 1 file covered. (0.0%)

1354 existing lines in 113 files now uncovered.

8767 of 13155 relevant lines covered (66.64%)

0.67 hits per line

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

47.17
/evadb/expression/logical_expression.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 evadb.expression.abstract_expression import (
1✔
16
    AbstractExpression,
17
    ExpressionReturnType,
18
    ExpressionType,
19
)
20

21

22
class LogicalExpression(AbstractExpression):
1✔
23
    def __init__(
1✔
24
        self,
25
        exp_type: ExpressionType,
26
        left: AbstractExpression,
27
        right: AbstractExpression,
28
    ):
29
        children = []
1✔
30
        if left is not None:
1✔
31
            children.append(left)
1✔
32
        if right is not None:
1✔
33
            children.append(right)
1✔
34
        super().__init__(
1✔
35
            exp_type, rtype=ExpressionReturnType.BOOLEAN, children=children
36
        )
37

38
    def evaluate(self, batch, **kwargs):
1✔
39
        if self.get_children_count() == 2:
1✔
40
            left_batch = self.get_child(0).evaluate(batch, **kwargs)
1✔
41
            if self.etype == ExpressionType.LOGICAL_AND:
1✔
42
                if left_batch.all_false():  # check if all are false
1✔
UNCOV
43
                    return left_batch
×
44
                mask = left_batch.create_mask()
1✔
UNCOV
45
            elif self.etype == ExpressionType.LOGICAL_OR:
×
UNCOV
46
                if left_batch.all_true():  # check if all are true
×
UNCOV
47
                    return left_batch
×
UNCOV
48
                mask = left_batch.create_inverted_mask()
×
49

50
            # When some rows are filtered, the push down batch indices need to
51
            # be reset as well.
52
            pushdown_batch = batch[mask]
1✔
53
            pushdown_batch.reset_index()
1✔
54

55
            right_batch = self.get_child(1).evaluate(pushdown_batch, **kwargs)
1✔
56
            left_batch.update_indices(mask, right_batch)
1✔
57

58
            return left_batch
1✔
59
        else:
UNCOV
60
            batch = self.get_child(0).evaluate(batch, **kwargs)
×
UNCOV
61
            if self.etype == ExpressionType.LOGICAL_NOT:
×
UNCOV
62
                batch.invert()
×
UNCOV
63
                return batch
×
64

65
    def __eq__(self, other):
1✔
UNCOV
66
        is_subtree_equal = super().__eq__(other)
×
UNCOV
67
        if not isinstance(other, LogicalExpression):
×
UNCOV
68
            return False
×
UNCOV
69
        return is_subtree_equal and self.etype == other.etype
×
70

71
    def get_symbol(self) -> str:
1✔
UNCOV
72
        if self.etype == ExpressionType.LOGICAL_AND:
×
UNCOV
73
            return "AND"
×
UNCOV
74
        elif self.etype == ExpressionType.LOGICAL_OR:
×
UNCOV
75
            return "OR"
×
76
        elif self.etype == ExpressionType.LOGICAL_NOT:
×
77
            return "NOT"
×
78
        else:
79
            raise NotImplementedError
80

81
    def __str__(self) -> str:
1✔
UNCOV
82
        expr_str = "("
×
UNCOV
83
        if self.get_child(0):
×
UNCOV
84
            expr_str += f"{str(self.get_child(0))}"
×
UNCOV
85
        if self.etype:
×
UNCOV
86
            expr_str += f" {str(self.get_symbol())} "
×
UNCOV
87
        if self.get_child(1):
×
UNCOV
88
            expr_str += f"{str(self.get_child(1))}"
×
UNCOV
89
        expr_str += ")"
×
UNCOV
90
        return expr_str
×
91

92
    def __hash__(self) -> int:
1✔
93
        return super().__hash__()
1✔
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