• 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

50.0
/evadb/expression/aggregation_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
from evadb.models.storage.batch import Batch
1✔
21

22

23
class AggregationExpression(AbstractExpression):
1✔
24
    def __init__(
1✔
25
        self,
26
        exp_type: ExpressionType,
27
        left: AbstractExpression,
28
        right: AbstractExpression,
29
    ):
30
        children = []
1✔
31
        if left is not None:
1✔
UNCOV
32
            children.append(left)
×
33
        if right is not None:
1✔
34
            children.append(right)
1✔
35
        super().__init__(
1✔
36
            exp_type, rtype=ExpressionReturnType.INTEGER, children=children
37
        )  # can also be a float
38

39
    def evaluate(self, *args, **kwargs):
1✔
40
        batch: Batch = self.get_child(0).evaluate(*args, **kwargs)
1✔
41
        if self.etype == ExpressionType.AGGREGATION_FIRST:
1✔
42
            batch = batch[0]
1✔
43
        elif self.etype == ExpressionType.AGGREGATION_LAST:
1✔
44
            batch = batch[-1]
1✔
45
        elif self.etype == ExpressionType.AGGREGATION_SEGMENT:
1✔
46
            batch = Batch.stack(batch)
1✔
47
        elif self.etype == ExpressionType.AGGREGATION_SUM:
1✔
UNCOV
48
            batch.aggregate("sum")
×
49
        elif self.etype == ExpressionType.AGGREGATION_COUNT:
1✔
50
            batch.aggregate("count")
1✔
51
        elif self.etype == ExpressionType.AGGREGATION_AVG:
1✔
52
            batch.aggregate("mean")
1✔
UNCOV
53
        elif self.etype == ExpressionType.AGGREGATION_MIN:
×
UNCOV
54
            batch.aggregate("min")
×
UNCOV
55
        elif self.etype == ExpressionType.AGGREGATION_MAX:
×
UNCOV
56
            batch.aggregate("max")
×
57
        batch.reset_index()
1✔
58

59
        column_name = self.etype.name
1✔
60
        if column_name.find("AGGREGATION_") != -1:
1✔
61
            # AGGREGATION_MAX -> MAX
62
            updated_column_name = column_name.replace("AGGREGATION_", "")
1✔
63
            batch.modify_column_alias(updated_column_name)
1✔
64

65
        # TODO: Raise exception if data type doesn't match
66
        return batch
1✔
67

68
    def get_symbol(self) -> str:
1✔
UNCOV
69
        if self.etype == ExpressionType.AGGREGATION_FIRST:
×
UNCOV
70
            return "FIRST"
×
UNCOV
71
        if self.etype == ExpressionType.AGGREGATION_LAST:
×
UNCOV
72
            return "LAST"
×
UNCOV
73
        if self.etype == ExpressionType.AGGREGATION_SEGMENT:
×
UNCOV
74
            return "SEGMENT"
×
UNCOV
75
        if self.etype == ExpressionType.AGGREGATION_SUM:
×
UNCOV
76
            return "SUM"
×
UNCOV
77
        elif self.etype == ExpressionType.AGGREGATION_COUNT:
×
UNCOV
78
            return "COUNT"
×
UNCOV
79
        elif self.etype == ExpressionType.AGGREGATION_AVG:
×
UNCOV
80
            return "AVG"
×
UNCOV
81
        elif self.etype == ExpressionType.AGGREGATION_MIN:
×
UNCOV
82
            return "MIN"
×
UNCOV
83
        elif self.etype == ExpressionType.AGGREGATION_MAX:
×
UNCOV
84
            return "MAX"
×
85
        else:
86
            raise NotImplementedError
87

88
    def signature(self) -> str:
1✔
89
        child_sigs = []
×
90
        for child in self.children:
×
91
            child_sigs.append(child.signature())
×
92
        return f"{self.get_symbol().lower()}({','.join(child_sigs)})"
×
93

94
    def __str__(self) -> str:
1✔
UNCOV
95
        expr_str = ""
×
UNCOV
96
        if self.etype:
×
UNCOV
97
            expr_str = f"{str(self.get_symbol())}()"
×
UNCOV
98
        return expr_str
×
99

100
    def __eq__(self, other):
1✔
UNCOV
101
        is_subtree_equal = super().__eq__(other)
×
UNCOV
102
        if not isinstance(other, AggregationExpression):
×
UNCOV
103
            return False
×
UNCOV
104
        return is_subtree_equal and self.etype == other.etype
×
105

106
    def __hash__(self) -> int:
1✔
107
        return hash(
1✔
108
            (
109
                super().__hash__(),
110
                self.etype,
111
            )
112
        )
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