• 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

90.0
/evadb/expression/tuple_value_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 typing import Union
1✔
16

17
from evadb.catalog.models.column_catalog import ColumnCatalogEntry
1✔
18
from evadb.catalog.models.udf_io_catalog import UdfIOCatalogEntry
1✔
19
from evadb.models.storage.batch import Batch
1✔
20

21
from .abstract_expression import (
1✔
22
    AbstractExpression,
23
    ExpressionReturnType,
24
    ExpressionType,
25
)
26

27

28
class TupleValueExpression(AbstractExpression):
1✔
29
    def __init__(
1✔
30
        self,
31
        name: str = None,
32
        table_alias: str = None,
33
        col_object: Union[ColumnCatalogEntry, UdfIOCatalogEntry] = None,
34
        col_alias=None,
35
    ):
36
        super().__init__(ExpressionType.TUPLE_VALUE, rtype=ExpressionReturnType.INVALID)
1✔
37
        self._name = name
1✔
38
        self._table_alias = table_alias
1✔
39
        self._col_object = col_object
1✔
40
        self._col_alias = col_alias
1✔
41

42
    @property
1✔
43
    def table_alias(self) -> str:
1✔
44
        return self._table_alias
1✔
45

46
    @table_alias.setter
1✔
47
    def table_alias(self, table_alias):
1✔
48
        self._table_alias = table_alias
1✔
49

50
    @property
1✔
51
    def name(self) -> str:
1✔
52
        return self._name
1✔
53

54
    @property
1✔
55
    def col_object(self) -> Union[ColumnCatalogEntry, UdfIOCatalogEntry]:
1✔
56
        return self._col_object
1✔
57

58
    @col_object.setter
1✔
59
    def col_object(self, value: Union[ColumnCatalogEntry, UdfIOCatalogEntry]):
1✔
60
        self._col_object = value
1✔
61

62
    @property
1✔
63
    def col_alias(self) -> str:
1✔
64
        return self._col_alias
1✔
65

66
    @col_alias.setter
1✔
67
    def col_alias(self, value: str):
1✔
68
        self._col_alias = value
1✔
69

70
    def evaluate(self, batch: Batch, *args, **kwargs):
1✔
71
        return batch.project([self.col_alias])
1✔
72

73
    def signature(self):
1✔
74
        """It constructs the signature of the tuple value expression.
75
        It assumes the col_object attribute is populated by the binder with the catalog
76
        entries. For a standard column in the table, it returns `table_name.col_name`,
77
        and for UDF output columns it returns `udf_name.col_name`
78
        Raises:
79
            ValueError: If the col_object is not a `Union[ColumnCatalogEntry, UdfIOCatalogEntry]`. This can occur if the expression has not been bound using the binder.
80
        Returns:
81
            str: signature string
82
        """
83
        assert isinstance(self.col_object, ColumnCatalogEntry) or isinstance(
1✔
84
            self.col_object, UdfIOCatalogEntry
85
        ), f"Unsupported type of self.col_object {type(self.col_object)}, expected ColumnCatalogEntry or UdfIOCatalogEntry"
86

87
        col_name = self.col_object.name
1✔
88
        row_id = self.col_object.row_id
1✔
89
        if isinstance(self.col_object, ColumnCatalogEntry):
1✔
90
            return f"{self.col_object.table_name}.{col_name}[{row_id}]"
1✔
91
        elif isinstance(self.col_object, UdfIOCatalogEntry):
×
92
            return f"{self.col_object.udf_name}.{col_name}[{row_id}]"
×
93

94
    def __eq__(self, other):
1✔
95
        is_subtree_equal = super().__eq__(other)
×
96
        if not isinstance(other, TupleValueExpression):
×
97
            return False
×
98
        return (
×
99
            is_subtree_equal
100
            and self.table_alias == other.table_alias
101
            and self.name == other.name
102
            and self.col_alias == other.col_alias
103
            and self.col_object == other.col_object
104
        )
105

106
    def __str__(self) -> str:
1✔
107
        expr_str = ""
1✔
108
        if self.table_alias:
1✔
109
            expr_str += f"{str(self.table_alias)}."
1✔
110
        if self.name:
1✔
111
            expr_str += f"{str(self.name)}"
1✔
112
        if self.col_alias:
1✔
113
            expr_str += f" AS {str(self.col_alias)}"
1✔
114
        expr_str += ""
1✔
115
        return expr_str
1✔
116

117
    def __hash__(self) -> int:
1✔
118
        return hash(
1✔
119
            (
120
                super().__hash__(),
121
                self.table_alias,
122
                self.name,
123
                self.col_alias,
124
                self.col_object,
125
            )
126
        )
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