teradataml 20.0.0.0__py3-none-any.whl → 20.0.0.2__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 +183 -0
- teradataml/__init__.py +6 -3
- teradataml/_version.py +2 -2
- teradataml/analytics/__init__.py +3 -2
- teradataml/analytics/analytic_function_executor.py +275 -40
- teradataml/analytics/analytic_query_generator.py +92 -0
- teradataml/analytics/byom/__init__.py +3 -2
- teradataml/analytics/json_parser/metadata.py +1 -0
- teradataml/analytics/json_parser/utils.py +17 -21
- teradataml/analytics/meta_class.py +40 -1
- teradataml/analytics/sqle/DecisionTreePredict.py +1 -1
- teradataml/analytics/sqle/__init__.py +10 -2
- teradataml/analytics/table_operator/__init__.py +3 -2
- teradataml/analytics/uaf/__init__.py +21 -2
- teradataml/analytics/utils.py +62 -1
- teradataml/analytics/valib.py +1 -1
- teradataml/automl/__init__.py +1553 -319
- teradataml/automl/custom_json_utils.py +139 -61
- teradataml/automl/data_preparation.py +276 -319
- teradataml/automl/data_transformation.py +163 -81
- teradataml/automl/feature_engineering.py +402 -239
- teradataml/automl/feature_exploration.py +9 -2
- teradataml/automl/model_evaluation.py +48 -51
- teradataml/automl/model_training.py +291 -189
- teradataml/catalog/byom.py +8 -8
- teradataml/catalog/model_cataloging_utils.py +1 -1
- teradataml/clients/auth_client.py +133 -0
- teradataml/clients/pkce_client.py +1 -1
- teradataml/common/aed_utils.py +3 -2
- teradataml/common/constants.py +48 -6
- teradataml/common/deprecations.py +13 -7
- teradataml/common/garbagecollector.py +156 -120
- teradataml/common/messagecodes.py +6 -1
- teradataml/common/messages.py +3 -1
- teradataml/common/sqlbundle.py +1 -1
- teradataml/common/utils.py +103 -11
- teradataml/common/wrapper_utils.py +1 -1
- teradataml/context/context.py +121 -31
- teradataml/data/advertising.csv +201 -0
- teradataml/data/bank_marketing.csv +11163 -0
- teradataml/data/bike_sharing.csv +732 -0
- teradataml/data/boston2cols.csv +721 -0
- teradataml/data/breast_cancer.csv +570 -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/customer_segmentation_test.csv +2628 -0
- teradataml/data/customer_segmentation_train.csv +8069 -0
- teradataml/data/dataframe_example.json +10 -0
- teradataml/data/docs/sqle/docs_17_10/OneHotEncodingFit.py +3 -1
- teradataml/data/docs/sqle/docs_17_10/OneHotEncodingTransform.py +6 -0
- teradataml/data/docs/sqle/docs_17_10/OutlierFilterTransform.py +5 -1
- teradataml/data/docs/sqle/docs_17_20/ANOVA.py +61 -1
- teradataml/data/docs/sqle/docs_17_20/CFilter.py +132 -0
- teradataml/data/docs/sqle/docs_17_20/ColumnTransformer.py +2 -0
- teradataml/data/docs/sqle/docs_17_20/FTest.py +105 -26
- teradataml/data/docs/sqle/docs_17_20/GLM.py +162 -1
- teradataml/data/docs/sqle/docs_17_20/GetFutileColumns.py +5 -3
- teradataml/data/docs/sqle/docs_17_20/KMeans.py +48 -1
- teradataml/data/docs/sqle/docs_17_20/NaiveBayes.py +162 -0
- teradataml/data/docs/sqle/docs_17_20/NonLinearCombineFit.py +3 -2
- teradataml/data/docs/sqle/docs_17_20/OneHotEncodingFit.py +5 -0
- teradataml/data/docs/sqle/docs_17_20/OneHotEncodingTransform.py +6 -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/ROC.py +3 -2
- teradataml/data/docs/sqle/docs_17_20/SVMPredict.py +13 -2
- teradataml/data/docs/sqle/docs_17_20/ScaleFit.py +119 -1
- teradataml/data/docs/sqle/docs_17_20/ScaleTransform.py +93 -1
- teradataml/data/docs/sqle/docs_17_20/Shap.py +197 -0
- teradataml/data/docs/sqle/docs_17_20/TDGLMPredict.py +163 -1
- 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/Unpivoting.py +216 -0
- teradataml/data/docs/sqle/docs_17_20/XGBoost.py +12 -4
- teradataml/data/docs/sqle/docs_17_20/XGBoostPredict.py +7 -1
- teradataml/data/docs/sqle/docs_17_20/ZTest.py +72 -7
- 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/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/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/glm_example.json +28 -1
- teradataml/data/grocery_transaction.csv +19 -0
- teradataml/data/housing_train_segment.csv +201 -0
- teradataml/data/idwt2d_dataTable.csv +5 -0
- teradataml/data/idwt_dataTable.csv +8 -0
- teradataml/data/idwt_filterTable.csv +3 -0
- teradataml/data/insect2Cols.csv +61 -0
- teradataml/data/interval_data.csv +5 -0
- teradataml/data/jsons/paired_functions.json +14 -0
- teradataml/data/jsons/sqle/17.20/TD_ANOVA.json +99 -27
- teradataml/data/jsons/sqle/17.20/TD_CFilter.json +118 -0
- teradataml/data/jsons/sqle/17.20/TD_FTest.json +166 -83
- teradataml/data/jsons/sqle/17.20/TD_GLM.json +90 -14
- teradataml/data/jsons/sqle/17.20/TD_GLMPREDICT.json +48 -5
- teradataml/data/jsons/sqle/17.20/TD_GetFutileColumns.json +5 -3
- teradataml/data/jsons/sqle/17.20/TD_KMeans.json +31 -11
- 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_NonLinearCombineFit.json +3 -2
- 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_ROC.json +2 -1
- teradataml/data/jsons/sqle/17.20/TD_SVM.json +16 -16
- teradataml/data/jsons/sqle/17.20/TD_SVMPredict.json +19 -1
- teradataml/data/jsons/sqle/17.20/TD_ScaleFit.json +168 -15
- teradataml/data/jsons/sqle/17.20/TD_ScaleTransform.json +50 -1
- 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_Unpivoting.json +235 -0
- teradataml/data/jsons/sqle/17.20/TD_XGBoost.json +25 -7
- teradataml/data/jsons/sqle/17.20/TD_XGBoostPredict.json +17 -4
- teradataml/data/jsons/sqle/17.20/TD_ZTest.json +157 -80
- teradataml/data/jsons/storedprocedure/17.20/TD_FILTERFACTORY1D.json +150 -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_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 +208 -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 +400 -0
- teradataml/data/kmeans_example.json +5 -0
- teradataml/data/kmeans_table.csv +10 -0
- teradataml/data/load_example_data.py +8 -2
- teradataml/data/naivebayestextclassifier_example.json +1 -1
- teradataml/data/naivebayestextclassifierpredict_example.json +11 -0
- teradataml/data/onehot_encoder_train.csv +4 -0
- teradataml/data/openml_example.json +29 -0
- teradataml/data/peppers.png +0 -0
- teradataml/data/real_values.csv +14 -0
- teradataml/data/sax_example.json +8 -0
- teradataml/data/scale_attributes.csv +3 -0
- teradataml/data/scale_example.json +52 -1
- teradataml/data/scale_input_part_sparse.csv +31 -0
- teradataml/data/scale_input_partitioned.csv +16 -0
- teradataml/data/scale_input_sparse.csv +11 -0
- teradataml/data/scale_parameters.csv +3 -0
- teradataml/data/scripts/deploy_script.py +21 -2
- teradataml/data/scripts/sklearn/sklearn_fit.py +40 -37
- teradataml/data/scripts/sklearn/sklearn_fit_predict.py +22 -30
- teradataml/data/scripts/sklearn/sklearn_function.template +42 -24
- teradataml/data/scripts/sklearn/sklearn_model_selection_split.py +23 -33
- teradataml/data/scripts/sklearn/sklearn_neighbors.py +19 -28
- teradataml/data/scripts/sklearn/sklearn_score.py +32 -32
- teradataml/data/scripts/sklearn/sklearn_transform.py +85 -42
- teradataml/data/star_pivot.csv +8 -0
- teradataml/data/templates/open_source_ml.json +2 -1
- teradataml/data/teradataml_example.json +97 -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/windowdfft.csv +16 -0
- teradataml/data/ztest_example.json +16 -0
- teradataml/dataframe/copy_to.py +9 -4
- teradataml/dataframe/data_transfer.py +125 -64
- teradataml/dataframe/dataframe.py +575 -57
- teradataml/dataframe/dataframe_utils.py +47 -9
- teradataml/dataframe/fastload.py +273 -90
- teradataml/dataframe/functions.py +339 -0
- teradataml/dataframe/row.py +160 -0
- teradataml/dataframe/setop.py +2 -2
- teradataml/dataframe/sql.py +740 -18
- teradataml/dataframe/window.py +1 -1
- teradataml/dbutils/dbutils.py +324 -18
- 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/sklearn/_sklearn_wrapper.py +254 -122
- teradataml/options/__init__.py +16 -5
- teradataml/options/configure.py +39 -6
- teradataml/options/display.py +2 -2
- teradataml/plot/axis.py +4 -4
- teradataml/scriptmgmt/UserEnv.py +26 -19
- teradataml/scriptmgmt/lls_utils.py +120 -16
- teradataml/table_operators/Script.py +4 -5
- teradataml/table_operators/TableOperator.py +160 -26
- teradataml/table_operators/table_operator_util.py +88 -41
- 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/validators.py +41 -3
- {teradataml-20.0.0.0.dist-info → teradataml-20.0.0.2.dist-info}/METADATA +191 -6
- {teradataml-20.0.0.0.dist-info → teradataml-20.0.0.2.dist-info}/RECORD +263 -185
- {teradataml-20.0.0.0.dist-info → teradataml-20.0.0.2.dist-info}/WHEEL +0 -0
- {teradataml-20.0.0.0.dist-info → teradataml-20.0.0.2.dist-info}/top_level.txt +0 -0
- {teradataml-20.0.0.0.dist-info → teradataml-20.0.0.2.dist-info}/zip-safe +0 -0
|
@@ -14,11 +14,11 @@ File implements classes for following:
|
|
|
14
14
|
* _TableOperatorExecutor
|
|
15
15
|
* _BYOMFunctionExecutor
|
|
16
16
|
"""
|
|
17
|
-
|
|
17
|
+
from collections import OrderedDict
|
|
18
18
|
from teradataml.options.configure import configure
|
|
19
19
|
from teradataml.common.constants import TeradataConstants, TeradataAnalyticFunctionTypes
|
|
20
20
|
from teradataml.analytics.json_parser import PartitionKind
|
|
21
|
-
from teradataml.analytics.analytic_query_generator import AnalyticQueryGenerator, UAFQueryGenerator
|
|
21
|
+
from teradataml.analytics.analytic_query_generator import AnalyticQueryGenerator, UAFQueryGenerator, StoredProcedureQueryGenerator
|
|
22
22
|
from teradataml.analytics.json_parser.json_store import _JsonStore
|
|
23
23
|
from teradataml.analytics.utils import FuncSpecialCaseHandler
|
|
24
24
|
from teradataml.options.display import display
|
|
@@ -28,8 +28,11 @@ from teradataml.common.messages import Messages, MessageCodes
|
|
|
28
28
|
from teradataml.common.wrapper_utils import AnalyticsWrapperUtils
|
|
29
29
|
from teradataml.common.utils import UtilFuncs
|
|
30
30
|
from teradataml.context.context import _get_context_temp_databasename
|
|
31
|
+
from teradataml.dataframe.dataframe import in_schema
|
|
32
|
+
from teradataml.dbutils.dbutils import _create_table, db_drop_table
|
|
33
|
+
from teradatasqlalchemy.types import *
|
|
31
34
|
from teradataml.table_operators.table_operator_query_generator import TableOperatorQueryGenerator
|
|
32
|
-
from
|
|
35
|
+
from teradataml.telemetry_utils.queryband import collect_queryband
|
|
33
36
|
from teradataml.utils.dtypes import _ListOf
|
|
34
37
|
from teradataml.utils.validators import _Validators
|
|
35
38
|
|
|
@@ -86,6 +89,9 @@ class _AnlyticFunctionExecutor:
|
|
|
86
89
|
# Initialize FuncSpecialCaseHandler.
|
|
87
90
|
self._spl_func_obj = FuncSpecialCaseHandler(self.func_name)
|
|
88
91
|
|
|
92
|
+
# Initialize database object type.
|
|
93
|
+
self.db_object_type = TeradataConstants.TERADATA_VIEW
|
|
94
|
+
|
|
89
95
|
@staticmethod
|
|
90
96
|
def _validate_analytic_function_argument(func_arg_name, func_arg_value, argument, additional_valid_types=None):
|
|
91
97
|
"""
|
|
@@ -152,7 +158,7 @@ class _AnlyticFunctionExecutor:
|
|
|
152
158
|
_Validators._validate_function_arguments([argument_info])
|
|
153
159
|
|
|
154
160
|
@collect_queryband(attr="func_name")
|
|
155
|
-
def _execute_query(self, persist=False, volatile=False):
|
|
161
|
+
def _execute_query(self, persist=False, volatile=False, display_table_name=True):
|
|
156
162
|
"""
|
|
157
163
|
DESCRIPTION:
|
|
158
164
|
Function to execute query on Vantage.
|
|
@@ -169,6 +175,13 @@ class _AnlyticFunctionExecutor:
|
|
|
169
175
|
Specifies whether to create a volatile table or not.
|
|
170
176
|
Default Value: False
|
|
171
177
|
Type: bool
|
|
178
|
+
|
|
179
|
+
display_table_name:
|
|
180
|
+
Optional Argument.
|
|
181
|
+
Specifies whether to display the table names or not when
|
|
182
|
+
persist is set to True.
|
|
183
|
+
Default Value: True
|
|
184
|
+
Type: bool
|
|
172
185
|
|
|
173
186
|
RETURNS:
|
|
174
187
|
None
|
|
@@ -178,7 +191,7 @@ class _AnlyticFunctionExecutor:
|
|
|
178
191
|
|
|
179
192
|
EXAMPLES:
|
|
180
193
|
self._execute_query()
|
|
181
|
-
"""
|
|
194
|
+
"""
|
|
182
195
|
# Generate STDOUT table name and add it to the output table list.
|
|
183
196
|
func_params = self._get_generate_temp_table_params(persist=persist, volatile=volatile)
|
|
184
197
|
sqlmr_stdout_temp_tablename = UtilFuncs._generate_temp_table_name(**func_params)
|
|
@@ -203,7 +216,8 @@ class _AnlyticFunctionExecutor:
|
|
|
203
216
|
else:
|
|
204
217
|
self._function_output_table_map["result"] = sqlmr_stdout_temp_tablename
|
|
205
218
|
|
|
206
|
-
if
|
|
219
|
+
# Print the table/view names if display_table_name is set to True.
|
|
220
|
+
if persist and display_table_name:
|
|
207
221
|
# SQL is executed. So, print the table/view names.
|
|
208
222
|
for output_attribute, table_name in self._function_output_table_map.items():
|
|
209
223
|
print("{} data stored in table '{}'".format(output_attribute, table_name))
|
|
@@ -248,25 +262,18 @@ class _AnlyticFunctionExecutor:
|
|
|
248
262
|
self._get_generate_temp_table_params(True, True)
|
|
249
263
|
"""
|
|
250
264
|
use_default_database = True
|
|
251
|
-
db_object_type = TeradataConstants.TERADATA_VIEW
|
|
252
265
|
prefix = "td_sqlmr_out_"
|
|
253
266
|
gc_on_quit = True
|
|
254
267
|
|
|
255
|
-
# If
|
|
256
|
-
#
|
|
257
|
-
# reading from a view created on output, then 'db_object_type' should be "table".
|
|
258
|
-
if len(self._metadata.output_tables) > 0 or not self._metadata._is_view_supported:
|
|
259
|
-
db_object_type = TeradataConstants.TERADATA_TABLE
|
|
260
|
-
|
|
261
|
-
# If result is to be persisted or if the table is a volaile table then, db_object_type
|
|
262
|
-
# should be "table" and it must not be Garbage collected.
|
|
268
|
+
# If result is to be persisted or if the table is a volaile table then,
|
|
269
|
+
# it must not be Garbage collected.
|
|
263
270
|
if persist or volatile:
|
|
264
271
|
gc_on_quit = False
|
|
265
|
-
db_object_type = TeradataConstants.TERADATA_TABLE
|
|
266
272
|
prefix = "td_sqlmr_{}_out_".format("persist" if persist else "volatile")
|
|
273
|
+
use_default_database = False if volatile else True
|
|
267
274
|
|
|
268
275
|
return {"use_default_database": use_default_database,
|
|
269
|
-
"table_type": db_object_type,
|
|
276
|
+
"table_type": self.db_object_type,
|
|
270
277
|
"prefix": prefix,
|
|
271
278
|
"gc_on_quit": gc_on_quit}
|
|
272
279
|
|
|
@@ -682,6 +689,7 @@ class _AnlyticFunctionExecutor:
|
|
|
682
689
|
start_time = time.time()
|
|
683
690
|
persist = kwargs.get("persist", False)
|
|
684
691
|
volatile = kwargs.get("volatile", False)
|
|
692
|
+
display_table_name = kwargs.get("display_table_name", True)
|
|
685
693
|
|
|
686
694
|
# Validate local_order_column argument type and values.
|
|
687
695
|
arg_info_matrix = [["persist", persist, True, bool], ["volatile", volatile, True, bool]]
|
|
@@ -694,23 +702,53 @@ class _AnlyticFunctionExecutor:
|
|
|
694
702
|
MessageCodes.CANNOT_USE_TOGETHER_WITH)
|
|
695
703
|
|
|
696
704
|
self._dyn_cls_data_members.update(kwargs)
|
|
697
|
-
|
|
705
|
+
|
|
706
|
+
# If function produces output tables, i.e., function has output table arguments,
|
|
707
|
+
# then 'db_object_type' should be "table" or if analytic function does not support
|
|
708
|
+
# reading from a view created on output, then 'db_object_type' should be "table".
|
|
709
|
+
# If result is to be persisted or if the table is a volaile table then, db_object_type
|
|
710
|
+
# should be "table" else it should be "view".
|
|
711
|
+
self.db_object_type = (
|
|
712
|
+
TeradataConstants.TERADATA_VOLATILE_TABLE if volatile
|
|
713
|
+
else TeradataConstants.TERADATA_TABLE if len(self._metadata.output_tables) > 0 \
|
|
714
|
+
or not self._metadata._is_view_supported or persist
|
|
715
|
+
else TeradataConstants.TERADATA_VIEW
|
|
716
|
+
)
|
|
698
717
|
if not skip_input_arg_processing:
|
|
699
718
|
self._process_input_argument(**kwargs)
|
|
700
719
|
|
|
720
|
+
# check func_name is GLM and data_partition_column, data_hash_column, local_order_data are passed
|
|
721
|
+
if self.func_name in ['GLM', 'TDGLMPredict'] and \
|
|
722
|
+
any(key in kwargs for key in ['data_partition_column', 'data_hash_column', 'local_order_data']):
|
|
723
|
+
skip_output_arg_processing = True
|
|
724
|
+
|
|
701
725
|
if not skip_output_arg_processing:
|
|
702
726
|
self._process_output_argument(**kwargs)
|
|
703
727
|
|
|
704
728
|
if not skip_other_arg_processing:
|
|
705
729
|
self._process_other_argument(**kwargs)
|
|
706
730
|
|
|
707
|
-
|
|
731
|
+
# When Analytic function is executed it stores the result in _function_output_table_map['result'].
|
|
732
|
+
# If we want to skip the query execution of the function then we need to pass result table in '_result_data'.
|
|
708
733
|
|
|
709
|
-
#
|
|
710
|
-
|
|
711
|
-
|
|
734
|
+
# Execute the query only if the '_result_data' is not passed as an argument in kwargs.
|
|
735
|
+
# Otherwise, store the result table in _function_output_table_map.
|
|
736
|
+
if kwargs.get("_result_data", None) is None:
|
|
737
|
+
self._generate_query(volatile=volatile)
|
|
712
738
|
|
|
713
|
-
|
|
739
|
+
# Print SQL-MR query if requested to do so.
|
|
740
|
+
if display.print_sqlmr_query:
|
|
741
|
+
print(self.sqlmr_query)
|
|
742
|
+
|
|
743
|
+
self._execute_query(persist, volatile, display_table_name)
|
|
744
|
+
else:
|
|
745
|
+
# This is useful when we already have the result table and
|
|
746
|
+
# need to pass function result as an object to another function
|
|
747
|
+
# without executing the function again.
|
|
748
|
+
|
|
749
|
+
# Store the result table in map.
|
|
750
|
+
self._function_output_table_map["result"] = kwargs.pop("_result_data")
|
|
751
|
+
self._dyn_cls_data_members['result'] = self._dyn_cls_data_members.pop('_result_data')
|
|
714
752
|
|
|
715
753
|
if not skip_func_output_processing:
|
|
716
754
|
self._process_function_output(**kwargs)
|
|
@@ -856,22 +894,34 @@ class _SQLEFunctionExecutor(_AnlyticFunctionExecutor):
|
|
|
856
894
|
EXAMPLES:
|
|
857
895
|
self._get_input_args()
|
|
858
896
|
"""
|
|
897
|
+
sort_order = list(kwargs.keys())
|
|
898
|
+
input_table_dict = {}
|
|
899
|
+
|
|
859
900
|
for _inp_attribute in self._metadata.input_tables:
|
|
860
901
|
input_table_arg = _inp_attribute.get_lang_name()
|
|
861
|
-
yield input_table_arg, _inp_attribute
|
|
862
902
|
|
|
863
|
-
#
|
|
903
|
+
# Store the first argument directly into the dictionary
|
|
904
|
+
input_table_dict[input_table_arg] = _inp_attribute
|
|
905
|
+
|
|
906
|
+
# Check if SQL function allows multiple values as input.
|
|
864
907
|
if _inp_attribute.allows_lists():
|
|
865
908
|
_index = 1
|
|
866
909
|
while True:
|
|
867
910
|
_input_table_arg = "{}{}".format(input_table_arg, _index)
|
|
868
|
-
# If the corresponding object is available in kwargs, then extract it.
|
|
869
|
-
# Otherwise, stop looking for multiple arguments and proceed for next attribute.
|
|
870
911
|
if _input_table_arg in kwargs:
|
|
871
|
-
|
|
872
|
-
_index
|
|
912
|
+
input_table_dict[_input_table_arg] = _inp_attribute
|
|
913
|
+
_index += 1
|
|
873
914
|
else:
|
|
874
915
|
break
|
|
916
|
+
|
|
917
|
+
# For ColumnTransformer, yield the input arguments in the order they are passed.
|
|
918
|
+
if self.func_name == "ColumnTransformer":
|
|
919
|
+
for key in sort_order:
|
|
920
|
+
if key in input_table_dict:
|
|
921
|
+
yield key, input_table_dict[key]
|
|
922
|
+
else:
|
|
923
|
+
for key in input_table_dict:
|
|
924
|
+
yield key, input_table_dict[key]
|
|
875
925
|
|
|
876
926
|
def _process_input_argument(self, **kwargs):
|
|
877
927
|
"""
|
|
@@ -1465,7 +1515,7 @@ class _TableOperatorExecutor(_SQLEFunctionExecutor):
|
|
|
1465
1515
|
|
|
1466
1516
|
class _UAFFunctionExecutor(_SQLEFunctionExecutor):
|
|
1467
1517
|
""" Class to hold the attributes and provide methods to enable execution for UAF Functions. """
|
|
1468
|
-
def __init__(self, func_name):
|
|
1518
|
+
def __init__(self, func_name, func_type = TeradataAnalyticFunctionTypes.UAF.value):
|
|
1469
1519
|
"""
|
|
1470
1520
|
DESCRIPTION:
|
|
1471
1521
|
Constructor for the class.
|
|
@@ -1482,7 +1532,7 @@ class _UAFFunctionExecutor(_SQLEFunctionExecutor):
|
|
|
1482
1532
|
EXAMPLES:
|
|
1483
1533
|
_UAFFunctionExecutor("ArimaEstimate")
|
|
1484
1534
|
"""
|
|
1485
|
-
super().__init__(func_name,
|
|
1535
|
+
super().__init__(func_name, func_type)
|
|
1486
1536
|
self._func_other_args = {}
|
|
1487
1537
|
self._func_input_fmt_arguments = {}
|
|
1488
1538
|
self._func_output_fmt_arguments = {}
|
|
@@ -1510,6 +1560,7 @@ class _UAFFunctionExecutor(_SQLEFunctionExecutor):
|
|
|
1510
1560
|
EXAMPLES:
|
|
1511
1561
|
self._generate_query()
|
|
1512
1562
|
"""
|
|
1563
|
+
|
|
1513
1564
|
query_generator = UAFQueryGenerator(function_name=self._metadata.sql_function_name,
|
|
1514
1565
|
func_input_args=self._func_input_args,
|
|
1515
1566
|
func_input_filter_expr_args=self._func_input_filter_expr_args,
|
|
@@ -1707,14 +1758,17 @@ class _UAFFunctionExecutor(_SQLEFunctionExecutor):
|
|
|
1707
1758
|
self._get_generate_temp_table_params(True, True)
|
|
1708
1759
|
"""
|
|
1709
1760
|
prefix = "td_uaf_out_"
|
|
1710
|
-
|
|
1761
|
+
gc_on_quit = True
|
|
1711
1762
|
# If result is to be persisted then, it must not be Garbage collected.
|
|
1712
|
-
|
|
1763
|
+
if persist or volatile:
|
|
1764
|
+
gc_on_quit = False
|
|
1765
|
+
prefix = "td_uaf_{}_out_".format("persist" if persist else "volatile")
|
|
1713
1766
|
|
|
1714
|
-
return {"table_type":
|
|
1767
|
+
return {"table_type": self.db_object_type,
|
|
1715
1768
|
"prefix": prefix,
|
|
1716
1769
|
"gc_on_quit": gc_on_quit,
|
|
1717
|
-
"databasename": output_db if output_db else _get_context_temp_databasename(
|
|
1770
|
+
"databasename": output_db if output_db else _get_context_temp_databasename(
|
|
1771
|
+
table_type=self.db_object_type)}
|
|
1718
1772
|
|
|
1719
1773
|
def _process_output_argument(self, **kwargs):
|
|
1720
1774
|
"""
|
|
@@ -1762,7 +1816,7 @@ class _UAFFunctionExecutor(_SQLEFunctionExecutor):
|
|
|
1762
1816
|
# If database name is not provided by user, get the default database name
|
|
1763
1817
|
# else use user provided database name.
|
|
1764
1818
|
db_name = output_db_name if output_db_name is not None else \
|
|
1765
|
-
_get_context_temp_databasename()
|
|
1819
|
+
_get_context_temp_databasename(table_type=self.db_object_type)
|
|
1766
1820
|
|
|
1767
1821
|
# Get the fully qualified table name.
|
|
1768
1822
|
table_name = "{}.{}".format(UtilFuncs._teradata_quote_arg(db_name,
|
|
@@ -1909,7 +1963,7 @@ class _UAFFunctionExecutor(_SQLEFunctionExecutor):
|
|
|
1909
1963
|
**kwargs))
|
|
1910
1964
|
|
|
1911
1965
|
@collect_queryband(attr="func_name")
|
|
1912
|
-
def _execute_query(self, persist=False, volatile=None):
|
|
1966
|
+
def _execute_query(self, persist=False, volatile=None, display_table_name=True):
|
|
1913
1967
|
"""
|
|
1914
1968
|
DESCRIPTION:
|
|
1915
1969
|
Function to execute query on Vantage.
|
|
@@ -1920,6 +1974,13 @@ class _UAFFunctionExecutor(_SQLEFunctionExecutor):
|
|
|
1920
1974
|
Specifies whether to persist a table or not.
|
|
1921
1975
|
Default Value: False
|
|
1922
1976
|
Type: bool
|
|
1977
|
+
|
|
1978
|
+
display_table_name:
|
|
1979
|
+
Optional Argument.
|
|
1980
|
+
Specifies whether to display the table names or not when
|
|
1981
|
+
persist is set to True.
|
|
1982
|
+
Default Value: True
|
|
1983
|
+
Type: bool
|
|
1923
1984
|
|
|
1924
1985
|
RETURNS:
|
|
1925
1986
|
None
|
|
@@ -1933,9 +1994,10 @@ class _UAFFunctionExecutor(_SQLEFunctionExecutor):
|
|
|
1933
1994
|
try:
|
|
1934
1995
|
# Execute already generated query.
|
|
1935
1996
|
UtilFuncs._execute_query(query=self.sqlmr_query)
|
|
1936
|
-
|
|
1937
|
-
if
|
|
1938
|
-
|
|
1997
|
+
|
|
1998
|
+
# Print the table/view names if display_table_name is set to True.
|
|
1999
|
+
if persist and display_table_name:
|
|
2000
|
+
# SQL is executed. So, print the table/view names.
|
|
1939
2001
|
for output_attribute, table_name in self._function_output_table_map.items():
|
|
1940
2002
|
print("{} data stored in table '{}'".format(output_attribute, table_name))
|
|
1941
2003
|
|
|
@@ -2011,3 +2073,176 @@ class _BYOMFunctionExecutor(_SQLEFunctionExecutor):
|
|
|
2011
2073
|
|
|
2012
2074
|
# Invoke call to SQL-MR generation.
|
|
2013
2075
|
self.sqlmr_query = self.__aqg_obj._gen_sqlmr_select_stmt_sql()
|
|
2076
|
+
|
|
2077
|
+
class _StoredProcedureExecutor(_UAFFunctionExecutor):
|
|
2078
|
+
"""
|
|
2079
|
+
Class to hold the attributes and provide methods to enable execution for Stored Procedures.
|
|
2080
|
+
As the stored procedure JSONs are written like UAF Functions we will use
|
|
2081
|
+
_UAFFunctionExecutor as the base class.
|
|
2082
|
+
"""
|
|
2083
|
+
def __init__(self, func_name):
|
|
2084
|
+
"""
|
|
2085
|
+
DESCRIPTION:
|
|
2086
|
+
Constructor for the class.
|
|
2087
|
+
|
|
2088
|
+
PARAMETERS:
|
|
2089
|
+
func_name:
|
|
2090
|
+
Required Argument.
|
|
2091
|
+
Specifies the name of the analytic function, which is exposed to the user.
|
|
2092
|
+
Types: str
|
|
2093
|
+
|
|
2094
|
+
RAISES:
|
|
2095
|
+
None
|
|
2096
|
+
|
|
2097
|
+
EXAMPLES:
|
|
2098
|
+
_StoredProcedureExecutor("FilterFactory1d")
|
|
2099
|
+
"""
|
|
2100
|
+
super().__init__(func_name, TeradataAnalyticFunctionTypes.STORED_PROCEDURE.value)
|
|
2101
|
+
self._func_other_args = OrderedDict()
|
|
2102
|
+
|
|
2103
|
+
def _generate_query(self, volatile=False):
|
|
2104
|
+
"""
|
|
2105
|
+
DESCRIPTION:
|
|
2106
|
+
Function to generate the SQL query for Stored Procedures.
|
|
2107
|
+
|
|
2108
|
+
PARAMETERS:
|
|
2109
|
+
volatile:
|
|
2110
|
+
Optional Argument.
|
|
2111
|
+
Specifies whether to create a volatile table or not.
|
|
2112
|
+
Default Value: False
|
|
2113
|
+
Type: bool
|
|
2114
|
+
|
|
2115
|
+
RETURNS:
|
|
2116
|
+
None.
|
|
2117
|
+
|
|
2118
|
+
RAISES:
|
|
2119
|
+
None.
|
|
2120
|
+
|
|
2121
|
+
EXAMPLES:
|
|
2122
|
+
self._generate_query()
|
|
2123
|
+
"""
|
|
2124
|
+
# update the db_name.
|
|
2125
|
+
db_name = None
|
|
2126
|
+
if configure.stored_procedure_install_location is not None:
|
|
2127
|
+
db_name = configure.stored_procedure_install_location
|
|
2128
|
+
|
|
2129
|
+
self.__aqg_obj = StoredProcedureQueryGenerator(function_name=self._metadata.sql_function_name,
|
|
2130
|
+
func_other_args_values=self._func_other_args,
|
|
2131
|
+
db_name=db_name)
|
|
2132
|
+
|
|
2133
|
+
# Invoke call to SQL-MR generation.
|
|
2134
|
+
self.sqlmr_query = self.__aqg_obj._gen_call_stmt()
|
|
2135
|
+
|
|
2136
|
+
def _process_other_argument(self, **kwargs):
|
|
2137
|
+
"""
|
|
2138
|
+
DESCRIPTION:
|
|
2139
|
+
Internal function to process the arguments.
|
|
2140
|
+
1. The function does the following:
|
|
2141
|
+
* Checks the required arguments are passed or not.
|
|
2142
|
+
* Checks the type of the arguments are expected or not.
|
|
2143
|
+
* Checks for permitted values.
|
|
2144
|
+
* Checks for empty string.
|
|
2145
|
+
* If validations run fine,
|
|
2146
|
+
then returns a dict with the SQL name of the argument as key
|
|
2147
|
+
and user provided value as the value {arg_sql_name : value}
|
|
2148
|
+
|
|
2149
|
+
PARAMETERS:
|
|
2150
|
+
|
|
2151
|
+
kwargs:
|
|
2152
|
+
Specifies the keyword arguments passed to a function.
|
|
2153
|
+
|
|
2154
|
+
RETURNS:
|
|
2155
|
+
None.
|
|
2156
|
+
|
|
2157
|
+
RAISES:
|
|
2158
|
+
ValueError OR TypeError OR TeradataMlException.
|
|
2159
|
+
|
|
2160
|
+
EXAMPLES:
|
|
2161
|
+
self._process_other_arguments(argument, arg1="string", arg2="db", arg3=2)
|
|
2162
|
+
|
|
2163
|
+
"""
|
|
2164
|
+
## As the function 'FilterFactory1d' requries the output table to be created before the stored procedure call,
|
|
2165
|
+
## creating it and adding them as parameters as stored procedure requires them
|
|
2166
|
+
|
|
2167
|
+
if self.func_name == "FilterFactory1d":
|
|
2168
|
+
columns_to_create = {"ID": INTEGER,
|
|
2169
|
+
"row_i": INTEGER,
|
|
2170
|
+
"FilterMag": FLOAT,
|
|
2171
|
+
"description": VARCHAR}
|
|
2172
|
+
|
|
2173
|
+
schema_name = UtilFuncs._extract_db_name(self._func_output_args)
|
|
2174
|
+
table_name = UtilFuncs._extract_table_name(self._func_output_args)
|
|
2175
|
+
|
|
2176
|
+
_create_table(table_name=table_name,
|
|
2177
|
+
columns=columns_to_create,
|
|
2178
|
+
schema_name=schema_name,
|
|
2179
|
+
primary_index=["ID", "row_i"])
|
|
2180
|
+
self._func_other_args['database_name'] = UtilFuncs._teradata_quote_arg(schema_name, "\'", False)
|
|
2181
|
+
self._func_other_args['table_name'] = UtilFuncs._teradata_quote_arg(table_name, "\'", False)
|
|
2182
|
+
|
|
2183
|
+
for argument in self._metadata.arguments:
|
|
2184
|
+
sql_name = argument.get_name()
|
|
2185
|
+
lang_name = argument.get_lang_name()
|
|
2186
|
+
arg_value = kwargs.get(lang_name)
|
|
2187
|
+
# Set the "argument".
|
|
2188
|
+
self._spl_func_obj.set_arg_name(argument)
|
|
2189
|
+
# Let's get spl handler if function requires.
|
|
2190
|
+
special_case_handler = self._spl_func_obj._get_handle()
|
|
2191
|
+
|
|
2192
|
+
self._validate_analytic_function_argument(lang_name, arg_value, argument)
|
|
2193
|
+
# As stored procedures require the argument to passed in positional order and
|
|
2194
|
+
# NULL is required for arguments which are not present
|
|
2195
|
+
if arg_value is None:
|
|
2196
|
+
self._func_other_args[sql_name] = 'NULL'
|
|
2197
|
+
|
|
2198
|
+
# If argument is not None add the sql_name and arg_value to the dict.
|
|
2199
|
+
else:
|
|
2200
|
+
# If get_match_length_of_arguments is True, check if the arg_value is
|
|
2201
|
+
# a list and of the required size.
|
|
2202
|
+
if argument.get_match_length_of_arguments():
|
|
2203
|
+
required_length = argument.get_required_length()
|
|
2204
|
+
if (isinstance(arg_value, list) and len(arg_value) != required_length) or\
|
|
2205
|
+
(not isinstance(arg_value, list)):
|
|
2206
|
+
raise TeradataMlException(Messages.get_message(
|
|
2207
|
+
MessageCodes.INVALID_LIST_LENGTH).format(lang_name,
|
|
2208
|
+
required_length),
|
|
2209
|
+
MessageCodes.INVALID_LIST_LENGTH)
|
|
2210
|
+
|
|
2211
|
+
# Perform the checks which are specific to argument(_AnlyFuncArgument) type.
|
|
2212
|
+
# Check lower bound and upper bound for numeric arguments.
|
|
2213
|
+
if isinstance(arg_value, (int, float)):
|
|
2214
|
+
lower_bound_inclusive = argument.get_lower_bound_type() == "INCLUSIVE"
|
|
2215
|
+
upper_bound_inclusive = argument.get_upper_bound_type() == "INCLUSIVE"
|
|
2216
|
+
_Validators._validate_argument_range(arg_value,
|
|
2217
|
+
lang_name,
|
|
2218
|
+
lbound=argument.get_lower_bound(),
|
|
2219
|
+
ubound=argument.get_upper_bound(),
|
|
2220
|
+
lbound_inclusive=lower_bound_inclusive,
|
|
2221
|
+
ubound_inclusive=upper_bound_inclusive)
|
|
2222
|
+
|
|
2223
|
+
# If the argument is a bool type, convert it to integer since SQL do
|
|
2224
|
+
# not know boolean processing.
|
|
2225
|
+
if bool in argument.get_python_type() and isinstance(arg_value, bool):
|
|
2226
|
+
arg_value = int(arg_value)
|
|
2227
|
+
|
|
2228
|
+
# Handle special cases for "arg_values" based on handling method.
|
|
2229
|
+
arg_value = special_case_handler(arg_value) if special_case_handler is not None else arg_value
|
|
2230
|
+
self._func_other_args[sql_name] = arg_value
|
|
2231
|
+
|
|
2232
|
+
|
|
2233
|
+
def _process_function_output(self, **kwargs):
|
|
2234
|
+
"""
|
|
2235
|
+
DESCRIPTION:
|
|
2236
|
+
Internal function to process the function output.
|
|
2237
|
+
"""
|
|
2238
|
+
for lang_name, table_name in self._function_output_table_map.items():
|
|
2239
|
+
out_table_name = UtilFuncs._extract_table_name(table_name)
|
|
2240
|
+
out_db_name = UtilFuncs._extract_db_name(table_name)
|
|
2241
|
+
df = self._awu._create_data_set_object(
|
|
2242
|
+
df_input=out_table_name, database_name=out_db_name, source_type="table")
|
|
2243
|
+
self._dyn_cls_data_members[lang_name] = df
|
|
2244
|
+
# Condition make sure that the first element always be result or output in _mlresults.
|
|
2245
|
+
if lang_name in ["output", "result"]:
|
|
2246
|
+
self._mlresults.insert(0, df)
|
|
2247
|
+
else:
|
|
2248
|
+
self._mlresults.append(df)
|
|
@@ -956,3 +956,95 @@ class UAFQueryGenerator:
|
|
|
956
956
|
sql,
|
|
957
957
|
on_preserve_clause)
|
|
958
958
|
return sql
|
|
959
|
+
|
|
960
|
+
|
|
961
|
+
class StoredProcedureQueryGenerator:
|
|
962
|
+
"""
|
|
963
|
+
This class creates a SQL-MR object, which can be used to generate
|
|
964
|
+
Stored Procedure Query Generator in FFE syntax for Teradata.
|
|
965
|
+
"""
|
|
966
|
+
|
|
967
|
+
def __init__(self, function_name,
|
|
968
|
+
func_other_args_values,
|
|
969
|
+
db_name="SYSLIB"):
|
|
970
|
+
"""
|
|
971
|
+
StoredProcedureQueryGenerator constructor, to create query for Stored Procedures.
|
|
972
|
+
|
|
973
|
+
PARAMETERS:
|
|
974
|
+
function_name:
|
|
975
|
+
Required Argument.
|
|
976
|
+
Specifies the name of the function.
|
|
977
|
+
|
|
978
|
+
func_other_args_values:
|
|
979
|
+
Required Argument.
|
|
980
|
+
Specifies a dict in the format: {'sql_name':'value'}.
|
|
981
|
+
|
|
982
|
+
db_name:
|
|
983
|
+
Optional Argument.
|
|
984
|
+
Specifies the install location of Stored Procedures.
|
|
985
|
+
Default Value: SYSLIB
|
|
986
|
+
|
|
987
|
+
RETURNS:
|
|
988
|
+
StoredProcedureQueryGenerator object.
|
|
989
|
+
|
|
990
|
+
EXAMPLES:
|
|
991
|
+
aqg_obj = StoredProcedureQueryGenerator(function_name, other_sql_args, db_name="mldb")
|
|
992
|
+
"""
|
|
993
|
+
self.__function_name = function_name
|
|
994
|
+
|
|
995
|
+
# If the db_name is provided, append it to the stored
|
|
996
|
+
# procedure function name.
|
|
997
|
+
self.__db_name = db_name
|
|
998
|
+
if self.__db_name:
|
|
999
|
+
self.__function_name = "\"{}\".{}".format(self.__db_name,
|
|
1000
|
+
self.__function_name)
|
|
1001
|
+
|
|
1002
|
+
self.__func_other_args_values = func_other_args_values
|
|
1003
|
+
self.__CALL_STMT_FMT = "Call {}({})"
|
|
1004
|
+
self.__QUERY_SIZE = self.__get_string_size(self.__CALL_STMT_FMT) + 20
|
|
1005
|
+
|
|
1006
|
+
|
|
1007
|
+
def __generate_sqlmr_func_other_arg_sql(self):
|
|
1008
|
+
"""
|
|
1009
|
+
Private function to generate a SQL clause for other function arguments.
|
|
1010
|
+
For Example, two paramater values of {a:False, b:"BINOMIAL"} are
|
|
1011
|
+
appened like: False, "BINOMIAL", in the same order.
|
|
1012
|
+
|
|
1013
|
+
RETURNS:
|
|
1014
|
+
SQL string for other function arguments, as shown in example here.
|
|
1015
|
+
|
|
1016
|
+
EXAMPLES:
|
|
1017
|
+
__func_other_args_values = {"a":False, "b":"BINOMIAL"}
|
|
1018
|
+
other_arg_sql = self.__generate_sqlmr_func_other_arg_sql()
|
|
1019
|
+
# Output is as shown in example in description.
|
|
1020
|
+
|
|
1021
|
+
"""
|
|
1022
|
+
args_sql_str = ','.join(map(str, self.__func_other_args_values.values()))
|
|
1023
|
+
self.__QUERY_SIZE = self.__QUERY_SIZE + self.__get_string_size(args_sql_str)
|
|
1024
|
+
return args_sql_str
|
|
1025
|
+
|
|
1026
|
+
def _gen_call_stmt(self):
|
|
1027
|
+
"""
|
|
1028
|
+
Protected function to generate complete query.
|
|
1029
|
+
For Example,
|
|
1030
|
+
CALL SYSLIB.TD_FILTERFACTORY1D ('test', 'filters', 33, 'lowpass', 'blackman', NULL, 20.0, 40.0, NULL, 200, NULL);
|
|
1031
|
+
|
|
1032
|
+
PARAMETERS:
|
|
1033
|
+
|
|
1034
|
+
RETURNS:
|
|
1035
|
+
A SQL-MR/Analytical query, as shown in example here.
|
|
1036
|
+
|
|
1037
|
+
RAISES:
|
|
1038
|
+
|
|
1039
|
+
EXAMPLES:
|
|
1040
|
+
aqg_obj = StoredProcedureQueryGenerator(function_name=self._metadata.sql_function_name,
|
|
1041
|
+
func_other_args_values=self._func_other_args,
|
|
1042
|
+
db_name=db_name)
|
|
1043
|
+
anly_query = aqg_obj._gen_sqlmr_select_stmt_sql()
|
|
1044
|
+
# Output is as shown in example in description.
|
|
1045
|
+
|
|
1046
|
+
"""
|
|
1047
|
+
return self.__CALL_STMT_FMT.format(self.__function_name, self.__generate_sqlmr_func_other_arg_sql())
|
|
1048
|
+
|
|
1049
|
+
def __get_string_size(self, string):
|
|
1050
|
+
return len(string.encode("utf8"))
|
|
@@ -2,7 +2,7 @@ from teradataml.analytics.byom.H2OPredict import H2OPredict
|
|
|
2
2
|
from teradataml.analytics.byom.PMMLPredict import PMMLPredict
|
|
3
3
|
|
|
4
4
|
from teradataml.analytics.meta_class import _AnalyticFunction
|
|
5
|
-
from teradataml.analytics.meta_class import _common_init
|
|
5
|
+
from teradataml.analytics.meta_class import _common_init, _common_dir
|
|
6
6
|
|
|
7
7
|
_byom_functions = ['H2OPredict', 'PMMLPredict', 'ONNXPredict', 'DataikuPredict', 'DataRobotPredict']
|
|
8
8
|
|
|
@@ -12,4 +12,5 @@ for func in _byom_functions:
|
|
|
12
12
|
**kwargs: _common_init(self,
|
|
13
13
|
'byom',
|
|
14
14
|
**kwargs),
|
|
15
|
-
"__doc__": _AnalyticFunction.__doc__
|
|
15
|
+
"__doc__": _AnalyticFunction.__doc__,
|
|
16
|
+
"__dir__": _common_dir})
|
|
@@ -111,6 +111,7 @@ class _AnlyFuncMetadata:
|
|
|
111
111
|
TeradataAnalyticFunctionTypes.TABLEOPERATOR.value,
|
|
112
112
|
TeradataAnalyticFunctionTypes.UAF.value,
|
|
113
113
|
TeradataAnalyticFunctionTypes.BYOM.value,
|
|
114
|
+
TeradataAnalyticFunctionTypes.STORED_PROCEDURE.value,
|
|
114
115
|
None]])
|
|
115
116
|
arg_info_matrix.append(["json_file", json_file, False, str, True])
|
|
116
117
|
_Validators._validate_function_arguments(arg_info_matrix)
|