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

georgia-tech-db / eva / d88c9094-1a92-4944-91ea-5e7e8275cb11

23 Nov 2023 10:19PM UTC coverage: 67.117% (+67.1%) from 0.0%
d88c9094-1a92-4944-91ea-5e7e8275cb11

push

circleci

web-flow
Merge branch 'georgia-tech-db:staging' into cost_batching

342 of 692 new or added lines in 47 files covered. (49.42%)

12 existing lines in 4 files now uncovered.

9189 of 13691 relevant lines covered (67.12%)

0.67 hits per line

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

74.42
/evadb/parser/create_statement.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 dataclasses import dataclass
1✔
16
from typing import List, Optional, Tuple
1✔
17

18
from evadb.catalog.catalog_type import ColumnType, NdArrayType
1✔
19
from evadb.parser.select_statement import SelectStatement
1✔
20
from evadb.parser.statement import AbstractStatement
1✔
21
from evadb.parser.table_ref import TableInfo
1✔
22
from evadb.parser.types import StatementType
1✔
23

24

25
class ColConstraintInfo:
1✔
26
    def __init__(self, nullable=False, default_value=None, primary=False, unique=False):
1✔
27
        self.nullable = nullable
1✔
28
        self.default_value = default_value
1✔
29
        self.primary = primary
1✔
30
        self.unique = unique
1✔
31

32
    def __eq__(self, other):
1✔
33
        if not isinstance(other, ColConstraintInfo):
×
34
            return False
×
35
        return (
×
36
            self.nullable == other.nullable
37
            and self.default_value == other.default_value
38
            and self.primary == other.primary
39
            and self.unique == other.unique
40
        )
41

42
    def __hash__(self) -> int:
1✔
43
        return hash((self.nullable, self.default_value, self.primary, self.unique))
1✔
44

45

46
class ColumnDefinition:
1✔
47
    def __init__(
1✔
48
        self,
49
        col_name: str,
50
        col_type: ColumnType,
51
        col_array_type: NdArrayType,
52
        col_dim: Tuple[int],
53
        cci: ColConstraintInfo = ColConstraintInfo(),
54
    ):
55
        self._name = col_name
1✔
56
        self._type = col_type
1✔
57
        self._array_type = col_array_type
1✔
58
        self._dimension = col_dim or ()
1✔
59
        self._cci = cci
1✔
60

61
    @property
1✔
62
    def name(self):
1✔
63
        return self._name
1✔
64

65
    @name.setter
1✔
66
    def name(self, value):
1✔
67
        self._name = value
×
68

69
    @property
1✔
70
    def type(self):
1✔
71
        return self._type
1✔
72

73
    @property
1✔
74
    def array_type(self):
1✔
75
        return self._array_type
1✔
76

77
    @property
1✔
78
    def dimension(self):
1✔
79
        return self._dimension
1✔
80

81
    @property
1✔
82
    def cci(self):
1✔
83
        return self._cci
1✔
84

85
    def __str__(self):
1✔
86
        dimension_str = ""
×
87
        if self._dimension is not None:
×
88
            dimension_str += "["
×
89
            for dim in self._dimension:
×
90
                dimension_str += str(dim) + ", "
×
91
            dimension_str = dimension_str.rstrip(", ")
×
92
            dimension_str += "]"
×
93

94
        if self.array_type is None:
×
95
            return "{} {}".format(self._name, self._type)
×
96
        else:
97
            return "{} {} {} {}".format(
×
98
                self._name, self._type, self.array_type, dimension_str
99
            )
100

101
    def __eq__(self, other):
1✔
102
        if not isinstance(other, ColumnDefinition):
×
103
            return False
×
104

105
        return (
×
106
            self.name == other.name
107
            and self.type == other.type
108
            and self.array_type == other.array_type
109
            and self.dimension == other.dimension
110
            and self.cci == other.cci
111
        )
112

113
    def __hash__(self) -> int:
1✔
114
        return hash((self.name, self.type, self.array_type, self.dimension, self.cci))
1✔
115

116

117
class CreateTableStatement(AbstractStatement):
1✔
118
    """Create Table Statement constructed after parsing the input query
119

120
    Attributes:
121
        TableRef: table reference in the create table statement
122
        ColumnList: list of columns
123
    """
124

125
    def __init__(
1✔
126
        self,
127
        table_info: TableInfo,
128
        if_not_exists: bool,
129
        column_list: List[ColumnDefinition] = None,
130
        query: SelectStatement = None,
131
    ):
132
        super().__init__(StatementType.CREATE)
1✔
133
        self._table_info = table_info
