teradataml 20.0.0.4__py3-none-any.whl → 20.0.0.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of teradataml might be problematic. Click here for more details.
- teradataml/LICENSE-3RD-PARTY.pdf +0 -0
- teradataml/README.md +182 -13
- teradataml/__init__.py +2 -1
- teradataml/_version.py +2 -2
- teradataml/analytics/analytic_function_executor.py +8 -13
- teradataml/analytics/json_parser/analytic_functions_argument.py +4 -0
- teradataml/analytics/sqle/__init__.py +16 -1
- teradataml/analytics/utils.py +60 -1
- teradataml/automl/__init__.py +290 -106
- teradataml/automl/autodataprep/__init__.py +471 -0
- teradataml/automl/data_preparation.py +29 -10
- teradataml/automl/data_transformation.py +11 -0
- teradataml/automl/feature_engineering.py +64 -4
- teradataml/automl/feature_exploration.py +639 -25
- teradataml/automl/model_training.py +1 -1
- teradataml/clients/auth_client.py +12 -8
- teradataml/clients/keycloak_client.py +165 -0
- teradataml/common/constants.py +71 -26
- teradataml/common/exceptions.py +32 -0
- teradataml/common/messagecodes.py +28 -0
- teradataml/common/messages.py +13 -4
- teradataml/common/sqlbundle.py +3 -2
- teradataml/common/utils.py +345 -45
- teradataml/context/context.py +259 -93
- teradataml/data/apriori_example.json +22 -0
- teradataml/data/docs/sqle/docs_17_20/Apriori.py +138 -0
- teradataml/data/docs/sqle/docs_17_20/NERExtractor.py +121 -0
- teradataml/data/docs/sqle/docs_17_20/NGramSplitter.py +3 -3
- teradataml/data/docs/sqle/docs_17_20/SMOTE.py +212 -0
- teradataml/data/docs/sqle/docs_17_20/TextMorph.py +119 -0
- teradataml/data/docs/sqle/docs_17_20/TextParser.py +54 -3
- teradataml/data/docs/uaf/docs_17_20/ACF.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/ArimaEstimate.py +2 -2
- teradataml/data/docs/uaf/docs_17_20/ArimaXEstimate.py +2 -2
- teradataml/data/docs/uaf/docs_17_20/DFFT.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/DFFT2.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/DFFT2Conv.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/DFFTConv.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/FilterFactory1d.py +4 -4
- teradataml/data/docs/uaf/docs_17_20/GenseriesSinusoids.py +2 -2
- teradataml/data/docs/uaf/docs_17_20/GoldfeldQuandt.py +2 -2
- teradataml/data/docs/uaf/docs_17_20/HoltWintersForecaster.py +6 -6
- teradataml/data/docs/uaf/docs_17_20/LineSpec.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/LinearRegr.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/Matrix2Image.py +4 -4
- teradataml/data/docs/uaf/docs_17_20/MultivarRegr.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/PACF.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/PowerSpec.py +2 -2
- teradataml/data/docs/uaf/docs_17_20/PowerTransform.py +3 -3
- teradataml/data/docs/uaf/docs_17_20/Resample.py +5 -5
- teradataml/data/docs/uaf/docs_17_20/SAX.py +3 -3
- teradataml/data/docs/uaf/docs_17_20/SignifPeriodicities.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/SimpleExp.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/Smoothma.py +3 -3
- teradataml/data/docs/uaf/docs_17_20/UNDIFF.py +1 -1
- teradataml/data/jsons/byom/onnxembeddings.json +1 -0
- teradataml/data/jsons/sqle/17.20/NGramSplitter.json +6 -6
- teradataml/data/jsons/sqle/17.20/TD_Apriori.json +181 -0
- teradataml/data/jsons/sqle/17.20/TD_NERExtractor.json +145 -0
- teradataml/data/jsons/sqle/17.20/TD_SMOTE.json +267 -0
- teradataml/data/jsons/sqle/17.20/TD_TextMorph.json +134 -0
- teradataml/data/jsons/sqle/17.20/TD_TextParser.json +114 -9
- teradataml/data/jsons/sqle/20.00/AI_AnalyzeSentiment.json +328 -0
- teradataml/data/jsons/sqle/20.00/AI_AskLLM.json +420 -0
- teradataml/data/jsons/sqle/20.00/AI_DetectLanguage.json +343 -0
- teradataml/data/jsons/sqle/20.00/AI_ExtractKeyPhrases.json +328 -0
- teradataml/data/jsons/sqle/20.00/AI_MaskPII.json +328 -0
- teradataml/data/jsons/sqle/20.00/AI_RecognizeEntities.json +328 -0
- teradataml/data/jsons/sqle/20.00/AI_RecognizePIIEntities.json +328 -0
- teradataml/data/jsons/sqle/20.00/AI_TextClassifier.json +359 -0
- teradataml/data/jsons/sqle/20.00/AI_TextEmbeddings.json +360 -0
- teradataml/data/jsons/sqle/20.00/AI_TextSummarize.json +343 -0
- teradataml/data/jsons/sqle/20.00/AI_TextTranslate.json +343 -0
- teradataml/data/jsons/sqle/20.00/TD_SMOTE.json +2 -2
- teradataml/data/jsons/sqle/20.00/TD_VectorDistance.json +1 -1
- teradataml/data/ner_dict.csv +8 -0
- teradataml/data/ner_input_eng.csv +7 -0
- teradataml/data/ner_rule.csv +5 -0
- teradataml/data/pattern_matching_data.csv +11 -0
- teradataml/data/pos_input.csv +40 -0
- teradataml/data/sdk/modelops/modelops_spec.json +101737 -0
- teradataml/data/tdnerextractor_example.json +14 -0
- teradataml/data/teradataml_example.json +21 -1
- teradataml/data/textmorph_example.json +5 -0
- teradataml/data/to_num_data.csv +4 -0
- teradataml/data/tochar_data.csv +5 -0
- teradataml/data/trans_dense.csv +16 -0
- teradataml/data/trans_sparse.csv +55 -0
- teradataml/data/url_data.csv +10 -9
- teradataml/dataframe/copy_to.py +38 -27
- teradataml/dataframe/data_transfer.py +61 -45
- teradataml/dataframe/dataframe.py +1110 -132
- teradataml/dataframe/dataframe_utils.py +73 -27
- teradataml/dataframe/functions.py +1070 -9
- teradataml/dataframe/sql.py +750 -959
- teradataml/dbutils/dbutils.py +33 -13
- teradataml/dbutils/filemgr.py +14 -10
- teradataml/hyperparameter_tuner/utils.py +4 -2
- teradataml/lib/aed_0_1.dll +0 -0
- teradataml/opensource/_base.py +12 -157
- teradataml/options/configure.py +24 -9
- teradataml/scriptmgmt/UserEnv.py +317 -39
- teradataml/scriptmgmt/lls_utils.py +456 -135
- teradataml/sdk/README.md +79 -0
- teradataml/sdk/__init__.py +4 -0
- teradataml/sdk/_auth_modes.py +422 -0
- teradataml/sdk/_func_params.py +487 -0
- teradataml/sdk/_json_parser.py +453 -0
- teradataml/sdk/_openapi_spec_constants.py +249 -0
- teradataml/sdk/_utils.py +236 -0
- teradataml/sdk/api_client.py +897 -0
- teradataml/sdk/constants.py +62 -0
- teradataml/sdk/modelops/__init__.py +98 -0
- teradataml/sdk/modelops/_client.py +406 -0
- teradataml/sdk/modelops/_constants.py +304 -0
- teradataml/sdk/modelops/models.py +2308 -0
- teradataml/sdk/spinner.py +107 -0
- teradataml/store/__init__.py +1 -1
- teradataml/table_operators/Apply.py +16 -1
- teradataml/table_operators/Script.py +20 -1
- teradataml/table_operators/query_generator.py +4 -21
- teradataml/table_operators/table_operator_util.py +58 -9
- teradataml/utils/dtypes.py +4 -2
- teradataml/utils/internal_buffer.py +22 -2
- teradataml/utils/utils.py +0 -1
- teradataml/utils/validators.py +318 -58
- {teradataml-20.0.0.4.dist-info → teradataml-20.0.0.6.dist-info}/METADATA +188 -14
- {teradataml-20.0.0.4.dist-info → teradataml-20.0.0.6.dist-info}/RECORD +131 -84
- {teradataml-20.0.0.4.dist-info → teradataml-20.0.0.6.dist-info}/WHEEL +0 -0
- {teradataml-20.0.0.4.dist-info → teradataml-20.0.0.6.dist-info}/top_level.txt +0 -0
- {teradataml-20.0.0.4.dist-info → teradataml-20.0.0.6.dist-info}/zip-safe +0 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
# ################################################################################################
|
|
2
|
+
#
|
|
3
|
+
# Copyright 2025 Teradata. All rights reserved.
|
|
4
|
+
# TERADATA CONFIDENTIAL AND TRADE SECRET
|
|
5
|
+
#
|
|
6
|
+
# Primary Owner: Adithya Avvaru (adithya.avvaru@teradata.com)
|
|
7
|
+
# Secondary Owner: Pankaj Purandare (pankajvinod.purandare@teradata.com)
|
|
8
|
+
#
|
|
9
|
+
# Version: 1.0
|
|
10
|
+
# ModelOps SDK Version: 1.0
|
|
11
|
+
#
|
|
12
|
+
# This file contains the constants from OpenAPI Specification that are used in the SDK.
|
|
13
|
+
# TODO: Not all constants from OpenAPI spec is used in the SDK. Will keep on adding based on the
|
|
14
|
+
# requirements.
|
|
15
|
+
#
|
|
16
|
+
# ################################################################################################
|
|
17
|
+
|
|
18
|
+
from enum import Enum
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class DefaultConstants(Enum):
|
|
22
|
+
"""
|
|
23
|
+
Constants for default values in OpenAPI Specification.
|
|
24
|
+
"""
|
|
25
|
+
DEFAULT_TAG = "DefaultAPI"
|
|
26
|
+
DEFAULT_CLASS = "DefaultApi"
|
|
27
|
+
DEFAULT_TAG_DESC = "APIs without a tag."
|
|
28
|
+
DEFAULT_SCHEMA_TYPE = "object"
|
|
29
|
+
DEFAULT_SCHEMA_VALUE = None
|
|
30
|
+
DEFAULT_DESCRIPTION = "No description available."
|
|
31
|
+
|
|
32
|
+
class OpenAPIObject(Enum):
|
|
33
|
+
"""
|
|
34
|
+
Constants for OpenAPI Specification.
|
|
35
|
+
"""
|
|
36
|
+
OPENAPI = "openapi"
|
|
37
|
+
INFO = "info"
|
|
38
|
+
SERVERS = "servers"
|
|
39
|
+
SECURITY = "security"
|
|
40
|
+
TAGS = "tags"
|
|
41
|
+
PATHS = "paths"
|
|
42
|
+
COMPONENTS = "components"
|
|
43
|
+
EXTERNAL_DOCS = "externalDocs"
|
|
44
|
+
JSON_SCHEMA_DIALECT = "jsonSchemaDialect"
|
|
45
|
+
WEBHOOKS = "webhooks"
|
|
46
|
+
|
|
47
|
+
class InfoObject(Enum):
|
|
48
|
+
"""
|
|
49
|
+
Constants for Info Object in OpenAPI Specification.
|
|
50
|
+
"""
|
|
51
|
+
TITLE = "title"
|
|
52
|
+
VERSION = "version"
|
|
53
|
+
DESCRIPTION = "description"
|
|
54
|
+
TERMS_OF_SERVICE = "termsOfService"
|
|
55
|
+
CONTACT = "contact"
|
|
56
|
+
LICENSE = "license"
|
|
57
|
+
SUMMARY = "summary"
|
|
58
|
+
|
|
59
|
+
class ContactObject(Enum):
|
|
60
|
+
"""
|
|
61
|
+
Constants for Contact Object in OpenAPI Specification.
|
|
62
|
+
"""
|
|
63
|
+
NAME = "name"
|
|
64
|
+
URL = "url"
|
|
65
|
+
EMAIL = "email"
|
|
66
|
+
|
|
67
|
+
class LicenseObject(Enum):
|
|
68
|
+
"""
|
|
69
|
+
Constants for License Object in OpenAPI Specification.
|
|
70
|
+
"""
|
|
71
|
+
NAME = "name"
|
|
72
|
+
URL = "url"
|
|
73
|
+
IDENTIFIER = "identifier"
|
|
74
|
+
|
|
75
|
+
class ServerObject(Enum):
|
|
76
|
+
"""
|
|
77
|
+
Constants for Server Object in OpenAPI Specification.
|
|
78
|
+
"""
|
|
79
|
+
URL = "url"
|
|
80
|
+
DESCRIPTION = "description"
|
|
81
|
+
VARIABLES = "variables"
|
|
82
|
+
|
|
83
|
+
class ServerVariableObject(Enum):
|
|
84
|
+
"""
|
|
85
|
+
Constants for Server Variable Object in OpenAPI Specification.
|
|
86
|
+
"""
|
|
87
|
+
ENUM = "enum"
|
|
88
|
+
DEFAULT = "default"
|
|
89
|
+
DESCRIPTION = "description"
|
|
90
|
+
|
|
91
|
+
class ComponentsObject(Enum):
|
|
92
|
+
"""
|
|
93
|
+
Constants for Components Object in OpenAPI Specification.
|
|
94
|
+
"""
|
|
95
|
+
SCHEMAS = "schemas"
|
|
96
|
+
RESPONSES = "responses"
|
|
97
|
+
PARAMETERS = "parameters"
|
|
98
|
+
EXAMPLES = "examples"
|
|
99
|
+
REQUEST_BODIES = "requestBodies"
|
|
100
|
+
HEADERS = "headers"
|
|
101
|
+
SECURITY_SCHEMES = "securitySchemes"
|
|
102
|
+
LINKS = "links"
|
|
103
|
+
CALLBACKS = "callbacks"
|
|
104
|
+
PATH_ITEMS = "pathItems"
|
|
105
|
+
|
|
106
|
+
class PathsObject(Enum):
|
|
107
|
+
"""
|
|
108
|
+
Constants for Paths Object in OpenAPI Specification.
|
|
109
|
+
"""
|
|
110
|
+
PATHS = "/{path}"
|
|
111
|
+
|
|
112
|
+
class PathItemObject(Enum):
|
|
113
|
+
"""
|
|
114
|
+
Constants for Path Item Object in OpenAPI Specification.
|
|
115
|
+
"""
|
|
116
|
+
REF = "$ref"
|
|
117
|
+
SUMMARY = "summary"
|
|
118
|
+
DESCRIPTION = "description"
|
|
119
|
+
GET = "get"
|
|
120
|
+
PUT = "put"
|
|
121
|
+
POST = "post"
|
|
122
|
+
DELETE = "delete"
|
|
123
|
+
OPTIONS = "options"
|
|
124
|
+
HEAD = "head"
|
|
125
|
+
PATCH = "patch"
|
|
126
|
+
TRACE = "trace"
|
|
127
|
+
SERVERS = "servers"
|
|
128
|
+
PARAMETERS = "parameters"
|
|
129
|
+
|
|
130
|
+
class OperationObject(Enum):
|
|
131
|
+
"""
|
|
132
|
+
Constants for Operation Object in OpenAPI Specification.
|
|
133
|
+
"""
|
|
134
|
+
TAGS = "tags"
|
|
135
|
+
SUMMARY = "summary"
|
|
136
|
+
DESCRIPTION = "description"
|
|
137
|
+
EXTERNAL_DOCS = "externalDocs"
|
|
138
|
+
OPERATION_ID = "operationId"
|
|
139
|
+
PARAMETERS = "parameters"
|
|
140
|
+
REQUEST_BODY = "requestBody"
|
|
141
|
+
RESPONSES = "responses"
|
|
142
|
+
CALLBACKS = "callbacks"
|
|
143
|
+
DEPRECATED = "deprecated"
|
|
144
|
+
SECURITY = "security"
|
|
145
|
+
SERVERS = "servers"
|
|
146
|
+
|
|
147
|
+
class ExternalDocumentationObject(Enum):
|
|
148
|
+
"""
|
|
149
|
+
Constants for External Documentation Object in OpenAPI Specification.
|
|
150
|
+
"""
|
|
151
|
+
DESCRIPTION = "description"
|
|
152
|
+
URL = "url"
|
|
153
|
+
|
|
154
|
+
class ParameterObject(Enum):
|
|
155
|
+
"""
|
|
156
|
+
Constants for Parameter Object in OpenAPI Specification.
|
|
157
|
+
"""
|
|
158
|
+
NAME = "name"
|
|
159
|
+
# If in is "path", the name field MUST correspond to a template expression
|
|
160
|
+
# occurring within the path field in the Paths Object.
|
|
161
|
+
# If in is "header" and the name field is "Accept", "Content-Type" or
|
|
162
|
+
# "Authorization", the parameter definition SHALL be ignored.
|
|
163
|
+
IN = "in" # Possible values are "query", "header", "path" or "cookie"
|
|
164
|
+
DESCRIPTION = "description"
|
|
165
|
+
REQUIRED = "required"
|
|
166
|
+
DEPRECATED = "deprecated"
|
|
167
|
+
ALLOW_EMPTY_VALUE = "allowEmptyValue"
|
|
168
|
+
# style: Describes how the parameter value will be serialized depending on
|
|
169
|
+
# the type of the parameter value. Default values (based on value of in):
|
|
170
|
+
# for "query" - "form"; for "path" - "simple"; for "header" - "simple";
|
|
171
|
+
# for "cookie" - "form".
|
|
172
|
+
STYLE = "style"
|
|
173
|
+
EXPLODE = "explode"
|
|
174
|
+
ALLOW_RESERVED = "allowReserved"
|
|
175
|
+
SCHEMA = "schema"
|
|
176
|
+
EXAMPLE = "example"
|
|
177
|
+
EXAMPLES = "examples"
|
|
178
|
+
CONTENT = "content"
|
|
179
|
+
|
|
180
|
+
class RequestBodyObject(Enum):
|
|
181
|
+
"""
|
|
182
|
+
Constants for Request Body Object in OpenAPI Specification.
|
|
183
|
+
"""
|
|
184
|
+
CONTENT = "content"
|
|
185
|
+
REQUIRED = "required"
|
|
186
|
+
DESCRIPTION = "description"
|
|
187
|
+
|
|
188
|
+
class MediaTypeObject(Enum):
|
|
189
|
+
"""
|
|
190
|
+
Constants for Media Type Object in OpenAPI Specification.
|
|
191
|
+
"""
|
|
192
|
+
SCHEMA = "schema"
|
|
193
|
+
EXAMPLE = "example"
|
|
194
|
+
EXAMPLES = "examples"
|
|
195
|
+
ENCODING = "encoding"
|
|
196
|
+
|
|
197
|
+
class EncodingObject(Enum):
|
|
198
|
+
"""
|
|
199
|
+
Constants for Encoding Object in OpenAPI Specification.
|
|
200
|
+
"""
|
|
201
|
+
CONTENT_TYPE = "contentType"
|
|
202
|
+
HEADERS = "headers"
|
|
203
|
+
STYLE = "style"
|
|
204
|
+
EXPLODE = "explode"
|
|
205
|
+
ALLOW_RESERVED = "allowReserved"
|
|
206
|
+
|
|
207
|
+
class ResponsesObject(Enum):
|
|
208
|
+
"""
|
|
209
|
+
Constants for Responses Object in OpenAPI Specification.
|
|
210
|
+
"""
|
|
211
|
+
RESPONSES = "responses"
|
|
212
|
+
DEFAULT = "default"
|
|
213
|
+
DESCRIPTION = "description"
|
|
214
|
+
HEADERS = "headers"
|
|
215
|
+
CONTENT = "content"
|
|
216
|
+
LINKS = "links"
|
|
217
|
+
|
|
218
|
+
class ResponseObject(Enum):
|
|
219
|
+
"""
|
|
220
|
+
Constants for Response Object in OpenAPI Specification.
|
|
221
|
+
"""
|
|
222
|
+
DESCRIPTION = "description"
|
|
223
|
+
HEADERS = "headers"
|
|
224
|
+
CONTENT = "content"
|
|
225
|
+
LINKS = "links"
|
|
226
|
+
|
|
227
|
+
class TagObject(Enum):
|
|
228
|
+
"""
|
|
229
|
+
Constants for Tag Object in OpenAPI Specification.
|
|
230
|
+
"""
|
|
231
|
+
NAME = "name"
|
|
232
|
+
DESCRIPTION = "description"
|
|
233
|
+
EXTERNAL_DOCS = "externalDocs"
|
|
234
|
+
|
|
235
|
+
class SchemaObject(Enum):
|
|
236
|
+
"""
|
|
237
|
+
Constants for Schema Object in OpenAPI Specification.
|
|
238
|
+
"""
|
|
239
|
+
TYPE = "type"
|
|
240
|
+
PROPERTIES = "properties"
|
|
241
|
+
ITEMS = "items"
|
|
242
|
+
REQUIRED = "required"
|
|
243
|
+
DESCRIPTION = "description"
|
|
244
|
+
FORMAT = "format"
|
|
245
|
+
EXAMPLE = "example"
|
|
246
|
+
EXAMPLES = "examples"
|
|
247
|
+
ENUM = "enum"
|
|
248
|
+
DEFAULT = "default"
|
|
249
|
+
REF = "$ref"
|
teradataml/sdk/_utils.py
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# ################################################################################################
|
|
2
|
+
#
|
|
3
|
+
# Copyright 2025 Teradata. All rights reserved.
|
|
4
|
+
# TERADATA CONFIDENTIAL AND TRADE SECRET
|
|
5
|
+
#
|
|
6
|
+
# Primary Owner: Adithya Avvaru (adithya.avvaru@teradata.com)
|
|
7
|
+
# Secondary Owner: Pankaj Purandare (pankajvinod.purandare@teradata.com)
|
|
8
|
+
#
|
|
9
|
+
# Version: 1.0
|
|
10
|
+
# SDK Version: 1.0
|
|
11
|
+
#
|
|
12
|
+
# This file contains utility functions for the OpenAPI SDK.
|
|
13
|
+
#
|
|
14
|
+
# ################################################################################################
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
import re
|
|
18
|
+
from typing import List, Union
|
|
19
|
+
|
|
20
|
+
from pydantic import BaseModel, ValidationError
|
|
21
|
+
|
|
22
|
+
from teradataml.utils.validators import _Validators
|
|
23
|
+
|
|
24
|
+
from .constants import _REQUEST_FUNCTION_MAPPER
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# Define a function to create dynamic classes
|
|
28
|
+
def _constructor(self, client):
|
|
29
|
+
"""
|
|
30
|
+
Constructor for the dynamic class.
|
|
31
|
+
:param client: The client instance to be used by the class.
|
|
32
|
+
"""
|
|
33
|
+
self._client = client
|
|
34
|
+
|
|
35
|
+
def _read_openapi_spec(file_path):
|
|
36
|
+
with open(file_path, "r") as file:
|
|
37
|
+
content = file.read()
|
|
38
|
+
|
|
39
|
+
return json.loads(content)
|
|
40
|
+
|
|
41
|
+
def _select_header_accept(accepts: List[str]):
|
|
42
|
+
"""
|
|
43
|
+
converts list of header into a string
|
|
44
|
+
|
|
45
|
+
Return:
|
|
46
|
+
(str): request header
|
|
47
|
+
"""
|
|
48
|
+
if not accepts:
|
|
49
|
+
return
|
|
50
|
+
|
|
51
|
+
return ", ".join([x.lower() for x in accepts])
|
|
52
|
+
|
|
53
|
+
def _remove_duplicate_preserve_order(lst: List[str]) -> List[str]:
|
|
54
|
+
"""
|
|
55
|
+
Removes duplicates from a list while preserving the order of elements.
|
|
56
|
+
|
|
57
|
+
Parameters:
|
|
58
|
+
lst (List[str]): The input list from which duplicates need to be removed.
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
List[str]: A new list with duplicates removed, preserving the original order.
|
|
62
|
+
"""
|
|
63
|
+
# Since order of return types matter, converting to sets will not retain order.
|
|
64
|
+
# Hence, removing duplicates using a dictionary and list to run in O(n) time.
|
|
65
|
+
_truncated_dict = {}
|
|
66
|
+
_truncated_values = []
|
|
67
|
+
for _header_type in lst:
|
|
68
|
+
if _truncated_dict.get(_header_type) is None: # O(1) check.
|
|
69
|
+
_truncated_dict[_header_type] = True
|
|
70
|
+
_truncated_values.append(_header_type)
|
|
71
|
+
return _truncated_values
|
|
72
|
+
|
|
73
|
+
# Get string to camel case
|
|
74
|
+
def _camel_case(s):
|
|
75
|
+
"""
|
|
76
|
+
This is a function to convert a string to camel case, for generating class names.
|
|
77
|
+
"Hello world" -> "HelloWorld"
|
|
78
|
+
"""
|
|
79
|
+
return ''.join([i.title() for i in s.split()])
|
|
80
|
+
|
|
81
|
+
# Convert camelCase to snake_case
|
|
82
|
+
def _camel_to_snake(name):
|
|
83
|
+
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
|
|
84
|
+
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
|
|
85
|
+
|
|
86
|
+
def _create_dynamic_method(processed_function_details, raw_function_details, debug):
|
|
87
|
+
def dynamic_function(*c, **kwargs):
|
|
88
|
+
self = c[0]
|
|
89
|
+
if len(c) > 1:
|
|
90
|
+
_class_name = self.__class__.__name__
|
|
91
|
+
_func_name = processed_function_details["func_name"]
|
|
92
|
+
raise ValueError("Only keyword arguments are allowed. " + \
|
|
93
|
+
f"Please check help({_class_name}.{_func_name}) for supported arguments.")
|
|
94
|
+
|
|
95
|
+
# dynamic_function.__doc__ = processed_function_details.get("doc_string")
|
|
96
|
+
|
|
97
|
+
# Mapping of old (in OpenAPI spec) to new (in function signature) param names.
|
|
98
|
+
_all_params_mapping = processed_function_details.get("query_params_dict").copy()
|
|
99
|
+
_all_params_mapping.update(processed_function_details.get("path_params_dict", {}))
|
|
100
|
+
|
|
101
|
+
_arg_info_matrix_all_args_dict = processed_function_details.get("arg_info_matrix_dict", {})
|
|
102
|
+
|
|
103
|
+
arg_info_matrix = []
|
|
104
|
+
|
|
105
|
+
# Process path and query params.
|
|
106
|
+
parameters = raw_function_details.get("parameters", [])
|
|
107
|
+
path_params_to_values = {}
|
|
108
|
+
query_params_to_values = {}
|
|
109
|
+
|
|
110
|
+
# Returns Pydantic model by default. Returns JSON if enabled in kwargs.
|
|
111
|
+
_return_dict = kwargs.get("return_dict", False)
|
|
112
|
+
|
|
113
|
+
for param in parameters:
|
|
114
|
+
old_param_name = param['name']
|
|
115
|
+
new_param_name = _all_params_mapping.get(old_param_name, old_param_name)
|
|
116
|
+
func_base_obj = _arg_info_matrix_all_args_dict[new_param_name]
|
|
117
|
+
arg_info_matrix.append(func_base_obj.get_arg_info_list(kwargs.get(new_param_name)))
|
|
118
|
+
|
|
119
|
+
if param.get('in') == 'path':
|
|
120
|
+
path_params_to_values[param['name']] = kwargs.get(new_param_name)
|
|
121
|
+
elif param.get('in') == 'query':
|
|
122
|
+
query_params_to_values[param['name']] = kwargs.get(new_param_name)
|
|
123
|
+
|
|
124
|
+
# If projection is added to the query params as special case (workaround).
|
|
125
|
+
# "projection" related issues will be fixed in JSON spec by modelOps team as per
|
|
126
|
+
# https://teradata-pe.atlassian.net/browse/VMO-1821.
|
|
127
|
+
if "projection" in _all_params_mapping and "projection" not in query_params_to_values:
|
|
128
|
+
old_param_name = "projection"
|
|
129
|
+
new_param_name = _all_params_mapping.get(old_param_name, old_param_name)
|
|
130
|
+
func_base_obj = _arg_info_matrix_all_args_dict[new_param_name]
|
|
131
|
+
arg_info_matrix.append(func_base_obj.get_arg_info_list(kwargs.get(new_param_name)))
|
|
132
|
+
query_params_to_values[old_param_name] = kwargs.get(new_param_name)
|
|
133
|
+
|
|
134
|
+
# Process body params.
|
|
135
|
+
body_params = {}
|
|
136
|
+
body_params_dict = processed_function_details.get("body_params_dict", {})
|
|
137
|
+
for old_param_name, new_param_name in body_params_dict.items():
|
|
138
|
+
# old_param_name will always be "body" for body params.
|
|
139
|
+
func_base_obj = _arg_info_matrix_all_args_dict[new_param_name]
|
|
140
|
+
param_value: Union[dict, BaseModel] = kwargs.get(new_param_name)
|
|
141
|
+
arg_info_values = func_base_obj.get_arg_info_list(param_value)
|
|
142
|
+
arg_info_matrix.append(arg_info_values)
|
|
143
|
+
|
|
144
|
+
if func_base_obj._in == 'body':
|
|
145
|
+
# Check if the value passed in body params is of schema type.
|
|
146
|
+
# If it is, convert it to dict if it's a Pydantic model.
|
|
147
|
+
if isinstance(param_value, arg_info_values[3][0]):
|
|
148
|
+
param_value = param_value.model_dump(by_alias=True, exclude_unset=True)
|
|
149
|
+
body_params[old_param_name] = param_value
|
|
150
|
+
|
|
151
|
+
_Validators._validate_missing_required_arguments(arg_info_matrix)
|
|
152
|
+
_Validators._validate_function_arguments(arg_info_matrix)
|
|
153
|
+
|
|
154
|
+
header_values = processed_function_details.get("header_values", [])
|
|
155
|
+
|
|
156
|
+
header_dict = self._client._prepare_header_dict(accept=header_values)
|
|
157
|
+
|
|
158
|
+
method = processed_function_details.get("method").lower()
|
|
159
|
+
path = processed_function_details.get("path")
|
|
160
|
+
|
|
161
|
+
all_params = {"path": path.format(**path_params_to_values),
|
|
162
|
+
"header_params": header_dict, "query_params": query_params_to_values}
|
|
163
|
+
if method != 'get':
|
|
164
|
+
all_params = {**all_params, **body_params}
|
|
165
|
+
|
|
166
|
+
if debug:
|
|
167
|
+
print("\nBuilt arg_info_matrix:\n", arg_info_matrix)
|
|
168
|
+
print("\nHeader values:\n", header_values)
|
|
169
|
+
print(f"\nCalling '{method}' request with params:\n{all_params}")
|
|
170
|
+
|
|
171
|
+
ret_opt = getattr(self._client, _REQUEST_FUNCTION_MAPPER[method])(**all_params)
|
|
172
|
+
|
|
173
|
+
if isinstance(ret_opt, dict) and _return_dict == False:
|
|
174
|
+
for return_type_ in processed_function_details["return_types"]:
|
|
175
|
+
if issubclass(return_type_, BaseModel):
|
|
176
|
+
return return_type_(**ret_opt)
|
|
177
|
+
|
|
178
|
+
return ret_opt
|
|
179
|
+
|
|
180
|
+
return dynamic_function
|
|
181
|
+
|
|
182
|
+
def _get_function_name_from_mapper(current_module, processed_function_details, raw_function_details):
|
|
183
|
+
"""
|
|
184
|
+
Get function name from the developer defined dictionary.
|
|
185
|
+
If not found, use the function name created from operationID of the OpenAPI spec.
|
|
186
|
+
"""
|
|
187
|
+
# Get function name from the developer defined dictionary.
|
|
188
|
+
# If not found, use the function name created from operationID of the OpenAPI spec.
|
|
189
|
+
func_name = processed_function_details["func_name"]
|
|
190
|
+
_mapper = getattr(getattr(current_module, "module_constants"), # _constants.py of module.
|
|
191
|
+
"_DEV_DEFINED_CLASS_FUNCTIONS_MAPPER")
|
|
192
|
+
_path = processed_function_details["path"]
|
|
193
|
+
_method = processed_function_details["method"]
|
|
194
|
+
_mapper_details_for_fn = _mapper.get(_path, {}).get(_method, {})
|
|
195
|
+
|
|
196
|
+
if _mapper_details_for_fn:
|
|
197
|
+
_operation_id_from_mapper = _mapper_details_for_fn.get("operationID")
|
|
198
|
+
_operation_id_from_spec = raw_function_details.get("operationId")
|
|
199
|
+
if _operation_id_from_mapper != _operation_id_from_spec:
|
|
200
|
+
raise ValueError(f"OperationID in the mapper for the path '{_path}' and method "\
|
|
201
|
+
f"'{_method}' does not match with OpenAPI spec. Please update "\
|
|
202
|
+
"the mapper with the correct operationID.")
|
|
203
|
+
# Update the function name with the one from the mapper.
|
|
204
|
+
func_name = _mapper_details_for_fn.get("function_name")
|
|
205
|
+
return func_name
|
|
206
|
+
|
|
207
|
+
def _create_methods(json_parser, current_module, debug):
|
|
208
|
+
for tag in json_parser._tag_names:
|
|
209
|
+
_class_name = json_parser._class_name_dict[tag]
|
|
210
|
+
|
|
211
|
+
# Create class methods dynamically from functions defined by json parser in
|
|
212
|
+
# `_class_name_to_function_dict`.
|
|
213
|
+
for function_details in json_parser._class_name_to_function_dict[_class_name]:
|
|
214
|
+
_raw_function_details = function_details[0]
|
|
215
|
+
_processed_function_details = function_details[1]
|
|
216
|
+
|
|
217
|
+
method_func = _create_dynamic_method(_processed_function_details,
|
|
218
|
+
_raw_function_details,
|
|
219
|
+
debug=debug)
|
|
220
|
+
method_func.__doc__ = _processed_function_details["doc_string"]
|
|
221
|
+
|
|
222
|
+
# Set the function name to the one from the mapper if it exists.
|
|
223
|
+
# Otherwise, use the one from the OpenAPI spec.
|
|
224
|
+
new_func_name = _get_function_name_from_mapper(current_module,
|
|
225
|
+
_processed_function_details,
|
|
226
|
+
_raw_function_details)
|
|
227
|
+
|
|
228
|
+
# Update the docstring to use new function name from mapper, if exists.
|
|
229
|
+
method_func.__name__ = new_func_name
|
|
230
|
+
method_func.__doc__ = _processed_function_details["doc_string"].format(
|
|
231
|
+
function_name=new_func_name,
|
|
232
|
+
description=_processed_function_details["func_description"],
|
|
233
|
+
class_name=_class_name,
|
|
234
|
+
module_name=current_module.__name__)
|
|
235
|
+
|
|
236
|
+
setattr(getattr(current_module, _class_name), method_func.__name__, method_func)
|