teradataml 20.0.0.3__py3-none-any.whl → 20.0.0.5__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 +193 -1
- teradataml/__init__.py +2 -1
- teradataml/_version.py +2 -2
- teradataml/analytics/analytic_function_executor.py +25 -18
- teradataml/analytics/byom/__init__.py +1 -1
- teradataml/analytics/json_parser/analytic_functions_argument.py +4 -0
- teradataml/analytics/sqle/__init__.py +20 -2
- teradataml/analytics/utils.py +15 -1
- teradataml/analytics/valib.py +18 -4
- teradataml/automl/__init__.py +341 -112
- teradataml/automl/autodataprep/__init__.py +471 -0
- teradataml/automl/data_preparation.py +84 -42
- teradataml/automl/data_transformation.py +69 -33
- teradataml/automl/feature_engineering.py +76 -9
- teradataml/automl/feature_exploration.py +639 -25
- teradataml/automl/model_training.py +35 -14
- teradataml/clients/auth_client.py +2 -2
- teradataml/common/__init__.py +1 -2
- teradataml/common/constants.py +122 -63
- teradataml/common/messagecodes.py +14 -3
- teradataml/common/messages.py +8 -4
- teradataml/common/sqlbundle.py +40 -10
- teradataml/common/utils.py +366 -74
- teradataml/common/warnings.py +11 -0
- teradataml/context/context.py +348 -86
- teradataml/data/amazon_reviews_25.csv +26 -0
- teradataml/data/apriori_example.json +22 -0
- teradataml/data/byom_example.json +11 -0
- teradataml/data/docs/byom/docs/DataRobotPredict.py +2 -2
- teradataml/data/docs/byom/docs/DataikuPredict.py +40 -1
- teradataml/data/docs/byom/docs/H2OPredict.py +2 -2
- teradataml/data/docs/byom/docs/ONNXEmbeddings.py +242 -0
- teradataml/data/docs/byom/docs/ONNXPredict.py +2 -2
- teradataml/data/docs/byom/docs/PMMLPredict.py +2 -2
- 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/Shap.py +28 -6
- 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/DWT2D.py +4 -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/hnsw_alter_data.csv +5 -0
- teradataml/data/hnsw_data.csv +10 -0
- teradataml/data/jsons/byom/h2opredict.json +1 -1
- teradataml/data/jsons/byom/onnxembeddings.json +266 -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_Shap.json +0 -1
- 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_HNSW.json +296 -0
- teradataml/data/jsons/sqle/20.00/TD_HNSWPredict.json +206 -0
- teradataml/data/jsons/sqle/20.00/TD_HNSWSummary.json +32 -0
- teradataml/data/jsons/sqle/20.00/TD_KMeans.json +2 -2
- teradataml/data/jsons/sqle/20.00/TD_SMOTE.json +3 -3
- teradataml/data/jsons/sqle/20.00/TD_VectorDistance.json +6 -6
- teradataml/data/ner_dict.csv +8 -0
- teradataml/data/ner_input_eng.csv +7 -0
- teradataml/data/ner_rule.csv +5 -0
- teradataml/data/pos_input.csv +40 -0
- teradataml/data/tdnerextractor_example.json +14 -0
- teradataml/data/teradataml_example.json +21 -0
- 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/vectordistance_example.json +1 -1
- teradataml/dataframe/copy_to.py +45 -29
- teradataml/dataframe/data_transfer.py +72 -46
- teradataml/dataframe/dataframe.py +642 -166
- teradataml/dataframe/dataframe_utils.py +167 -22
- teradataml/dataframe/functions.py +135 -20
- teradataml/dataframe/setop.py +11 -6
- teradataml/dataframe/sql.py +330 -78
- teradataml/dbutils/dbutils.py +556 -140
- teradataml/dbutils/filemgr.py +14 -10
- teradataml/hyperparameter_tuner/optimizer.py +12 -1
- teradataml/lib/aed_0_1.dll +0 -0
- teradataml/opensource/{sklearn/_sklearn_wrapper.py → _base.py} +168 -1013
- teradataml/opensource/_class.py +141 -17
- teradataml/opensource/{constants.py → _constants.py} +7 -3
- teradataml/opensource/_lightgbm.py +52 -53
- teradataml/opensource/_sklearn.py +1008 -0
- teradataml/opensource/_wrapper_utils.py +5 -5
- teradataml/options/__init__.py +47 -15
- teradataml/options/configure.py +103 -26
- teradataml/options/display.py +13 -2
- teradataml/plot/axis.py +47 -8
- teradataml/plot/figure.py +33 -0
- teradataml/plot/plot.py +63 -13
- teradataml/scriptmgmt/UserEnv.py +307 -40
- teradataml/scriptmgmt/lls_utils.py +428 -145
- teradataml/store/__init__.py +2 -3
- teradataml/store/feature_store/feature_store.py +102 -7
- teradataml/table_operators/Apply.py +48 -19
- teradataml/table_operators/Script.py +23 -2
- teradataml/table_operators/TableOperator.py +3 -1
- teradataml/table_operators/table_operator_util.py +58 -9
- teradataml/utils/dtypes.py +49 -1
- teradataml/utils/internal_buffer.py +38 -0
- teradataml/utils/validators.py +377 -62
- {teradataml-20.0.0.3.dist-info → teradataml-20.0.0.5.dist-info}/METADATA +200 -4
- {teradataml-20.0.0.3.dist-info → teradataml-20.0.0.5.dist-info}/RECORD +146 -112
- teradataml/data/SQL_Fundamentals.pdf +0 -0
- teradataml/libaed_0_1.dylib +0 -0
- teradataml/libaed_0_1.so +0 -0
- teradataml/opensource/sklearn/__init__.py +0 -0
- teradataml/store/vector_store/__init__.py +0 -1586
- {teradataml-20.0.0.3.dist-info → teradataml-20.0.0.5.dist-info}/WHEEL +0 -0
- {teradataml-20.0.0.3.dist-info → teradataml-20.0.0.5.dist-info}/top_level.txt +0 -0
- {teradataml-20.0.0.3.dist-info → teradataml-20.0.0.5.dist-info}/zip-safe +0 -0
teradataml/common/utils.py
CHANGED
|
@@ -13,50 +13,48 @@ 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
|
-
from inspect import getsource
|
|
17
16
|
import json
|
|
17
|
+
import os
|
|
18
|
+
import re
|
|
19
|
+
import time
|
|
18
20
|
import uuid
|
|
21
|
+
import warnings
|
|
22
|
+
from functools import reduce
|
|
23
|
+
from inspect import getsource
|
|
19
24
|
from math import floor
|
|
20
|
-
|
|
21
|
-
import
|
|
22
|
-
import re, requests
|
|
25
|
+
|
|
26
|
+
import requests
|
|
23
27
|
import sqlalchemy
|
|
24
|
-
from pathlib import Path
|
|
25
28
|
from numpy import number
|
|
26
29
|
from sqlalchemy import Column, MetaData, Table
|
|
27
|
-
|
|
28
|
-
from
|
|
30
|
+
from sqlalchemy.exc import OperationalError as sqlachemyOperationalError
|
|
31
|
+
from teradatasql import OperationalError
|
|
32
|
+
from teradatasqlalchemy.dialect import dialect as td_dialect
|
|
33
|
+
from teradatasqlalchemy.dialect import preparer
|
|
34
|
+
from teradatasqlalchemy.types import (BIGINT, BLOB, BYTE, BYTEINT, CHAR, CLOB,
|
|
35
|
+
DATE, DECIMAL, FLOAT, INTEGER, NUMBER,
|
|
36
|
+
SMALLINT, TIME, TIMESTAMP, VARBYTE,
|
|
37
|
+
VARCHAR, _TDType)
|
|
29
38
|
|
|
30
39
|
from teradataml import _version
|
|
31
|
-
from teradataml.
|
|
40
|
+
from teradataml.common import td_coltype_code_to_tdtype
|
|
41
|
+
from teradataml.common.constants import (HTTPRequest, PTITableConstants,
|
|
42
|
+
PythonTypes, TeradataConstants,
|
|
43
|
+
TeradataReservedKeywords,
|
|
44
|
+
TeradataTypes)
|
|
32
45
|
from teradataml.common.exceptions import TeradataMlException
|
|
33
|
-
from teradataml.common.
|
|
46
|
+
from teradataml.common.garbagecollector import GarbageCollector
|
|
34
47
|
from teradataml.common.messagecodes import MessageCodes
|
|
48
|
+
from teradataml.common.messages import Messages
|
|
35
49
|
from teradataml.common.sqlbundle import SQLBundle
|
|
36
|
-
from teradataml.common import
|
|
37
|
-
|
|
38
|
-
from teradataml.
|
|
39
|
-
from teradataml.common.garbagecollector import GarbageCollector
|
|
40
|
-
from teradataml.common.constants import TeradataConstants, PTITableConstants, \
|
|
41
|
-
TableOperatorConstants, HTTPRequest
|
|
42
|
-
from teradataml.common.warnings import VantageRuntimeWarning
|
|
50
|
+
from teradataml.common.warnings import (OneTimeUserWarning,
|
|
51
|
+
VantageRuntimeWarning)
|
|
52
|
+
from teradataml.context import context as tdmlctx
|
|
43
53
|
from teradataml.options.configure import configure
|
|
44
54
|
from teradataml.options.display import display
|
|
45
|
-
from teradataml.common.constants import TeradataReservedKeywords, TeradataConstants
|
|
46
|
-
|
|
47
|
-
from teradataml.utils.internal_buffer import _InternalBuffer
|
|
48
|
-
from teradatasqlalchemy.types import _TDType
|
|
49
|
-
from teradatasqlalchemy.types import (INTEGER, SMALLINT, BIGINT, BYTEINT,
|
|
50
|
-
DECIMAL, FLOAT, NUMBER)
|
|
51
|
-
from teradatasqlalchemy.types import (DATE, TIME, TIMESTAMP)
|
|
52
|
-
from teradatasqlalchemy.types import (BYTE, VARBYTE, BLOB)
|
|
53
|
-
from teradatasqlalchemy.types import (CHAR, VARCHAR, CLOB)
|
|
54
|
-
from functools import reduce
|
|
55
|
-
import warnings
|
|
56
55
|
from teradataml.telemetry_utils.queryband import collect_queryband
|
|
57
56
|
from teradataml.utils.utils import execute_sql
|
|
58
57
|
from teradataml.utils.validators import _Validators
|
|
59
|
-
from sqlalchemy.exc import OperationalError as sqlachemyOperationalError
|
|
60
58
|
|
|
61
59
|
|
|
62
60
|
class UtilFuncs():
|
|
@@ -304,13 +302,17 @@ class UtilFuncs():
|
|
|
304
302
|
tabname = "{}_{}".format(tabname, prefix)
|
|
305
303
|
|
|
306
304
|
tabname = "{}_{}".format(tabname, random_string)
|
|
307
|
-
|
|
305
|
+
|
|
308
306
|
# ELE-6710 - Use database user associated with the current context for volatile tables.
|
|
309
307
|
if table_type == TeradataConstants.TERADATA_VOLATILE_TABLE:
|
|
310
308
|
from teradataml.context.context import _get_user
|
|
311
309
|
tabname = "\"{}\".\"{}\"".format(_get_user(), tabname)
|
|
312
310
|
return tabname
|
|
313
311
|
|
|
312
|
+
if configure.temp_object_type == TeradataConstants.TERADATA_VOLATILE_TABLE:
|
|
313
|
+
from teradataml.context.context import _get_user
|
|
314
|
+
return "\"{}\".\"{}_{}\"".format(_get_user(), "vt", tabname)
|
|
315
|
+
|
|
314
316
|
if use_default_database and databasename is None:
|
|
315
317
|
tabname = "\"{}\".\"{}\"".format(tdmlctx._get_context_temp_databasename(
|
|
316
318
|
table_type=table_type), tabname)
|
|
@@ -450,9 +452,10 @@ class UtilFuncs():
|
|
|
450
452
|
>>> def udf(a, b): return a + b
|
|
451
453
|
>>> func = UtilFuncs._serialize_and_encode(udf)
|
|
452
454
|
"""
|
|
453
|
-
from dill import dumps as dill_dumps
|
|
454
455
|
from base64 import b64encode as base64_b64encode
|
|
455
456
|
|
|
457
|
+
from dill import dumps as dill_dumps
|
|
458
|
+
|
|
456
459
|
return base64_b64encode(dill_dumps(obj, recurse=True))
|
|
457
460
|
|
|
458
461
|
@staticmethod
|
|
@@ -694,6 +697,7 @@ class UtilFuncs():
|
|
|
694
697
|
EXAMPLES:
|
|
695
698
|
UtilFuncs._create_table('"dbname"."table_name"', "select * from table_name")
|
|
696
699
|
"""
|
|
700
|
+
|
|
697
701
|
crt_table = SQLBundle._build_create_table_with_data(table_name, query)
|
|
698
702
|
if volatile:
|
|
699
703
|
crt_table = SQLBundle._build_create_volatile_table_with_data(table_name, query)
|
|
@@ -757,13 +761,14 @@ class UtilFuncs():
|
|
|
757
761
|
return vtab_name
|
|
758
762
|
|
|
759
763
|
@staticmethod
|
|
760
|
-
def _drop_table(table_name, check_table_exist=True):
|
|
764
|
+
def _drop_table(table_name, check_table_exist=True, purge_clause=None):
|
|
761
765
|
"""
|
|
762
766
|
Drops a table.
|
|
763
767
|
|
|
764
768
|
PARAMETERS:
|
|
765
769
|
table_name - The table to drop.
|
|
766
770
|
check_table_exist - Checks if the table exist before dropping the table.
|
|
771
|
+
purge_clause - Specifies string representing purge clause to be appended to drop table query.
|
|
767
772
|
|
|
768
773
|
RETURNS:
|
|
769
774
|
True - if the table is dropped.
|
|
@@ -776,9 +781,11 @@ class UtilFuncs():
|
|
|
776
781
|
UtilFuncs._drop_table('mytab', check_table_exist = False)
|
|
777
782
|
UtilFuncs._drop_table('mydb.mytab', check_table_exist = False)
|
|
778
783
|
UtilFuncs._drop_table("mydb"."mytab", check_table_exist = True)
|
|
784
|
+
UtilFuncs._drop_table("my_lake"."my_db"."my_tab", purge_clause='PURGE ALL')
|
|
785
|
+
UtilFuncs._drop_table("my_lake"."my_db"."my_tab", purge_clause='NO PURGE')
|
|
779
786
|
|
|
780
787
|
"""
|
|
781
|
-
drop_tab = SQLBundle._build_drop_table(table_name)
|
|
788
|
+
drop_tab = SQLBundle._build_drop_table(table_name, purge_clause)
|
|
782
789
|
if check_table_exist is True:
|
|
783
790
|
helptable = UtilFuncs._get_help_tablename(table_name)
|
|
784
791
|
if helptable:
|
|
@@ -958,6 +965,22 @@ class UtilFuncs():
|
|
|
958
965
|
"""
|
|
959
966
|
return UtilFuncs._execute_query(SQLBundle._build_help_table(table_name))
|
|
960
967
|
|
|
968
|
+
@staticmethod
|
|
969
|
+
def _get_help_datalakename(datalake_name):
|
|
970
|
+
"""
|
|
971
|
+
Function to get help of the datalake.
|
|
972
|
+
|
|
973
|
+
PARAMETERS:
|
|
974
|
+
datalake_name - The name of the datalake.
|
|
975
|
+
|
|
976
|
+
RETURNS:
|
|
977
|
+
The help information of the datalake specified by datalake_name.
|
|
978
|
+
|
|
979
|
+
EXAMPLES:
|
|
980
|
+
UtilFuncs._get_help_datalakename(mydatalake)
|
|
981
|
+
"""
|
|
982
|
+
return UtilFuncs._execute_query(SQLBundle._build_help_datalake(datalake_name))
|
|
983
|
+
|
|
961
984
|
@staticmethod
|
|
962
985
|
def _get_select_table(table_name):
|
|
963
986
|
"""
|
|
@@ -1251,7 +1274,7 @@ class UtilFuncs():
|
|
|
1251
1274
|
return UtilFuncs._teradata_quote_arg(keyword, "\"", False)
|
|
1252
1275
|
|
|
1253
1276
|
return keyword
|
|
1254
|
-
|
|
1277
|
+
|
|
1255
1278
|
def _contains_space(item):
|
|
1256
1279
|
"""
|
|
1257
1280
|
Check if the specified string in item has spaces or tabs in it.
|
|
@@ -1283,46 +1306,74 @@ class UtilFuncs():
|
|
|
1283
1306
|
# If the input is a list, check each element
|
|
1284
1307
|
if isinstance(item, list):
|
|
1285
1308
|
# Check each item in the list
|
|
1286
|
-
return any(UtilFuncs._contains_space(col) for col in item)
|
|
1309
|
+
return any(UtilFuncs._contains_space(col) for col in item)
|
|
1287
1310
|
|
|
1288
|
-
return False
|
|
1311
|
+
return False
|
|
1289
1312
|
|
|
1290
|
-
|
|
1291
|
-
def _in_schema(schema_name, table_name):
|
|
1313
|
+
def _is_ascii(col_lst):
|
|
1292
1314
|
"""
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
Note:
|
|
1296
|
-
teradataml recommends to use this function to access table(s)/view(s),
|
|
1297
|
-
from the database other than the default database.
|
|
1315
|
+
Description:
|
|
1316
|
+
Check if the specified string in col_lst has non-ASCII characters in it.
|
|
1298
1317
|
|
|
1299
1318
|
PARAMETERS:
|
|
1300
|
-
|
|
1301
|
-
Required Argument
|
|
1302
|
-
Specifies
|
|
1303
|
-
Types:
|
|
1319
|
+
col_lst:
|
|
1320
|
+
Required Argument.
|
|
1321
|
+
Specifies a list of strings to check for non-ASCII characters.
|
|
1322
|
+
Types: list
|
|
1304
1323
|
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
Specifies the table name or view name in Vantage.
|
|
1308
|
-
Types: str
|
|
1324
|
+
RETURNS:
|
|
1325
|
+
True, if the specified string has non-ASCII characters in it, else False.
|
|
1309
1326
|
|
|
1327
|
+
RAISES:
|
|
1328
|
+
None.
|
|
1329
|
+
|
|
1310
1330
|
EXAMPLES:
|
|
1311
|
-
|
|
1331
|
+
# Passing column name with non-ASCII characters returns True.
|
|
1332
|
+
>>> is_non_ascii = UtilFuncs._is_ascii(["col name", "がく片の長さ@name"])
|
|
1333
|
+
>>> print(is_non_ascii)
|
|
1334
|
+
>>> True
|
|
1335
|
+
# Passing column name without non-ASCII characters returns False.
|
|
1336
|
+
>>> is_non_ascii = UtilFuncs._is_ascii(["colname", "col_name"])
|
|
1337
|
+
>>> print(is_non_ascii)
|
|
1338
|
+
>>> False
|
|
1339
|
+
"""
|
|
1340
|
+
if isinstance(col_lst, str):
|
|
1341
|
+
# Check if the input is a string and look for non-ASCII characters
|
|
1342
|
+
return not col_lst.isascii()
|
|
1343
|
+
|
|
1344
|
+
if isinstance(col_lst, list):
|
|
1345
|
+
for item in col_lst:
|
|
1346
|
+
if isinstance(item, str) and not item.isascii():
|
|
1347
|
+
return True
|
|
1348
|
+
return False
|
|
1312
1349
|
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1350
|
+
@staticmethod
|
|
1351
|
+
def __get_dot_separated_names(full_qualified_name):
|
|
1352
|
+
"""
|
|
1353
|
+
Takes in fully qualified name of the table/view (db.table), and returns
|
|
1354
|
+
a dot separated name from the same.
|
|
1317
1355
|
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1356
|
+
PARAMETERS:
|
|
1357
|
+
full_qualified_name - Name of the table/view
|
|
1358
|
+
|
|
1359
|
+
EXAMPLES:
|
|
1360
|
+
UtilFuncs._extract_db_name('"db1"."tablename"')
|
|
1361
|
+
UtilFuncs._extract_db_name('"Icebergs"."db1"."tablename"')
|
|
1362
|
+
|
|
1363
|
+
RETURNS:
|
|
1364
|
+
List of dot separated name from the provided name.
|
|
1322
1365
|
|
|
1323
1366
|
"""
|
|
1324
|
-
|
|
1325
|
-
|
|
1367
|
+
# If condition to handle the quoted name.
|
|
1368
|
+
if '"' in full_qualified_name:
|
|
1369
|
+
# Extract the double quoted strings.
|
|
1370
|
+
names = re.findall(r'["](.*?)["]', full_qualified_name)
|
|
1371
|
+
# Remove quotes around the string.
|
|
1372
|
+
names = [i.replace('"', '') for i in names]
|
|
1373
|
+
# Handle non-quoted string with dot separated name.
|
|
1374
|
+
else:
|
|
1375
|
+
names = full_qualified_name.split(".")
|
|
1376
|
+
return names
|
|
1326
1377
|
|
|
1327
1378
|
@staticmethod
|
|
1328
1379
|
def _extract_db_name(full_qualified_name):
|
|
@@ -1334,19 +1385,19 @@ class UtilFuncs():
|
|
|
1334
1385
|
full_qualified_name - Name of the table/view
|
|
1335
1386
|
|
|
1336
1387
|
EXAMPLES:
|
|
1337
|
-
UtilFuncs._extract_db_name("db1"."tablename")
|
|
1388
|
+
UtilFuncs._extract_db_name('"db1"."tablename"')
|
|
1389
|
+
UtilFuncs._extract_db_name('"Icebergs"."db1"."tablename"')
|
|
1338
1390
|
|
|
1339
1391
|
RETURNS:
|
|
1340
1392
|
Database name from the provided name.
|
|
1341
1393
|
|
|
1342
1394
|
"""
|
|
1343
|
-
|
|
1344
|
-
names = re.findall(r'["](.*?)["]', full_qualified_name)
|
|
1345
|
-
# Remove quotes around the string.
|
|
1346
|
-
names = [i.replace('"', '') for i in names]
|
|
1395
|
+
names = UtilFuncs.__get_dot_separated_names(full_qualified_name)
|
|
1347
1396
|
if names:
|
|
1348
1397
|
if len(names) == 2:
|
|
1349
1398
|
return names[0]
|
|
1399
|
+
elif len(names) == 3:
|
|
1400
|
+
return names[1]
|
|
1350
1401
|
else:
|
|
1351
1402
|
return None
|
|
1352
1403
|
|
|
@@ -1360,23 +1411,45 @@ class UtilFuncs():
|
|
|
1360
1411
|
full_qualified_name - Name of the table/view
|
|
1361
1412
|
|
|
1362
1413
|
EXAMPLES:
|
|
1363
|
-
UtilFuncs.
|
|
1414
|
+
UtilFuncs._extract_table_name('"db1"."tablename"')
|
|
1415
|
+
UtilFuncs._extract_table_name('"Icebergs"."db1"."tablename"')
|
|
1364
1416
|
|
|
1365
1417
|
RETURNS:
|
|
1366
1418
|
Table/View name from the provided name.
|
|
1367
1419
|
|
|
1368
1420
|
"""
|
|
1369
|
-
|
|
1370
|
-
names = re.findall(r'["](.*?)["]', full_qualified_name)
|
|
1371
|
-
# Remove quotes around the string.
|
|
1372
|
-
names = [i.replace('"', '') for i in names]
|
|
1421
|
+
names = UtilFuncs.__get_dot_separated_names(full_qualified_name)
|
|
1373
1422
|
if names:
|
|
1374
1423
|
if len(names) == 2:
|
|
1375
1424
|
return names[1]
|
|
1425
|
+
elif len(names) == 3:
|
|
1426
|
+
return names[2]
|
|
1376
1427
|
else:
|
|
1377
1428
|
return names[0]
|
|
1378
1429
|
return full_qualified_name
|
|
1379
1430
|
|
|
1431
|
+
@staticmethod
|
|
1432
|
+
def _extract_datalake_name(full_qualified_name):
|
|
1433
|
+
"""
|
|
1434
|
+
Takes in fully qualified name of the table/view (db.table), and returns
|
|
1435
|
+
a datalake name from the same.
|
|
1436
|
+
|
|
1437
|
+
PARAMETERS:
|
|
1438
|
+
full_qualified_name - Name of the table/view
|
|
1439
|
+
|
|
1440
|
+
EXAMPLES:
|
|
1441
|
+
UtilFuncs._extract_datalake_name('"db1"."tablename"')
|
|
1442
|
+
UtilFuncs._extract_datalake_name('"Icebergs"."db1"."tablename"')
|
|
1443
|
+
|
|
1444
|
+
RETURNS:
|
|
1445
|
+
Database name from the provided name.
|
|
1446
|
+
|
|
1447
|
+
"""
|
|
1448
|
+
names = UtilFuncs.__get_dot_separated_names(full_qualified_name)
|
|
1449
|
+
if names and len(names) == 3:
|
|
1450
|
+
return names[0]
|
|
1451
|
+
return None
|
|
1452
|
+
|
|
1380
1453
|
@staticmethod
|
|
1381
1454
|
def _teradata_quote_arg(args, quote="'", call_from_wrapper=True):
|
|
1382
1455
|
"""
|
|
@@ -2402,7 +2475,14 @@ class UtilFuncs():
|
|
|
2402
2475
|
# and determine the system type accordingly.
|
|
2403
2476
|
if tbl_operator is None:
|
|
2404
2477
|
from teradataml.context.context import _get_database_version
|
|
2405
|
-
|
|
2478
|
+
if int(_get_database_version().split(".")[0]) < 20:
|
|
2479
|
+
return False
|
|
2480
|
+
# If the database version is 20 or higher, check if the system is VCL or not.
|
|
2481
|
+
try:
|
|
2482
|
+
res = UtilFuncs._execute_query("SELECT 1 WHERE TD_GetSystemType('PRODUCT') = 'VCL';")
|
|
2483
|
+
return True if res else False
|
|
2484
|
+
except OperationalError:
|
|
2485
|
+
return True
|
|
2406
2486
|
|
|
2407
2487
|
return tbl_operator == "apply"
|
|
2408
2488
|
|
|
@@ -2429,7 +2509,6 @@ class UtilFuncs():
|
|
|
2429
2509
|
return "python" if UtilFuncs._is_lake() else \
|
|
2430
2510
|
'{}/bin/python3'.format(configure.indb_install_location)
|
|
2431
2511
|
|
|
2432
|
-
|
|
2433
2512
|
def _is_view(tablename):
|
|
2434
2513
|
"""
|
|
2435
2514
|
DESCRIPTION:
|
|
@@ -2515,7 +2594,7 @@ class UtilFuncs():
|
|
|
2515
2594
|
raise tdml_e
|
|
2516
2595
|
except Exception as exc:
|
|
2517
2596
|
raise exc
|
|
2518
|
-
|
|
2597
|
+
|
|
2519
2598
|
def _get_env_name(col=None):
|
|
2520
2599
|
"""
|
|
2521
2600
|
DESCRIPTION:
|
|
@@ -2630,6 +2709,219 @@ class UtilFuncs():
|
|
|
2630
2709
|
"""
|
|
2631
2710
|
return '"{}"."{}"'.format(schema_name, table_name)
|
|
2632
2711
|
|
|
2712
|
+
def _check_python_version_diff(env = None):
|
|
2713
|
+
"""
|
|
2714
|
+
DESCRIPTION:
|
|
2715
|
+
Internal function to check the python version difference between Vantage and local.
|
|
2716
|
+
|
|
2717
|
+
PARAMETERS:
|
|
2718
|
+
env:
|
|
2719
|
+
Optional Argument.
|
|
2720
|
+
Specifies the user environment for Vantage Cloud Lake.
|
|
2721
|
+
Types: str, object of class UserEnv
|
|
2722
|
+
Default Value: None
|
|
2723
|
+
|
|
2724
|
+
RAISES:
|
|
2725
|
+
TeradataMlException
|
|
2726
|
+
|
|
2727
|
+
RETURNS:
|
|
2728
|
+
None.
|
|
2729
|
+
|
|
2730
|
+
EXAMPLES:
|
|
2731
|
+
>>> self._check_python_version_diff(env)
|
|
2732
|
+
"""
|
|
2733
|
+
if env:
|
|
2734
|
+
# Get the Python interpreter version of the user environment.
|
|
2735
|
+
from teradataml.scriptmgmt.lls_utils import list_user_envs
|
|
2736
|
+
from teradataml.scriptmgmt.UserEnv import UserEnv
|
|
2737
|
+
env_list = list_user_envs()
|
|
2738
|
+
user_env_name = env.env_name if isinstance(env, UserEnv) else env
|
|
2739
|
+
env_base_version = env_list[env_list['env_name'] == user_env_name].base_env_name.values
|
|
2740
|
+
# Check if the user environment is not found, then return.
|
|
2741
|
+
if len(env_base_version) == 0:
|
|
2742
|
+
return
|
|
2743
|
+
python_env = env_base_version[0].split("_")[1]
|
|
2744
|
+
|
|
2745
|
+
# Get the Python interpreter version of the local environment.
|
|
2746
|
+
from teradataml.context import context as tdmlctx
|
|
2747
|
+
python_local = tdmlctx.python_version_local.rsplit(".", 1)[0]
|
|
2748
|
+
# Check if the Python interpreter major versions are consistent between Lake user environment and local.
|
|
2749
|
+
# If not, raise an exception.
|
|
2750
|
+
if python_env != python_local:
|
|
2751
|
+
raise TeradataMlException(Messages.get_message(MessageCodes.PYTHON_VERSION_MISMATCH_OAF,
|
|
2752
|
+
python_env, python_local),
|
|
2753
|
+
MessageCodes.PYTHON_VERSION_MISMATCH_OAF)
|
|
2754
|
+
else:
|
|
2755
|
+
from teradataml.context import context as tdmlctx
|
|
2756
|
+
from teradataml.dbutils.dbutils import (db_python_version_diff, set_session_param)
|
|
2757
|
+
set_session_param("searchuifdbpath",
|
|
2758
|
+
UtilFuncs._get_dialect_quoted_name(tdmlctx._get_current_databasename()))
|
|
2759
|
+
if len(db_python_version_diff()) > 0:
|
|
2760
|
+
# Raise exception when python versions don't match between Vantage and local.
|
|
2761
|
+
py_major_vantage_version = tdmlctx.python_version_vantage.rsplit(".", 1)[0]
|
|
2762
|
+
raise TeradataMlException(Messages.get_message(MessageCodes.PYTHON_VERSION_MISMATCH,
|
|
2763
|
+
tdmlctx.python_version_vantage, py_major_vantage_version),
|
|
2764
|
+
MessageCodes.PYTHON_VERSION_MISMATCH)
|
|
2765
|
+
|
|
2766
|
+
def _check_package_version_diff(func, packages, env=None):
|
|
2767
|
+
"""
|
|
2768
|
+
DESCRIPTION:
|
|
2769
|
+
Internal function to process packages differences between Vantage and local.
|
|
2770
|
+
Note:
|
|
2771
|
+
* Raises a warning if the versions of certain Python packages are not consistent between Vantage and local.
|
|
2772
|
+
|
|
2773
|
+
PARAMETERS:
|
|
2774
|
+
func:
|
|
2775
|
+
Required Argument.
|
|
2776
|
+
Specifies the function name.
|
|
2777
|
+
Types: str
|
|
2778
|
+
|
|
2779
|
+
packages:
|
|
2780
|
+
Required Argument.
|
|
2781
|
+
Specifies the list of package names.
|
|
2782
|
+
Types: list of str
|
|
2783
|
+
|
|
2784
|
+
env:
|
|
2785
|
+
Optional Argument.
|
|
2786
|
+
Specifies the user environment for Vantage Cloud Lake.
|
|
2787
|
+
Types: str, object of class UserEnv
|
|
2788
|
+
Default Value: None
|
|
2789
|
+
|
|
2790
|
+
RETURNS:
|
|
2791
|
+
None
|
|
2792
|
+
|
|
2793
|
+
RAISES:
|
|
2794
|
+
OneTimeUserWarning
|
|
2795
|
+
|
|
2796
|
+
EXAMPLES:
|
|
2797
|
+
self._process_package_differences("apply", ["dill"], env)
|
|
2798
|
+
"""
|
|
2799
|
+
|
|
2800
|
+
# Check if OSML required packages are verified or not.
|
|
2801
|
+
from teradataml.opensource._constants import _packages_verified_in_vantage
|
|
2802
|
+
_is_packages_verfied_in_vantage = _packages_verified_in_vantage.get(
|
|
2803
|
+
func, None)
|
|
2804
|
+
if _is_packages_verfied_in_vantage:
|
|
2805
|
+
return
|
|
2806
|
+
|
|
2807
|
+
if env:
|
|
2808
|
+
from teradataml.scriptmgmt.lls_utils import get_env
|
|
2809
|
+
from teradataml.scriptmgmt.UserEnv import UserEnv
|
|
2810
|
+
env = env if isinstance(env, UserEnv) else get_env(env)
|
|
2811
|
+
env_pkg_df = env.libs
|
|
2812
|
+
pkgs_dict = dict(zip(env_pkg_df['name'], env_pkg_df['version']))
|
|
2813
|
+
|
|
2814
|
+
from importlib.metadata import version
|
|
2815
|
+
warning_raised = False
|
|
2816
|
+
strr = []
|
|
2817
|
+
for pkg in packages:
|
|
2818
|
+
env_version = pkgs_dict.get(pkg)
|
|
2819
|
+
local_version = version(pkg)
|
|
2820
|
+
# Write the requirements file listing all the related packages and their versions
|
|
2821
|
+
# if the versions Python packages are not consistent between Vantage and local.
|
|
2822
|
+
if env_version != local_version:
|
|
2823
|
+
warning_raised = True
|
|
2824
|
+
strr.append(f"{pkg}=={local_version}")
|
|
2825
|
+
|
|
2826
|
+
# If there are differences in package versions, display a warning message to the user.
|
|
2827
|
+
# about the package differences and the requirements file created for the user to install the packages
|
|
2828
|
+
if warning_raised:
|
|
2829
|
+
file_name = f"requirements_{func}.txt"
|
|
2830
|
+
req_file = os.path.join(GarbageCollector._get_temp_dir_name(), file_name)
|
|
2831
|
+
with open(req_file, "w") as f:
|
|
2832
|
+
f.write("\n".join(strr))
|
|
2833
|
+
|
|
2834
|
+
packages = "{}".format(packages[0]) if len(packages) == 1 else\
|
|
2835
|
+
"', '".join(packages[:-1]) + "' and '" + packages[-1]
|
|
2836
|
+
|
|
2837
|
+
if func == "apply":
|
|
2838
|
+
warning_msg = f"The version of certain Python packages are not consistent between Lake "\
|
|
2839
|
+
f"user environment and local. Teradata recommends to maintain same version of '{packages}' "\
|
|
2840
|
+
f"between Lake user environment and local for '{func}'."
|
|
2841
|
+
else:
|
|
2842
|
+
_packages_verified_in_vantage[func] = True
|
|
2843
|
+
warning_msg = "The versions of certain Python packages are not consistent between "\
|
|
2844
|
+
"Lake user environment and local. OpenSourceML compares the versions of '{}' "\
|
|
2845
|
+
f"(and also matches the patterns of these packages) used by 'td_{func}'. "\
|
|
2846
|
+
"Teradata recommends same versions for all the Python packages between Lake "\
|
|
2847
|
+
"user environment and local."
|
|
2848
|
+
|
|
2849
|
+
req = f"\nA requirements file listing all '{func}' " + \
|
|
2850
|
+
f"related packages and their versions has been written to '{req_file}'. "+ \
|
|
2851
|
+
"Update the Lake user environment with the required packages.\n"
|
|
2852
|
+
|
|
2853
|
+
warning_msg += req
|
|
2854
|
+
warnings.warn(warning_msg.format(packages), category=OneTimeUserWarning)
|
|
2855
|
+
|
|
2856
|
+
else:
|
|
2857
|
+
# Check if the versions of Python packages are consistent between Vantage and local.
|
|
2858
|
+
from teradataml.dbutils.dbutils import _db_python_package_version_diff
|
|
2859
|
+
all_package_versions = _db_python_package_version_diff(packages, only_diff=False)
|
|
2860
|
+
package_difference = \
|
|
2861
|
+
all_package_versions[all_package_versions.vantage != all_package_versions.local]
|
|
2862
|
+
# If there are differences in package versions, raise a warning.
|
|
2863
|
+
if package_difference.shape[0] > 0:
|
|
2864
|
+
strr = []
|
|
2865
|
+
# Write the requirements file listing all the related packages and their versions.
|
|
2866
|
+
for rec in all_package_versions.to_records():
|
|
2867
|
+
strr.append(f"{rec[1]}=={rec[2]}")
|
|
2868
|
+
file_name = f"requirements_{func}.txt"
|
|
2869
|
+
req_file = os.path.join(GarbageCollector._get_temp_dir_name(), file_name)
|
|
2870
|
+
with open(req_file, "w") as f:
|
|
2871
|
+
f.write("\n".join(strr))
|
|
2872
|
+
|
|
2873
|
+
packages = "{}".format(packages[0]) if len(packages) == 1 else\
|
|
2874
|
+
"', '".join(packages[:-1]) + "' and '" + packages[-1]
|
|
2875
|
+
|
|
2876
|
+
if func in ["map_row", "map_partition"]:
|
|
2877
|
+
warning_msg = f"The version of certain Python packages are not consistent between "\
|
|
2878
|
+
"Vantage and local. User can identify them using db_python_package_version_diff() "\
|
|
2879
|
+
f"function. Teradata recommends to maintain same version of '{packages}' "\
|
|
2880
|
+
f"between Vantage and local for '{func}'."
|
|
2881
|
+
else:
|
|
2882
|
+
_packages_verified_in_vantage[func] = True
|
|
2883
|
+
warning_msg = "The versions of certain Python packages are not consistent between "\
|
|
2884
|
+
"Vantage and local. User can identify them using db_python_package_version_diff() "\
|
|
2885
|
+
"function. OpenSourceML compares the versions of '{}' (and also matches the "\
|
|
2886
|
+
f"patterns of these packages) used by 'td_{func}'. Teradata "\
|
|
2887
|
+
"recommends to maintain same versions for all the Python packages between Vantage "\
|
|
2888
|
+
"and local."
|
|
2889
|
+
|
|
2890
|
+
# Display a warning message to the user about the package differences
|
|
2891
|
+
# and the requirements file created for the user to install the packages.
|
|
2892
|
+
req = f"\nA requirements file listing all '{func}' " + \
|
|
2893
|
+
f"related packages and their versions has been written to '{req_file}'.\n"
|
|
2894
|
+
|
|
2895
|
+
warning_msg += req
|
|
2896
|
+
warnings.warn(warning_msg.format(packages), category=OneTimeUserWarning)
|
|
2897
|
+
|
|
2898
|
+
@staticmethod
|
|
2899
|
+
def _get_dialect_quoted_name(object_name):
|
|
2900
|
+
"""
|
|
2901
|
+
DESCRIPTION:
|
|
2902
|
+
Function to quote the SQL identifiers as per teradatasqlalchemy's quoting rules.
|
|
2903
|
+
|
|
2904
|
+
PARAMETERS:
|
|
2905
|
+
object_name
|
|
2906
|
+
Required Argument.
|
|
2907
|
+
Specifies the name of the SQL identifier to be quoted.
|
|
2908
|
+
Type: str
|
|
2909
|
+
|
|
2910
|
+
RAISES:
|
|
2911
|
+
None
|
|
2912
|
+
|
|
2913
|
+
RETURNS:
|
|
2914
|
+
Quoted object name.
|
|
2915
|
+
|
|
2916
|
+
EXAMPLES:
|
|
2917
|
+
_get_dialect_quoted_name(object_name = "tdml.alice")
|
|
2918
|
+
|
|
2919
|
+
OUTPUT:
|
|
2920
|
+
'"tdml.alice"'
|
|
2921
|
+
"""
|
|
2922
|
+
tdp = preparer(td_dialect)
|
|
2923
|
+
return tdp.quote(object_name)
|
|
2924
|
+
|
|
2633
2925
|
|
|
2634
2926
|
from teradataml.common.aed_utils import AedUtils
|
|
2635
2927
|
from teradataml.dbutils.filemgr import remove_file
|
teradataml/common/warnings.py
CHANGED
|
@@ -17,9 +17,20 @@ class VantageRuntimeWarning(RuntimeWarning):
|
|
|
17
17
|
"""
|
|
18
18
|
pass
|
|
19
19
|
|
|
20
|
+
|
|
20
21
|
class TeradataMlRuntimeWarning(RuntimeWarning):
|
|
21
22
|
"""
|
|
22
23
|
The TeradataMlRuntimeWarning is thrown whenever there are Warnings in runtime execution of objects in teradataml.
|
|
23
24
|
"""
|
|
24
25
|
# For future purpose
|
|
25
26
|
pass
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class OneTimeUserWarning(UserWarning):
|
|
31
|
+
"""
|
|
32
|
+
The OneTimeUserWarning is thrown when the warning should only be displayed once to the user.
|
|
33
|
+
This can be useful for deprecation warnings, configuration issues, or other
|
|
34
|
+
non-critical warnings that do not need to be repeated multiple times.
|
|
35
|
+
"""
|
|
36
|
+
pass
|