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.

Files changed (131) hide show
  1. teradataml/LICENSE-3RD-PARTY.pdf +0 -0
  2. teradataml/README.md +182 -13
  3. teradataml/__init__.py +2 -1
  4. teradataml/_version.py +2 -2
  5. teradataml/analytics/analytic_function_executor.py +8 -13
  6. teradataml/analytics/json_parser/analytic_functions_argument.py +4 -0
  7. teradataml/analytics/sqle/__init__.py +16 -1
  8. teradataml/analytics/utils.py +60 -1
  9. teradataml/automl/__init__.py +290 -106
  10. teradataml/automl/autodataprep/__init__.py +471 -0
  11. teradataml/automl/data_preparation.py +29 -10
  12. teradataml/automl/data_transformation.py +11 -0
  13. teradataml/automl/feature_engineering.py +64 -4
  14. teradataml/automl/feature_exploration.py +639 -25
  15. teradataml/automl/model_training.py +1 -1
  16. teradataml/clients/auth_client.py +12 -8
  17. teradataml/clients/keycloak_client.py +165 -0
  18. teradataml/common/constants.py +71 -26
  19. teradataml/common/exceptions.py +32 -0
  20. teradataml/common/messagecodes.py +28 -0
  21. teradataml/common/messages.py +13 -4
  22. teradataml/common/sqlbundle.py +3 -2
  23. teradataml/common/utils.py +345 -45
  24. teradataml/context/context.py +259 -93
  25. teradataml/data/apriori_example.json +22 -0
  26. teradataml/data/docs/sqle/docs_17_20/Apriori.py +138 -0
  27. teradataml/data/docs/sqle/docs_17_20/NERExtractor.py +121 -0
  28. teradataml/data/docs/sqle/docs_17_20/NGramSplitter.py +3 -3
  29. teradataml/data/docs/sqle/docs_17_20/SMOTE.py +212 -0
  30. teradataml/data/docs/sqle/docs_17_20/TextMorph.py +119 -0
  31. teradataml/data/docs/sqle/docs_17_20/TextParser.py +54 -3
  32. teradataml/data/docs/uaf/docs_17_20/ACF.py +1 -1
  33. teradataml/data/docs/uaf/docs_17_20/ArimaEstimate.py +2 -2
  34. teradataml/data/docs/uaf/docs_17_20/ArimaXEstimate.py +2 -2
  35. teradataml/data/docs/uaf/docs_17_20/DFFT.py +1 -1
  36. teradataml/data/docs/uaf/docs_17_20/DFFT2.py +1 -1
  37. teradataml/data/docs/uaf/docs_17_20/DFFT2Conv.py +1 -1
  38. teradataml/data/docs/uaf/docs_17_20/DFFTConv.py +1 -1
  39. teradataml/data/docs/uaf/docs_17_20/FilterFactory1d.py +4 -4
  40. teradataml/data/docs/uaf/docs_17_20/GenseriesSinusoids.py +2 -2
  41. teradataml/data/docs/uaf/docs_17_20/GoldfeldQuandt.py +2 -2
  42. teradataml/data/docs/uaf/docs_17_20/HoltWintersForecaster.py +6 -6
  43. teradataml/data/docs/uaf/docs_17_20/LineSpec.py +1 -1
  44. teradataml/data/docs/uaf/docs_17_20/LinearRegr.py +1 -1
  45. teradataml/data/docs/uaf/docs_17_20/Matrix2Image.py +4 -4
  46. teradataml/data/docs/uaf/docs_17_20/MultivarRegr.py +1 -1
  47. teradataml/data/docs/uaf/docs_17_20/PACF.py +1 -1
  48. teradataml/data/docs/uaf/docs_17_20/PowerSpec.py +2 -2
  49. teradataml/data/docs/uaf/docs_17_20/PowerTransform.py +3 -3
  50. teradataml/data/docs/uaf/docs_17_20/Resample.py +5 -5
  51. teradataml/data/docs/uaf/docs_17_20/SAX.py +3 -3
  52. teradataml/data/docs/uaf/docs_17_20/SignifPeriodicities.py +1 -1
  53. teradataml/data/docs/uaf/docs_17_20/SimpleExp.py +1 -1
  54. teradataml/data/docs/uaf/docs_17_20/Smoothma.py +3 -3
  55. teradataml/data/docs/uaf/docs_17_20/UNDIFF.py +1 -1
  56. teradataml/data/jsons/byom/onnxembeddings.json +1 -0
  57. teradataml/data/jsons/sqle/17.20/NGramSplitter.json +6 -6
  58. teradataml/data/jsons/sqle/17.20/TD_Apriori.json +181 -0
  59. teradataml/data/jsons/sqle/17.20/TD_NERExtractor.json +145 -0
  60. teradataml/data/jsons/sqle/17.20/TD_SMOTE.json +267 -0
  61. teradataml/data/jsons/sqle/17.20/TD_TextMorph.json +134 -0
  62. teradataml/data/jsons/sqle/17.20/TD_TextParser.json +114 -9
  63. teradataml/data/jsons/sqle/20.00/AI_AnalyzeSentiment.json +328 -0
  64. teradataml/data/jsons/sqle/20.00/AI_AskLLM.json +420 -0
  65. teradataml/data/jsons/sqle/20.00/AI_DetectLanguage.json +343 -0
  66. teradataml/data/jsons/sqle/20.00/AI_ExtractKeyPhrases.json +328 -0
  67. teradataml/data/jsons/sqle/20.00/AI_MaskPII.json +328 -0
  68. teradataml/data/jsons/sqle/20.00/AI_RecognizeEntities.json +328 -0
  69. teradataml/data/jsons/sqle/20.00/AI_RecognizePIIEntities.json +328 -0
  70. teradataml/data/jsons/sqle/20.00/AI_TextClassifier.json +359 -0
  71. teradataml/data/jsons/sqle/20.00/AI_TextEmbeddings.json +360 -0
  72. teradataml/data/jsons/sqle/20.00/AI_TextSummarize.json +343 -0
  73. teradataml/data/jsons/sqle/20.00/AI_TextTranslate.json +343 -0
  74. teradataml/data/jsons/sqle/20.00/TD_SMOTE.json +2 -2
  75. teradataml/data/jsons/sqle/20.00/TD_VectorDistance.json +1 -1
  76. teradataml/data/ner_dict.csv +8 -0
  77. teradataml/data/ner_input_eng.csv +7 -0
  78. teradataml/data/ner_rule.csv +5 -0
  79. teradataml/data/pattern_matching_data.csv +11 -0
  80. teradataml/data/pos_input.csv +40 -0
  81. teradataml/data/sdk/modelops/modelops_spec.json +101737 -0
  82. teradataml/data/tdnerextractor_example.json +14 -0
  83. teradataml/data/teradataml_example.json +21 -1
  84. teradataml/data/textmorph_example.json +5 -0
  85. teradataml/data/to_num_data.csv +4 -0
  86. teradataml/data/tochar_data.csv +5 -0
  87. teradataml/data/trans_dense.csv +16 -0
  88. teradataml/data/trans_sparse.csv +55 -0
  89. teradataml/data/url_data.csv +10 -9
  90. teradataml/dataframe/copy_to.py +38 -27
  91. teradataml/dataframe/data_transfer.py +61 -45
  92. teradataml/dataframe/dataframe.py +1110 -132
  93. teradataml/dataframe/dataframe_utils.py +73 -27
  94. teradataml/dataframe/functions.py +1070 -9
  95. teradataml/dataframe/sql.py +750 -959
  96. teradataml/dbutils/dbutils.py +33 -13
  97. teradataml/dbutils/filemgr.py +14 -10
  98. teradataml/hyperparameter_tuner/utils.py +4 -2
  99. teradataml/lib/aed_0_1.dll +0 -0
  100. teradataml/opensource/_base.py +12 -157
  101. teradataml/options/configure.py +24 -9
  102. teradataml/scriptmgmt/UserEnv.py +317 -39
  103. teradataml/scriptmgmt/lls_utils.py +456 -135
  104. teradataml/sdk/README.md +79 -0
  105. teradataml/sdk/__init__.py +4 -0
  106. teradataml/sdk/_auth_modes.py +422 -0
  107. teradataml/sdk/_func_params.py +487 -0
  108. teradataml/sdk/_json_parser.py +453 -0
  109. teradataml/sdk/_openapi_spec_constants.py +249 -0
  110. teradataml/sdk/_utils.py +236 -0
  111. teradataml/sdk/api_client.py +897 -0
  112. teradataml/sdk/constants.py +62 -0
  113. teradataml/sdk/modelops/__init__.py +98 -0
  114. teradataml/sdk/modelops/_client.py +406 -0
  115. teradataml/sdk/modelops/_constants.py +304 -0
  116. teradataml/sdk/modelops/models.py +2308 -0
  117. teradataml/sdk/spinner.py +107 -0
  118. teradataml/store/__init__.py +1 -1
  119. teradataml/table_operators/Apply.py +16 -1
  120. teradataml/table_operators/Script.py +20 -1
  121. teradataml/table_operators/query_generator.py +4 -21
  122. teradataml/table_operators/table_operator_util.py +58 -9
  123. teradataml/utils/dtypes.py +4 -2
  124. teradataml/utils/internal_buffer.py +22 -2
  125. teradataml/utils/utils.py +0 -1
  126. teradataml/utils/validators.py +318 -58
  127. {teradataml-20.0.0.4.dist-info → teradataml-20.0.0.6.dist-info}/METADATA +188 -14
  128. {teradataml-20.0.0.4.dist-info → teradataml-20.0.0.6.dist-info}/RECORD +131 -84
  129. {teradataml-20.0.0.4.dist-info → teradataml-20.0.0.6.dist-info}/WHEEL +0 -0
  130. {teradataml-20.0.0.4.dist-info → teradataml-20.0.0.6.dist-info}/top_level.txt +0 -0
  131. {teradataml-20.0.0.4.dist-info → teradataml-20.0.0.6.dist-info}/zip-safe +0 -0
