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

georgia-tech-db / eva / e6161546-9e33-42e7-a2b6-f8fbe6aa8255

08 Sep 2023 02:22AM UTC coverage: 80.449% (-12.5%) from 92.929%
e6161546-9e33-42e7-a2b6-f8fbe6aa8255

push

circle-ci

jiashenC
fix lint

13 of 13 new or added lines in 8 files covered. (100.0%)

9398 of 11682 relevant lines covered (80.45%)

1.45 hits per line

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

96.62
/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
2✔
16

17
from typing import Union
2✔
18

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

25

26
class TableInfo:
2✔
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):
2✔
32
        self._table_name = table_name
2✔
33
        self._schema_name = schema_name
2✔
34
        self._database_name = database_name
2✔
35
        self._table_obj = None
2✔
36

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

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

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

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

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

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

60
        return table_info_str
2✔
61

62
    def __eq__(self, other):
2✔
63
        if not isinstance(other, TableInfo):
1✔
64
            return False
1✔
65
        return (
1✔
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:
2✔
73
        return hash(
2✔
74
            (
75
                self.table_name,
76
                self.schema_name,
77
                self.database_name,
78
                self.table_obj,
79
            )
80
        )
81

82

83
class JoinNode:
2✔
84
    def __init__(
2✔
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
2✔
92
        self.right = right
2✔
93
        self.predicate = predicate
2✔
94
        self.join_type = join_type
2✔
95

96
    def __eq__(self, other):
2✔
97
        if not isinstance(other, JoinNode):
1✔
98
            return False
1✔
99
        return (
1✔
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:
2✔
107
        if self.predicate is not None:
1✔
108
            return "{} {} {} ON {}".format(
1✔
109
                self.left, self.join_type, self.right, self.predicate
110
            )
111
        else:
112
            return "{} {} {}".format(self.left, self.join_type, self.right)
1✔
113

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

117

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

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

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

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

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

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

144

145
class TableRef:
2✔
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__(
2✔
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
2✔
168
        self._sample_freq = sample_freq
2✔
169
        self._sample_type = sample_type
2✔
170
        self._get_audio = get_audio
2✔
171
        self._get_video = get_video
2✔
172

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

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

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

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

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

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

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

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

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

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

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

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

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

231
    @property
2✔
232
    def table_valued_expr(self) -> TableValuedExpression:
2✔
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
2✔
242
    def join_node(self) -> JoinNode:
2✔
243
        assert isinstance(
2✔
244
            self._ref_handle, JoinNode
245
        ), "Expected \
246
                JoinNode, got {}".format(
247
            type(self._ref_handle)
248
        )
249
        return self._ref_handle
2✔
250

251
    @property
2✔
252
    def select_statement(self) -> SelectStatement:
2✔
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:
2✔
262
        # create alias for the table
263
        # TableInfo -> table_name.lower()
264
        # SelectStatement -> select
265
        if isinstance(self._ref_handle, TableInfo):
2✔
266
            return Alias(self._ref_handle.table_name.lower())
2✔
267

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

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

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

287
        return " ".join(parts)
1✔
288

289
    def __eq__(self, other):
2✔
290
        if not isinstance(other, TableRef):
1✔
291
            return False
1✔
292
        return (
1✔
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:
2✔
303
        return hash(
2✔
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