• 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

77.7
/evadb/parser/table_ref.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 __future__ import annotations
1✔
16

17
from typing import Union
1✔
18

19
from evadb.expression.abstract_expression import AbstractExpression
1✔
20
from evadb.expression.function_expression import FunctionExpression
1✔
21
from evadb.parser.alias import Alias
1✔
22
from evadb.parser.select_statement import SelectStatement
1✔
23
from evadb.parser.types import JoinType
1✔
24

25

26
class TableInfo:
1✔
27
    """
28
    stores all the table info, inspired from postgres
29
    """
30

31
    def __init__(self, table_name=None, schema_name=None, database_name=None):
1✔
32
        self._table_name = table_name
1✔
33
        self._schema_name = schema_name
1✔
34
        self._database_name = database_name
1✔
35
        self._table_obj = None
1✔
36

37
    @property
1✔
38
    def table_name(self):
1✔
39
        return self._table_name
1✔
40

41
    @property
1✔
42
    def schema_name(self):
1✔
43
        return self._schema_name
1✔
44

45
    @property
1✔
46
    def database_name(self):
1✔
47
        return self._database_name
1✔
48

49
    @property
1✔
50
    def table_obj(self):
1✔
51
        return self._table_obj
1✔
52

53
    @table_obj.setter
1✔
54
    def table_obj(self, obj):
1✔
55
        self._table_obj = obj
1✔
56

57
    def __str__(self):
1✔
58
        table_info_str = self._table_name
1✔
59

60
        return table_info_str
1✔
61

62
    def __eq__(self, other):
1✔
UNCOV
63
        if not isinstance(other, TableInfo):
×
UNCOV
64
            return False
×
UNCOV
65
        return (
×
66
            self.table_name == other.table_name
67
            and self.schema_name == other.schema_name
68
            and self.database_name == other.database_name
69
            and self.table_obj == other.table_obj
70
        )
71

72
    def __hash__(self) -> int:
1✔
73
        return hash(
1✔
74
            (
75
                self.table_name,
76
                self.schema_name,
77
                self.database_name,
78
                self.table_obj,
79
            )
80
        )
81

82

83
class JoinNode:
1✔
84
    def __init__(
1✔
85
        self,
86
        left: "TableRef" = None,
87
        right: "TableRef" = None,
88
        predicate: AbstractExpression = None,
89
        join_type: JoinType = None,
90
    ) -> None:
91
        self.left = left
1✔
92
        self.right = right
1✔
93
        self.predicate = predicate
1✔
94
        self.join_type = join_type
1✔
95

96
    def __eq__(self, other):
1✔
UNCOV
97
        if not isinstance(other, JoinNode):
×
UNCOV
98
            return False
×
UNCOV
99
        return (
×
100
            self.left == other.left
101
            and self.right == other.right
102
            and self.predicate == other.predicate
103
            and self.join_type == other.join_type
104
        )
105

106
    def __str__(self) -> str:
1✔
UNCOV
107
        if self.predicate is not None:
×
UNCOV
108
            return "{} {} {} ON {}".format(
×
109
                self.left, self.join_type, self.right, self.predicate
110
            )
111
        else:
UNCOV
112
            return "{} {} {}".format(self.left, self.join_type, self.right)
×
113

114
    def __hash__(self) -> int:
1✔
UNCOV
115
        return hash((self.join_type, self.left, self.right, self.predicate))
×
116

117

118
class TableValuedExpression:
1✔
119
    def __init__(self, func_expr: FunctionExpression, do_unnest: bool = False) -> None:
1✔
120
        self._func_expr = func_expr
1✔
121
        self._do_unnest = do_unnest
1✔
122

123
    @property
1✔
124
    def func_expr(self):
1✔
125
        return self._func_expr
1✔
126

127
    @property
1✔
128
    def do_unnest(self):
1✔
129
        return self._do_unnest
1✔
130

131
    def __str__(self) -> str:
1✔
UNCOV
132
        if self.do_unnest:
×
133
            return f"unnest({self._func_expr})"
×
UNCOV
134
        return f"{self._func_expr}"
×
135

136
    def __eq__(self, other):
1✔
UNCOV
137
        if not isinstance(other, TableValuedExpression):
×
UNCOV
138
            return False
×
UNCOV
139
        return self.func_expr == other.func_expr and self.do_unnest == other.do_unnest
×
140

141
    def __hash__(self) -> int:
1✔
UNCOV
142
        return hash((self.func_expr, self.do_unnest))
×
143

144

145
class TableRef:
1✔
146
    """
147
    Attributes:
148
        : can be one of the following based on the query type:
149
            TableInfo: expression of table name and database name,
150
            TableValuedExpression: lateral function calls
151
            SelectStatement: select statement in case of nested queries,
152
            JoinNode: join node in case of join queries
153
        sample_freq: sampling frequency for the table reference
154
    """
155

156
    def __init__(
1✔
157
        self,
158
        table: Union[TableInfo, TableValuedExpression, SelectStatement, JoinNode],
159
        alias: Alias = None,
160
        sample_freq: float = None,
161
        sample_type: str = None,
162
        get_audio: bool = False,
163
        get_video: bool = False,
164
        chunk_params: dict = {},
165
    ):
166
        # clean up so that we can support arbitrary new attributes
