teradataml 20.0.0.5__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 +96 -0
- teradataml/_version.py +1 -1
- teradataml/analytics/analytic_function_executor.py +1 -1
- teradataml/analytics/utils.py +56 -11
- teradataml/clients/auth_client.py +10 -6
- teradataml/clients/keycloak_client.py +165 -0
- teradataml/common/constants.py +10 -0
- teradataml/common/exceptions.py +32 -0
- teradataml/common/messagecodes.py +27 -0
- teradataml/common/messages.py +9 -1
- teradataml/common/sqlbundle.py +3 -2
- teradataml/common/utils.py +94 -12
- teradataml/context/context.py +37 -9
- teradataml/data/jsons/byom/onnxembeddings.json +1 -0
- teradataml/data/pattern_matching_data.csv +11 -0
- teradataml/data/sdk/modelops/modelops_spec.json +101737 -0
- teradataml/data/teradataml_example.json +8 -1
- teradataml/data/url_data.csv +10 -9
- teradataml/dataframe/copy_to.py +1 -1
- teradataml/dataframe/dataframe.py +980 -82
- teradataml/dataframe/dataframe_utils.py +58 -25
- teradataml/dataframe/functions.py +962 -1
- teradataml/dataframe/sql.py +570 -1031
- teradataml/hyperparameter_tuner/utils.py +4 -2
- teradataml/lib/aed_0_1.dll +0 -0
- teradataml/opensource/_base.py +7 -1
- teradataml/options/configure.py +20 -4
- teradataml/scriptmgmt/UserEnv.py +13 -2
- teradataml/scriptmgmt/lls_utils.py +99 -24
- 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/table_operators/query_generator.py +4 -21
- teradataml/utils/dtypes.py +2 -1
- teradataml/utils/utils.py +0 -1
- teradataml/utils/validators.py +5 -1
- {teradataml-20.0.0.5.dist-info → teradataml-20.0.0.6.dist-info}/METADATA +101 -2
- {teradataml-20.0.0.5.dist-info → teradataml-20.0.0.6.dist-info}/RECORD +53 -36
- {teradataml-20.0.0.5.dist-info → teradataml-20.0.0.6.dist-info}/WHEEL +0 -0
- {teradataml-20.0.0.5.dist-info → teradataml-20.0.0.6.dist-info}/top_level.txt +0 -0
- {teradataml-20.0.0.5.dist-info → teradataml-20.0.0.6.dist-info}/zip-safe +0 -0
teradataml/common/utils.py
CHANGED
|
@@ -13,6 +13,7 @@ by other classes which can be reused according to the need.
|
|
|
13
13
|
Add all the common functions in this class like creating temporary table names, getting
|
|
14
14
|
the datatypes etc.
|
|
15
15
|
"""
|
|
16
|
+
import datetime
|
|
16
17
|
import json
|
|
17
18
|
import os
|
|
18
19
|
import re
|
|
@@ -39,7 +40,8 @@ from teradatasqlalchemy.types import (BIGINT, BLOB, BYTE, BYTEINT, CHAR, CLOB,
|
|
|
39
40
|
from teradataml import _version
|
|
40
41
|
from teradataml.common import td_coltype_code_to_tdtype
|
|
41
42
|
from teradataml.common.constants import (HTTPRequest, PTITableConstants,
|
|
42
|
-
PythonTypes,
|
|
43
|
+
PythonTypes, SQLConstants,
|
|
44
|
+
TeradataConstants,
|
|
43
45
|
TeradataReservedKeywords,
|
|
44
46
|
TeradataTypes)
|
|
45
47
|
from teradataml.common.exceptions import TeradataMlException
|
|
@@ -280,26 +282,37 @@ class UtilFuncs():
|
|
|
280
282
|
RAISES:
|
|
281
283
|
|
|
282
284
|
EXAMPLES:
|
|
283
|
-
new_table_name = UtilFuncs._generate_temp_table_name(user='tdqg', prefix="from_pandas")
|
|
284
|
-
new_table_name = UtilFuncs._generate_temp_table_name(user='tdqg', prefix="from_pandas",
|
|
285
|
+
>>> new_table_name = UtilFuncs._generate_temp_table_name(user='tdqg', prefix="from_pandas")
|
|
286
|
+
>>> new_table_name = UtilFuncs._generate_temp_table_name(user='tdqg', prefix="from_pandas",
|
|
285
287
|
table_type = TeradataConstants.TERADATA_VIEW)
|
|
286
|
-
new_table_name = UtilFuncs._generate_temp_table_name(user='tdqg', prefix="from_pandas",
|
|
288
|
+
>>> new_table_name = UtilFuncs._generate_temp_table_name(user='tdqg', prefix="from_pandas",
|
|
287
289
|
table_type = TeradataConstants.TERADATA_TABLE)
|
|
290
|
+
# Example when use_short_object_name is set to True
|
|
291
|
+
>>> from teradataml.options.configure import configure
|
|
292
|
+
>>> configure.use_short_object_name = True
|
|
293
|
+
>>> new_table_name = UtilFuncs._generate_temp_table_name(user='tdqg', prefix="from_pandas")
|
|
288
294
|
|
|
289
295
|
Output:
|
|
290
296
|
tdml_temp_table__1517501990393350 (or)
|
|
291
297
|
tdqg.tdml_temp_table__1517501990393350 (or)
|
|
292
298
|
tdml_temp_table__from_pandas_1517501990393350 (or)
|
|
293
|
-
tdqg.tdml_temp_table__from_pandas_1517501990393350
|
|
299
|
+
tdqg.tdml_temp_table__from_pandas_1517501990393350 (or)
|
|
300
|
+
ml__1749637109887272
|
|
294
301
|
"""
|
|
295
302
|
# Number of seconds since Jan 1, 1970 00:00:00
|
|
296
303
|
timestamp = time.time()
|
|
304
|
+
use_short_name = configure.use_short_object_name
|
|
297
305
|
tabname = "ml_"
|
|
298
306
|
random_string = "{}{}".format(floor(timestamp / 1000000),
|
|
299
307
|
floor(timestamp % 1000000 * 1000000 +
|
|
300
308
|
int(str(uuid.uuid4().fields[-1])[:10])))
|
|
301
|
-
|
|
309
|
+
|
|
310
|
+
# Append prefix only if use_short_object_name is False and prefix is provided.
|
|
311
|
+
if (not use_short_name) and (prefix is not None):
|
|
302
312
|
tabname = "{}_{}".format(tabname, prefix)
|
|
313
|
+
# Append prefix "tdml" when use_short_object_name is True and random string is of length 15.
|
|
314
|
+
elif use_short_name and (len(random_string)==15):
|
|
315
|
+
tabname = "tdml"
|
|
303
316
|
|
|
304
317
|
tabname = "{}_{}".format(tabname, random_string)
|
|
305
318
|
|
|
@@ -309,7 +322,8 @@ class UtilFuncs():
|
|
|
309
322
|
tabname = "\"{}\".\"{}\"".format(_get_user(), tabname)
|
|
310
323
|
return tabname
|
|
311
324
|
|
|
312
|
-
if configure.temp_object_type == TeradataConstants.
|
|
325
|
+
if (not use_short_name) and (configure.temp_object_type == TeradataConstants.
|
|
326
|
+
TERADATA_VOLATILE_TABLE):
|
|
313
327
|
from teradataml.context.context import _get_user
|
|
314
328
|
return "\"{}\".\"{}_{}\"".format(_get_user(), "vt", tabname)
|
|
315
329
|
|
|
@@ -1310,7 +1324,8 @@ class UtilFuncs():
|
|
|
1310
1324
|
|
|
1311
1325
|
return False
|
|
1312
1326
|
|
|
1313
|
-
|
|
1327
|
+
@staticmethod
|
|
1328
|
+
def _is_non_ascii(col_lst):
|
|
1314
1329
|
"""
|
|
1315
1330
|
Description:
|
|
1316
1331
|
Check if the specified string in col_lst has non-ASCII characters in it.
|
|
@@ -2670,7 +2685,10 @@ class UtilFuncs():
|
|
|
2670
2685
|
user_function_code = ""
|
|
2671
2686
|
for func in user_functions:
|
|
2672
2687
|
# Get the source code of the user function.
|
|
2673
|
-
|
|
2688
|
+
# Note that, checking for lambda function is required for teradatamlspk UDFs
|
|
2689
|
+
# If the function is a lambda function, get the source code from __source__.
|
|
2690
|
+
func = getsource(func) if func.__code__.co_name != "<lambda>" else func.__source__
|
|
2691
|
+
|
|
2674
2692
|
# If the function have any extra space in the beginning remove it.
|
|
2675
2693
|
func = func.lstrip()
|
|
2676
2694
|
# Function can have decorator,e.g. udf as decorator, remove it.
|
|
@@ -2753,7 +2771,8 @@ class UtilFuncs():
|
|
|
2753
2771
|
MessageCodes.PYTHON_VERSION_MISMATCH_OAF)
|
|
2754
2772
|
else:
|
|
2755
2773
|
from teradataml.context import context as tdmlctx
|
|
2756
|
-
from teradataml.dbutils.dbutils import (db_python_version_diff,
|
|
2774
|
+
from teradataml.dbutils.dbutils import (db_python_version_diff,
|
|
2775
|
+
set_session_param)
|
|
2757
2776
|
set_session_param("searchuifdbpath",
|
|
2758
2777
|
UtilFuncs._get_dialect_quoted_name(tdmlctx._get_current_databasename()))
|
|
2759
2778
|
if len(db_python_version_diff()) > 0:
|
|
@@ -2798,7 +2817,8 @@ class UtilFuncs():
|
|
|
2798
2817
|
"""
|
|
2799
2818
|
|
|
2800
2819
|
# Check if OSML required packages are verified or not.
|
|
2801
|
-
from teradataml.opensource._constants import
|
|
2820
|
+
from teradataml.opensource._constants import \
|
|
2821
|
+
_packages_verified_in_vantage
|
|
2802
2822
|
_is_packages_verfied_in_vantage = _packages_verified_in_vantage.get(
|
|
2803
2823
|
func, None)
|
|
2804
2824
|
if _is_packages_verfied_in_vantage:
|
|
@@ -2855,7 +2875,8 @@ class UtilFuncs():
|
|
|
2855
2875
|
|
|
2856
2876
|
else:
|
|
2857
2877
|
# Check if the versions of Python packages are consistent between Vantage and local.
|
|
2858
|
-
from teradataml.dbutils.dbutils import
|
|
2878
|
+
from teradataml.dbutils.dbutils import \
|
|
2879
|
+
_db_python_package_version_diff
|
|
2859
2880
|
all_package_versions = _db_python_package_version_diff(packages, only_diff=False)
|
|
2860
2881
|
package_difference = \
|
|
2861
2882
|
all_package_versions[all_package_versions.vantage != all_package_versions.local]
|
|
@@ -2922,6 +2943,67 @@ class UtilFuncs():
|
|
|
2922
2943
|
tdp = preparer(td_dialect)
|
|
2923
2944
|
return tdp.quote(object_name)
|
|
2924
2945
|
|
|
2946
|
+
@staticmethod
|
|
2947
|
+
def _get_http_status_phrases_description():
|
|
2948
|
+
"""
|
|
2949
|
+
DESCRIPTION:
|
|
2950
|
+
Function to get phrases and description for all HTTP status codes.
|
|
2951
|
+
|
|
2952
|
+
PARAMETERS:
|
|
2953
|
+
None
|
|
2954
|
+
|
|
2955
|
+
RETURNS:
|
|
2956
|
+
dict
|
|
2957
|
+
|
|
2958
|
+
EXAMPLES:
|
|
2959
|
+
>>> UtilFuncs._get_http_status_phrases_description()
|
|
2960
|
+
"""
|
|
2961
|
+
from http import HTTPStatus
|
|
2962
|
+
return {status.value: {"phrase": status.phrase, "description": status.description} \
|
|
2963
|
+
for status in HTTPStatus}
|
|
2964
|
+
|
|
2965
|
+
@staticmethod
|
|
2966
|
+
def _get_time_formatted_string(period):
|
|
2967
|
+
"""
|
|
2968
|
+
DESCRIPTION:
|
|
2969
|
+
Converts a string representing Period to the formatted TIMESTAMP/DATE string for snapshot queries.
|
|
2970
|
+
|
|
2971
|
+
PARAMETERS:
|
|
2972
|
+
period:
|
|
2973
|
+
Required Argument.
|
|
2974
|
+
Specifies the period string to be converted.
|
|
2975
|
+
Types: str
|
|
2976
|
+
|
|
2977
|
+
RETURNS:
|
|
2978
|
+
The formatted TIMESTAMP/DATE string.
|
|
2979
|
+
|
|
2980
|
+
RAISES:
|
|
2981
|
+
ValueError.
|
|
2925
2982
|
|
|
2983
|
+
EXAMPLES:
|
|
2984
|
+
>>> UtilFuncs._get_time_formatted_string('2025-06-01 12:00:00.123')
|
|
2985
|
+
"""
|
|
2986
|
+
# Try to parse as datetime string
|
|
2987
|
+
try:
|
|
2988
|
+
for fmt in ["%Y-%m-%d %H:%M:%S.%f", "%Y-%m-%d %H:%M:%S", "%Y-%m-%d"]:
|
|
2989
|
+
try:
|
|
2990
|
+
dt = datetime.datetime.strptime(period, fmt)
|
|
2991
|
+
# If input had microseconds, preserve them
|
|
2992
|
+
if "%f" in fmt and "." in period:
|
|
2993
|
+
# Remove trailing zeros and dot if needed
|
|
2994
|
+
result = "TIMESTAMP'{}'".format(dt.strftime("%Y-%m-%d %H:%M:%S.%f").rstrip("0").rstrip("."))
|
|
2995
|
+
elif "%S" in fmt:
|
|
2996
|
+
result = "TIMESTAMP'{}'".format(dt.strftime("%Y-%m-%d %H:%M:%S"))
|
|
2997
|
+
else:
|
|
2998
|
+
result = "DATE'{}'".format(dt.strftime("%Y-%m-%d"))
|
|
2999
|
+
return result
|
|
3000
|
+
except ValueError:
|
|
3001
|
+
continue
|
|
3002
|
+
raise ValueError(f"Unrecognized period format: {period}")
|
|
3003
|
+
except Exception as e:
|
|
3004
|
+
raise ValueError(f"Could not convert period: {period}") from e
|
|
3005
|
+
|
|
3006
|
+
|
|
3007
|
+
# Keeping at the end to avoid circular dependency
|
|
2926
3008
|
from teradataml.common.aed_utils import AedUtils
|
|
2927
3009
|
from teradataml.dbutils.filemgr import remove_file
|
teradataml/context/context.py
CHANGED
|
@@ -414,6 +414,18 @@ def create_context(host=None, username=None, password=None, tdsqlengine=None, te
|
|
|
414
414
|
and the name of the pem file is `key1(1).pem`, then pass value 'key1' to the argument "kid".
|
|
415
415
|
Types: str
|
|
416
416
|
|
|
417
|
+
auth_url:
|
|
418
|
+
Optional Argument.
|
|
419
|
+
Specifies the endpoint URL for a keycloak server.
|
|
420
|
+
Types: str
|
|
421
|
+
|
|
422
|
+
rest_client:
|
|
423
|
+
Optional Argument.
|
|
424
|
+
Specifies the service for which keycloak token is to be generated.
|
|
425
|
+
Permitted values: "VECTORSTORE"
|
|
426
|
+
Default value: "VECTORSTORE"
|
|
427
|
+
Types: str
|
|
428
|
+
|
|
417
429
|
auth_mech:
|
|
418
430
|
Specifies the mechanism to be used for generating authentication token.
|
|
419
431
|
Notes:
|
|
@@ -428,7 +440,8 @@ def create_context(host=None, username=None, password=None, tdsqlengine=None, te
|
|
|
428
440
|
using user credentials passed in "username" and "password"
|
|
429
441
|
arguments.
|
|
430
442
|
* JWT : Readily available token in "auth_token" argument is used.
|
|
431
|
-
|
|
443
|
+
* KEYCLOAK: Token generation is done using keycloak.
|
|
444
|
+
Permitted Values: "OAuth", "PAT", "BASIC", "JWT", "KEYCLOAK".
|
|
432
445
|
Types: str
|
|
433
446
|
|
|
434
447
|
RETURNS:
|
|
@@ -585,6 +598,15 @@ def create_context(host=None, username=None, password=None, tdsqlengine=None, te
|
|
|
585
598
|
... base_url=getpass.getpass("base_url : "),
|
|
586
599
|
... auth_mech="OAuth")
|
|
587
600
|
|
|
601
|
+
# Example 24: Create context and set authentication token by providing auth_url and
|
|
602
|
+
# rest_client arguments.
|
|
603
|
+
>>> import getpass
|
|
604
|
+
>>> create_context(host="host",
|
|
605
|
+
... username=getpass.getpass("username : "),
|
|
606
|
+
... password=getpass.getpass("password : "),
|
|
607
|
+
... base_url=getpass.getpass("base_url : "),
|
|
608
|
+
... auth_url=getpass.getpass("auth_url : "),
|
|
609
|
+
... rest_client=getpass.getpass("rest_client : "))
|
|
588
610
|
"""
|
|
589
611
|
global td_connection
|
|
590
612
|
global td_sqlalchemy_engine
|
|
@@ -612,7 +634,8 @@ def create_context(host=None, username=None, password=None, tdsqlengine=None, te
|
|
|
612
634
|
# set_auth_token parameters
|
|
613
635
|
_set_auth_token_params = {}
|
|
614
636
|
auth_mech = kwargs.get('auth_mech', None)
|
|
615
|
-
for param in ['base_url', 'pat_token', 'pem_file', 'client_id', 'auth_token', 'expiration_time',
|
|
637
|
+
for param in ['base_url', 'pat_token', 'pem_file', 'client_id', 'auth_token', 'expiration_time',
|
|
638
|
+
'kid', 'auth_mech', 'auth_url', 'rest_client']:
|
|
616
639
|
if kwargs.get(param):
|
|
617
640
|
_set_auth_token_params[param] = kwargs.pop(param)
|
|
618
641
|
|
|
@@ -696,9 +719,6 @@ def create_context(host=None, username=None, password=None, tdsqlengine=None, te
|
|
|
696
719
|
raise TeradataMlException(Messages.get_message(MessageCodes.CONNECTION_FAILURE),
|
|
697
720
|
MessageCodes.CONNECTION_FAILURE) from err
|
|
698
721
|
|
|
699
|
-
# Load function aliases from config.
|
|
700
|
-
_load_function_aliases()
|
|
701
|
-
|
|
702
722
|
python_packages_installed = False
|
|
703
723
|
python_version_vantage = None
|
|
704
724
|
python_version_local = sys.version.split(" ")[0].strip()
|
|
@@ -729,7 +749,12 @@ def create_context(host=None, username=None, password=None, tdsqlengine=None, te
|
|
|
729
749
|
if _set_auth_token_params.get('base_url'):
|
|
730
750
|
from teradataml.scriptmgmt.lls_utils import set_auth_token
|
|
731
751
|
try:
|
|
732
|
-
|
|
752
|
+
# password needs to be passed to set_auth_token only when any of the following is True:
|
|
753
|
+
# 1. auth_mech is set to either 'basic' or 'keycloak'
|
|
754
|
+
# 2. 'auth_url' argument is passed which represents 'keycloak' authentication mechanism.
|
|
755
|
+
if ((auth_mech and auth_mech.lower() in ['basic', 'keycloak']) or
|
|
756
|
+
_set_auth_token_params.get('auth_url'))\
|
|
757
|
+
and password:
|
|
733
758
|
_set_auth_token_params['password'] = password
|
|
734
759
|
set_auth_token(**_set_auth_token_params)
|
|
735
760
|
except Exception as err:
|
|
@@ -741,6 +766,9 @@ def create_context(host=None, username=None, password=None, tdsqlengine=None, te
|
|
|
741
766
|
# Add global lock to internal buffer
|
|
742
767
|
_InternalBuffer.add(global_lock=threading.Lock())
|
|
743
768
|
|
|
769
|
+
# Set _check_py_version to True to check the python version between local and Vantage.
|
|
770
|
+
_InternalBuffer.add(_check_py_version=True)
|
|
771
|
+
|
|
744
772
|
# Return the connection by default
|
|
745
773
|
return td_sqlalchemy_engine
|
|
746
774
|
|
|
@@ -899,9 +927,6 @@ def set_context(tdsqlengine, temp_database_name=None):
|
|
|
899
927
|
else:
|
|
900
928
|
return None
|
|
901
929
|
|
|
902
|
-
# Load function aliases from config.
|
|
903
|
-
_load_function_aliases()
|
|
904
|
-
|
|
905
930
|
python_packages_installed = False
|
|
906
931
|
python_version_vantage = None
|
|
907
932
|
python_version_local = sys.version.split(" ")[0].strip()
|
|
@@ -912,6 +937,9 @@ def set_context(tdsqlengine, temp_database_name=None):
|
|
|
912
937
|
# Add global lock to internal buffer
|
|
913
938
|
_InternalBuffer.add(global_lock=threading.Lock())
|
|
914
939
|
|
|
940
|
+
# Set _check_py_version to True to check the python version between local and Vantage.
|
|
941
|
+
_InternalBuffer.add(_check_py_version=True)
|
|
942
|
+
|
|
915
943
|
return td_connection
|
|
916
944
|
|
|
917
945
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
id,data,pattern,level
|
|
2
|
+
1,user_Alpha,user!_%,Advanced
|
|
3
|
+
2,user%2025,user!%%,Beginner
|
|
4
|
+
3,data_2024,d%,Novice
|
|
5
|
+
4,data%backup,data@%%,Advanced
|
|
6
|
+
5,prod_01,prod_01%,Beginner
|
|
7
|
+
6,prod%v2,prod!_%,Novice
|
|
8
|
+
7,log_file,log^_file,Advanced
|
|
9
|
+
8,log%2024,l_g%,Beginner
|
|
10
|
+
9,temp_file,temp!__%,Novice
|
|
11
|
+
10,backup_9,restore!_9,Beginner
|