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

georgia-tech-db / eva / #754

04 Sep 2023 09:54PM UTC coverage: 74.807% (-5.5%) from 80.336%
#754

push

circle-ci

jiashenC
update case

8727 of 11666 relevant lines covered (74.81%)

0.75 hits per line

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

97.01
/evadb/expression/comparison_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

16
from evadb.expression.abstract_expression import (
1✔
17
    AbstractExpression,
18
    ExpressionReturnType,
19
    ExpressionType,
20
)
21
from evadb.models.storage.batch import Batch
1✔
22

23

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

40
    def evaluate(self, *args, **kwargs):
1✔
41
        # cast in to numpy array
42
        lbatch = self.get_child(0).evaluate(*args, **kwargs)
1✔
43
        rbatch = self.get_child(1).evaluate(*args, **kwargs)
1✔
44

45
        assert len(lbatch) == len(
1✔
46
            rbatch
47
        ), f"Left and Right batch does not have equal elements: left: {len(lbatch)} right: {len(rbatch)}"
48

49
        assert self.etype in [
1✔
50
            ExpressionType.COMPARE_EQUAL,
51
            ExpressionType.COMPARE_GREATER,
52
            ExpressionType.COMPARE_LESSER,
53
            ExpressionType.COMPARE_GEQ,
54
            ExpressionType.COMPARE_LEQ,
55
            ExpressionType.COMPARE_NEQ,
56
            ExpressionType.COMPARE_CONTAINS,
57
            ExpressionType.COMPARE_IS_CONTAINED,
58
            ExpressionType.COMPARE_LIKE,
59
        ], f"Expression type not supported {self.etype}"
60

61
        if self.etype == ExpressionType.COMPARE_EQUAL:
1✔
62
            return Batch.from_eq(lbatch, rbatch)
1✔
63
        elif self.etype == ExpressionType.COMPARE_GREATER:
1✔
64
            return Batch.from_greater(lbatch, rbatch)
1✔
65
        elif self.etype == ExpressionType.COMPARE_LESSER:
1✔
66
            return Batch.from_lesser(lbatch, rbatch)
1✔
67
        elif self.etype == ExpressionType.COMPARE_GEQ:
1✔
68
            return Batch.from_greater_eq(lbatch, rbatch)
1✔
69
        elif self.etype == ExpressionType.COMPARE_LEQ:
1✔
70
            return Batch.from_lesser_eq(lbatch, rbatch)
1✔
71
        elif self.etype == ExpressionType.COMPARE_NEQ:
1✔
72
            return Batch.from_not_eq(lbatch, rbatch)
1✔
73
        elif self.etype == ExpressionType.COMPARE_CONTAINS:
1✔
74
            return Batch.compare_contains(lbatch, rbatch)
1✔
75
        elif self.etype == ExpressionType.COMPARE_IS_CONTAINED:
1✔
76
            return Batch.compare_is_contained(lbatch, rbatch)
1✔
77
        elif self.etype == ExpressionType.COMPARE_LIKE:
×
78
            return Batch.compare_like(lbatch, rbatch)
×
79

80
    def get_symbol(self) -> str:
1✔
81
        if self.etype == ExpressionType.COMPARE_EQUAL:
1✔
82
            return "="
1✔
83
        elif self.etype == ExpressionType.COMPARE_GREATER:
1✔
84
            return ">"
1✔
85
        elif self.etype == ExpressionType.COMPARE_LESSER:
1✔
86
            return "<"
1✔
87
        elif self.etype == ExpressionType.COMPARE_GEQ:
1✔
88
            return ">="
1✔
89
        elif self.etype == ExpressionType.COMPARE_LEQ:
1✔
90
            return "<="
1✔
91
        elif self.etype == ExpressionType.COMPARE_NEQ:
1✔
92
            return "!="
1✔
93
        elif self.etype == ExpressionType.COMPARE_CONTAINS:
1✔
94
            return "@>"
1✔
95
        elif self.etype == ExpressionType.COMPARE_IS_CONTAINED:
1✔
96
            return "<@"
1✔
97

98
    def __str__(self) -> str:
1✔
99
        expr_str = "("
1✔
100
        if self.get_child(0):
1✔
101
            expr_str += f"{self.get_child(0)}"
1✔
102
        if self.etype:
1✔
103
            expr_str += f" {self.get_symbol()} "
1✔
104
        if self.get_child(1):
1✔
105
            expr_str += f"{self.get_child(1)}"
1✔
106
        expr_str += ")"
1✔
107
        return expr_str
1✔
108

109
    def __eq__(self, other):
1✔
110
        is_subtree_equal = super().__eq__(other)
1✔
111
        if not isinstance(other, ComparisonExpression):
1✔
112
            return False
1✔
113
        return is_subtree_equal and self.etype == other.etype
1✔
114

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

© 2025 Coveralls, Inc