@@ -775,7 +775,7 @@ class _ModelTraining:
775
775
 
776
776
  # Defining training data
777
777
  data_types = ['lasso', 'rfe', 'pca']
778
- trainng_datas = tuple(DataFrame(self.table_name_mapping[f'{data_type}_train']) for data_type in data_types)
778
+ trainng_datas = tuple(DataFrame(self.data_mapping[f'{data_type}_train']) for data_type in data_types)
779
779
 
780
780
  if self.task_type == "Classification":
781
781
  response_values = trainng_datas[0].get(self.target_column).drop_duplicate().get_values().flatten().tolist()
@@ -1,6 +1,6 @@
1
1
  """
2
2
  Unpublished work.
3
- Copyright (c) 2024 by Teradata Corporation. All rights reserved.
3
+ Copyright (c) 2025 by Teradata Corporation. All rights reserved.
4
4
  TERADATA CORPORATION CONFIDENTIAL AND TRADE SECRET
5
5
  Primary Owner: gouri.patwardhan@teradata.com
6
6
  Secondary Owner: Pradeep.Garre@teradata.com
@@ -33,6 +33,8 @@ class _AuthWorkflow:
33
33
  5. "username" which is the DB user.
34
34
  5. "expiration_time" which is the expiration time for the token and has a default value of
35
35
  31536000 seconds.
36
+ 6. "valid_from" which states epoch seconds representing time from which JWT token will be valid
37
+ and same is used as iat claim in payload.
36
38
  Types: dict
37
39
 
38
40
  RETURNS:
@@ -52,7 +54,7 @@ class _AuthWorkflow:
52
54
  Generate expiry epoch time.
53
55
 
54
56
  RETURNS:
55
- float
57
+ tuple
56
58
  """
