-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy path__init__.py
286 lines (201 loc) · 7.62 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
from __future__ import annotations
from abc import ABC
from enum import Enum
from pydantic import BaseModel, Field, SecretStr
from starlette.status import (
HTTP_404_NOT_FOUND,
HTTP_422_UNPROCESSABLE_ENTITY,
HTTP_500_INTERNAL_SERVER_ERROR,
)
manifest_str_field = Field(alias="manifestStr", description="Base64 manifest")
connection_info_field = Field(alias="connectionInfo")
class QueryDTO(BaseModel):
sql: str
manifest_str: str = manifest_str_field
connection_info: ConnectionInfo = connection_info_field
class QueryBigQueryDTO(QueryDTO):
connection_info: BigQueryConnectionInfo = connection_info_field
class QueryCannerDTO(QueryDTO):
connection_info: ConnectionUrl | CannerConnectionInfo = connection_info_field
class QueryClickHouseDTO(QueryDTO):
connection_info: ConnectionUrl | ClickHouseConnectionInfo = connection_info_field
class QueryMSSqlDTO(QueryDTO):
connection_info: ConnectionUrl | MSSqlConnectionInfo = connection_info_field
class QueryMySqlDTO(QueryDTO):
connection_info: ConnectionUrl | MySqlConnectionInfo = connection_info_field
class QueryOracleDTO(QueryDTO):
connection_info: ConnectionUrl | OracleConnectionInfo = connection_info_field
class QueryPostgresDTO(QueryDTO):
connection_info: ConnectionUrl | PostgresConnectionInfo = connection_info_field
class QuerySnowflakeDTO(QueryDTO):
connection_info: SnowflakeConnectionInfo = connection_info_field
class QueryTrinoDTO(QueryDTO):
connection_info: ConnectionUrl | TrinoConnectionInfo = connection_info_field
class QueryLocalFileDTO(QueryDTO):
connection_info: LocalFileConnectionInfo = connection_info_field
class QueryS3FileDTO(QueryDTO):
connection_info: S3FileConnectionInfo = connection_info_field
class QueryMinioFileDTO(QueryDTO):
connection_info: MinioFileConnectionInfo = connection_info_field
class QueryGcsFileDTO(QueryDTO):
connection_info: GcsFileConnectionInfo = connection_info_field
class BigQueryConnectionInfo(BaseModel):
project_id: SecretStr
dataset_id: SecretStr
credentials: SecretStr = Field(description="Base64 encode `credentials.json`")
class CannerConnectionInfo(BaseModel):
host: SecretStr = Field(examples=["localhost"])
port: SecretStr = Field(examples=[7432])
user: SecretStr
pat: SecretStr
workspace: SecretStr
enable_ssl: bool = Field(
description="Enable SSL connection", default=False, alias="enableSSL"
)
class ClickHouseConnectionInfo(BaseModel):
host: SecretStr
port: SecretStr
database: SecretStr
user: SecretStr
password: SecretStr | None = None
class MSSqlConnectionInfo(BaseModel):
host: SecretStr
port: SecretStr
database: SecretStr
user: SecretStr
password: SecretStr | None = None
driver: str = Field(default="ODBC Driver 18 for SQL Server")
tds_version: str = Field(default="8.0", alias="TDS_Version")
kwargs: dict[str, str] | None = Field(
description="Additional keyword arguments to pass to PyODBC", default=None
)
class MySqlConnectionInfo(BaseModel):
host: SecretStr
port: SecretStr
database: SecretStr
user: SecretStr
password: SecretStr | None = None
ssl_mode: SecretStr | None = Field(
alias="sslMode",
default="ENABLED",
description="Use ssl connection or not. The default value is `ENABLED` because MySQL uses `caching_sha2_password` by default and the driver MySQLdb support caching_sha2_password with ssl only.",
)
ssl_ca: SecretStr | None = Field(alias="sslCA", default=None)
kwargs: dict[str, str] | None = Field(
description="Additional keyword arguments to pass to PyMySQL", default=None
)
class ConnectionUrl(BaseModel):
connection_url: SecretStr = Field(alias="connectionUrl")
class PostgresConnectionInfo(BaseModel):
host: SecretStr = Field(examples=["localhost"])
port: SecretStr = Field(examples=[5432])
database: SecretStr
user: SecretStr
password: SecretStr | None = None
class OracleConnectionInfo(BaseModel):
host: SecretStr = Field(examples=["localhost"])
port: SecretStr = Field(examples=[1521])
database: SecretStr
user: SecretStr
password: SecretStr | None = None
class SnowflakeConnectionInfo(BaseModel):
user: SecretStr
password: SecretStr
account: SecretStr
database: SecretStr
sf_schema: SecretStr = Field(
alias="schema"
) # Use `sf_schema` to avoid `schema` shadowing in BaseModel
class TrinoConnectionInfo(BaseModel):
host: SecretStr
port: SecretStr = Field(default="8080")
catalog: SecretStr
trino_schema: SecretStr = Field(
alias="schema"
) # Use `trino_schema` to avoid `schema` shadowing in BaseModel
user: SecretStr | None = None
password: SecretStr | None = None
class LocalFileConnectionInfo(BaseModel):
url: SecretStr
format: str = Field(
description="File format", default="csv", examples=["csv", "parquet", "json"]
)
class S3FileConnectionInfo(BaseModel):
url: SecretStr = Field(description="the root path of the s3 bucket", default="/")
format: str = Field(
description="File format", default="csv", examples=["csv", "parquet", "json"]
)
bucket: SecretStr
region: SecretStr
access_key: SecretStr
secret_key: SecretStr
class MinioFileConnectionInfo(BaseModel):
url: SecretStr = Field(description="the root path of the minio bucket", default="/")
format: str = Field(
description="File format", default="csv", examples=["csv", "parquet", "json"]
)
ssl_enabled: bool = Field(
description="use the ssl connection or not", default=False
)
endpoint: SecretStr
bucket: SecretStr
access_key: SecretStr
secret_key: SecretStr
class GcsFileConnectionInfo(BaseModel):
url: SecretStr = Field(description="the root path of the gcs bucket", default="/")
format: str = Field(
description="File format", default="csv", examples=["csv", "parquet", "json"]
)
bucket: SecretStr
key_id: SecretStr
secret_key: SecretStr
credentials: SecretStr = Field(description="Base64 encode `credentials.json`")
ConnectionInfo = (
BigQueryConnectionInfo
| CannerConnectionInfo
| ConnectionUrl
| MSSqlConnectionInfo
| MySqlConnectionInfo
| OracleConnectionInfo
| PostgresConnectionInfo
| SnowflakeConnectionInfo
| TrinoConnectionInfo
| LocalFileConnectionInfo
| S3FileConnectionInfo
| MinioFileConnectionInfo
| GcsFileConnectionInfo
)
class ValidateDTO(BaseModel):
manifest_str: str = manifest_str_field
parameters: dict[str, str]
connection_info: ConnectionInfo = connection_info_field
class AnalyzeSQLDTO(BaseModel):
manifest_str: str = manifest_str_field
sql: str
class AnalyzeSQLBatchDTO(BaseModel):
manifest_str: str = manifest_str_field
sqls: list[str]
class DryPlanDTO(BaseModel):
manifest_str: str = manifest_str_field
sql: str
class TranspileDTO(BaseModel):
manifest_str: str = manifest_str_field
connection_info: ConnectionInfo = connection_info_field
sql: str
class ConfigModel(BaseModel):
diagnose: bool
class UnknownIbisError(Exception):
def __init__(self, message):
self.message = f"Unknown ibis error: {message!s}"
class CustomHttpError(ABC, Exception):
status_code: int
class InternalServerError(CustomHttpError):
status_code = HTTP_500_INTERNAL_SERVER_ERROR
class UnprocessableEntityError(CustomHttpError):
status_code = HTTP_422_UNPROCESSABLE_ENTITY
class NotFoundError(CustomHttpError):
status_code = HTTP_404_NOT_FOUND
class SSLMode(str, Enum):
DISABLED = "disabled"
ENABLED = "enabled"
VERIFY_CA = "verify_ca"