• 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

99.09
/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 typing import List, Tuple
2✔
16

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

23

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

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

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

44

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

60
    @property
2✔
61
    def name(self):
2✔
62
        return self._name
2✔
63

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

68
    @property
2✔
69
    def type(self):
2✔
70
        return self._type
2✔
71

72
    @property
2✔
73
    def array_type(self):
2✔
74
        return self._array_type
2✔
75

76
    @property
2✔
77
    def dimension(self):
2✔
78
        return self._dimension
2✔
79

80
    @property
2✔
81
    def cci(self):
2✔
82
        return self._cci
2✔
83

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

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

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

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

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

115

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

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

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

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

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

145
        for column in self.column_list:
1✔
146
            print_str += str(column) + "\n"
1✔
147

148
        return print_str
1✔
149

150
    @property
2✔
151
    def table_info(self):
2✔
152
        return self._table_info
2✔
153

154
    @property
2✔
155
    def if_not_exists(self):
2✔
156
        return self._if_not_exists
2✔
157

158
    @property
2✔
159
    def column_list(self):
2✔
160
        return self._column_list
2✔
161

162
    @property
2✔
163
    def query(self):
2✔
164
        return self._query
2✔
165

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

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

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

191

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

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

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

223
    def __str__(self) -> str:
2✔
224
        return (
2✔
225
            f"CREATE DATABASE {self.database_name} \n"
226
            f"WITH ENGINE '{self.engine}' , \n"
227
            f"PARAMETERS = {self.param_dict};"
228
        )
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