57
59
  current_epoch_time = int(time.time())
58
60
  expiry_epoch_time = current_epoch_time + self.state.get('expiration_time')
@@ -67,7 +69,7 @@ class _AuthWorkflow:
67
69
  dict
68
70
  """
69
71
  # Extract the pem file name without extension.
70
- kid = pathlib.Path(self.state.get('pem_file')).stem
72
+ kid = pathlib.Path(self.state.get('pem_file')).stem if not self.state.get('kid') else self.state['kid']
71
73
  header = {
72
74
  "alg": "RS256",
73
75
  "kid": kid,
@@ -83,12 +85,11 @@ class _AuthWorkflow:
83
85
  RETURNS:
84
86
  A dictionary with the JWT payload.
85
87
  """
86
- iat, exp= self._get_epoch_time()
88
+ _, exp = self._get_epoch_time()
87
89
  payload = {
88
90
  "aud": [
89
91
  "td:service:authentication"
90
92
  ],
91
- "iat": iat,
92
93
  "exp": exp,
93
94
  "iss": "teradataml",
94
95
  "multi-use": True,
@@ -96,6 +97,9 @@ class _AuthWorkflow:
96
97
  "pat": self.state['pat_token'],
97
98
  "sub": self.state['username']
98
99
  }
100
+ # Add iat if required.
101
+ if self.state['valid_from']:
102
+ payload.update({"iat": self.state['valid_from']})
99
103
  return payload
100
104
 
101
105
  def _sign_jwt(self, payload, header):
@@ -128,6 +132,6 @@ class _AuthWorkflow:
128
132
  RETURNS:
129
133
  str
