• 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

70.91
/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
1✔
16

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

23

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

31
    def __eq__(self, other):
1✔
UNCOV
32
        if not isinstance(other, ColConstraintInfo):
×
UNCOV
33
            return False
×
UNCOV
34
        return (
×
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:
1✔
42
        return hash((self.nullable, self.default_value, self.primary, self.unique))
1✔
43

44

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

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

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

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

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

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

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

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

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

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

UNCOV
104
        return (
×
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:
1✔
113
        return hash((self.name, self.type, self.array_type, self.dimension, self.cci))
1✔
114

115

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

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

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

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

UNCOV
148
        return print_str
×
149

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

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

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

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

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

170
    def __eq__(self, other):
1✔
UNCOV
171
        if not isinstance(other, CreateTableStatement):
×
UNCOV
172
            return False
×
UNCOV
173
        return (
×
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:
1✔
UNCOV
181
        return hash(
×
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):
1✔
193
    def __init__(
1✔
194
        self, database_name: str, if_not_exists: bool, engine: str, param_dict: dict
195
    ):
196
        super().__init__(StatementType.CREATE_DATABASE)
1✔
197
        self.database_name = database_name
1✔
198
        self.if_not_exists = if_not_exists
1✔
199
        self.engine = engine
1✔
200
        self.param_dict = param_dict
1✔
201

202
    def __eq__(self, other):
1✔
UNCOV
203
        if not isinstance(other, CreateDatabaseStatement):
×
UNCOV
204
            return False
×
UNCOV
205
        return (
×
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:
1✔
UNCOV
213
        return hash(
×
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:
1✔
224
        return (
1✔
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

© 2025 Coveralls, Inc