teradataml 20.0.0.1__py3-none-any.whl → 20.0.0.3__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/LICENSE.pdf +0 -0
- teradataml/README.md +306 -0
- teradataml/__init__.py +10 -3
- teradataml/_version.py +1 -1
- teradataml/analytics/__init__.py +3 -2
- teradataml/analytics/analytic_function_executor.py +299 -16
- teradataml/analytics/analytic_query_generator.py +92 -0
- teradataml/analytics/byom/__init__.py +3 -2
- teradataml/analytics/json_parser/metadata.py +13 -3
- teradataml/analytics/json_parser/utils.py +13 -6
- teradataml/analytics/meta_class.py +40 -1
- teradataml/analytics/sqle/DecisionTreePredict.py +1 -1
- teradataml/analytics/sqle/__init__.py +11 -2
- teradataml/analytics/table_operator/__init__.py +4 -3
- teradataml/analytics/uaf/__init__.py +21 -2
- teradataml/analytics/utils.py +66 -1
- teradataml/analytics/valib.py +1 -1
- teradataml/automl/__init__.py +1502 -323
- teradataml/automl/custom_json_utils.py +139 -61
- teradataml/automl/data_preparation.py +247 -307
- teradataml/automl/data_transformation.py +32 -12
- teradataml/automl/feature_engineering.py +325 -86
- teradataml/automl/model_evaluation.py +44 -35
- teradataml/automl/model_training.py +122 -153
- teradataml/catalog/byom.py +8 -8
- teradataml/clients/pkce_client.py +1 -1
- teradataml/common/__init__.py +2 -1
- teradataml/common/constants.py +72 -0
- teradataml/common/deprecations.py +13 -7
- teradataml/common/garbagecollector.py +152 -120
- teradataml/common/messagecodes.py +11 -2
- teradataml/common/messages.py +4 -1
- teradataml/common/sqlbundle.py +26 -4
- teradataml/common/utils.py +225 -14
- teradataml/common/wrapper_utils.py +1 -1
- teradataml/context/context.py +82 -2
- teradataml/data/SQL_Fundamentals.pdf +0 -0
- teradataml/data/complaints_test_tokenized.csv +353 -0
- teradataml/data/complaints_tokens_model.csv +348 -0
- teradataml/data/covid_confirm_sd.csv +83 -0
- teradataml/data/dataframe_example.json +27 -1
- teradataml/data/docs/sqle/docs_17_20/CFilter.py +132 -0
- teradataml/data/docs/sqle/docs_17_20/NaiveBayes.py +162 -0
- teradataml/data/docs/sqle/docs_17_20/OutlierFilterFit.py +2 -0
- teradataml/data/docs/sqle/docs_17_20/Pivoting.py +279 -0
- teradataml/data/docs/sqle/docs_17_20/Shap.py +203 -0
- teradataml/data/docs/sqle/docs_17_20/TDNaiveBayesPredict.py +189 -0
- teradataml/data/docs/sqle/docs_17_20/TFIDF.py +142 -0
- teradataml/data/docs/sqle/docs_17_20/TextParser.py +3 -3
- teradataml/data/docs/sqle/docs_17_20/Unpivoting.py +216 -0
- teradataml/data/docs/tableoperator/docs_17_20/Image2Matrix.py +118 -0
- teradataml/data/docs/uaf/docs_17_20/ACF.py +1 -10
- teradataml/data/docs/uaf/docs_17_20/ArimaEstimate.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/ArimaForecast.py +35 -5
- teradataml/data/docs/uaf/docs_17_20/ArimaValidate.py +3 -1
- teradataml/data/docs/uaf/docs_17_20/ArimaXEstimate.py +293 -0
- teradataml/data/docs/uaf/docs_17_20/AutoArima.py +354 -0
- teradataml/data/docs/uaf/docs_17_20/BreuschGodfrey.py +3 -2
- teradataml/data/docs/uaf/docs_17_20/BreuschPaganGodfrey.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/Convolve.py +13 -10
- teradataml/data/docs/uaf/docs_17_20/Convolve2.py +4 -1
- teradataml/data/docs/uaf/docs_17_20/CopyArt.py +145 -0
- teradataml/data/docs/uaf/docs_17_20/CumulPeriodogram.py +5 -4
- teradataml/data/docs/uaf/docs_17_20/DFFT2Conv.py +4 -4
- teradataml/data/docs/uaf/docs_17_20/DWT.py +235 -0
- teradataml/data/docs/uaf/docs_17_20/DWT2D.py +214 -0
- teradataml/data/docs/uaf/docs_17_20/DickeyFuller.py +18 -21
- teradataml/data/docs/uaf/docs_17_20/DurbinWatson.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/ExtractResults.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/FilterFactory1d.py +160 -0
- teradataml/data/docs/uaf/docs_17_20/GenseriesSinusoids.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/GoldfeldQuandt.py +9 -31
- teradataml/data/docs/uaf/docs_17_20/HoltWintersForecaster.py +4 -2
- teradataml/data/docs/uaf/docs_17_20/IDFFT2.py +1 -8
- teradataml/data/docs/uaf/docs_17_20/IDWT.py +236 -0
- teradataml/data/docs/uaf/docs_17_20/IDWT2D.py +226 -0
- teradataml/data/docs/uaf/docs_17_20/IQR.py +134 -0
- teradataml/data/docs/uaf/docs_17_20/LineSpec.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/LinearRegr.py +2 -2
- teradataml/data/docs/uaf/docs_17_20/MAMean.py +3 -3
- teradataml/data/docs/uaf/docs_17_20/Matrix2Image.py +297 -0
- teradataml/data/docs/uaf/docs_17_20/MatrixMultiply.py +15 -6
- teradataml/data/docs/uaf/docs_17_20/PACF.py +0 -1
- teradataml/data/docs/uaf/docs_17_20/Portman.py +2 -2
- teradataml/data/docs/uaf/docs_17_20/PowerSpec.py +2 -2
- teradataml/data/docs/uaf/docs_17_20/Resample.py +9 -1
- teradataml/data/docs/uaf/docs_17_20/SAX.py +246 -0
- teradataml/data/docs/uaf/docs_17_20/SeasonalNormalize.py +17 -10
- teradataml/data/docs/uaf/docs_17_20/SignifPeriodicities.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/WhitesGeneral.py +3 -1
- teradataml/data/docs/uaf/docs_17_20/WindowDFFT.py +368 -0
- teradataml/data/dwt2d_dataTable.csv +65 -0
- teradataml/data/dwt_dataTable.csv +8 -0
- teradataml/data/dwt_filterTable.csv +3 -0
- teradataml/data/finance_data4.csv +13 -0
- teradataml/data/grocery_transaction.csv +19 -0
- teradataml/data/idwt2d_dataTable.csv +5 -0
- teradataml/data/idwt_dataTable.csv +8 -0
- teradataml/data/idwt_filterTable.csv +3 -0
- teradataml/data/interval_data.csv +5 -0
- teradataml/data/jsons/paired_functions.json +14 -0
- teradataml/data/jsons/sqle/17.20/TD_CFilter.json +118 -0
- teradataml/data/jsons/sqle/17.20/TD_NaiveBayes.json +193 -0
- teradataml/data/jsons/sqle/17.20/TD_NaiveBayesPredict.json +212 -0
- teradataml/data/jsons/sqle/17.20/TD_OneClassSVM.json +9 -9
- teradataml/data/jsons/sqle/17.20/TD_Pivoting.json +280 -0
- teradataml/data/jsons/sqle/17.20/TD_Shap.json +222 -0
- teradataml/data/jsons/sqle/17.20/TD_TFIDF.json +162 -0
- teradataml/data/jsons/sqle/17.20/TD_TextParser.json +1 -1
- teradataml/data/jsons/sqle/17.20/TD_Unpivoting.json +235 -0
- teradataml/data/jsons/sqle/20.00/TD_KMeans.json +250 -0
- teradataml/data/jsons/sqle/20.00/TD_SMOTE.json +266 -0
- teradataml/data/jsons/sqle/20.00/TD_VectorDistance.json +278 -0
- teradataml/data/jsons/storedprocedure/17.20/TD_COPYART.json +71 -0
- teradataml/data/jsons/storedprocedure/17.20/TD_FILTERFACTORY1D.json +150 -0
- teradataml/data/jsons/tableoperator/17.20/IMAGE2MATRIX.json +53 -0
- teradataml/data/jsons/uaf/17.20/TD_ACF.json +1 -18
- teradataml/data/jsons/uaf/17.20/TD_ARIMAESTIMATE.json +3 -16
- teradataml/data/jsons/uaf/17.20/TD_ARIMAFORECAST.json +0 -3
- teradataml/data/jsons/uaf/17.20/TD_ARIMAVALIDATE.json +5 -3
- teradataml/data/jsons/uaf/17.20/TD_ARIMAXESTIMATE.json +362 -0
- teradataml/data/jsons/uaf/17.20/TD_AUTOARIMA.json +469 -0
- teradataml/data/jsons/uaf/17.20/TD_BINARYMATRIXOP.json +0 -3
- teradataml/data/jsons/uaf/17.20/TD_BINARYSERIESOP.json +0 -2
- teradataml/data/jsons/uaf/17.20/TD_BREUSCH_GODFREY.json +2 -1
- teradataml/data/jsons/uaf/17.20/TD_BREUSCH_PAGAN_GODFREY.json +2 -5
- teradataml/data/jsons/uaf/17.20/TD_CONVOLVE.json +3 -6
- teradataml/data/jsons/uaf/17.20/TD_CONVOLVE2.json +1 -3
- teradataml/data/jsons/uaf/17.20/TD_CUMUL_PERIODOGRAM.json +0 -5
- teradataml/data/jsons/uaf/17.20/TD_DFFT.json +1 -4
- teradataml/data/jsons/uaf/17.20/TD_DFFT2.json +2 -7
- teradataml/data/jsons/uaf/17.20/TD_DFFT2CONV.json +1 -2
- teradataml/data/jsons/uaf/17.20/TD_DFFTCONV.json +0 -2
- teradataml/data/jsons/uaf/17.20/TD_DICKEY_FULLER.json +10 -19
- teradataml/data/jsons/uaf/17.20/TD_DTW.json +3 -6
- teradataml/data/jsons/uaf/17.20/TD_DWT.json +173 -0
- teradataml/data/jsons/uaf/17.20/TD_DWT2D.json +160 -0
- teradataml/data/jsons/uaf/17.20/TD_FITMETRICS.json +1 -1
- teradataml/data/jsons/uaf/17.20/TD_GOLDFELD_QUANDT.json +16 -30
- teradataml/data/jsons/uaf/17.20/{TD_HOLT_WINTERS_FORECAST.json → TD_HOLT_WINTERS_FORECASTER.json} +1 -2
- teradataml/data/jsons/uaf/17.20/TD_IDFFT2.json +1 -15
- teradataml/data/jsons/uaf/17.20/TD_IDWT.json +162 -0
- teradataml/data/jsons/uaf/17.20/TD_IDWT2D.json +149 -0
- teradataml/data/jsons/uaf/17.20/TD_IQR.json +117 -0
- teradataml/data/jsons/uaf/17.20/TD_LINEAR_REGR.json +1 -1
- teradataml/data/jsons/uaf/17.20/TD_LINESPEC.json +1 -1
- teradataml/data/jsons/uaf/17.20/TD_MAMEAN.json +1 -3
- teradataml/data/jsons/uaf/17.20/TD_MATRIX2IMAGE.json +209 -0
- teradataml/data/jsons/uaf/17.20/TD_PACF.json +2 -2
- teradataml/data/jsons/uaf/17.20/TD_POWERSPEC.json +5 -5
- teradataml/data/jsons/uaf/17.20/TD_RESAMPLE.json +48 -28
- teradataml/data/jsons/uaf/17.20/TD_SAX.json +210 -0
- teradataml/data/jsons/uaf/17.20/TD_SEASONALNORMALIZE.json +12 -6
- teradataml/data/jsons/uaf/17.20/TD_SIMPLEEXP.json +0 -1
- teradataml/data/jsons/uaf/17.20/TD_TRACKINGOP.json +8 -8
- teradataml/data/jsons/uaf/17.20/TD_UNDIFF.json +1 -1
- teradataml/data/jsons/uaf/17.20/TD_UNNORMALIZE.json +1 -1
- teradataml/data/jsons/uaf/17.20/TD_WINDOWDFFT.json +410 -0
- teradataml/data/load_example_data.py +8 -2
- teradataml/data/medical_readings.csv +101 -0
- teradataml/data/naivebayestextclassifier_example.json +1 -1
- teradataml/data/naivebayestextclassifierpredict_example.json +11 -0
- teradataml/data/patient_profile.csv +101 -0
- teradataml/data/peppers.png +0 -0
- teradataml/data/real_values.csv +14 -0
- teradataml/data/sax_example.json +8 -0
- teradataml/data/scripts/deploy_script.py +1 -1
- teradataml/data/scripts/lightgbm/dataset.template +157 -0
- teradataml/data/scripts/lightgbm/lightgbm_class_functions.template +247 -0
- teradataml/data/scripts/lightgbm/lightgbm_function.template +216 -0
- teradataml/data/scripts/lightgbm/lightgbm_sklearn.template +159 -0
- teradataml/data/scripts/sklearn/sklearn_fit.py +194 -160
- teradataml/data/scripts/sklearn/sklearn_fit_predict.py +136 -115
- teradataml/data/scripts/sklearn/sklearn_function.template +34 -16
- teradataml/data/scripts/sklearn/sklearn_model_selection_split.py +155 -137
- teradataml/data/scripts/sklearn/sklearn_neighbors.py +1 -1
- teradataml/data/scripts/sklearn/sklearn_score.py +12 -3
- teradataml/data/scripts/sklearn/sklearn_transform.py +162 -24
- teradataml/data/star_pivot.csv +8 -0
- teradataml/data/target_udt_data.csv +8 -0
- teradataml/data/templates/open_source_ml.json +3 -1
- teradataml/data/teradataml_example.json +20 -1
- teradataml/data/timestamp_data.csv +4 -0
- teradataml/data/titanic_dataset_unpivoted.csv +19 -0
- teradataml/data/uaf_example.json +55 -1
- teradataml/data/unpivot_example.json +15 -0
- teradataml/data/url_data.csv +9 -0
- teradataml/data/vectordistance_example.json +4 -0
- teradataml/data/windowdfft.csv +16 -0
- teradataml/dataframe/copy_to.py +1 -1
- teradataml/dataframe/data_transfer.py +5 -3
- teradataml/dataframe/dataframe.py +1002 -201
- teradataml/dataframe/fastload.py +3 -3
- teradataml/dataframe/functions.py +867 -0
- teradataml/dataframe/row.py +160 -0
- teradataml/dataframe/setop.py +2 -2
- teradataml/dataframe/sql.py +840 -33
- teradataml/dataframe/window.py +1 -1
- teradataml/dbutils/dbutils.py +878 -34
- teradataml/dbutils/filemgr.py +48 -1
- teradataml/geospatial/geodataframe.py +1 -1
- teradataml/geospatial/geodataframecolumn.py +1 -1
- teradataml/hyperparameter_tuner/optimizer.py +13 -13
- teradataml/lib/aed_0_1.dll +0 -0
- teradataml/opensource/__init__.py +1 -1
- teradataml/opensource/{sklearn/_class.py → _class.py} +102 -17
- teradataml/opensource/_lightgbm.py +950 -0
- teradataml/opensource/{sklearn/_wrapper_utils.py → _wrapper_utils.py} +1 -2
- teradataml/opensource/{sklearn/constants.py → constants.py} +13 -10
- teradataml/opensource/sklearn/__init__.py +0 -1
- teradataml/opensource/sklearn/_sklearn_wrapper.py +1019 -574
- teradataml/options/__init__.py +9 -23
- teradataml/options/configure.py +42 -4
- teradataml/options/display.py +2 -2
- teradataml/plot/axis.py +4 -4
- teradataml/scriptmgmt/UserEnv.py +13 -9
- teradataml/scriptmgmt/lls_utils.py +77 -23
- teradataml/store/__init__.py +13 -0
- teradataml/store/feature_store/__init__.py +0 -0
- teradataml/store/feature_store/constants.py +291 -0
- teradataml/store/feature_store/feature_store.py +2223 -0
- teradataml/store/feature_store/models.py +1505 -0
- teradataml/store/vector_store/__init__.py +1586 -0
- teradataml/table_operators/Script.py +2 -2
- teradataml/table_operators/TableOperator.py +106 -20
- teradataml/table_operators/query_generator.py +3 -0
- teradataml/table_operators/table_operator_query_generator.py +3 -1
- teradataml/table_operators/table_operator_util.py +102 -56
- teradataml/table_operators/templates/dataframe_register.template +69 -0
- teradataml/table_operators/templates/dataframe_udf.template +63 -0
- teradataml/telemetry_utils/__init__.py +0 -0
- teradataml/telemetry_utils/queryband.py +52 -0
- teradataml/utils/dtypes.py +4 -2
- teradataml/utils/validators.py +34 -2
- {teradataml-20.0.0.1.dist-info → teradataml-20.0.0.3.dist-info}/METADATA +311 -3
- {teradataml-20.0.0.1.dist-info → teradataml-20.0.0.3.dist-info}/RECORD +240 -157
- {teradataml-20.0.0.1.dist-info → teradataml-20.0.0.3.dist-info}/WHEEL +0 -0
- {teradataml-20.0.0.1.dist-info → teradataml-20.0.0.3.dist-info}/top_level.txt +0 -0
- {teradataml-20.0.0.1.dist-info → teradataml-20.0.0.3.dist-info}/zip-safe +0 -0
teradataml/common/utils.py
CHANGED
|
@@ -13,6 +13,8 @@ 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
|
+
import json
|
|
16
18
|
import uuid
|
|
17
19
|
from math import floor
|
|
18
20
|
import os, itertools
|
|
@@ -22,6 +24,7 @@ import sqlalchemy
|
|
|
22
24
|
from pathlib import Path
|
|
23
25
|
from numpy import number
|
|
24
26
|
from sqlalchemy import Column, MetaData, Table
|
|
27
|
+
|
|
25
28
|
from teradataml.context.context import get_connection
|
|
26
29
|
|
|
27
30
|
from teradataml import _version
|
|
@@ -41,6 +44,7 @@ from teradataml.options.configure import configure
|
|
|
41
44
|
from teradataml.options.display import display
|
|
42
45
|
from teradataml.common.constants import TeradataReservedKeywords, TeradataConstants
|
|
43
46
|
|
|
47
|
+
from teradataml.utils.internal_buffer import _InternalBuffer
|
|
44
48
|
from teradatasqlalchemy.types import _TDType
|
|
45
49
|
from teradatasqlalchemy.types import (INTEGER, SMALLINT, BIGINT, BYTEINT,
|
|
46
50
|
DECIMAL, FLOAT, NUMBER)
|
|
@@ -49,7 +53,7 @@ from teradatasqlalchemy.types import (BYTE, VARBYTE, BLOB)
|
|
|
49
53
|
from teradatasqlalchemy.types import (CHAR, VARCHAR, CLOB)
|
|
50
54
|
from functools import reduce
|
|
51
55
|
import warnings
|
|
52
|
-
from
|
|
56
|
+
from teradataml.telemetry_utils.queryband import collect_queryband
|
|
53
57
|
from teradataml.utils.utils import execute_sql
|
|
54
58
|
from teradataml.utils.validators import _Validators
|
|
55
59
|
from sqlalchemy.exc import OperationalError as sqlachemyOperationalError
|
|
@@ -1247,6 +1251,41 @@ class UtilFuncs():
|
|
|
1247
1251
|
return UtilFuncs._teradata_quote_arg(keyword, "\"", False)
|
|
1248
1252
|
|
|
1249
1253
|
return keyword
|
|
1254
|
+
|
|
1255
|
+
def _contains_space(item):
|
|
1256
|
+
"""
|
|
1257
|
+
Check if the specified string in item has spaces or tabs in it.
|
|
1258
|
+
|
|
1259
|
+
PARAMETERS:
|
|
1260
|
+
item:
|
|
1261
|
+
Required Argument.
|
|
1262
|
+
Specifies a string to check for spaces or tabs.
|
|
1263
|
+
Types: str
|
|
1264
|
+
|
|
1265
|
+
RETURNS:
|
|
1266
|
+
True, if the specified string has spaces or tabs in it, else False.
|
|
1267
|
+
|
|
1268
|
+
RAISES:
|
|
1269
|
+
None.
|
|
1270
|
+
|
|
1271
|
+
EXAMPLES:
|
|
1272
|
+
# Passing column name with spaces returns True.
|
|
1273
|
+
is_space = UtilFuncs._contains_space("col name")
|
|
1274
|
+
print(is_space)
|
|
1275
|
+
# Passing column name without spaces returns False.
|
|
1276
|
+
is_space = UtilFuncs._contains_space("colname")
|
|
1277
|
+
print(is_space)
|
|
1278
|
+
"""
|
|
1279
|
+
# Check if the input is a string and look for spaces or tabs
|
|
1280
|
+
if isinstance(item, str):
|
|
1281
|
+
return any(char in {' ', '\t'} for char in item)
|
|
1282
|
+
|
|
1283
|
+
# If the input is a list, check each element
|
|
1284
|
+
if isinstance(item, list):
|
|
1285
|
+
# Check each item in the list
|
|
1286
|
+
return any(UtilFuncs._contains_space(col) for col in item)
|
|
1287
|
+
|
|
1288
|
+
return False
|
|
1250
1289
|
|
|
1251
1290
|
@staticmethod
|
|
1252
1291
|
def _in_schema(schema_name, table_name):
|
|
@@ -1857,7 +1896,7 @@ class UtilFuncs():
|
|
|
1857
1896
|
con = tdmlctx.get_connection()
|
|
1858
1897
|
|
|
1859
1898
|
if check_table_exists:
|
|
1860
|
-
table_exists = con.dialect.has_table(con, table_name, schema_name)
|
|
1899
|
+
table_exists = con.dialect.has_table(con, table_name, schema_name, table_only=True)
|
|
1861
1900
|
|
|
1862
1901
|
if not table_exists:
|
|
1863
1902
|
raise TeradataMlException(Messages.get_message(MessageCodes.TABLE_DOES_NOT_EXIST, table_name),
|
|
@@ -2356,8 +2395,16 @@ class UtilFuncs():
|
|
|
2356
2395
|
>>> self._is_lake()
|
|
2357
2396
|
"""
|
|
2358
2397
|
|
|
2359
|
-
|
|
2360
|
-
|
|
2398
|
+
tbl_operator = configure.table_operator.lower() \
|
|
2399
|
+
if configure.table_operator else None
|
|
2400
|
+
|
|
2401
|
+
# If the user does not provide a table_operator, check the database version
|
|
2402
|
+
# and determine the system type accordingly.
|
|
2403
|
+
if tbl_operator is None:
|
|
2404
|
+
from teradataml.context.context import _get_database_version
|
|
2405
|
+
return int(_get_database_version().split(".")[0]) >= 20
|
|
2406
|
+
|
|
2407
|
+
return tbl_operator == "apply"
|
|
2361
2408
|
|
|
2362
2409
|
@staticmethod
|
|
2363
2410
|
def _get_python_execution_path():
|
|
@@ -2377,14 +2424,11 @@ class UtilFuncs():
|
|
|
2377
2424
|
EXAMPLES:
|
|
2378
2425
|
>>> self._get_python_execution_path()
|
|
2379
2426
|
"""
|
|
2427
|
+
# 'indb_install_location' expects python installation directory path.
|
|
2428
|
+
# Hence, postfixing python binary path.
|
|
2429
|
+
return "python" if UtilFuncs._is_lake() else \
|
|
2430
|
+
'{}/bin/python3'.format(configure.indb_install_location)
|
|
2380
2431
|
|
|
2381
|
-
if UtilFuncs._is_lake():
|
|
2382
|
-
return "python"
|
|
2383
|
-
else:
|
|
2384
|
-
if configure.indb_install_location == "/var/opt/teradata/languages/sles12sp3/Python/":
|
|
2385
|
-
return '{}bin/python3'.format(configure.indb_install_location)
|
|
2386
|
-
else:
|
|
2387
|
-
return configure.indb_install_location
|
|
2388
2432
|
|
|
2389
2433
|
def _is_view(tablename):
|
|
2390
2434
|
"""
|
|
@@ -2404,21 +2448,188 @@ class UtilFuncs():
|
|
|
2404
2448
|
"""
|
|
2405
2449
|
db_name = UtilFuncs._teradata_unquote_arg(UtilFuncs._extract_db_name(tablename), "\"")
|
|
2406
2450
|
table_view_name = UtilFuncs._teradata_unquote_arg(UtilFuncs._extract_table_name(tablename), "\"")
|
|
2407
|
-
query = SQLBundle._build_select_table_kind(db_name, "{0}".format(table_view_name), "'V'")
|
|
2451
|
+
query = SQLBundle._build_select_table_kind(db_name, "'{0}'".format(table_view_name), "'V'")
|
|
2408
2452
|
|
|
2409
2453
|
df = UtilFuncs._execute_query(query)
|
|
2410
2454
|
if len(df) > 0:
|
|
2411
2455
|
return True
|
|
2412
2456
|
else:
|
|
2413
2457
|
return False
|
|
2458
|
+
|
|
2414
2459
|
@staticmethod
|
|
2415
2460
|
def _set_queryband():
|
|
2461
|
+
from teradataml import session_queryband
|
|
2416
2462
|
try:
|
|
2417
|
-
qb_query =
|
|
2463
|
+
qb_query = session_queryband.generate_set_queryband_query()
|
|
2418
2464
|
execute_sql(qb_query)
|
|
2419
|
-
except Exception:
|
|
2465
|
+
except Exception as _set_queryband_err:
|
|
2420
2466
|
pass
|
|
2421
2467
|
|
|
2468
|
+
def _create_or_get_env(template):
|
|
2469
|
+
"""
|
|
2470
|
+
DESCRIPTION:
|
|
2471
|
+
Internal function to return the environment if already exists else
|
|
2472
|
+
creates the environment using template file and return the environment.
|
|
2473
|
+
|
|
2474
|
+
PARAMETERS:
|
|
2475
|
+
template:
|
|
2476
|
+
Required Argument.
|
|
2477
|
+
Template json file name containing details of environment(s) to be created.
|
|
2478
|
+
Types: str
|
|
2479
|
+
|
|
2480
|
+
RAISES:
|
|
2481
|
+
TeradataMLException
|
|
2482
|
+
|
|
2483
|
+
RETURNS:
|
|
2484
|
+
An object of class UserEnv representing the user environment.
|
|
2485
|
+
|
|
2486
|
+
EXAMPLES:
|
|
2487
|
+
>>> self._create_or_get_env("open_source_ml.json")
|
|
2488
|
+
"""
|
|
2489
|
+
# Get the template file path.
|
|
2490
|
+
from teradataml import _TDML_DIRECTORY
|
|
2491
|
+
from teradataml.scriptmgmt.lls_utils import create_env, get_env
|
|
2492
|
+
template_dir_path = os.path.join(_TDML_DIRECTORY, "data", "templates", template)
|
|
2493
|
+
|
|
2494
|
+
# Read template file.
|
|
2495
|
+
with open(template_dir_path, "r") as r_file:
|
|
2496
|
+
data = json.load(r_file)
|
|
2497
|
+
|
|
2498
|
+
# Get env_name.
|
|
2499
|
+
_env_name = data["env_specs"][0]["env_name"]
|
|
2500
|
+
|
|
2501
|
+
try:
|
|
2502
|
+
# Call function to get env.
|
|
2503
|
+
return get_env(_env_name)
|
|
2504
|
+
except TeradataMlException as tdml_e:
|
|
2505
|
+
# We will get here when error says, env does not exist otherwise raise the exception as is.
|
|
2506
|
+
# Env does not exist so create one.
|
|
2507
|
+
|
|
2508
|
+
exc_msg = "Failed to execute get_env(). User environment '{}' not " \
|
|
2509
|
+
"found.".format(_env_name)
|
|
2510
|
+
if exc_msg in tdml_e.args[0]:
|
|
2511
|
+
print(f"No OpenAF environment with name '{_env_name}' found. Creating one with "\
|
|
2512
|
+
"latest supported python and required packages.")
|
|
2513
|
+
return create_env(template=template_dir_path)
|
|
2514
|
+
else:
|
|
2515
|
+
raise tdml_e
|
|
2516
|
+
except Exception as exc:
|
|
2517
|
+
raise exc
|
|
2518
|
+
|
|
2519
|
+
def _get_env_name(col=None):
|
|
2520
|
+
"""
|
|
2521
|
+
DESCRIPTION:
|
|
2522
|
+
Internal function to get the env name if passed with ColumnExpression
|
|
2523
|
+
else the default "openml_env".
|
|
2524
|
+
|
|
2525
|
+
PARAMETERS:
|
|
2526
|
+
col:
|
|
2527
|
+
Optional Argument.
|
|
2528
|
+
Specifies teradataml DataFrame ColumnExpression.
|
|
2529
|
+
Types: teradataml DataFrame ColumnExpression
|
|
2530
|
+
Default Value: None
|
|
2531
|
+
|
|
2532
|
+
RAISES:
|
|
2533
|
+
None.
|
|
2534
|
+
|
|
2535
|
+
RETURNS:
|
|
2536
|
+
string
|
|
2537
|
+
|
|
2538
|
+
EXAMPLES:
|
|
2539
|
+
>>> self._get_env_name(col)
|
|
2540
|
+
"""
|
|
2541
|
+
|
|
2542
|
+
# If ColumnExpression is passed and env_name is passed with it fetch the env name,
|
|
2543
|
+
# else check if default "openml_user_env" env is configured or not,
|
|
2544
|
+
# else get the default "openml_env" env if exists or create new deafult env.
|
|
2545
|
+
if col and col._env_name is not None:
|
|
2546
|
+
from teradataml.scriptmgmt.UserEnv import UserEnv
|
|
2547
|
+
env = col._env_name
|
|
2548
|
+
env_name = env.env_name if isinstance(col._env_name, UserEnv) else env
|
|
2549
|
+
elif configure.openml_user_env is not None:
|
|
2550
|
+
env_name = configure.openml_user_env.env_name
|
|
2551
|
+
else:
|
|
2552
|
+
env_name = UtilFuncs._create_or_get_env("open_source_ml.json").env_name
|
|
2553
|
+
return env_name
|
|
2554
|
+
|
|
2555
|
+
def _func_to_string(user_functions):
|
|
2556
|
+
"""
|
|
2557
|
+
DESCRIPTION:
|
|
2558
|
+
Internal function to get the user functions in a single string format.
|
|
2559
|
+
|
|
2560
|
+
PARAMETERS:
|
|
2561
|
+
user_functions:
|
|
2562
|
+
Required Argument.
|
|
2563
|
+
List of user functions.
|
|
2564
|
+
Types: list
|
|
2565
|
+
|
|
2566
|
+
RAISES:
|
|
2567
|
+
None.
|
|
2568
|
+
|
|
2569
|
+
RETURNS:
|
|
2570
|
+
string
|
|
2571
|
+
|
|
2572
|
+
EXAMPLES:
|
|
2573
|
+
>>> from teradataml.dataframe.functions import udf
|
|
2574
|
+
>>> @udf(returns=VARCHAR())
|
|
2575
|
+
... def sum(x, y):
|
|
2576
|
+
... return x+y
|
|
2577
|
+
>>>
|
|
2578
|
+
>>> def to_upper(s):
|
|
2579
|
+
... return s.upper()
|
|
2580
|
+
>>> user_functions = [sum(1,2)._udf, to_upper]
|
|
2581
|
+
>>> res = self._func_to_string(user_functions)
|
|
2582
|
+
>>> print(res)
|
|
2583
|
+
def sum(x, y):
|
|
2584
|
+
return x+y
|
|
2585
|
+
|
|
2586
|
+
def to_upper(s):
|
|
2587
|
+
return s.upper()
|
|
2588
|
+
|
|
2589
|
+
>>>
|
|
2590
|
+
"""
|
|
2591
|
+
user_function_code = ""
|
|
2592
|
+
for func in user_functions:
|
|
2593
|
+
# Get the source code of the user function.
|
|
2594
|
+
func = getsource(func)
|
|
2595
|
+
# If the function have any extra space in the beginning remove it.
|
|
2596
|
+
func = func.lstrip()
|
|
2597
|
+
# Function can have decorator,e.g. udf as decorator, remove it.
|
|
2598
|
+
if func.startswith("@"):
|
|
2599
|
+
func = func[func.find("\n")+1: ].lstrip()
|
|
2600
|
+
# If multiple functions are passed, separate them with new line.
|
|
2601
|
+
user_function_code += func + '\n'
|
|
2602
|
+
return user_function_code
|
|
2603
|
+
|
|
2604
|
+
@staticmethod
|
|
2605
|
+
def _get_qualified_table_name(schema_name, table_name):
|
|
2606
|
+
"""
|
|
2607
|
+
DESCRIPTION:
|
|
2608
|
+
Internal function to get the fully qualified name of table.
|
|
2609
|
+
|
|
2610
|
+
PARAMETERS:
|
|
2611
|
+
schema_name:
|
|
2612
|
+
Required Argument.
|
|
2613
|
+
Specifies the name of the schema.
|
|
2614
|
+
Types: str
|
|
2615
|
+
|
|
2616
|
+
table_name:
|
|
2617
|
+
Required Argument.
|
|
2618
|
+
Specifies the name of the table.
|
|
2619
|
+
Types: str
|
|
2620
|
+
|
|
2621
|
+
RAISES:
|
|
2622
|
+
None.
|
|
2623
|
+
|
|
2624
|
+
RETURNS:
|
|
2625
|
+
string
|
|
2626
|
+
|
|
2627
|
+
EXAMPLES:
|
|
2628
|
+
>>> UtilFuncs._get_qualified_table_name("schema_name", "table_name")
|
|
2629
|
+
'"schema_name"."table_name"'
|
|
2630
|
+
"""
|
|
2631
|
+
return '"{}"."{}"'.format(schema_name, table_name)
|
|
2632
|
+
|
|
2422
2633
|
|
|
2423
2634
|
from teradataml.common.aed_utils import AedUtils
|
|
2424
2635
|
from teradataml.dbutils.filemgr import remove_file
|
|
@@ -317,7 +317,7 @@ class AnalyticsWrapperUtils:
|
|
|
317
317
|
#TODO: Add support for nested level query as in R.
|
|
318
318
|
return table_ref
|
|
319
319
|
|
|
320
|
-
def _validate_input_table_datatype(self, data, arg_name, reference_function_name
|
|
320
|
+
def _validate_input_table_datatype(self, data, arg_name, reference_function_name=None):
|
|
321
321
|
"""
|
|
322
322
|
Method to verify that the input table parameters of type DataFrame.
|
|
323
323
|
|
teradataml/context/context.py
CHANGED
|
@@ -13,9 +13,10 @@ A teradataml context functions provide interface to Teradata Vantage. Provides f
|
|
|
13
13
|
context which can be used by other analytical functions to get the Teradata Vantage connection.
|
|
14
14
|
|
|
15
15
|
"""
|
|
16
|
+
import ipaddress
|
|
16
17
|
from pathlib import Path
|
|
17
18
|
from sqlalchemy import create_engine
|
|
18
|
-
from
|
|
19
|
+
from teradataml.telemetry_utils.queryband import collect_queryband
|
|
19
20
|
from teradataml.common.deprecations import argument_deprecation
|
|
20
21
|
from teradataml.common.exceptions import TeradataMlException
|
|
21
22
|
from teradataml.common.warnings import TeradataMlRuntimeWarning
|
|
@@ -35,6 +36,8 @@ from sqlalchemy.engine.url import URL
|
|
|
35
36
|
import os
|
|
36
37
|
import warnings
|
|
37
38
|
import atexit
|
|
39
|
+
import socket
|
|
40
|
+
import threading
|
|
38
41
|
import urllib.parse
|
|
39
42
|
|
|
40
43
|
# Store a global Teradata Vantage Connection.
|
|
@@ -517,6 +520,9 @@ def create_context(host = None, username = None, password = None, tdsqlengine =
|
|
|
517
520
|
# Process Analytic functions.
|
|
518
521
|
from teradataml.analytics import _process_analytic_functions
|
|
519
522
|
_process_analytic_functions()
|
|
523
|
+
|
|
524
|
+
# Add global lock to internal buffer
|
|
525
|
+
_InternalBuffer.add(global_lock=threading.Lock())
|
|
520
526
|
|
|
521
527
|
# Return the connection by default
|
|
522
528
|
return td_sqlalchemy_engine
|
|
@@ -620,6 +626,8 @@ def set_context(tdsqlengine, temp_database_name=None):
|
|
|
620
626
|
global user_specified_connection
|
|
621
627
|
global python_packages_installed
|
|
622
628
|
if td_connection is not None:
|
|
629
|
+
# Clearing the internal buffer.
|
|
630
|
+
_InternalBuffer.clean()
|
|
623
631
|
warnings.warn(Messages.get_message(MessageCodes.OVERWRITE_CONTEXT), stacklevel=2)
|
|
624
632
|
remove_context()
|
|
625
633
|
|
|
@@ -649,6 +657,9 @@ def set_context(tdsqlengine, temp_database_name=None):
|
|
|
649
657
|
|
|
650
658
|
# Initialise Dag
|
|
651
659
|
__initalise_dag()
|
|
660
|
+
|
|
661
|
+
# Add global lock to internal buffer
|
|
662
|
+
_InternalBuffer.add(global_lock=threading.Lock())
|
|
652
663
|
|
|
653
664
|
return td_connection
|
|
654
665
|
|
|
@@ -681,6 +692,7 @@ def remove_context():
|
|
|
681
692
|
# Initiate the garbage collection
|
|
682
693
|
__cleanup_garbage_collection()
|
|
683
694
|
|
|
695
|
+
# Check if connection is established or not.
|
|
684
696
|
if user_specified_connection is not True:
|
|
685
697
|
try:
|
|
686
698
|
# Close the connection if not user specified connection.
|
|
@@ -839,7 +851,8 @@ def _get_vantage_version():
|
|
|
839
851
|
EXAMPLES:
|
|
840
852
|
_get_vantage_version()
|
|
841
853
|
"""
|
|
842
|
-
if td_connection.dialect.has_table(td_connection, "versionInfo", schema="pm"
|
|
854
|
+
if td_connection.dialect.has_table(td_connection, "versionInfo", schema="pm",
|
|
855
|
+
table_only=True):
|
|
843
856
|
|
|
844
857
|
# BTEQ -- Enter your SQL request or BTEQ command:
|
|
845
858
|
# select * from pm.versionInfo;
|
|
@@ -980,6 +993,73 @@ def _get_user():
|
|
|
980
993
|
td_user = _get_database_username()
|
|
981
994
|
return td_user
|
|
982
995
|
|
|
996
|
+
def _get_host():
|
|
997
|
+
"""
|
|
998
|
+
DESCRIPTION:
|
|
999
|
+
An internal function to get the host associated with the current context.
|
|
1000
|
+
|
|
1001
|
+
PARAMETERS:
|
|
1002
|
+
None.
|
|
1003
|
+
|
|
1004
|
+
RETURNS:
|
|
1005
|
+
Host associated with the current context.
|
|
1006
|
+
|
|
1007
|
+
RAISES:
|
|
1008
|
+
None.
|
|
1009
|
+
|
|
1010
|
+
EXAMPLES:
|
|
1011
|
+
_get_host()
|
|
1012
|
+
"""
|
|
1013
|
+
if td_connection is None:
|
|
1014
|
+
return None
|
|
1015
|
+
else:
|
|
1016
|
+
return td_sqlalchemy_engine.url.host
|
|
1017
|
+
|
|
1018
|
+
def _get_host_ip():
|
|
1019
|
+
"""
|
|
1020
|
+
DESCRIPTION:
|
|
1021
|
+
Function to return the host IP address or host name associated with the current context.
|
|
1022
|
+
|
|
1023
|
+
PARAMETERS:
|
|
1024
|
+
None.
|
|
1025
|
+
|
|
1026
|
+
RETURNS:
|
|
1027
|
+
Host IP address or host name associated with the current context.
|
|
1028
|
+
|
|
1029
|
+
RAISES:
|
|
1030
|
+
None.
|
|
1031
|
+
|
|
1032
|
+
EXAMPLES:
|
|
1033
|
+
GarbageCollector._get_host_ip()
|
|
1034
|
+
"""
|
|
1035
|
+
# Return None if connection is not established.
|
|
1036
|
+
if td_connection is None:
|
|
1037
|
+
return None
|
|
1038
|
+
|
|
1039
|
+
host = _get_host()
|
|
1040
|
+
try:
|
|
1041
|
+
# Validate if host_ip is a valid IP address (IPv4 or IPv6)
|
|
1042
|
+
ipaddress.ip_address(host)
|
|
1043
|
+
return host
|
|
1044
|
+
except ValueError:
|
|
1045
|
+
# If host is not an IP address, get the IP address by DNS name from _InternalBuffer.
|
|
1046
|
+
dns_host_ip = _InternalBuffer.get('dns_host_ip')
|
|
1047
|
+
if dns_host_ip:
|
|
1048
|
+
return dns_host_ip
|
|
1049
|
+
|
|
1050
|
+
# If DNS host ip not found, resolve the host name to get the IP address.
|
|
1051
|
+
# If there is issue in resolving the host name, it will proceed with DNS host as it is.
|
|
1052
|
+
try:
|
|
1053
|
+
# Get the list of addresses(compatible for both IPv4 and IPv6)
|
|
1054
|
+
addr_info = socket.getaddrinfo(host, None)
|
|
1055
|
+
# Pick the first address from the list
|
|
1056
|
+
host_ip = addr_info[0][4][0]
|
|
1057
|
+
# Add the DNS host IP to the _InternalBuffer.
|
|
1058
|
+
_InternalBuffer.add(dns_host_ip=host_ip)
|
|
1059
|
+
except socket.gaierror:
|
|
1060
|
+
# Use dns host as it is
|
|
1061
|
+
host_ip = host
|
|
1062
|
+
return host_ip
|
|
983
1063
|
|
|
984
1064
|
class ContextUtilFuncs():
|
|
985
1065
|
@staticmethod
|
|
Binary file
|