130
134
  """
131
- jwt = self._sign_jwt(self._generate_payload(), self._generate_header())
132
- self.state['jwt'] = jwt
133
- return(jwt)
135
+ jwt_token = self._sign_jwt(self._generate_payload(), self._generate_header())
136
+ self.state['jwt'] = jwt_token
137
+ return jwt_token
@@ -0,0 +1,165 @@
1
+ """
2
+ Unpublished work.
3
+ Copyright (c) 2025 by Teradata Corporation. All rights reserved.
4
+ TERADATA CORPORATION CONFIDENTIAL AND TRADE SECRET
5
+ Primary Owner: shivani.kondewar@teradata.com
6
+ Secondary Owner: aanchal.kavedia@teradata.com
7
+ This file implements _KeycloakManager class used to store data for keycloak token generation.
8
+ """
9
+
10
+ import time
11
+ from enum import Enum
12
+
13
+ from teradataml import TeradataMlException, MessageCodes
14
+ from teradataml.common.constants import HTTPRequest
15
+ from teradataml.context.context import _get_user
16
+
17
+
18
+ class GrantType(Enum):
19
+ PASS = "password"
20
+ REFRESH = "refresh_token"
21
+ CLIENT = "client_credentials"
22
+
23
+
24
+ class _KeycloakManager():
25
+
26
+ def __init__(self, auth_url, client_id):
27
+ """
28
+ DESCRIPTION:
29
+ Constructor to initiate keycloak manager.
30
+
31
+ PARAMETERS:
32
+ auth_url:
33
+ Required Argument.
34
+ Specifies the endpoint URL for a keycloak server.
35
+ Types: str
36
+
37
+ client_id:
38
+ Required Argument.
39
+ Specifies the client/service for which keycloak server avails a token.
40
+ Types: str
41
+
42
+ RETURNS:
43
+ Instance of _KeycloakManager.
44
+
45
+ RAISES:
46
+ None
47
+
48
+ EXAMPLES:
49
+ >>> token_generator = _KeycloakManager(auth_url=auth_url,
50
+ ... username=username,
51
+ ... client_id=client_id)
52
+ """
53
+ self._auth_url = auth_url
54
+ self._client_id = client_id
55
+ self._header = {"Content-Type": "application/x-www-form-urlencoded"}
56
+ self._expires_at = None
57
+ self._refresh_expires_at = None
58
+
59
+ def generate_token(self, username=None, password=None, refresh=False):
60
+ """
61
+ DESCRIPTION:
62
+ Method generates keycloak token.
63
+ Token can be generated using any one of the following information:
64
+ * Username and password
65
+ * Refresh token
66
+
67
+ PARAMETERS:
68
+ username:
69
+ Optional Argument.
70
+ Specifies the username for database user for which keycloak token is
71
+ to be generated. If not specified, then user associated with current
72
+ connection is used.
73
+ Types: str
74
+
75
+ password:
76
+ Optional Argument.
77
+ Specifies the password for database user.
78
+ Types: str
79
+
80
+ refresh:
81
+ Optional Argument.
82
+ Specifies the boolean flag to indicate if token needs to be generated
83
+ using existing refresh token or not.
84
+ Default value: False
85
+ Types: Boolean
86
+
87
+ RETURNS:
88
+ Keycloak token
89
+
90
+ RAISES:
91
+ RuntimeError.
92
+
93
+ EXAMPLES:
94
+ # Example 1: Generate the authentication token using username and password.
95
+ >>> keycloak_obj.generate_token(username="username", password="password")
96
+
97
+ # Example 2: Generate the authentication token using default username for
98
+ # current session and provided password.
99
+ >>> keycloak_obj.generate_token(password="password")
100
+
101
+ # Example 3: Generate the authentication token using refresh token which is
102
+ # already available.
103
+ >>> keycloak_obj.generate_token(refresh=True)
104
+ """
105
+ # Define the payload.
106
+ if password:
107
+ payload = {
108
+ "grant_type": GrantType.PASS.value,
109
+ "client_id": self._client_id,
110
+ "username": username if username else _get_user(),
111
+ "password": password
112
+ }
113
+ if refresh:
114
+ payload = {
115
+ "grant_type": GrantType.REFRESH.value,
116
+ "client_id": self._client_id,
117
+ "refresh_token": self._refresh_token
118
+ }
119
+
120
+ # Make the POST request.
121
+ # Importing locally to avoid circular import.
122
+ from teradataml import UtilFuncs
123
+ response = UtilFuncs._http_request(self._auth_url, HTTPRequest.POST,
124
+ headers=self._header, data=payload)
125
+
126
+ # Check the response.
127
+ if 200 <= response.status_code < 300:
128
+ response_data = response.json()
129
+ self._auth_token = response_data['access_token']
130
+ self._refresh_token = response_data['refresh_token']
131
+ # 30 is buffer time to assume delay in processing of response_data.
132
+ self._expires_at = time.time() + response_data['expires_in'] - 30
133
+ self._refresh_expires_at = time.time() + response_data['refresh_expires_in'] - 30
134
+ else:
135
+ raise
136
+
137
+ return self._auth_token
138
+
139
+ def get_token(self):
140
+ """
141
+ DESCRIPTION:
142
+ Function to get keycloak token.
143
+ If access token is not expired, existing token is returned.
144
+ If access token is expired, and refresh token is alive, new access token is generated.
145
+ If both access token and refresh token are expired, TeradataMlException is raised
146
+
147
+ RETURNS:
148
+ Keycloak token
149
+
150
+ RAISES:
151
+ TeradataMlException.
152
+
153
+ """
154
+ # If existing auth_token is expired, regenerate using refresh token.
155
+ if self._expires_at and time.time() > self._expires_at:
156
+ # If refresh token is expired, raise error.
157
+ if self._refresh_expires_at and time.time() > self._refresh_expires_at:
158
+ raise TeradataMlException("Refresh token for keycloak is expired."
159
+ " Execute set_auth_token() to set fresh authentication token.",
160
+ MessageCodes.FUNC_EXECUTION_FAILED)
161
+ else:
162
+ # Regenerate fresh access token using refresh token.
163
+ self.generate_token(refresh=True)
164
+
165
+ return self._auth_token
@@ -20,7 +20,7 @@ from teradatasqlalchemy.types import (BYTE, VARBYTE, BLOB)
20
20
  from teradatasqlalchemy import (CHAR, CLOB)
21
21
  from teradatasqlalchemy import (PERIOD_DATE, PERIOD_TIME, PERIOD_TIMESTAMP)
22
22
  from teradatasqlalchemy import (INTERVAL_YEAR, INTERVAL_YEAR_TO_MONTH, INTERVAL_MONTH,
23
- INTERVAL_DAY,INTERVAL_DAY_TO_HOUR, INTERVAL_DAY_TO_MINUTE,
23
+ INTERVAL_DAY, INTERVAL_DAY_TO_HOUR, INTERVAL_DAY_TO_MINUTE,
24
24
  INTERVAL_DAY_TO_SECOND, INTERVAL_HOUR,
25
25
  INTERVAL_HOUR_TO_MINUTE, INTERVAL_HOUR_TO_SECOND,
26
26
  INTERVAL_MINUTE, INTERVAL_MINUTE_TO_SECOND,
@@ -65,6 +65,8 @@ class SQLConstants(Enum):
65
65
  SQL_HELP_DATALAKE = 34
66
66
  CONSTRAINT = ["check_constraint", "primary_key_constraint",
67
67
  "foreign_key_constraint", "unique_key_constraint"]
68
+ SQL_TD_OTF_METADATA = 35
69
+ SQL_TD_OTF_SNAPSHOT = 36
68
70
 
69
71
 
70
72
  class TeradataConstants(Enum):
@@ -82,7 +84,7 @@ class TeradataConstants(Enum):
82
84
  # Order of operators
83
85
  # shouldn't be changed. This is the order in which join condition is tested - first, operators
84
86
  # with two characters and then the operators with single character.
85
- SUPPORTED_ENGINES = {"ENGINE_SQL" : {"name" : "sqle", "file" : "sqlengine_alias_definitions"}}
87
+ SUPPORTED_ENGINES = {"ENGINE_SQL": {"name": "sqle", "file": "sqlengine_alias_definitions"}}
86
88
  SUPPORTED_VANTAGE_VERSIONS = {"vantage1.0": "v1.0", "vantage1.1": "v1.1",
87
89
  "vantage1.3": "v1.3", "vantage2.0": "v1.1"}
88
90
  RANGE_SEPARATORS = [":"]
@@ -90,7 +92,7 @@ class TeradataConstants(Enum):
90
92
 
91
93
  class AEDConstants(Enum):
92
94
  AED_NODE_NOT_EXECUTED = 0
93
- AED_NODE_EXECUTED = 1
95
+ AED_NODE_EXECUTED = 1
94
96
  AED_DB_OBJECT_NAME_BUFFER_SIZE = 128
95
97
  AED_NODE_TYPE_BUFFER_SIZE = 32
96
98
  AED_ASSIGN_DROP_EXISITING_COLUMNS = "Y"
@@ -148,7 +150,7 @@ class TeradataTableKindConstants(Enum):
148
150
  TABLE = "table"
149
151
  VIEW = "view"
150
152
  TEMP = "temp"
151
- ALL = "all"
153
+ ALL = "all"
152
154
  ML_PATTERN = "ml_%"
153
155
  VOLATILE_TABLE_NAME = 'Table Name'
154
156
  REGULAR_TABLE_NAME = 'TableName'
@@ -220,7 +222,7 @@ class ModelCatalogingConstants(Enum):
220
222
 
221
223
 
222
224
  class CopyToConstants(Enum):
223
- DBAPI_BATCHSIZE = 16383
225
+ DBAPI_BATCHSIZE = 16383
224
226
 
225
227
 
226
228
  class PTITableConstants(Enum):
@@ -377,34 +379,34 @@ class GeospatialConstants(Enum):
377
379
  "buffer": lambda x: "ST_Buffer",
378
380
  "contains": lambda x: "ST_Contains",
379
381
  "crosses": lambda x: "ST_Crosses",
380
- "difference": lambda x: "ST_Difference", # M
382
+ "difference": lambda x: "ST_Difference", # M
381
383
  "disjoint": lambda x: "ST_Disjoint",
382
- "distance": lambda x: "ST_Distance", # M
383
- "distance_3D": lambda x: "ST_3DDistance", # M
384
+ "distance": lambda x: "ST_Distance", # M
385
+ "distance_3D": lambda x: "ST_3DDistance", # M
384
386
  "geom_equals": lambda x: "ST_Equals",
385
387
  "intersection": lambda x: "ST_Intersection",
386
- #"intersect": lambda x: "ST_Intersect", # M
388
+ # "intersect": lambda x: "ST_Intersect", # M
387
389
  "make_2D": lambda x: "Make_2D",
388
390
  "overlaps": lambda x: "ST_Overlaps",
389
391
  "relates": lambda x: "ST_Relate",
390
392
  "simplify": lambda x: "SimplifyPreserveTopology",
391
- "sym_difference": lambda x: "ST_SymDifference", # M
393
+ "sym_difference": lambda x: "ST_SymDifference", # M
392
394
  "touches": lambda x: "ST_Touches",
393
395
  "transform": lambda x: "ST_Transform",
394
396
  "union": lambda x: "ST_Union",
395
397
  "within": lambda x: "ST_Within",
396
- "wkb_geom_to_sql": lambda x: "ST_WKBToSQL", # M
397
- "wkt_geom_to_sql": lambda x: "ST_WKTToSQL", # M
398
+ "wkb_geom_to_sql": lambda x: "ST_WKBToSQL", # M
399
+ "wkt_geom_to_sql": lambda x: "ST_WKTToSQL", # M
398
400
  "set_srid": lambda x: "ST_SRID",
399
401
 
400
402
  ## *** Geometry Type ST_Point Methods *** ##
401
403
  "set_x": lambda x: "ST_X",
402
404
  "set_y": lambda x: "ST_Y",
403
405
  "set_z": lambda x: "ST_Z",
404
- "spherical_buffer": lambda x: "ST_SphericalBufferMBR", # M
405
- "spherical_distance": lambda x: "ST_SphericalDistance", # M
406
- "spheroidal_buffer": lambda x: "ST_SpheroidalBufferMBR", # M
407
- "spheroidal_distance": lambda x: "ST_SpheroidalDistance", # M
406
+ "spherical_buffer": lambda x: "ST_SphericalBufferMBR", # M
407
+ "spherical_distance": lambda x: "ST_SphericalDistance", # M
408
+ "spheroidal_buffer": lambda x: "ST_SpheroidalBufferMBR", # M
409
+ "spheroidal_distance": lambda x: "ST_SpheroidalDistance", # M
408
410
 
409
411
  ## *** Geometry Type ST_LineString Methods *** ##
410
412
  "line_interpolate_point": lambda x: "ST_Line_Interpolate_Point",
@@ -509,9 +511,18 @@ class TableOperatorConstants(Enum):
509
511
  "delimiter(' ') " \
510
512
  "returns('package VARCHAR({2}), " \
511
513
  "version VARCHAR({2})'))"
512
-
514
+
513
515
  SCRIPT_LIST_FILES_QUERY = "SELECT DISTINCT * FROM SCRIPT (SCRIPT_COMMAND " \
514
- "('ls ./{}') RETURNS ('Files VARCHAR({})'))"
516
+ "('ls ./{}') RETURNS ('Files VARCHAR({})'))"
517
+
518
+
519
+ # OpenBlas by default is multi-threaded, needs to be set to single-threaded.
520
+ OPENBLAS_NUM_THREADS = "OPENBLAS_NUM_THREADS=1"
521
+
522
+ # Query to create a DataFrame with a range of numbers.
523
+ RANGE_QUERY = "WITH RECURSIVE NumberSeries (id) AS (SELECT id AS id from {0} "\
524
+ "UNION ALL SELECT id {3} {1} FROM NumberSeries WHERE id {3} {1} {4} {2}) "\
525
+ "SELECT id FROM NumberSeries;"
515
526
 
516
527
  class ValibConstants(Enum):
517
528
  # A dictionary that maps teradataml name of the exposed VALIB function name
@@ -1355,7 +1366,7 @@ class SQLFunctionConstants(Enum):
1355
1366
  "regexp_replace": "REGEXP_REPLACE",
1356
1367
  "regexp_similar": "REGEXP_SIMILAR",
1357
1368
  "regexp_substr": "REGEXP_SUBSTR",
1358
-
1369
+
1359
1370
  # DateTime Functions
1360
1371
  'week_begin': 'td_week_begin',
1361
1372
  'week_start': 'td_week_begin',
@@ -1426,6 +1437,7 @@ class TeradataReservedKeywords(Enum):
1426
1437
  "TYPE"
1427
1438
  ]
1428
1439
 
1440
+
1429
1441
  class TeradataAnalyticFunctionTypes(Enum):
1430
1442
  SQLE = "FASTPATH"
1431
1443
  UAF = "UAF"
@@ -1435,15 +1447,15 @@ class TeradataAnalyticFunctionTypes(Enum):
1435
1447
 
1436
1448
 
1437
1449
  class TeradataAnalyticFunctionInfo(Enum):
1438
-
1439
- FASTPATH = {"func_type": "sqle", "lowest_version": "16.20", "display_function_type_name" :"SQLE"}
1450
+ FASTPATH = {"func_type": "sqle", "lowest_version": "16.20", "display_function_type_name": "SQLE"}
1440
1451
  UAF = {"func_type": "uaf", "lowest_version": "17.20", "display_function_type_name": "UAF",
1441
- "metadata_class" : "_AnlyFuncMetadataUAF"}
1452
+ "metadata_class": "_AnlyFuncMetadataUAF"}
1442
1453
  TABLE_OPERATOR = {"func_type": "tableoperator", "lowest_version": "17.00 ",
1443
- "display_function_type_name" :"TABLE OPERATOR"}
1454
+ "display_function_type_name": "TABLE OPERATOR"}
1444
1455
  BYOM = {"func_type": "byom", "lowest_version": None, "display_function_type_name": "BYOM"}
1445
1456
  STORED_PROCEDURE = {"func_type": "storedprocedure", "lowest_version": "17.20", "display_function_type_name": "UAF",
1446
- "metadata_class" : "_AnlyFuncMetadataUAF"}
1457
+ "metadata_class": "_AnlyFuncMetadataUAF"}
1458
+
1447
1459
 
1448
1460
  class TeradataUAFSpecificArgs(Enum):
1449
1461
  INPUT_MODE = "input_mode"
@@ -1451,9 +1463,11 @@ class TeradataUAFSpecificArgs(Enum):
1451
1463
  OUTPUT_FMT_INDEX = "output_fmt_index"
1452
1464
  OUTPUT_FMT_INDEX_STYLE = "output_fmt_index_style"
1453
1465
 
1466
+
1454
1467
  class Query(Enum):
1455
1468
  VANTAGE_VERSION = "SELECT InfoData FROM DBC.DBCInfoV where InfoKey = 'VERSION'"
1456
1469
 
1470
+
1457
1471
  class DriverEscapeFunctions(Enum):
1458
1472
  # Holds variables for the teradatasql driver escape functions to be used
1459
1473
  NATIVE_SQL = "{fn teradata_nativesql}"
@@ -1494,6 +1508,13 @@ class AsyncStatusColumns(Enum):
1494
1508
  ADDITIONAL_DETAILS = "Additional Details"
1495
1509
 
1496
1510
 
1511
+ class AsyncOpStatus(Enum):
1512
+ # Holds valid status for asynchronous operatiosns in UES.
1513
+ FILE_INSTALLED = "File Installed"
1514
+ ERRED = "Errored"
1515
+ FINISHED = "Finished"
1516
+
1517
+
1497
1518
  class CloudProvider(Enum):
1498
1519
  # Holds variable names for Cloud Providers.
1499
1520
  AWS = "AWS"
@@ -1503,7 +1524,8 @@ class CloudProvider(Enum):
1503
1524
  X_MS_VERSION = "2019-12-12"
1504
1525
  X_MS_BLOB_TYPE = "BlockBlob"
1505
1526
 
1506
- class SessionParamsSQL:
1527
+
1528
+ class SessionParamsSQL(Enum):
1507
1529
  # Holds the SQL Statements for Session params.
1508
1530
  TIMEZONE = "SET TIME ZONE {}"
1509
1531
  ACCOUNT = "SET SESSION ACCOUNT = '{}' FOR {}"
@@ -1523,7 +1545,8 @@ class SessionParamsSQL:
1523
1545
  QUERY_BAND = "SET QUERY_BAND = {} FOR {}"
1524
1546
  UDFSEARCHPATH = "SET SESSION UDFSEARCHPATH = {} FOR FUNCTION = {}"
1525
1547
 
1526
- class SessionParamsPythonNames:
1548
+
1549
+ class SessionParamsPythonNames(Enum):
1527
1550
  # Holds the SQL Statements for Session params.
1528
1551
  TIMEZONE = "Session Time Zone"
1529
1552
  ACCOUNT = "Account Name"
@@ -1532,3 +1555,25 @@ class SessionParamsPythonNames:
1532
1555
  DATABASE = "Current DataBase"
1533
1556
  DATEFORM = 'Current DateForm'
1534
1557
 
1558
+
1559
+ class AutoMLConstants(Enum):
1560
+ # List stores feature selection methods
1561
+ FEATURE_SELECTION_MTDS = ["lasso", "rfe", "pca"]
1562
+
1563
+
1564
+ class AuthMechs(Enum):
1565
+ """
1566
+ Enum to hold permitted values for authentication mechanism.
1567
+ """
1568
+ OAUTH = "OAuth"
1569
+ JWT = "JWT"
1570
+ PAT = "PAT"
1571
+ BASIC = "BASIC"
1572
+ KEYCLOAK = "KEYCLOAK"
1573
+
1574
+ class TDServices(Enum):
1575
+ """
1576
+ Enum to hold permitted values for types for services availed on Teradata vantage.
1577
+ """
1578
+ VECTORSTORE = "vectorstore"
1579
+ MOPS = "MODELOPS" # For future reference
@@ -12,6 +12,12 @@ teradataml.common.exceptions
12
12
  An Error class for the teradataml python module
13
13
  """
