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,487 @@
|
|
|
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 _SDKParam class which is used to create SDK function parameters'
|
|
13
|
+
# argInfoMatrix.
|
|
14
|
+
#
|
|
15
|
+
# ################################################################################################
|
|
16
|
+
|
|
17
|
+
import logging
|
|
18
|
+
from typing import Any, Dict, Tuple, Union
|
|
19
|
+
|
|
20
|
+
from ._openapi_spec_constants import DefaultConstants as dc
|
|
21
|
+
from ._openapi_spec_constants import ParameterObject as po
|
|
22
|
+
from ._openapi_spec_constants import RequestBodyObject as rbo
|
|
23
|
+
from ._openapi_spec_constants import SchemaObject as so
|
|
24
|
+
|
|
25
|
+
from._openapi_spec_constants import ResponseObject as ro
|
|
26
|
+
from teradataml.common.messagecodes import MessageCodes
|
|
27
|
+
from teradataml.common.messages import Messages
|
|
28
|
+
from teradataml.common.utils import UtilFuncs
|
|
29
|
+
from teradataml.sdk._utils import _remove_duplicate_preserve_order
|
|
30
|
+
|
|
31
|
+
from ._openapi_spec_constants import MediaTypeObject as mto
|
|
32
|
+
from ._utils import _camel_to_snake
|
|
33
|
+
from .constants import \
|
|
34
|
+
_OPENAPI_TO_PYTHON_PARAM_TYPE_MAPPER as param_type_mapper
|
|
35
|
+
from .constants import ParameterTypes
|
|
36
|
+
|
|
37
|
+
_logger = logging.getLogger(__name__)
|
|
38
|
+
|
|
39
|
+
class _SDKParam(object):
|
|
40
|
+
"""
|
|
41
|
+
Base class for SDK function parameters.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
def __init__(self, path: str, method: str, operation_id: str,
|
|
45
|
+
current_module: Any,
|
|
46
|
+
# Dict for parameters - body, path, query.
|
|
47
|
+
# Tuple for response - (response_code, response_value).
|
|
48
|
+
parameter: Union[Dict, Tuple[str, Dict[str, Any]]]=None,
|
|
49
|
+
param_type: ParameterTypes=ParameterTypes.PARAM,
|
|
50
|
+
check_empty: bool=True,
|
|
51
|
+
debug: bool=False,
|
|
52
|
+
process_header_values: bool=False):
|
|
53
|
+
"""
|
|
54
|
+
DESCRIPTION:
|
|
55
|
+
Initialize the SDK function parameters.
|
|
56
|
+
|
|
57
|
+
PARAMETERS:
|
|
58
|
+
* path (str): The path of the API endpoint.
|
|
59
|
+
* method (str): The HTTP method of the API endpoint.
|
|
60
|
+
* operation_id (str): The operation ID of the API endpoint.
|
|
61
|
+
* current_module (Any): The current module where the SDK function is defined.
|
|
62
|
+
* parameter (Union[Dict, Tuple[str, Dict[str, Any]]]): The parameter dictionary or
|
|
63
|
+
a tuple containing the response code and response value.
|
|
64
|
+
* param_type (ParameterTypes): The type of the parameter (e.g., PARAM, BODY, PROJECTION, RESPONSE).
|
|
65
|
+
* check_empty (bool): Whether to check for empty string values in the parameter.
|
|
66
|
+
* debug (bool): Whether to enable debug mode for logging.
|
|
67
|
+
* process_header_values (bool): Whether to process header values for response parameters.
|
|
68
|
+
"""
|
|
69
|
+
self._parameter = self._response = None
|
|
70
|
+
if param_type == ParameterTypes.RESPONSE:
|
|
71
|
+
self._response_code = parameter[0]
|
|
72
|
+
self._response = parameter[1]
|
|
73
|
+
else:
|
|
74
|
+
self._parameter = parameter
|
|
75
|
+
self._check_empty = check_empty
|
|
76
|
+
self._debug = debug
|
|
77
|
+
self._path = path
|
|
78
|
+
self._method = method
|
|
79
|
+
self._operation_id = operation_id
|
|
80
|
+
self._current_module = current_module
|
|
81
|
+
self._missing_description = None
|
|
82
|
+
if param_type == ParameterTypes.PARAM:
|
|
83
|
+
self._process_regular_parameter()
|
|
84
|
+
elif param_type == ParameterTypes.BODY:
|
|
85
|
+
self._process_body_parameter()
|
|
86
|
+
elif param_type == ParameterTypes.PROJECTION:
|
|
87
|
+
self._process_projection_query_parameter()
|
|
88
|
+
elif param_type == ParameterTypes.RESPONSE:
|
|
89
|
+
self._process_response_parameter(process_header_values=process_header_values)
|
|
90
|
+
|
|
91
|
+
def _update_params_dict(self, path_params_dict:dict, query_params_dict:dict):
|
|
92
|
+
"""
|
|
93
|
+
Update the path and query parameters dictionaries with key as old parameter name
|
|
94
|
+
(as in spec) and value as the new parameter names, based on path or query parameter type.
|
|
95
|
+
Args:
|
|
96
|
+
path_params_dict (dict): The dictionary of path parameters.
|
|
97
|
+
query_params_dict (dict): The dictionary of query parameters.
|
|
98
|
+
"""
|
|
99
|
+
if self._in == "path":
|
|
100
|
+
# Path parameters are mandatory.
|
|
101
|
+
path_params_dict[self._old_name] = self._new_name
|
|
102
|
+
elif self._in == "query":
|
|
103
|
+
# Query parameters are optional.
|
|
104
|
+
query_params_dict[self._old_name] = self._new_name
|
|
105
|
+
else:
|
|
106
|
+
raise ValueError(f"Unsupported parameter type: {self._in}. "\
|
|
107
|
+
"Currently only path and query parameters are supported.")
|
|
108
|
+
|
|
109
|
+
def _process_regular_parameter(self):
|
|
110
|
+
"""
|
|
111
|
+
Process the parameter to extract relevant information.
|
|
112
|
+
"""
|
|
113
|
+
param = self._parameter
|
|
114
|
+
|
|
115
|
+
self._old_name = param.get(po.NAME.value)
|
|
116
|
+
self._new_name = _camel_to_snake(self._old_name)
|
|
117
|
+
|
|
118
|
+
# If the "required" field is not specified, the default value depends on the in value:
|
|
119
|
+
# in: path → "required" defaults to True (mandatory).
|
|
120
|
+
# in: query, in: header, and in: cookie → required defaults to False (optional).
|
|
121
|
+
|
|
122
|
+
self._in = param.get(po.IN.value)
|
|
123
|
+
# Default for required field is False for query, cookie and header params.
|
|
124
|
+
p_required = True if self._in == "path" else False
|
|
125
|
+
|
|
126
|
+
_req_key_name = po.REQUIRED.value
|
|
127
|
+
self._required = param.get(_req_key_name) == True or param.get(_req_key_name) == "true" \
|
|
128
|
+
or p_required
|
|
129
|
+
|
|
130
|
+
_schema = param.get(po.SCHEMA.value)
|
|
131
|
+
|
|
132
|
+
if not _schema:
|
|
133
|
+
print(f"Warning: No schema found for parameter {self._old_name}. Not processing it.")
|
|
134
|
+
else:
|
|
135
|
+
self.__process_schema(_schema)
|
|
136
|
+
|
|
137
|
+
_description = param.get(rbo.DESCRIPTION.value)
|
|
138
|
+
if _description is None:
|
|
139
|
+
_description = dc.DEFAULT_DESCRIPTION.value
|
|
140
|
+
self._missing_description = self._old_name
|
|
141
|
+
if self._debug:
|
|
142
|
+
msg = self.__get_warning_message(
|
|
143
|
+
not_provided=f"Description of path/query parameter '{self._old_name}'",
|
|
144
|
+
default_value=f"description '{_description}'")
|
|
145
|
+
_logger.warning(msg=msg)
|
|
146
|
+
|
|
147
|
+
self.__build_docstring(self._in, _description)
|
|
148
|
+
|
|
149
|
+
def __build_permitted_types_str(self):
|
|
150
|
+
"""
|
|
151
|
+
Builds and returns a string representation of the permitted types for the object.
|
|
152
|
+
This method iterates over the `_permitted_types` attribute, which is expected to be a list
|
|
153
|
+
of types or other objects.
|
|
154
|
+
Note:
|
|
155
|
+
If `_permitted_types` is empty, the default string "dict" is used.
|
|
156
|
+
|
|
157
|
+
Returns:
|
|
158
|
+
str: A string describing the permitted types, formatted as "Types: <types>".
|
|
159
|
+
"""
|
|
160
|
+
|
|
161
|
+
_perm_list = []
|
|
162
|
+
for a in self._permitted_types:
|
|
163
|
+
try:
|
|
164
|
+
_perm_list.append(a.__name__)
|
|
165
|
+
except AttributeError:
|
|
166
|
+
# Handle case where a is not a class or does not have __name__ attribute
|
|
167
|
+
_perm_list.append(a)
|
|
168
|
+
_permitted_str = ", ".join(_perm_list) if self._permitted_types else "dict"
|
|
169
|
+
return f"Types: {_permitted_str}"
|
|
170
|
+
|
|
171
|
+
def __build_docstring(self, in_: str, description: str, incl_in: bool=False):
|
|
172
|
+
"""
|
|
173
|
+
Build the docstring for the parameter, given whether in path/query/body and description.
|
|
174
|
+
"""
|
|
175
|
+
_req_str = "Required" if self._required else "Optional"
|
|
176
|
+
|
|
177
|
+
# Docstring containing arg details - name, optional/required, query/path/body.
|
|
178
|
+
self._docstr_arg_details = f"{self._new_name} ({_req_str})"
|
|
179
|
+
if incl_in:
|
|
180
|
+
# If 'in' is included, append it to the arg details.
|
|
181
|
+
self._docstr_arg_details += f" ({in_}):"
|
|
182
|
+
else:
|
|
183
|
+
# If 'in' is not included, append it to the arg details.
|
|
184
|
+
self._docstr_arg_details += ":"
|
|
185
|
+
# Docstring containing description.
|
|
186
|
+
self._docstr_desc = description
|
|
187
|
+
# Docstring containing permitted types.
|
|
188
|
+
self._docstr_perm_types = self.__build_permitted_types_str()
|
|
189
|
+
# Docstring containing permitted values.
|
|
190
|
+
self._docstr_perm_values = None
|
|
191
|
+
if self._permitted_values:
|
|
192
|
+
_permitted_values_str = ", ".join([str(v) for v in self._permitted_values])
|
|
193
|
+
self._docstr_perm_values = f"Permitted values: {_permitted_values_str}"
|
|
194
|
+
|
|
195
|
+
def _process_body_parameter(self):
|
|
196
|
+
"""
|
|
197
|
+
Process the body parameter to extract relevant information.
|
|
198
|
+
"""
|
|
199
|
+
body = self._parameter
|
|
200
|
+
|
|
201
|
+
# Only one requestBody is allowed per operation.
|
|
202
|
+
# Use oneOf or anyOf for multiple schema possibilities.
|
|
203
|
+
# Use different media types to handle various content types.
|
|
204
|
+
# TODO: So, body.get("content", {}) can have multiple content types.
|
|
205
|
+
|
|
206
|
+
_schema = body.get(rbo.CONTENT.value, {}).get("application/json", {}).get("schema")
|
|
207
|
+
|
|
208
|
+
if _schema:
|
|
209
|
+
self._old_name = "body"
|
|
210
|
+
self._new_name = "body"
|
|
211
|
+
self._in = "body"
|
|
212
|
+
|
|
213
|
+
# "required" field documentation in https://swagger.io/specification/#request-body-object
|
|
214
|
+
# required, boolean, Determines if the request body is required in the request. Defaults to false.
|
|
215
|
+
self._required = body.get(rbo.REQUIRED.value)
|
|
216
|
+
|
|
217
|
+
if self._required is None:
|
|
218
|
+
self._required = False
|
|
219
|
+
if self._debug:
|
|
220
|
+
msg = self.__get_warning_message(not_provided="'required' field of requestBody",
|
|
221
|
+
default_value=f"value '{self._required}'")
|
|
222
|
+
_logger.warning(msg=msg)
|
|
223
|
+
|
|
224
|
+
self.__process_schema(_schema)
|
|
225
|
+
|
|
226
|
+
_description = body.get(rbo.DESCRIPTION.value)
|
|
227
|
+
if _description is None:
|
|
228
|
+
# If description is None, set it to default value.
|
|
229
|
+
_description = "Specifies body description."
|
|
230
|
+
self._missing_description = "requestBody"
|
|
231
|
+
if self._debug:
|
|
232
|
+
msg = self.__get_warning_message(not_provided=f"Description of 'requestBody'",
|
|
233
|
+
default_value=f"description '{_description}'")
|
|
234
|
+
_logger.warning(msg=msg)
|
|
235
|
+
|
|
236
|
+
self.__build_docstring("body", _description)
|
|
237
|
+
|
|
238
|
+
else:
|
|
239
|
+
# If there is no schema.
|
|
240
|
+
print("Warning: No schema found for 'requestBody'. Not processing it.")
|
|
241
|
+
|
|
242
|
+
def _process_projection_query_parameter(self):
|
|
243
|
+
"""
|
|
244
|
+
Set required class variables to add "projection" as query parameter.
|
|
245
|
+
"""
|
|
246
|
+
self._old_name = "projection"
|
|
247
|
+
self._new_name = "projection"
|
|
248
|
+
self._in = "query"
|
|
249
|
+
self._required = False
|
|
250
|
+
self._permitted_types = (str,)
|
|
251
|
+
self._permitted_values = None
|
|
252
|
+
self._default = None
|
|
253
|
+
# Docstring containing arg details - name, optional/required, query/path/body.
|
|
254
|
+
self._docstr_arg_details = "projection (Optional) (query):"
|
|
255
|
+
# Docstring containing description.
|
|
256
|
+
self._docstr_desc = "Specifies the projection type."
|
|
257
|
+
# Docstring containing permitted types.
|
|
258
|
+
self._docstr_perm_types = "Types: str"
|
|
259
|
+
# Docstring containing permitted values.
|
|
260
|
+
self._docstr_perm_values = None
|
|
261
|
+
self._missing_description = "projection" # Description is not provided for projection.
|
|
262
|
+
if self._debug:
|
|
263
|
+
msg = self.__get_warning_message(
|
|
264
|
+
not_provided="Description of path parameter 'projection'",
|
|
265
|
+
default_value=f"description '{self._docstr_desc}'")
|
|
266
|
+
_logger.warning(msg=msg)
|
|
267
|
+
|
|
268
|
+
def _process_response_parameter(self, process_header_values: bool=False):
|
|
269
|
+
"""
|
|
270
|
+
Process the response parameter to extract relevant information.
|
|
271
|
+
"""
|
|
272
|
+
_int_code = int(self._response_code)
|
|
273
|
+
_content:Dict = self._response.get(ro.CONTENT.value)
|
|
274
|
+
_description = self._response.get(ro.DESCRIPTION.value)
|
|
275
|
+
if _description is None:
|
|
276
|
+
_description = UtilFuncs._get_http_status_phrases_description()[_int_code]["phrase"]
|
|
277
|
+
|
|
278
|
+
self._permitted_types = None
|
|
279
|
+
self._permitted_values = None
|
|
280
|
+
self._return_types = []
|
|
281
|
+
self._header_values = []
|
|
282
|
+
|
|
283
|
+
self._response_docstr = f"{_int_code} ({_description})"
|
|
284
|
+
|
|
285
|
+
if _content:
|
|
286
|
+
self._process_response_content(_content)
|
|
287
|
+
|
|
288
|
+
self._header_values = _remove_duplicate_preserve_order(self._header_values)
|
|
289
|
+
|
|
290
|
+
_other_output = ""
|
|
291
|
+
if self._return_types:
|
|
292
|
+
# If return types are found, build the permitted types string.
|
|
293
|
+
self._return_types = _remove_duplicate_preserve_order(self._return_types)
|
|
294
|
+
_other_output += f"{', '.join([t.__name__ for t in self._return_types])}"
|
|
295
|
+
|
|
296
|
+
if self._header_values and process_header_values:
|
|
297
|
+
if _other_output != "":
|
|
298
|
+
_other_output += " "
|
|
299
|
+
_other_output += f"{self._header_values}"
|
|
300
|
+
|
|
301
|
+
if _other_output != "":
|
|
302
|
+
self._response_docstr += f": {_other_output}"
|
|
303
|
+
|
|
304
|
+
def _process_response_content(self, content:dict):
|
|
305
|
+
"""
|
|
306
|
+
Process the response content to extract relevant information - like header values and return types.
|
|
307
|
+
|
|
308
|
+
Args:
|
|
309
|
+
content (dict): The response content dictionary.
|
|
310
|
+
|
|
311
|
+
This method updates the _header_values and _return_types attributes based on the response content.
|
|
312
|
+
For 2xx response codes, it processes the schema to populate permitted types and values.
|
|
313
|
+
"""
|
|
314
|
+
_int_code = int(self._response_code)
|
|
315
|
+
for _resp_header, _resp_schema in content.items():
|
|
316
|
+
self._header_values.append(_resp_header)
|
|
317
|
+
if 200 <= _int_code < 300:
|
|
318
|
+
_schema_obj = _resp_schema.get(mto.SCHEMA.value, {})
|
|
319
|
+
self.__process_schema(_schema_obj) # popualates permitted types and values.
|
|
320
|
+
self._return_types.extend(list(self._permitted_types))
|
|
321
|
+
else:
|
|
322
|
+
self._response_docstr = None
|
|
323
|
+
|
|
324
|
+
def get_arg_info_list(self, arg_value: Any):
|
|
325
|
+
"""
|
|
326
|
+
Get the argument information list.
|
|
327
|
+
|
|
328
|
+
Returns:
|
|
329
|
+
list: A list containing the argument information.
|
|
330
|
+
"""
|
|
331
|
+
# arginfomatrix:
|
|
332
|
+
# 0 - arg_name
|
|
333
|
+
# 1 - arg_value
|
|
334
|
+
# 2 - is_optional or not - False means the argument is required.
|
|
335
|
+
# 3 - permitted Data types
|
|
336
|
+
# 4 - empty string check - True means the argument should be checked for empty string.
|
|
337
|
+
# 5 - permitted values if not None
|
|
338
|
+
return [self._new_name, arg_value, self.is_optional, self._permitted_types,
|
|
339
|
+
self._check_empty, self._permitted_values]
|
|
340
|
+
|
|
341
|
+
def __get_warning_message(self, not_provided: str, default_value: str):
|
|
342
|
+
"""
|
|
343
|
+
Get the warning message for missing description.
|
|
344
|
+
|
|
345
|
+
Args:
|
|
346
|
+
not_provided (str): The name/info of the parameter that is not provided.
|
|
347
|
+
default_value (str): The default info to be used.
|
|
348
|
+
|
|
349
|
+
Returns:
|
|
350
|
+
str: The warning message.
|
|
351
|
+
"""
|
|
352
|
+
return Messages.get_message(MessageCodes.INFO_NOT_PROVIDED_USE_DEFAULT,
|
|
353
|
+
not_provided,
|
|
354
|
+
self._path,
|
|
355
|
+
self._method,
|
|
356
|
+
self._operation_id,
|
|
357
|
+
default_value)
|
|
358
|
+
|
|
359
|
+
@property
|
|
360
|
+
def is_optional(self):
|
|
361
|
+
"""
|
|
362
|
+
Check if the parameter is optional.
|
|
363
|
+
|
|
364
|
+
Returns:
|
|
365
|
+
bool: True if the parameter is optional, False otherwise.
|
|
366
|
+
"""
|
|
367
|
+
return not self._required
|
|
368
|
+
|
|
369
|
+
@property
|
|
370
|
+
def param_name(self):
|
|
371
|
+
"""
|
|
372
|
+
Get the parameter name.
|
|
373
|
+
|
|
374
|
+
Returns:
|
|
375
|
+
str: The parameter name.
|
|
376
|
+
"""
|
|
377
|
+
return self._new_name
|
|
378
|
+
|
|
379
|
+
@property
|
|
380
|
+
def permitted_types(self):
|
|
381
|
+
"""
|
|
382
|
+
Get the permitted types for the parameter.
|
|
383
|
+
|
|
384
|
+
Returns:
|
|
385
|
+
tuple: A tuple containing the permitted types.
|
|
386
|
+
"""
|
|
387
|
+
return self._permitted_types
|
|
388
|
+
|
|
389
|
+
@property
|
|
390
|
+
def permitted_values(self):
|
|
391
|
+
"""
|
|
392
|
+
Get the permitted values for the parameter.
|
|
393
|
+
|
|
394
|
+
Returns:
|
|
395
|
+
list: A list of permitted values.
|
|
396
|
+
"""
|
|
397
|
+
return self._permitted_values
|
|
398
|
+
|
|
399
|
+
# def __get_param_arg_signature(self):
|
|
400
|
+
# """
|
|
401
|
+
# Returns the parameter argument signature.
|
|
402
|
+
# """
|
|
403
|
+
# # TODO: Need some modification here. Seems to be incorrect for required and default values.
|
|
404
|
+
# param_arg_signature_value = f"{p_name}"
|
|
405
|
+
# if p_required or p_default == "None":
|
|
406
|
+
# param_arg_signature_value = f"{param_arg_signature_value} = None"
|
|
407
|
+
# elif p_default:
|
|
408
|
+
# param_arg_signature_value = f"{param_arg_signature_value} = {p_default}"
|
|
409
|
+
# return param_arg_signature_value
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
def __process_schema(self, schema:dict):
|
|
413
|
+
"""
|
|
414
|
+
Process the schema to extract relevant information.
|
|
415
|
+
|
|
416
|
+
Args:
|
|
417
|
+
schema (dict): The schema to process.
|
|
418
|
+
|
|
419
|
+
Returns:
|
|
420
|
+
tuple: A tuple containing the permitted types and values.
|
|
421
|
+
"""
|
|
422
|
+
_schema_ref = schema.get(so.REF.value)
|
|
423
|
+
if _schema_ref:
|
|
424
|
+
# If $ref exists, use the last part of the reference as the type.
|
|
425
|
+
# Example: "#/components/schemas/ModelOps" -> permitted type is ("ModelOps", dict).
|
|
426
|
+
# For body, permitted values and default values are not applicable.
|
|
427
|
+
_ref_obj_name = _schema_ref.split("/")[-1]
|
|
428
|
+
# TODO: See if we can use this ref_obj_name as argument name.
|
|
429
|
+
# Uncomment below line if we have to use it.
|
|
430
|
+
# self._new_name = _camel_to_snake(_ref_obj_name)
|
|
431
|
+
|
|
432
|
+
# Schema classes are present in models module of the current module.
|
|
433
|
+
models_module = None
|
|
434
|
+
try:
|
|
435
|
+
# If $ref is used, it should be present in the "models" module.
|
|
436
|
+
models_module = getattr(self._current_module, "models")
|
|
437
|
+
except AttributeError as e:
|
|
438
|
+
raise AttributeError(f"Module {self._current_module.__name__} does not have 'models' "
|
|
439
|
+
"attribute to access schema classes.") from e
|
|
440
|
+
try:
|
|
441
|
+
schema_class = getattr(models_module, _ref_obj_name)
|
|
442
|
+
except AttributeError as e:
|
|
443
|
+
raise AttributeError(f"Module '{self._current_module.__name__}.models' does not have "
|
|
444
|
+
f"'{_ref_obj_name}' class.") from e
|
|
445
|
+
|
|
446
|
+
self._permitted_types = (schema_class, dict)
|
|
447
|
+
# Special case for JsonNode because of issue in ModelOps OpenAPI spec.
|
|
448
|
+
# TODO: Remove this if condition and add check for list/array when this is fixed as
|
|
449
|
+
# part of https://teradata-pe.atlassian.net/browse/VMO-1881.
|
|
450
|
+
if _ref_obj_name == "JsonNode":
|
|
451
|
+
self._permitted_types = (dict, list)
|
|
452
|
+
|
|
453
|
+
self._permitted_values = None
|
|
454
|
+
self._default = None
|
|
455
|
+
return
|
|
456
|
+
|
|
457
|
+
# If no schema type is found, default to dict.
|
|
458
|
+
p_type = schema.get(so.TYPE.value, dc.DEFAULT_SCHEMA_TYPE.value) \
|
|
459
|
+
if schema else dc.DEFAULT_SCHEMA_TYPE.value
|
|
460
|
+
|
|
461
|
+
# Default to dict if not found in the mapper.
|
|
462
|
+
p_type = param_type_mapper.get(p_type, dict)
|
|
463
|
+
self._permitted_types = (p_type,)
|
|
464
|
+
if p_type == list:
|
|
465
|
+
# If the type is list, check types of items in the schema.
|
|
466
|
+
elem_type = schema.get(so.ITEMS.value, {}).get(so.TYPE.value, dc.DEFAULT_SCHEMA_TYPE.value)
|
|
467
|
+
if elem_type in param_type_mapper:
|
|
468
|
+
self._permitted_types = (param_type_mapper[elem_type], list)
|
|
469
|
+
else:
|
|
470
|
+
# Default to dict OR list of dicts if not found in the mapper.
|
|
471
|
+
self._permitted_types = (dict, list)
|
|
472
|
+
|
|
473
|
+
# Get permitted enum values from Schema object.
|
|
474
|
+
self._permitted_values = schema.get(so.ENUM.value)
|
|
475
|
+
|
|
476
|
+
self._default = schema.get(so.DEFAULT.value, dc.DEFAULT_SCHEMA_VALUE.value) \
|
|
477
|
+
if schema else dc.DEFAULT_SCHEMA_VALUE.value
|
|
478
|
+
|
|
479
|
+
def __repr__(self):
|
|
480
|
+
"""
|
|
481
|
+
Return a string representation of the SDK function parameters.
|
|
482
|
+
|
|
483
|
+
Returns:
|
|
484
|
+
str: String representation of the SDK function parameters.
|
|
485
|
+
"""
|
|
486
|
+
return f"{self.__class__.__name__}" +\
|
|
487
|
+
f"(param_name={self._new_name}, is_optional={not self._required}, ...)"
|