1✔
134
        self._if_not_exists = if_not_exists
1✔
135
        self._column_list = column_list
1✔
136
        self._query = query
1✔
137

138
    def __str__(self) -> str:
1✔
139
        print_str = "CREATE TABLE {} ({}) \n".format(
×
140
            self._table_info, self._if_not_exists
141
        )
142

143
        if self._query is not None:
×
144
            print_str = "CREATE TABLE {} AS {}\n".format(self._table_info, self._query)
×
145

146
        for column in self.column_list:
×
147
            print_str += str(column) + "\n"
×
148

149
        return print_str
×
150

151
    @property
1✔
152
    def table_info(self):
1✔
153
        return self._table_info
1✔
154

155
    @property
1✔
156
    def if_not_exists(self):
1✔
157
        return self._if_not_exists
1✔
158

159
    @property
1✔
160
    def column_list(self):
1✔
161
        return self._column_list
1✔
162

163
    @property
1✔
164
    def query(self):
1✔
165
        return self._query
1✔
166

167
    @column_list.setter
1✔
168
    def column_list(self, value):
1✔
169
        self._column_list = value
×
170

171
    def __eq__(self, other):
1✔
172
        if not isinstance(other, CreateTableStatement):
×
173
            return False
×
174
        return (
×
175
            self.table_info == other.table_info
176
            and self.if_not_exists == other.if_not_exists
177
            and self.column_list == other.column_list
178
            and self.query == other.query
179
        )
180

181
    def __hash__(self) -> int:
1✔
182
        return hash(
×
183
            (
184
                super().__hash__(),
185
                self.table_info,
186
                self.if_not_exists,
187
                tuple(self.column_list or []),
188
                self.query,
189
            )
190
        )
191

192

193
class CreateDatabaseStatement(AbstractStatement):
1✔
194
    def __init__(
1✔
195
        self, database_name: str, if_not_exists: bool, engine: str, param_dict: dict
196
    ):
197
        super().__init__(StatementType.CREATE_DATABASE)
1✔
198
        self.database_name = database_name
1✔
199
        self.if_not_exists = if_not_exists
1✔
200
        self.engine = engine
1✔
201
        self.param_dict = param_dict
1✔
202

203
    def __eq__(self, other):
1✔
204
        if not isinstance(other, CreateDatabaseStatement):
×
205
            return False
×
206
        return (
×
207
            self.database_name == other.database_name
208
            and self.if_not_exists == other.if_not_exists
209
            and self.engine == other.engine
210
            and self.param_dict == other.param_dict
211
        )
212

213
    def __hash__(self) -> int:
1✔
214
        return hash(
×
215
            (
216
                super().__hash__(),
217
                self.database_name,
218
                self.if_not_exists,
219
                self.engine,
220
                hash(frozenset(self.param_dict.items())),
221
            )
222
        )
223

224
    def __str__(self) -> str:
1✔
225
        return (
1✔
226
            f"CREATE DATABASE {self.database_name} \n"
227
            f"WITH ENGINE '{self.engine}' , \n"
228
            f"PARAMETERS = {self.param_dict};"
229
        )
230

231

232
@dataclass
1✔
233
class CreateJobStatement(AbstractStatement):
1✔
234
    job_name: str
1✔
235
    queries: list
1✔
236
    if_not_exists: bool
1✔
237
    start_time: Optional[str] = None
1✔
238
    end_time: Optional[str] = None
1✔
239
    repeat_interval: Optional[int] = None
1✔
240
    repeat_period: Optional[str] = None
1✔
241

242
    def __hash__(self):
1✔
NEW
243
        return hash(
×
244
            (
245
                super().__hash__(),
246
                self.job_name,
247
                tuple(self.queries),
248
                self.start_time,
249
                self.end_time,
250
                self.repeat_interval,
251
                self.repeat_period,
252
            )
253
        )
254

255
    def __post_init__(self):
1✔
256
        super().__init__(StatementType.CREATE_JOB)
1✔
257

258
    def __str__(self):
1✔
259
        start_str = f"\nSTART {self.start_time}" if self.start_time is not None else ""
1✔
260
        end_str = f"\nEND {self.end_time}" if self.end_time is not None else ""
1✔
261
        repeat_str = (
1✔
262
            f"\nEVERY {self.repeat_interval} {self.repeat_period}"
263
            if self.repeat_interval is not None
264
            else ""
265
        )
266
        return (
1✔
267
            f"CREATE JOB {self.job_name} AS\n"
268
            f"({(str(q) for q in self.queries)})"
269
            f"{start_str} {end_str} {repeat_str}"
270
        )
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