14
14
 
15
+
16
+ import warnings
17
+ import json
18
+ import pprint
19
+
20
+
15
21
  class TeradataMlException(Exception):
16
22
  """
17
23
  Teradata Ml Exception class.
@@ -71,3 +77,29 @@ class TeradataMlException(Exception):
71
77
  """
72
78
  super(TeradataMlException, self).__init__(msg)
73
79
  self.code = code
80
+
81
+ class TeradatamlRestException(TeradataMlException):
82
+ def __init__(self, msg, code, raw_message=None):
83
+ super().__init__(msg, code)
84
+
85
+ self._msg = msg
86
+ self._raw_message = raw_message
87
+
88
+ @property
89
+ def json_response(self):
90
+ """
91
+ Returns the JSON response from the server.
92
+ """
93
+ if self._raw_message is not None and self._raw_message.startswith("Error message: "):
94
+ failure_msg = f"Could not convert msg to json. Message is \n{self._raw_message}"
95
+ try:
96
+ json_resp = self._msg.split("Error message: ")[1]
97
+ json_resp = json.loads(json_resp)
98
+ return pprint.pformat(json_resp)
99
+ except json.JSONDecodeError as _:
100
+ warnings.warn(failure_msg)
101
+ elif self._raw_message is None:
102
+ return None
103
+ else:
104
+ warnings.warn(failure_msg)
105
+
@@ -125,6 +125,7 @@ class ErrorInfoCodes(Enum):
125
125
  SPECIFY_AT_LEAST_ONE_ARG = 'TDML_2037'
