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

georgia-tech-db / eva / #852

16 Nov 2023 08:34AM UTC coverage: 0.0%. Remained the same
#852

push

circleci

Andy Xu
Skip neuralforecast testcases

0 of 12596 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/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
×
16
from typing import List, Optional, Tuple
×
17

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

24

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

32
    def __eq__(self, other):
×
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:
×
43
        return hash((self.nullable, self.default_value, self.primary, self.unique))
×
44

45

46
class ColumnDefinition:
×
47
    def __init__(
×
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
×
56
        self._type = col_type
×
57
        self._array_type = col_array_type
×
58
        self._dimension = col_dim or ()
×
59
        self._cci = cci
×
60

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

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

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

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

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

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

85
    def __str__(self):
×
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):
×
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:
×
114
        return hash((self.name, self.type, self.array_type, self.dimension, self.cci))
×
115

116

117
class CreateTableStatement(AbstractStatement):
×
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__(
×
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)
×
133
        self._table_info = table_info
×
134
        self._if_not_exists = if_not_exists
×
135
        self._column_list = column_list
×
136
        self._query = query
×
137

138
    def __str__(self) -> str:
×
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
×
152
    def table_info(self):
×
153
        return self._table_info
×
154

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

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

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

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

171
    def __eq__(self, other):
×
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:
×
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):
×
194
    def __init__(
×
195
        self, database_name: str, if_not_exists: bool, engine: str, param_dict: dict
196
    ):
197
        super().__init__(StatementType.CREATE_DATABASE)
×
198
        self.database_name = database_name
×
199
        self.if_not_exists = if_not_exists
×
200
        self.engine = engine
×
201
        self.param_dict = param_dict
×
202

203
    def __eq__(self, other):
×
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:
×
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:
×
225
        return (
×
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
×
233
class CreateJobStatement(AbstractStatement):
×
234
    job_name: str
×
235
    queries: list
×
236
    if_not_exists: bool
×
237
    start_time: Optional[str] = None
×
238
    end_time: Optional[str] = None
×
239
    repeat_interval: Optional[int] = None
×
240
    repeat_period: Optional[str] = None
×
241

242
    def __hash__(self):
×
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):
×
256
        super().__init__(StatementType.CREATE_JOB)
×
257

258
    def __str__(self):
×
259
        start_str = f"\nSTART {self.start_time}" if self.start_time is not None else ""
×
260
        end_str = f"\nEND {self.end_time}" if self.end_time is not None else ""
×
261
        repeat_str = (
×
262
            f"\nEVERY {self.repeat_interval} {self.repeat_period}"
263
            if self.repeat_interval is not None
264
            else ""
265
        )
266
        return (
×
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