167
        self._ref_handle = table
1✔
168
        self._sample_freq = sample_freq
1✔
169
        self._sample_type = sample_type
1✔
170
        self._get_audio = get_audio
1✔
171
        self._get_video = get_video
1✔
172

173
        # related to DOCUMENT tables
174
        # chunk_size, chunk_overlap
175
        self.chunk_params = chunk_params
1✔
176
        # Alias generation must happen after ref handle is initialized
177
        self.alias = alias or self.generate_alias()
1✔
178

179
    @property
1✔
180
    def sample_freq(self):
1✔
181
        return self._sample_freq
1✔
182

183
    @property
1✔
184
    def sample_type(self):
1✔
185
        return self._sample_type
1✔
186

187
    @property
1✔
188
    def get_audio(self):
1✔
189
        return self._get_audio
1✔
190

191
    @property
1✔
192
    def get_video(self):
1✔
193
        return self._get_video
1✔
194

195
    @get_audio.setter
1✔
196
    def get_audio(self, get_audio):
1✔
197
        self._get_audio = get_audio
×
198

199
    @get_video.setter
1✔
200
    def get_video(self, get_video):
1✔
201
        self._get_video = get_video
1✔
202

203
    def is_table_atom(self) -> bool:
1✔
204
        return isinstance(self._ref_handle, TableInfo)
1✔
205

206
    def is_table_valued_expr(self) -> bool:
1✔
207
        return isinstance(self._ref_handle, TableValuedExpression)
1✔
208

209
    def is_select(self) -> bool:
1✔
210
        return isinstance(self._ref_handle, SelectStatement)
1✔
211

212
    def is_join(self) -> bool:
1✔
213
        return isinstance(self._ref_handle, JoinNode)
1✔
214

215
    @property
1✔
216
    def ref_handle(
1✔
217
        self,
218
    ) -> Union[TableInfo, TableValuedExpression, SelectStatement, JoinNode]:
219
        return self._ref_handle
×
220

221
    @property
1✔
222
    def table(self) -> TableInfo:
1✔
223
        assert isinstance(
1✔
224
            self._ref_handle, TableInfo
225
        ), "Expected \
226
                TableInfo, got {}".format(
227
            type(self._ref_handle)
228
        )
229
        return self._ref_handle
1✔
230

231
    @property
1✔
232
    def table_valued_expr(self) -> TableValuedExpression:
1✔
233
        assert isinstance(
1✔
234
            self._ref_handle, TableValuedExpression
235
        ), "Expected \
236
                TableValuedExpression, got {}".format(
237
            type(self._ref_handle)
238
        )
239
        return self._ref_handle
1✔
240

241
    @property
1✔
242
    def join_node(self) -> JoinNode:
1✔
243
        assert isinstance(
1✔
244
            self._ref_handle, JoinNode
245
        ), "Expected \
246
                JoinNode, got {}".format(
247
            type(self._ref_handle)
248
        )
249
        return self._ref_handle
1✔
250

251
    @property
1✔
252
    def select_statement(self) -> SelectStatement:
1✔
253
        assert isinstance(
1✔
254
            self._ref_handle, SelectStatement
255
        ), "Expected \
256
                SelectStatement, got{}".format(
257
            type(self._ref_handle)
258
        )
259
        return self._ref_handle
1✔
260

261
    def generate_alias(self) -> Alias:
1✔
262
        # create alias for the table
263
        # TableInfo -> table_name.lower()
264
        # SelectStatement -> select
265
        if isinstance(self._ref_handle, TableInfo):
1✔
266
            return Alias(self._ref_handle.table_name.lower())
1✔
267

268
    def __str__(self):
1✔
UNCOV
269
        parts = []
×
UNCOV
270
        if self.is_select():
×
UNCOV
271
            parts.append(f"( {str(self._ref_handle)} ) AS {self.alias}")
×
272
        else:
UNCOV
273
            parts.append(str(self._ref_handle))
×
274

UNCOV
275
        if self.sample_freq is not None:
×
276
            parts.append(str(self.sample_freq))
×
UNCOV
277
        if self.sample_type is not None:
×
278
            parts.append(str(self.sample_type))
×
279

UNCOV
280
        if self.chunk_params is not None:
×
UNCOV
281
            parts.append(
×
282
                " ".join(
283
                    [f"{key}: {value}" for key, value in self.chunk_params.items()]
284
                )
285
            )
286

UNCOV
287
        return " ".join(parts)
×
288

289
    def __eq__(self, other):
1✔
UNCOV
290
        if not isinstance(other, TableRef):
×
UNCOV
291
            return False
×
UNCOV
292
        return (
×
293
            self._ref_handle == other._ref_handle
294
            and self.alias == other.alias
295
            and self.sample_freq == other.sample_freq
296
            and self.sample_type == other.sample_type
297
            and self.get_video == other.get_video
298
            and self.get_audio == other.get_audio
299
            and self.chunk_params == other.chunk_params
300
        )
301

302
    def __hash__(self) -> int:
1✔
303
        return hash(
1✔
304
            (
305
                self._ref_handle,
306
                self.alias,
307
                self.sample_freq,
308
                self.sample_type,
309
                self.get_video,
310
                self.get_audio,
311
                frozenset(self.chunk_params.items()),
312
            )
313
        )
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