126
126
  CANNOT_USE_TOGETHER_WITH = 'TDML_2042'
127
127
  TABLE_DOES_NOT_EXIST = 'TDML_2046'
128
+ DEPENDENT_METHOD = 'TDML_2113'
128
129
 
129
130
  # Reserved for Generic Error Messages: 2121 - 2199
130
131
  RESERVED_KEYWORD = 'TDML_2121'
@@ -227,6 +228,21 @@ class ErrorInfoCodes(Enum):
227
228
  # OpenAF Error codes starting from 2551 - Reserved till 2560.
228
229
  SET_REQUIRED_PARAMS = 'TDML_2551'
229
230
 
231
+ # Error codes for OTF. Reserved till 2570.
232
+ OTF_TABLE_REQUIRED = 'TDML_2561'
233
+
234
+ # Rest Excceptions. Reserved for 2570 - 2580
235
+ REST_HTTP_ERROR = 'TDML_2570'
236
+ REST_AUTH_MISSING_ARG = 'TDML_2571'
237
+ REST_NOT_CONFIGURED = 'TDML_2572'
238
+ REST_DEVICE_CODE_NO_BOTH = 'TDML_2573'
239
+ REST_DEVICE_CODE_GEN_FAILED = 'TDML_2574'
240
+ REST_DEVICE_CODE_AUTH_FAILED = 'TDML_2575'
241
+
242
+ # Python SDK Error codes starting from 2580 - Reserved till 2590.
243
+ INFO_NOT_PROVIDED_USE_DEFAULT = 'TDML_W_2580' # Logger warning.
244
+
245
+
230
246
  class MessageCodes(Enum):
