• 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

65.67
/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)
×
65
        elif self.etype == ExpressionType.COMPARE_LESSER:
1✔
66
            return Batch.from_lesser(lbatch, rbatch)
×
67
        elif self.etype == ExpressionType.COMPARE_GEQ:
1✔
68
            return Batch.from_greater_eq(lbatch, rbatch)
×
69
        elif self.etype == ExpressionType.COMPARE_LEQ:
1✔
70
            return Batch.from_lesser_eq(lbatch, rbatch)
×
71
        elif self.etype == ExpressionType.COMPARE_NEQ:
1✔
72
            return Batch.from_not_eq(lbatch, rbatch)
×
73
        elif self.etype == ExpressionType.COMPARE_CONTAINS:
1✔
74
            return Batch.compare_contains(lbatch, rbatch)
×
75
        elif self.etype == ExpressionType.COMPARE_IS_CONTAINED:
1✔
76
            return Batch.compare_is_contained(lbatch, rbatch)
×
77
        elif self.etype == ExpressionType.COMPARE_LIKE:
1✔
78
            return Batch.compare_like(lbatch, rbatch)
1✔
79

80
    def get_symbol(self) -> str:
1✔
81
        if self.etype == ExpressionType.COMPARE_EQUAL:
1✔
82
            return "="
×
83
        elif self.etype == ExpressionType.COMPARE_GREATER:
1✔
84
            return ">"
×
85
        elif self.etype == ExpressionType.COMPARE_LESSER:
1✔
86
            return "<"
1✔
87
        elif self.etype == ExpressionType.COMPARE_GEQ:
×
88
            return ">="
×
89
        elif self.etype == ExpressionType.COMPARE_LEQ:
×
90
            return "<="
×
91
        elif self.etype == ExpressionType.COMPARE_NEQ:
×
92
            return "!="
×
93
        elif self.etype == ExpressionType.COMPARE_CONTAINS:
×
94
            return "@>"
×
95
        elif self.etype == ExpressionType.COMPARE_IS_CONTAINED:
×
96
            return "<@"
×
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)
×
111
        if not isinstance(other, ComparisonExpression):
×
112
            return False
×
113
        return is_subtree_equal and self.etype == other.etype
×
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

© 2026 Coveralls, Inc