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

georgia-tech-db / eva / #832

12 Oct 2023 08:31AM UTC coverage: 0.0% (-68.5%) from 68.493%
#832

push

circle-ci

xzdandy
Minor

0 of 12331 relevant lines covered (0.0%)

0.0 hits per line

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

0.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 (
×
16
    AbstractExpression,
17
    ExpressionReturnType,
18
    ExpressionType,
19
)
20
from evadb.models.storage.batch import Batch
×
21

22

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

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

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

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

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

88
    def signature(self) -> str:
×
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:
×
95
        expr_str = ""
×
96
        if self.etype:
×
97
            expr_str = f"{str(self.get_symbol())}()"
×
98
        return expr_str
×
99

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

106
    def __hash__(self) -> int:
×
107
        return hash(
×
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