231
247
  """
232
248
  MessageCodes contains all the messages that are displayed to the user which are informational
@@ -440,4 +456,16 @@ class MessageCodes(Enum):
440
456
  CONNECTION_PARAMS = "Required connection parameters are missing. Connection parameters should either be " \
441
457
  "explicitly passed to function or specified using a configuration file, or setting up " \
442
458
  "the environment variables."
459
+ DEPENDENT_METHOD = "Method(s) {} must be called before calling '{}'."
460
+ REST_HTTP_ERROR = "Failed to run rest API:\n{}"
461
+ REST_AUTH_MISSING_ARG = "For '{}' authentication, '{}' is/are not provided in config file or "\
462
+ "environment variable or through constructor argument 'auth'."
463
+ REST_NOT_CONFIGURED = "The argument '{}' is not set. {} endpoint not configured.\n" \
464
+ "Try (re)copy the CLI configuration from {} UI -> Session Details -> CLI Config."
465
+ REST_DEVICE_CODE_NO_BOTH = "Token does not contain access_token or refresh_token. Received token: {}"
466
+ REST_DEVICE_CODE_GEN_FAILED = "Error generating the device code. Received code: {}."
467
+ REST_DEVICE_CODE_AUTH_FAILED = "Error authenticating the device code.\n{}."
468
+
469
+ INFO_NOT_PROVIDED_USE_DEFAULT = "{} is not provided in path '{}' method '{}' for operationID '{}' using default {}."
470
+ OTF_TABLE_REQUIRED = "{} is supported only with OTF table."
443
471
 
@@ -195,7 +195,16 @@ class Messages():
195
195
  [ErrorInfoCodes.PATH_NOT_FOUND, MessageCodes.PATH_NOT_FOUND],
196
196
  [ErrorInfoCodes.TARGET_COL_NOT_FOUND_FOR_EVALUATE, MessageCodes.TARGET_COL_NOT_FOUND_FOR_EVALUATE],
197
197
  [ErrorInfoCodes.SET_REQUIRED_PARAMS, MessageCodes.SET_REQUIRED_PARAMS],
198
- [ErrorInfoCodes.MISSING_ARGS, MessageCodes.CONNECTION_PARAMS]
198
+ [ErrorInfoCodes.MISSING_ARGS, MessageCodes.CONNECTION_PARAMS],
199
+ [ErrorInfoCodes.DEPENDENT_METHOD, MessageCodes.DEPENDENT_METHOD],
200
+ [ErrorInfoCodes.REST_HTTP_ERROR, MessageCodes.REST_HTTP_ERROR],
201
+ [ErrorInfoCodes.REST_AUTH_MISSING_ARG, MessageCodes.REST_AUTH_MISSING_ARG],
202
+ [ErrorInfoCodes.REST_NOT_CONFIGURED, MessageCodes.REST_NOT_CONFIGURED],
203
+ [ErrorInfoCodes.REST_DEVICE_CODE_NO_BOTH, MessageCodes.REST_DEVICE_CODE_NO_BOTH],
204
+ [ErrorInfoCodes.REST_DEVICE_CODE_GEN_FAILED, MessageCodes.REST_DEVICE_CODE_GEN_FAILED],
205
+ [ErrorInfoCodes.REST_DEVICE_CODE_AUTH_FAILED, MessageCodes.REST_DEVICE_CODE_AUTH_FAILED],
206
+ [ErrorInfoCodes.INFO_NOT_PROVIDED_USE_DEFAULT, MessageCodes.INFO_NOT_PROVIDED_USE_DEFAULT],
207
+ [ErrorInfoCodes.OTF_TABLE_REQUIRED, MessageCodes.OTF_TABLE_REQUIRED]
199
208
  ]
200
209
 
201
210
  @staticmethod
@@ -224,11 +233,11 @@ class Messages():
224
233
 
225
234
  """
