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

georgia-tech-db / eva / a4c010ba-78be-4818-8e6f-1da08c6af280

31 Aug 2023 11:59PM UTC coverage: 70.992% (-10.6%) from 81.552%
a4c010ba-78be-4818-8e6f-1da08c6af280

push

circle-ci

web-flow
Merge branch 'staging' into evadb_staging

54 of 54 new or added lines in 3 files covered. (100.0%)

8020 of 11297 relevant lines covered (70.99%)

0.71 hits per line

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

45.1
/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✔
43
                    return left_batch
×
44
                mask = left_batch.create_mask()
1✔
45
            elif self.etype == ExpressionType.LOGICAL_OR:
×
46
                if left_batch.all_true():  # check if all are true
×
47
                    return left_batch
×
48
                mask = left_batch.create_inverted_mask()
×
49

50
            right_batch = self.get_child(1).evaluate(batch[mask], **kwargs)
1✔
51
            left_batch.update_indices(mask, right_batch)
1✔
52

53
            return left_batch
1✔
54
        else:
55
            batch = self.get_child(0).evaluate(batch, **kwargs)
×
56
            if self.etype == ExpressionType.LOGICAL_NOT:
×
57
                batch.invert()
×
58
                return batch
×
59

60
    def __eq__(self, other):
1✔
61
        is_subtree_equal = super().__eq__(other)
×
62
        if not isinstance(other, LogicalExpression):
×
63
            return False
×
64
        return is_subtree_equal and self.etype == other.etype
×
65

66
    def get_symbol(self) -> str:
1✔
67
        if self.etype == ExpressionType.LOGICAL_AND:
×
68
            return "AND"
×
69
        elif self.etype == ExpressionType.LOGICAL_OR:
×
70
            return "OR"
×
71
        elif self.etype == ExpressionType.LOGICAL_NOT:
×
72
            return "NOT"
×
73
        else:
74
            raise NotImplementedError
75

76
    def __str__(self) -> str:
1✔
77
        expr_str = "("
×
78
        if self.get_child(0):
×
79
            expr_str += f"{str(self.get_child(0))}"
×
80
        if self.etype:
×
81
            expr_str += f" {str(self.get_symbol())} "
×
82
        if self.get_child(1):
×
83
            expr_str += f"{str(self.get_child(1))}"
×
84
        expr_str += ")"
×
85
        return expr_str
×
86

87
    def __hash__(self) -> int:
1✔
88
        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