226
235
  for msg in Messages.__messages:
227
- if msg[1] == messagecode :
236
+ if msg[1] == messagecode:
228
237
  message = "{}({}) {}".format(Messages.__standard_message, msg[0].value, msg[1].value)
229
238
  if len(variables) != 0:
230
239
  message = message.format(*variables)
231
- if len(kwargs) != 0 :
240
+ if len(kwargs) != 0:
232
241
  message = "{} {}".format(message, kwargs)
233
-
242
+ break
234
243
  return message
@@ -70,8 +70,9 @@ class SQLBundle:
70
70
  [SQLConstants.SQL_EXEC_STORED_PROCEDURE, "call {0}"],
71
71
  [SQLConstants.SQL_SELECT_COLUMNNAMES_WITH_WHERE, "sel {0} from {1} where {2}"],
72
72
  [SQLConstants.SQL_HELP_DATABASE, "HELP DATABASE {0}"],
73
- [SQLConstants.SQL_HELP_DATALAKE, "HELP DATALAKE {0}"]
74
-
73
+ [SQLConstants.SQL_HELP_DATALAKE, "HELP DATALAKE {0}"],
74
+ [SQLConstants.SQL_TD_OTF_METADATA, "SELECT * FROM {0}(ON ({1})) D;"],
75
+ [SQLConstants.SQL_TD_OTF_SNAPSHOT, "SELECT * FROM {0} FOR SNAPSHOT AS OF {1};"]
75
76
  ]
76
77
  self._add_sql_version()
77
78