teradataml 20.0.0.8__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.
- teradataml/LICENSE-3RD-PARTY.pdf +0 -0
- teradataml/LICENSE.pdf +0 -0
- teradataml/README.md +2762 -0
- teradataml/__init__.py +78 -0
- teradataml/_version.py +11 -0
- teradataml/analytics/Transformations.py +2996 -0
- teradataml/analytics/__init__.py +82 -0
- teradataml/analytics/analytic_function_executor.py +2416 -0
- teradataml/analytics/analytic_query_generator.py +1050 -0
- teradataml/analytics/byom/H2OPredict.py +514 -0
- teradataml/analytics/byom/PMMLPredict.py +437 -0
- teradataml/analytics/byom/__init__.py +16 -0
- teradataml/analytics/json_parser/__init__.py +133 -0
- teradataml/analytics/json_parser/analytic_functions_argument.py +1805 -0
- teradataml/analytics/json_parser/json_store.py +191 -0
- teradataml/analytics/json_parser/metadata.py +1666 -0
- teradataml/analytics/json_parser/utils.py +805 -0
- teradataml/analytics/meta_class.py +236 -0
- teradataml/analytics/sqle/DecisionTreePredict.py +456 -0
- teradataml/analytics/sqle/NaiveBayesPredict.py +420 -0
- teradataml/analytics/sqle/__init__.py +128 -0
- teradataml/analytics/sqle/json/decisiontreepredict_sqle.json +78 -0
- teradataml/analytics/sqle/json/naivebayespredict_sqle.json +62 -0
- teradataml/analytics/table_operator/__init__.py +11 -0
- teradataml/analytics/uaf/__init__.py +82 -0
- teradataml/analytics/utils.py +828 -0
- teradataml/analytics/valib.py +1617 -0
- teradataml/automl/__init__.py +5835 -0
- teradataml/automl/autodataprep/__init__.py +493 -0
- teradataml/automl/custom_json_utils.py +1625 -0
- teradataml/automl/data_preparation.py +1384 -0
- teradataml/automl/data_transformation.py +1254 -0
- teradataml/automl/feature_engineering.py +2273 -0
- teradataml/automl/feature_exploration.py +1873 -0
- teradataml/automl/model_evaluation.py +488 -0
- teradataml/automl/model_training.py +1407 -0
- teradataml/catalog/__init__.py +2 -0
- teradataml/catalog/byom.py +1759 -0
- teradataml/catalog/function_argument_mapper.py +859 -0
- teradataml/catalog/model_cataloging_utils.py +491 -0
- teradataml/clients/__init__.py +0 -0
- teradataml/clients/auth_client.py +137 -0
- teradataml/clients/keycloak_client.py +165 -0
- teradataml/clients/pkce_client.py +481 -0
- teradataml/common/__init__.py +1 -0
- teradataml/common/aed_utils.py +2078 -0
- teradataml/common/bulk_exposed_utils.py +113 -0
- teradataml/common/constants.py +1669 -0
- teradataml/common/deprecations.py +166 -0
- teradataml/common/exceptions.py +147 -0
- teradataml/common/formula.py +743 -0
- teradataml/common/garbagecollector.py +666 -0
- teradataml/common/logger.py +1261 -0
- teradataml/common/messagecodes.py +518 -0
- teradataml/common/messages.py +262 -0
- teradataml/common/pylogger.py +67 -0
- teradataml/common/sqlbundle.py +764 -0
- teradataml/common/td_coltype_code_to_tdtype.py +48 -0
- teradataml/common/utils.py +3166 -0
- teradataml/common/warnings.py +36 -0
- teradataml/common/wrapper_utils.py +625 -0
- teradataml/config/__init__.py +0 -0
- teradataml/config/dummy_file1.cfg +5 -0
- teradataml/config/dummy_file2.cfg +3 -0
- teradataml/config/sqlengine_alias_definitions_v1.0 +14 -0
- teradataml/config/sqlengine_alias_definitions_v1.1 +20 -0
- teradataml/config/sqlengine_alias_definitions_v1.3 +19 -0
- teradataml/context/__init__.py +0 -0
- teradataml/context/aed_context.py +223 -0
- teradataml/context/context.py +1462 -0
- teradataml/data/A_loan.csv +19 -0
- teradataml/data/BINARY_REALS_LEFT.csv +11 -0
- teradataml/data/BINARY_REALS_RIGHT.csv +11 -0
- teradataml/data/B_loan.csv +49 -0
- teradataml/data/BuoyData2.csv +17 -0
- teradataml/data/CONVOLVE2_COMPLEX_LEFT.csv +5 -0
- teradataml/data/CONVOLVE2_COMPLEX_RIGHT.csv +5 -0
- teradataml/data/Convolve2RealsLeft.csv +5 -0
- teradataml/data/Convolve2RealsRight.csv +5 -0
- teradataml/data/Convolve2ValidLeft.csv +11 -0
- teradataml/data/Convolve2ValidRight.csv +11 -0
- teradataml/data/DFFTConv_Real_8_8.csv +65 -0
- teradataml/data/Employee.csv +5 -0
- teradataml/data/Employee_Address.csv +4 -0
- teradataml/data/Employee_roles.csv +5 -0
- teradataml/data/JulesBelvezeDummyData.csv +100 -0
- teradataml/data/Mall_customer_data.csv +201 -0
- teradataml/data/Orders1_12mf.csv +25 -0
- teradataml/data/Pi_loan.csv +7 -0
- teradataml/data/SMOOTHED_DATA.csv +7 -0
- teradataml/data/TestDFFT8.csv +9 -0
- teradataml/data/TestRiver.csv +109 -0
- teradataml/data/Traindata.csv +28 -0
- teradataml/data/__init__.py +0 -0
- teradataml/data/acf.csv +17 -0
- teradataml/data/adaboost_example.json +34 -0
- teradataml/data/adaboostpredict_example.json +24 -0
- teradataml/data/additional_table.csv +11 -0
- teradataml/data/admissions_test.csv +21 -0
- teradataml/data/admissions_train.csv +41 -0
- teradataml/data/admissions_train_nulls.csv +41 -0
- teradataml/data/advertising.csv +201 -0
- teradataml/data/ageandheight.csv +13 -0
- teradataml/data/ageandpressure.csv +31 -0
- teradataml/data/amazon_reviews_25.csv +26 -0
- teradataml/data/antiselect_example.json +36 -0
- teradataml/data/antiselect_input.csv +8 -0
- teradataml/data/antiselect_input_mixed_case.csv +8 -0
- teradataml/data/applicant_external.csv +7 -0
- teradataml/data/applicant_reference.csv +7 -0
- teradataml/data/apriori_example.json +22 -0
- teradataml/data/arima_example.json +9 -0
- teradataml/data/assortedtext_input.csv +8 -0
- teradataml/data/attribution_example.json +34 -0
- teradataml/data/attribution_sample_table.csv +27 -0
- teradataml/data/attribution_sample_table1.csv +6 -0
- teradataml/data/attribution_sample_table2.csv +11 -0
- teradataml/data/bank_churn.csv +10001 -0
- teradataml/data/bank_marketing.csv +11163 -0
- teradataml/data/bank_web_clicks1.csv +43 -0
- teradataml/data/bank_web_clicks2.csv +91 -0
- teradataml/data/bank_web_url.csv +85 -0
- teradataml/data/barrier.csv +2 -0
- teradataml/data/barrier_new.csv +3 -0
- teradataml/data/betweenness_example.json +14 -0
- teradataml/data/bike_sharing.csv +732 -0
- teradataml/data/bin_breaks.csv +8 -0
- teradataml/data/bin_fit_ip.csv +4 -0
- teradataml/data/binary_complex_left.csv +11 -0
- teradataml/data/binary_complex_right.csv +11 -0
- teradataml/data/binary_matrix_complex_left.csv +21 -0
- teradataml/data/binary_matrix_complex_right.csv +21 -0
- teradataml/data/binary_matrix_real_left.csv +21 -0
- teradataml/data/binary_matrix_real_right.csv +21 -0
- teradataml/data/blood2ageandweight.csv +26 -0
- teradataml/data/bmi.csv +501 -0
- teradataml/data/boston.csv +507 -0
- teradataml/data/boston2cols.csv +721 -0
- teradataml/data/breast_cancer.csv +570 -0
- teradataml/data/buoydata_mix.csv +11 -0
- teradataml/data/burst_data.csv +5 -0
- teradataml/data/burst_example.json +21 -0
- teradataml/data/byom_example.json +34 -0
- teradataml/data/bytes_table.csv +4 -0
- teradataml/data/cal_housing_ex_raw.csv +70 -0
- teradataml/data/callers.csv +7 -0
- teradataml/data/calls.csv +10 -0
- teradataml/data/cars_hist.csv +33 -0
- teradataml/data/cat_table.csv +25 -0
- teradataml/data/ccm_example.json +32 -0
- teradataml/data/ccm_input.csv +91 -0
- teradataml/data/ccm_input2.csv +13 -0
- teradataml/data/ccmexample.csv +101 -0
- teradataml/data/ccmprepare_example.json +9 -0
- teradataml/data/ccmprepare_input.csv +91 -0
- teradataml/data/cfilter_example.json +12 -0
- teradataml/data/changepointdetection_example.json +18 -0
- teradataml/data/changepointdetectionrt_example.json +8 -0
- teradataml/data/chi_sq.csv +3 -0
- teradataml/data/churn_data.csv +14 -0
- teradataml/data/churn_emission.csv +35 -0
- teradataml/data/churn_initial.csv +3 -0
- teradataml/data/churn_state_transition.csv +5 -0
- teradataml/data/citedges_2.csv +745 -0
- teradataml/data/citvertices_2.csv +1210 -0
- teradataml/data/clicks2.csv +16 -0
- teradataml/data/clickstream.csv +13 -0
- teradataml/data/clickstream1.csv +11 -0
- teradataml/data/closeness_example.json +16 -0
- teradataml/data/complaints.csv +21 -0
- teradataml/data/complaints_mini.csv +3 -0
- teradataml/data/complaints_test_tokenized.csv +353 -0
- teradataml/data/complaints_testtoken.csv +224 -0
- teradataml/data/complaints_tokens_model.csv +348 -0
- teradataml/data/complaints_tokens_test.csv +353 -0
- teradataml/data/complaints_traintoken.csv +472 -0
- teradataml/data/computers_category.csv +1001 -0
- teradataml/data/computers_test1.csv +1252 -0
- teradataml/data/computers_train1.csv +5009 -0
- teradataml/data/computers_train1_clustered.csv +5009 -0
- teradataml/data/confusionmatrix_example.json +9 -0
- teradataml/data/conversion_event_table.csv +3 -0
- teradataml/data/corr_input.csv +17 -0
- teradataml/data/correlation_example.json +11 -0
- teradataml/data/covid_confirm_sd.csv +83 -0
- teradataml/data/coxhazardratio_example.json +39 -0
- teradataml/data/coxph_example.json +15 -0
- teradataml/data/coxsurvival_example.json +28 -0
- teradataml/data/cpt.csv +41 -0
- teradataml/data/credit_ex_merged.csv +45 -0
- teradataml/data/creditcard_data.csv +1001 -0
- teradataml/data/customer_loyalty.csv +301 -0
- teradataml/data/customer_loyalty_newseq.csv +31 -0
- teradataml/data/customer_segmentation_test.csv +2628 -0
- teradataml/data/customer_segmentation_train.csv +8069 -0
- teradataml/data/dataframe_example.json +173 -0
- teradataml/data/decisionforest_example.json +37 -0
- teradataml/data/decisionforestpredict_example.json +38 -0
- teradataml/data/decisiontree_example.json +21 -0
- teradataml/data/decisiontreepredict_example.json +45 -0
- teradataml/data/dfft2_size4_real.csv +17 -0
- teradataml/data/dfft2_test_matrix16.csv +17 -0
- teradataml/data/dfft2conv_real_4_4.csv +65 -0
- teradataml/data/diabetes.csv +443 -0
- teradataml/data/diabetes_test.csv +89 -0
- teradataml/data/dict_table.csv +5 -0
- teradataml/data/docperterm_table.csv +4 -0
- teradataml/data/docs/__init__.py +1 -0
- teradataml/data/docs/byom/__init__.py +0 -0
- teradataml/data/docs/byom/docs/DataRobotPredict.py +180 -0
- teradataml/data/docs/byom/docs/DataikuPredict.py +217 -0
- teradataml/data/docs/byom/docs/H2OPredict.py +325 -0
- teradataml/data/docs/byom/docs/ONNXEmbeddings.py +242 -0
- teradataml/data/docs/byom/docs/ONNXPredict.py +283 -0
- teradataml/data/docs/byom/docs/ONNXSeq2Seq.py +255 -0
- teradataml/data/docs/byom/docs/PMMLPredict.py +278 -0
- teradataml/data/docs/byom/docs/__init__.py +0 -0
- teradataml/data/docs/sqle/__init__.py +0 -0
- teradataml/data/docs/sqle/docs_17_10/Antiselect.py +83 -0
- teradataml/data/docs/sqle/docs_17_10/Attribution.py +200 -0
- teradataml/data/docs/sqle/docs_17_10/BincodeFit.py +172 -0
- teradataml/data/docs/sqle/docs_17_10/BincodeTransform.py +131 -0
- teradataml/data/docs/sqle/docs_17_10/CategoricalSummary.py +86 -0
- teradataml/data/docs/sqle/docs_17_10/ChiSq.py +90 -0
- teradataml/data/docs/sqle/docs_17_10/ColumnSummary.py +86 -0
- teradataml/data/docs/sqle/docs_17_10/ConvertTo.py +96 -0
- teradataml/data/docs/sqle/docs_17_10/DecisionForestPredict.py +139 -0
- teradataml/data/docs/sqle/docs_17_10/DecisionTreePredict.py +152 -0
- teradataml/data/docs/sqle/docs_17_10/FTest.py +161 -0
- teradataml/data/docs/sqle/docs_17_10/FillRowId.py +83 -0
- teradataml/data/docs/sqle/docs_17_10/Fit.py +88 -0
- teradataml/data/docs/sqle/docs_17_10/GLMPredict.py +144 -0
- teradataml/data/docs/sqle/docs_17_10/GetRowsWithMissingValues.py +85 -0
- teradataml/data/docs/sqle/docs_17_10/GetRowsWithoutMissingValues.py +82 -0
- teradataml/data/docs/sqle/docs_17_10/Histogram.py +165 -0
- teradataml/data/docs/sqle/docs_17_10/MovingAverage.py +134 -0
- teradataml/data/docs/sqle/docs_17_10/NGramSplitter.py +209 -0
- teradataml/data/docs/sqle/docs_17_10/NPath.py +266 -0
- teradataml/data/docs/sqle/docs_17_10/NaiveBayesPredict.py +116 -0
- teradataml/data/docs/sqle/docs_17_10/NaiveBayesTextClassifierPredict.py +176 -0
- teradataml/data/docs/sqle/docs_17_10/NumApply.py +147 -0
- teradataml/data/docs/sqle/docs_17_10/OneHotEncodingFit.py +135 -0
- teradataml/data/docs/sqle/docs_17_10/OneHotEncodingTransform.py +109 -0
- teradataml/data/docs/sqle/docs_17_10/OutlierFilterFit.py +166 -0
- teradataml/data/docs/sqle/docs_17_10/OutlierFilterTransform.py +105 -0
- teradataml/data/docs/sqle/docs_17_10/Pack.py +128 -0
- teradataml/data/docs/sqle/docs_17_10/PolynomialFeaturesFit.py +112 -0
- teradataml/data/docs/sqle/docs_17_10/PolynomialFeaturesTransform.py +102 -0
- teradataml/data/docs/sqle/docs_17_10/QQNorm.py +105 -0
- teradataml/data/docs/sqle/docs_17_10/RoundColumns.py +110 -0
- teradataml/data/docs/sqle/docs_17_10/RowNormalizeFit.py +118 -0
- teradataml/data/docs/sqle/docs_17_10/RowNormalizeTransform.py +99 -0
- teradataml/data/docs/sqle/docs_17_10/SVMSparsePredict.py +153 -0
- teradataml/data/docs/sqle/docs_17_10/ScaleFit.py +197 -0
- teradataml/data/docs/sqle/docs_17_10/ScaleTransform.py +99 -0
- teradataml/data/docs/sqle/docs_17_10/Sessionize.py +114 -0
- teradataml/data/docs/sqle/docs_17_10/SimpleImputeFit.py +116 -0
- teradataml/data/docs/sqle/docs_17_10/SimpleImputeTransform.py +98 -0
- teradataml/data/docs/sqle/docs_17_10/StrApply.py +187 -0
- teradataml/data/docs/sqle/docs_17_10/StringSimilarity.py +146 -0
- teradataml/data/docs/sqle/docs_17_10/Transform.py +105 -0
- teradataml/data/docs/sqle/docs_17_10/UnivariateStatistics.py +142 -0
- teradataml/data/docs/sqle/docs_17_10/Unpack.py +214 -0
- teradataml/data/docs/sqle/docs_17_10/WhichMax.py +83 -0
- teradataml/data/docs/sqle/docs_17_10/WhichMin.py +83 -0
- teradataml/data/docs/sqle/docs_17_10/ZTest.py +155 -0
- teradataml/data/docs/sqle/docs_17_10/__init__.py +0 -0
- teradataml/data/docs/sqle/docs_17_20/ANOVA.py +186 -0
- teradataml/data/docs/sqle/docs_17_20/Antiselect.py +83 -0
- teradataml/data/docs/sqle/docs_17_20/Apriori.py +138 -0
- teradataml/data/docs/sqle/docs_17_20/Attribution.py +201 -0
- teradataml/data/docs/sqle/docs_17_20/BincodeFit.py +172 -0
- teradataml/data/docs/sqle/docs_17_20/BincodeTransform.py +139 -0
- teradataml/data/docs/sqle/docs_17_20/CFilter.py +132 -0
- teradataml/data/docs/sqle/docs_17_20/CategoricalSummary.py +86 -0
- teradataml/data/docs/sqle/docs_17_20/ChiSq.py +90 -0
- teradataml/data/docs/sqle/docs_17_20/ClassificationEvaluator.py +166 -0
- teradataml/data/docs/sqle/docs_17_20/ColumnSummary.py +86 -0
- teradataml/data/docs/sqle/docs_17_20/ColumnTransformer.py +246 -0
- teradataml/data/docs/sqle/docs_17_20/ConvertTo.py +113 -0
- teradataml/data/docs/sqle/docs_17_20/DecisionForest.py +280 -0
- teradataml/data/docs/sqle/docs_17_20/DecisionForestPredict.py +144 -0
- teradataml/data/docs/sqle/docs_17_20/DecisionTreePredict.py +136 -0
- teradataml/data/docs/sqle/docs_17_20/FTest.py +240 -0
- teradataml/data/docs/sqle/docs_17_20/FillRowId.py +83 -0
- teradataml/data/docs/sqle/docs_17_20/Fit.py +88 -0
- teradataml/data/docs/sqle/docs_17_20/GLM.py +541 -0
- teradataml/data/docs/sqle/docs_17_20/GLMPerSegment.py +415 -0
- teradataml/data/docs/sqle/docs_17_20/GLMPredict.py +144 -0
- teradataml/data/docs/sqle/docs_17_20/GLMPredictPerSegment.py +233 -0
- teradataml/data/docs/sqle/docs_17_20/GetFutileColumns.py +125 -0
- teradataml/data/docs/sqle/docs_17_20/GetRowsWithMissingValues.py +109 -0
- teradataml/data/docs/sqle/docs_17_20/GetRowsWithoutMissingValues.py +106 -0
- teradataml/data/docs/sqle/docs_17_20/Histogram.py +224 -0
- teradataml/data/docs/sqle/docs_17_20/KMeans.py +251 -0
- teradataml/data/docs/sqle/docs_17_20/KMeansPredict.py +144 -0
- teradataml/data/docs/sqle/docs_17_20/KNN.py +215 -0
- teradataml/data/docs/sqle/docs_17_20/MovingAverage.py +134 -0
- teradataml/data/docs/sqle/docs_17_20/NERExtractor.py +121 -0
- teradataml/data/docs/sqle/docs_17_20/NGramSplitter.py +209 -0
- teradataml/data/docs/sqle/docs_17_20/NPath.py +266 -0
- teradataml/data/docs/sqle/docs_17_20/NaiveBayes.py +162 -0
- teradataml/data/docs/sqle/docs_17_20/NaiveBayesPredict.py +116 -0
- teradataml/data/docs/sqle/docs_17_20/NaiveBayesTextClassifierPredict.py +177 -0
- teradataml/data/docs/sqle/docs_17_20/NaiveBayesTextClassifierTrainer.py +127 -0
- teradataml/data/docs/sqle/docs_17_20/NonLinearCombineFit.py +119 -0
- teradataml/data/docs/sqle/docs_17_20/NonLinearCombineTransform.py +112 -0
- teradataml/data/docs/sqle/docs_17_20/NumApply.py +147 -0
- teradataml/data/docs/sqle/docs_17_20/OneClassSVM.py +307 -0
- teradataml/data/docs/sqle/docs_17_20/OneClassSVMPredict.py +185 -0
- teradataml/data/docs/sqle/docs_17_20/OneHotEncodingFit.py +231 -0
- teradataml/data/docs/sqle/docs_17_20/OneHotEncodingTransform.py +121 -0
- teradataml/data/docs/sqle/docs_17_20/OrdinalEncodingFit.py +220 -0
- teradataml/data/docs/sqle/docs_17_20/OrdinalEncodingTransform.py +127 -0
- teradataml/data/docs/sqle/docs_17_20/OutlierFilterFit.py +191 -0
- teradataml/data/docs/sqle/docs_17_20/OutlierFilterTransform.py +117 -0
- teradataml/data/docs/sqle/docs_17_20/Pack.py +128 -0
- teradataml/data/docs/sqle/docs_17_20/Pivoting.py +279 -0
- teradataml/data/docs/sqle/docs_17_20/PolynomialFeaturesFit.py +112 -0
- teradataml/data/docs/sqle/docs_17_20/PolynomialFeaturesTransform.py +112 -0
- teradataml/data/docs/sqle/docs_17_20/QQNorm.py +105 -0
- teradataml/data/docs/sqle/docs_17_20/ROC.py +164 -0
- teradataml/data/docs/sqle/docs_17_20/RandomProjectionFit.py +155 -0
- teradataml/data/docs/sqle/docs_17_20/RandomProjectionMinComponents.py +106 -0
- teradataml/data/docs/sqle/docs_17_20/RandomProjectionTransform.py +120 -0
- teradataml/data/docs/sqle/docs_17_20/RegressionEvaluator.py +211 -0
- teradataml/data/docs/sqle/docs_17_20/RoundColumns.py +109 -0
- teradataml/data/docs/sqle/docs_17_20/RowNormalizeFit.py +118 -0
- teradataml/data/docs/sqle/docs_17_20/RowNormalizeTransform.py +111 -0
- teradataml/data/docs/sqle/docs_17_20/SMOTE.py +212 -0
- teradataml/data/docs/sqle/docs_17_20/SVM.py +414 -0
- teradataml/data/docs/sqle/docs_17_20/SVMPredict.py +213 -0
- teradataml/data/docs/sqle/docs_17_20/SVMSparsePredict.py +153 -0
- teradataml/data/docs/sqle/docs_17_20/ScaleFit.py +315 -0
- teradataml/data/docs/sqle/docs_17_20/ScaleTransform.py +202 -0
- teradataml/data/docs/sqle/docs_17_20/SentimentExtractor.py +206 -0
- teradataml/data/docs/sqle/docs_17_20/Sessionize.py +114 -0
- teradataml/data/docs/sqle/docs_17_20/Shap.py +225 -0
- teradataml/data/docs/sqle/docs_17_20/Silhouette.py +153 -0
- teradataml/data/docs/sqle/docs_17_20/SimpleImputeFit.py +116 -0
- teradataml/data/docs/sqle/docs_17_20/SimpleImputeTransform.py +109 -0
- teradataml/data/docs/sqle/docs_17_20/StrApply.py +187 -0
- teradataml/data/docs/sqle/docs_17_20/StringSimilarity.py +146 -0
- teradataml/data/docs/sqle/docs_17_20/TDDecisionForestPredict.py +207 -0
- teradataml/data/docs/sqle/docs_17_20/TDGLMPredict.py +333 -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/TargetEncodingFit.py +267 -0
- teradataml/data/docs/sqle/docs_17_20/TargetEncodingTransform.py +141 -0
- teradataml/data/docs/sqle/docs_17_20/TextMorph.py +119 -0
- teradataml/data/docs/sqle/docs_17_20/TextParser.py +224 -0
- teradataml/data/docs/sqle/docs_17_20/TrainTestSplit.py +160 -0
- teradataml/data/docs/sqle/docs_17_20/Transform.py +123 -0
- teradataml/data/docs/sqle/docs_17_20/UnivariateStatistics.py +142 -0
- teradataml/data/docs/sqle/docs_17_20/Unpack.py +214 -0
- teradataml/data/docs/sqle/docs_17_20/Unpivoting.py +216 -0
- teradataml/data/docs/sqle/docs_17_20/VectorDistance.py +169 -0
- teradataml/data/docs/sqle/docs_17_20/WhichMax.py +83 -0
- teradataml/data/docs/sqle/docs_17_20/WhichMin.py +83 -0
- teradataml/data/docs/sqle/docs_17_20/WordEmbeddings.py +237 -0
- teradataml/data/docs/sqle/docs_17_20/XGBoost.py +362 -0
- teradataml/data/docs/sqle/docs_17_20/XGBoostPredict.py +281 -0
- teradataml/data/docs/sqle/docs_17_20/ZTest.py +220 -0
- teradataml/data/docs/sqle/docs_17_20/__init__.py +0 -0
- teradataml/data/docs/tableoperator/__init__.py +0 -0
- teradataml/data/docs/tableoperator/docs_17_00/ReadNOS.py +430 -0
- teradataml/data/docs/tableoperator/docs_17_00/__init__.py +0 -0
- teradataml/data/docs/tableoperator/docs_17_05/ReadNOS.py +430 -0
- teradataml/data/docs/tableoperator/docs_17_05/WriteNOS.py +348 -0
- teradataml/data/docs/tableoperator/docs_17_05/__init__.py +0 -0
- teradataml/data/docs/tableoperator/docs_17_10/ReadNOS.py +429 -0
- teradataml/data/docs/tableoperator/docs_17_10/WriteNOS.py +348 -0
- teradataml/data/docs/tableoperator/docs_17_10/__init__.py +0 -0
- teradataml/data/docs/tableoperator/docs_17_20/Image2Matrix.py +118 -0
- teradataml/data/docs/tableoperator/docs_17_20/ReadNOS.py +440 -0
- teradataml/data/docs/tableoperator/docs_17_20/WriteNOS.py +387 -0
- teradataml/data/docs/tableoperator/docs_17_20/__init__.py +0 -0
- teradataml/data/docs/uaf/__init__.py +0 -0
- teradataml/data/docs/uaf/docs_17_20/ACF.py +186 -0
- teradataml/data/docs/uaf/docs_17_20/ArimaEstimate.py +370 -0
- teradataml/data/docs/uaf/docs_17_20/ArimaForecast.py +172 -0
- teradataml/data/docs/uaf/docs_17_20/ArimaValidate.py +161 -0
- 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/BinaryMatrixOp.py +248 -0
- teradataml/data/docs/uaf/docs_17_20/BinarySeriesOp.py +252 -0
- teradataml/data/docs/uaf/docs_17_20/BreuschGodfrey.py +178 -0
- teradataml/data/docs/uaf/docs_17_20/BreuschPaganGodfrey.py +175 -0
- teradataml/data/docs/uaf/docs_17_20/Convolve.py +230 -0
- teradataml/data/docs/uaf/docs_17_20/Convolve2.py +218 -0
- teradataml/data/docs/uaf/docs_17_20/CopyArt.py +145 -0
- teradataml/data/docs/uaf/docs_17_20/CumulPeriodogram.py +185 -0
- teradataml/data/docs/uaf/docs_17_20/DFFT.py +204 -0
- teradataml/data/docs/uaf/docs_17_20/DFFT2.py +216 -0
- teradataml/data/docs/uaf/docs_17_20/DFFT2Conv.py +216 -0
- teradataml/data/docs/uaf/docs_17_20/DFFTConv.py +192 -0
- teradataml/data/docs/uaf/docs_17_20/DIFF.py +175 -0
- teradataml/data/docs/uaf/docs_17_20/DTW.py +180 -0
- teradataml/data/docs/uaf/docs_17_20/DWT.py +235 -0
- teradataml/data/docs/uaf/docs_17_20/DWT2D.py +217 -0
- teradataml/data/docs/uaf/docs_17_20/DickeyFuller.py +142 -0
- teradataml/data/docs/uaf/docs_17_20/DurbinWatson.py +184 -0
- teradataml/data/docs/uaf/docs_17_20/ExtractResults.py +185 -0
- teradataml/data/docs/uaf/docs_17_20/FilterFactory1d.py +160 -0
- teradataml/data/docs/uaf/docs_17_20/FitMetrics.py +172 -0
- teradataml/data/docs/uaf/docs_17_20/GenseriesFormula.py +206 -0
- teradataml/data/docs/uaf/docs_17_20/GenseriesSinusoids.py +143 -0
- teradataml/data/docs/uaf/docs_17_20/GoldfeldQuandt.py +198 -0
- teradataml/data/docs/uaf/docs_17_20/HoltWintersForecaster.py +260 -0
- teradataml/data/docs/uaf/docs_17_20/IDFFT.py +165 -0
- teradataml/data/docs/uaf/docs_17_20/IDFFT2.py +191 -0
- 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/InputValidator.py +121 -0
- teradataml/data/docs/uaf/docs_17_20/LineSpec.py +156 -0
- teradataml/data/docs/uaf/docs_17_20/LinearRegr.py +215 -0
- teradataml/data/docs/uaf/docs_17_20/MAMean.py +174 -0
- teradataml/data/docs/uaf/docs_17_20/MInfo.py +134 -0
- teradataml/data/docs/uaf/docs_17_20/Matrix2Image.py +297 -0
- teradataml/data/docs/uaf/docs_17_20/MatrixMultiply.py +145 -0
- teradataml/data/docs/uaf/docs_17_20/MultivarRegr.py +191 -0
- teradataml/data/docs/uaf/docs_17_20/PACF.py +157 -0
- teradataml/data/docs/uaf/docs_17_20/Portman.py +217 -0
- teradataml/data/docs/uaf/docs_17_20/PowerSpec.py +203 -0
- teradataml/data/docs/uaf/docs_17_20/PowerTransform.py +155 -0
- teradataml/data/docs/uaf/docs_17_20/Resample.py +237 -0
- teradataml/data/docs/uaf/docs_17_20/SAX.py +246 -0
- teradataml/data/docs/uaf/docs_17_20/SInfo.py +123 -0
- teradataml/data/docs/uaf/docs_17_20/SeasonalNormalize.py +173 -0
- teradataml/data/docs/uaf/docs_17_20/SelectionCriteria.py +174 -0
- teradataml/data/docs/uaf/docs_17_20/SignifPeriodicities.py +171 -0
- teradataml/data/docs/uaf/docs_17_20/SignifResidmean.py +164 -0
- teradataml/data/docs/uaf/docs_17_20/SimpleExp.py +180 -0
- teradataml/data/docs/uaf/docs_17_20/Smoothma.py +208 -0
- teradataml/data/docs/uaf/docs_17_20/TrackingOp.py +151 -0
- teradataml/data/docs/uaf/docs_17_20/UNDIFF.py +171 -0
- teradataml/data/docs/uaf/docs_17_20/Unnormalize.py +202 -0
- teradataml/data/docs/uaf/docs_17_20/WhitesGeneral.py +171 -0
- teradataml/data/docs/uaf/docs_17_20/WindowDFFT.py +368 -0
- teradataml/data/docs/uaf/docs_17_20/__init__.py +0 -0
- teradataml/data/dtw_example.json +18 -0
- teradataml/data/dtw_t1.csv +11 -0
- teradataml/data/dtw_t2.csv +4 -0
- teradataml/data/dwt2d_dataTable.csv +65 -0
- teradataml/data/dwt2d_example.json +16 -0
- teradataml/data/dwt_dataTable.csv +8 -0
- teradataml/data/dwt_example.json +15 -0
- teradataml/data/dwt_filterTable.csv +3 -0
- teradataml/data/dwt_filter_dim.csv +5 -0
- teradataml/data/emission.csv +9 -0
- teradataml/data/emp_table_by_dept.csv +19 -0
- teradataml/data/employee_info.csv +4 -0
- teradataml/data/employee_table.csv +6 -0
- teradataml/data/excluding_event_table.csv +2 -0
- teradataml/data/finance_data.csv +6 -0
- teradataml/data/finance_data2.csv +61 -0
- teradataml/data/finance_data3.csv +93 -0
- teradataml/data/finance_data4.csv +13 -0
- teradataml/data/fish.csv +160 -0
- teradataml/data/fm_blood2ageandweight.csv +26 -0
- teradataml/data/fmeasure_example.json +12 -0
- teradataml/data/followers_leaders.csv +10 -0
- teradataml/data/fpgrowth_example.json +12 -0
- teradataml/data/frequentpaths_example.json +29 -0
- teradataml/data/friends.csv +9 -0
- teradataml/data/fs_input.csv +33 -0
- teradataml/data/fs_input1.csv +33 -0
- teradataml/data/genData.csv +513 -0
- teradataml/data/geodataframe_example.json +40 -0
- teradataml/data/glass_types.csv +215 -0
- teradataml/data/glm_admissions_model.csv +12 -0
- teradataml/data/glm_example.json +56 -0
- teradataml/data/glml1l2_example.json +28 -0
- teradataml/data/glml1l2predict_example.json +54 -0
- teradataml/data/glmpredict_example.json +54 -0
- teradataml/data/gq_t1.csv +21 -0
- teradataml/data/grocery_transaction.csv +19 -0
- teradataml/data/hconvolve_complex_right.csv +5 -0
- teradataml/data/hconvolve_complex_rightmulti.csv +5 -0
- teradataml/data/histogram_example.json +12 -0
- teradataml/data/hmmdecoder_example.json +79 -0
- teradataml/data/hmmevaluator_example.json +25 -0
- teradataml/data/hmmsupervised_example.json +10 -0
- teradataml/data/hmmunsupervised_example.json +8 -0
- teradataml/data/hnsw_alter_data.csv +5 -0
- teradataml/data/hnsw_data.csv +10 -0
- teradataml/data/house_values.csv +12 -0
- teradataml/data/house_values2.csv +13 -0
- teradataml/data/housing_cat.csv +7 -0
- teradataml/data/housing_data.csv +9 -0
- teradataml/data/housing_test.csv +47 -0
- teradataml/data/housing_test_binary.csv +47 -0
- teradataml/data/housing_train.csv +493 -0
- teradataml/data/housing_train_attribute.csv +5 -0
- teradataml/data/housing_train_binary.csv +437 -0
- teradataml/data/housing_train_parameter.csv +2 -0
- teradataml/data/housing_train_response.csv +493 -0
- teradataml/data/housing_train_segment.csv +201 -0
- teradataml/data/ibm_stock.csv +370 -0
- teradataml/data/ibm_stock1.csv +370 -0
- teradataml/data/identitymatch_example.json +22 -0
- teradataml/data/idf_table.csv +4 -0
- teradataml/data/idwt2d_dataTable.csv +5 -0
- teradataml/data/idwt_dataTable.csv +8 -0
- teradataml/data/idwt_filterTable.csv +3 -0
- teradataml/data/impressions.csv +101 -0
- teradataml/data/inflation.csv +21 -0
- teradataml/data/initial.csv +3 -0
- teradataml/data/insect2Cols.csv +61 -0
- teradataml/data/insect_sprays.csv +13 -0
- teradataml/data/insurance.csv +1339 -0
- teradataml/data/interpolator_example.json +13 -0
- teradataml/data/interval_data.csv +5 -0
- teradataml/data/iris_altinput.csv +481 -0
- teradataml/data/iris_attribute_output.csv +8 -0
- teradataml/data/iris_attribute_test.csv +121 -0
- teradataml/data/iris_attribute_train.csv +481 -0
- teradataml/data/iris_category_expect_predict.csv +31 -0
- teradataml/data/iris_data.csv +151 -0
- teradataml/data/iris_input.csv +151 -0
- teradataml/data/iris_response_train.csv +121 -0
- teradataml/data/iris_test.csv +31 -0
- teradataml/data/iris_train.csv +121 -0
- teradataml/data/join_table1.csv +4 -0
- teradataml/data/join_table2.csv +4 -0
- teradataml/data/jsons/anly_function_name.json +7 -0
- teradataml/data/jsons/byom/ONNXSeq2Seq.json +287 -0
- teradataml/data/jsons/byom/dataikupredict.json +148 -0
- teradataml/data/jsons/byom/datarobotpredict.json +147 -0
- teradataml/data/jsons/byom/h2opredict.json +195 -0
- teradataml/data/jsons/byom/onnxembeddings.json +267 -0
- teradataml/data/jsons/byom/onnxpredict.json +187 -0
- teradataml/data/jsons/byom/pmmlpredict.json +147 -0
- teradataml/data/jsons/paired_functions.json +450 -0
- teradataml/data/jsons/sqle/16.20/Antiselect.json +56 -0
- teradataml/data/jsons/sqle/16.20/Attribution.json +249 -0
- teradataml/data/jsons/sqle/16.20/DecisionForestPredict.json +156 -0
- teradataml/data/jsons/sqle/16.20/DecisionTreePredict.json +170 -0
- teradataml/data/jsons/sqle/16.20/GLMPredict.json +122 -0
- teradataml/data/jsons/sqle/16.20/MovingAverage.json +367 -0
- teradataml/data/jsons/sqle/16.20/NGramSplitter.json +239 -0
- teradataml/data/jsons/sqle/16.20/NaiveBayesPredict.json +136 -0
- teradataml/data/jsons/sqle/16.20/NaiveBayesTextClassifierPredict.json +235 -0
- teradataml/data/jsons/sqle/16.20/Pack.json +98 -0
- teradataml/data/jsons/sqle/16.20/SVMSparsePredict.json +162 -0
- teradataml/data/jsons/sqle/16.20/Sessionize.json +105 -0
- teradataml/data/jsons/sqle/16.20/StringSimilarity.json +86 -0
- teradataml/data/jsons/sqle/16.20/Unpack.json +166 -0
- teradataml/data/jsons/sqle/16.20/nPath.json +269 -0
- teradataml/data/jsons/sqle/17.00/Antiselect.json +56 -0
- teradataml/data/jsons/sqle/17.00/Attribution.json +249 -0
- teradataml/data/jsons/sqle/17.00/DecisionForestPredict.json +156 -0
- teradataml/data/jsons/sqle/17.00/DecisionTreePredict.json +170 -0
- teradataml/data/jsons/sqle/17.00/GLMPredict.json +122 -0
- teradataml/data/jsons/sqle/17.00/MovingAverage.json +367 -0
- teradataml/data/jsons/sqle/17.00/NGramSplitter.json +239 -0
- teradataml/data/jsons/sqle/17.00/NaiveBayesPredict.json +136 -0
- teradataml/data/jsons/sqle/17.00/NaiveBayesTextClassifierPredict.json +235 -0
- teradataml/data/jsons/sqle/17.00/Pack.json +98 -0
- teradataml/data/jsons/sqle/17.00/SVMSparsePredict.json +162 -0
- teradataml/data/jsons/sqle/17.00/Sessionize.json +105 -0
- teradataml/data/jsons/sqle/17.00/StringSimilarity.json +86 -0
- teradataml/data/jsons/sqle/17.00/Unpack.json +166 -0
- teradataml/data/jsons/sqle/17.00/nPath.json +269 -0
- teradataml/data/jsons/sqle/17.05/Antiselect.json +56 -0
- teradataml/data/jsons/sqle/17.05/Attribution.json +249 -0
- teradataml/data/jsons/sqle/17.05/DecisionForestPredict.json +156 -0
- teradataml/data/jsons/sqle/17.05/DecisionTreePredict.json +170 -0
- teradataml/data/jsons/sqle/17.05/GLMPredict.json +122 -0
- teradataml/data/jsons/sqle/17.05/MovingAverage.json +367 -0
- teradataml/data/jsons/sqle/17.05/NGramSplitter.json +239 -0
- teradataml/data/jsons/sqle/17.05/NaiveBayesPredict.json +136 -0
- teradataml/data/jsons/sqle/17.05/NaiveBayesTextClassifierPredict.json +235 -0
- teradataml/data/jsons/sqle/17.05/Pack.json +98 -0
- teradataml/data/jsons/sqle/17.05/SVMSparsePredict.json +162 -0
- teradataml/data/jsons/sqle/17.05/Sessionize.json +105 -0
- teradataml/data/jsons/sqle/17.05/StringSimilarity.json +86 -0
- teradataml/data/jsons/sqle/17.05/Unpack.json +166 -0
- teradataml/data/jsons/sqle/17.05/nPath.json +269 -0
- teradataml/data/jsons/sqle/17.10/Antiselect.json +56 -0
- teradataml/data/jsons/sqle/17.10/Attribution.json +249 -0
- teradataml/data/jsons/sqle/17.10/DecisionForestPredict.json +185 -0
- teradataml/data/jsons/sqle/17.10/DecisionTreePredict.json +172 -0
- teradataml/data/jsons/sqle/17.10/GLMPredict.json +151 -0
- teradataml/data/jsons/sqle/17.10/MovingAverage.json +368 -0
- teradataml/data/jsons/sqle/17.10/NGramSplitter.json +239 -0
- teradataml/data/jsons/sqle/17.10/NaiveBayesPredict.json +149 -0
- teradataml/data/jsons/sqle/17.10/NaiveBayesTextClassifierPredict.json +288 -0
- teradataml/data/jsons/sqle/17.10/Pack.json +133 -0
- teradataml/data/jsons/sqle/17.10/SVMSparsePredict.json +193 -0
- teradataml/data/jsons/sqle/17.10/Sessionize.json +105 -0
- teradataml/data/jsons/sqle/17.10/StringSimilarity.json +86 -0
- teradataml/data/jsons/sqle/17.10/TD_BinCodeFit.json +239 -0
- teradataml/data/jsons/sqle/17.10/TD_BinCodeTransform.json +70 -0
- teradataml/data/jsons/sqle/17.10/TD_CategoricalSummary.json +54 -0
- teradataml/data/jsons/sqle/17.10/TD_Chisq.json +68 -0
- teradataml/data/jsons/sqle/17.10/TD_ColumnSummary.json +54 -0
- teradataml/data/jsons/sqle/17.10/TD_ConvertTo.json +69 -0
- teradataml/data/jsons/sqle/17.10/TD_FTest.json +187 -0
- teradataml/data/jsons/sqle/17.10/TD_FillRowID.json +52 -0
- teradataml/data/jsons/sqle/17.10/TD_FunctionFit.json +46 -0
- teradataml/data/jsons/sqle/17.10/TD_FunctionTransform.json +72 -0
- teradataml/data/jsons/sqle/17.10/TD_GetRowsWithMissingValues.json +53 -0
- teradataml/data/jsons/sqle/17.10/TD_GetRowsWithoutMissingValues.json +53 -0
- teradataml/data/jsons/sqle/17.10/TD_Histogram.json +133 -0
- teradataml/data/jsons/sqle/17.10/TD_NumApply.json +147 -0
- teradataml/data/jsons/sqle/17.10/TD_OneHotEncodingFit.json +183 -0
- teradataml/data/jsons/sqle/17.10/TD_OneHotEncodingTransform.json +66 -0
- teradataml/data/jsons/sqle/17.10/TD_OutlierFilterFit.json +197 -0
- teradataml/data/jsons/sqle/17.10/TD_OutlierFilterTransform.json +48 -0
- teradataml/data/jsons/sqle/17.10/TD_PolynomialFeaturesFit.json +114 -0
- teradataml/data/jsons/sqle/17.10/TD_PolynomialFeaturesTransform.json +72 -0
- teradataml/data/jsons/sqle/17.10/TD_QQNorm.json +112 -0
- teradataml/data/jsons/sqle/17.10/TD_RoundColumns.json +93 -0
- teradataml/data/jsons/sqle/17.10/TD_RowNormalizeFit.json +128 -0
- teradataml/data/jsons/sqle/17.10/TD_RowNormalizeTransform.json +71 -0
- teradataml/data/jsons/sqle/17.10/TD_ScaleFit.json +157 -0
- teradataml/data/jsons/sqle/17.10/TD_ScaleTransform.json +71 -0
- teradataml/data/jsons/sqle/17.10/TD_SimpleImputeFit.json +148 -0
- teradataml/data/jsons/sqle/17.10/TD_SimpleImputeTransform.json +48 -0
- teradataml/data/jsons/sqle/17.10/TD_StrApply.json +240 -0
- teradataml/data/jsons/sqle/17.10/TD_UnivariateStatistics.json +119 -0
- teradataml/data/jsons/sqle/17.10/TD_WhichMax.json +53 -0
- teradataml/data/jsons/sqle/17.10/TD_WhichMin.json +53 -0
- teradataml/data/jsons/sqle/17.10/TD_ZTest.json +171 -0
- teradataml/data/jsons/sqle/17.10/Unpack.json +188 -0
- teradataml/data/jsons/sqle/17.10/nPath.json +269 -0
- teradataml/data/jsons/sqle/17.20/Antiselect.json +56 -0
- teradataml/data/jsons/sqle/17.20/Attribution.json +249 -0
- teradataml/data/jsons/sqle/17.20/DecisionForestPredict.json +185 -0
- teradataml/data/jsons/sqle/17.20/DecisionTreePredict.json +172 -0
- teradataml/data/jsons/sqle/17.20/GLMPredict.json +151 -0
- teradataml/data/jsons/sqle/17.20/MovingAverage.json +367 -0
- teradataml/data/jsons/sqle/17.20/NGramSplitter.json +239 -0
- teradataml/data/jsons/sqle/17.20/NaiveBayesPredict.json +149 -0
- teradataml/data/jsons/sqle/17.20/NaiveBayesTextClassifierPredict.json +287 -0
- teradataml/data/jsons/sqle/17.20/Pack.json +133 -0
- teradataml/data/jsons/sqle/17.20/SVMSparsePredict.json +192 -0
- teradataml/data/jsons/sqle/17.20/Sessionize.json +105 -0
- teradataml/data/jsons/sqle/17.20/StringSimilarity.json +86 -0
- teradataml/data/jsons/sqle/17.20/TD_ANOVA.json +149 -0
- teradataml/data/jsons/sqle/17.20/TD_Apriori.json +181 -0
- teradataml/data/jsons/sqle/17.20/TD_BinCodeFit.json +239 -0
- teradataml/data/jsons/sqle/17.20/TD_BinCodeTransform.json +71 -0
- teradataml/data/jsons/sqle/17.20/TD_CFilter.json +118 -0
- teradataml/data/jsons/sqle/17.20/TD_CategoricalSummary.json +53 -0
- teradataml/data/jsons/sqle/17.20/TD_Chisq.json +68 -0
- teradataml/data/jsons/sqle/17.20/TD_ClassificationEvaluator.json +146 -0
- teradataml/data/jsons/sqle/17.20/TD_ColumnSummary.json +53 -0
- teradataml/data/jsons/sqle/17.20/TD_ColumnTransformer.json +218 -0
- teradataml/data/jsons/sqle/17.20/TD_ConvertTo.json +92 -0
- teradataml/data/jsons/sqle/17.20/TD_DecisionForest.json +260 -0
- teradataml/data/jsons/sqle/17.20/TD_DecisionForestPredict.json +139 -0
- teradataml/data/jsons/sqle/17.20/TD_FTest.json +269 -0
- teradataml/data/jsons/sqle/17.20/TD_FillRowID.json +52 -0
- teradataml/data/jsons/sqle/17.20/TD_FunctionFit.json +46 -0
- teradataml/data/jsons/sqle/17.20/TD_FunctionTransform.json +72 -0
- teradataml/data/jsons/sqle/17.20/TD_GLM.json +507 -0
- teradataml/data/jsons/sqle/17.20/TD_GLMPREDICT.json +168 -0
- teradataml/data/jsons/sqle/17.20/TD_GLMPerSegment.json +411 -0
- teradataml/data/jsons/sqle/17.20/TD_GLMPredictPerSegment.json +146 -0
- teradataml/data/jsons/sqle/17.20/TD_GetFutileColumns.json +93 -0
- teradataml/data/jsons/sqle/17.20/TD_GetRowsWithMissingValues.json +76 -0
- teradataml/data/jsons/sqle/17.20/TD_GetRowsWithoutMissingValues.json +76 -0
- teradataml/data/jsons/sqle/17.20/TD_Histogram.json +152 -0
- teradataml/data/jsons/sqle/17.20/TD_KMeans.json +232 -0
- teradataml/data/jsons/sqle/17.20/TD_KMeansPredict.json +87 -0
- teradataml/data/jsons/sqle/17.20/TD_KNN.json +262 -0
- teradataml/data/jsons/sqle/17.20/TD_NERExtractor.json +145 -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_NaiveBayesTextClassifierTrainer.json +137 -0
- teradataml/data/jsons/sqle/17.20/TD_NonLinearCombineFit.json +102 -0
- teradataml/data/jsons/sqle/17.20/TD_NonLinearCombineTransform.json +71 -0
- teradataml/data/jsons/sqle/17.20/TD_NumApply.json +147 -0
- teradataml/data/jsons/sqle/17.20/TD_OneClassSVM.json +316 -0
- teradataml/data/jsons/sqle/17.20/TD_OneClassSVMPredict.json +124 -0
- teradataml/data/jsons/sqle/17.20/TD_OneHotEncodingFit.json +271 -0
- teradataml/data/jsons/sqle/17.20/TD_OneHotEncodingTransform.json +65 -0
- teradataml/data/jsons/sqle/17.20/TD_OrdinalEncodingFit.json +229 -0
- teradataml/data/jsons/sqle/17.20/TD_OrdinalEncodingTransform.json +75 -0
- teradataml/data/jsons/sqle/17.20/TD_OutlierFilterFit.json +217 -0
- teradataml/data/jsons/sqle/17.20/TD_OutlierFilterTransform.json +48 -0
- teradataml/data/jsons/sqle/17.20/TD_Pivoting.json +280 -0
- teradataml/data/jsons/sqle/17.20/TD_PolynomialFeaturesFit.json +114 -0
- teradataml/data/jsons/sqle/17.20/TD_PolynomialFeaturesTransform.json +72 -0
- teradataml/data/jsons/sqle/17.20/TD_QQNorm.json +111 -0
- teradataml/data/jsons/sqle/17.20/TD_ROC.json +179 -0
- teradataml/data/jsons/sqle/17.20/TD_RandomProjectionFit.json +179 -0
- teradataml/data/jsons/sqle/17.20/TD_RandomProjectionMinComponents.json +74 -0
- teradataml/data/jsons/sqle/17.20/TD_RandomProjectionTransform.json +74 -0
- teradataml/data/jsons/sqle/17.20/TD_RegressionEvaluator.json +138 -0
- teradataml/data/jsons/sqle/17.20/TD_RoundColumns.json +93 -0
- teradataml/data/jsons/sqle/17.20/TD_RowNormalizeFit.json +128 -0
- teradataml/data/jsons/sqle/17.20/TD_RowNormalizeTransform.json +71 -0
- teradataml/data/jsons/sqle/17.20/TD_SMOTE.json +267 -0
- teradataml/data/jsons/sqle/17.20/TD_SVM.json +389 -0
- teradataml/data/jsons/sqle/17.20/TD_SVMPredict.json +142 -0
- teradataml/data/jsons/sqle/17.20/TD_ScaleFit.json +310 -0
- teradataml/data/jsons/sqle/17.20/TD_ScaleTransform.json +120 -0
- teradataml/data/jsons/sqle/17.20/TD_SentimentExtractor.json +194 -0
- teradataml/data/jsons/sqle/17.20/TD_Shap.json +221 -0
- teradataml/data/jsons/sqle/17.20/TD_Silhouette.json +143 -0
- teradataml/data/jsons/sqle/17.20/TD_SimpleImputeFit.json +147 -0
- teradataml/data/jsons/sqle/17.20/TD_SimpleImputeTransform.json +48 -0
- teradataml/data/jsons/sqle/17.20/TD_StrApply.json +240 -0
- teradataml/data/jsons/sqle/17.20/TD_TFIDF.json +162 -0
- teradataml/data/jsons/sqle/17.20/TD_TargetEncodingFit.json +248 -0
- teradataml/data/jsons/sqle/17.20/TD_TargetEncodingTransform.json +75 -0
- teradataml/data/jsons/sqle/17.20/TD_TextMorph.json +134 -0
- teradataml/data/jsons/sqle/17.20/TD_TextParser.json +297 -0
- teradataml/data/jsons/sqle/17.20/TD_TrainTestSplit.json +142 -0
- teradataml/data/jsons/sqle/17.20/TD_UnivariateStatistics.json +117 -0
- teradataml/data/jsons/sqle/17.20/TD_Unpivoting.json +235 -0
- teradataml/data/jsons/sqle/17.20/TD_VectorDistance.json +183 -0
- teradataml/data/jsons/sqle/17.20/TD_WhichMax.json +53 -0
- teradataml/data/jsons/sqle/17.20/TD_WhichMin.json +53 -0
- teradataml/data/jsons/sqle/17.20/TD_WordEmbeddings.json +241 -0
- teradataml/data/jsons/sqle/17.20/TD_XGBoost.json +330 -0
- teradataml/data/jsons/sqle/17.20/TD_XGBoostPredict.json +195 -0
- teradataml/data/jsons/sqle/17.20/TD_ZTest.json +247 -0
- teradataml/data/jsons/sqle/17.20/Unpack.json +188 -0
- teradataml/data/jsons/sqle/17.20/nPath.json +269 -0
- teradataml/data/jsons/sqle/20.00/AI_AnalyzeSentiment.json +370 -0
- teradataml/data/jsons/sqle/20.00/AI_AskLLM.json +460 -0
- teradataml/data/jsons/sqle/20.00/AI_DetectLanguage.json +385 -0
- teradataml/data/jsons/sqle/20.00/AI_ExtractKeyPhrases.json +369 -0
- teradataml/data/jsons/sqle/20.00/AI_MaskPII.json +369 -0
- teradataml/data/jsons/sqle/20.00/AI_RecognizeEntities.json +369 -0
- teradataml/data/jsons/sqle/20.00/AI_RecognizePIIEntities.json +369 -0
- teradataml/data/jsons/sqle/20.00/AI_TextClassifier.json +400 -0
- teradataml/data/jsons/sqle/20.00/AI_TextEmbeddings.json +401 -0
- teradataml/data/jsons/sqle/20.00/AI_TextSummarize.json +384 -0
- teradataml/data/jsons/sqle/20.00/AI_TextTranslate.json +384 -0
- teradataml/data/jsons/sqle/20.00/TD_API_AzureML.json +151 -0
- teradataml/data/jsons/sqle/20.00/TD_API_Sagemaker.json +182 -0
- teradataml/data/jsons/sqle/20.00/TD_API_VertexAI.json +183 -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 +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.00/read_nos.json +198 -0
- teradataml/data/jsons/tableoperator/17.05/read_nos.json +198 -0
- teradataml/data/jsons/tableoperator/17.05/write_nos.json +195 -0
- teradataml/data/jsons/tableoperator/17.10/read_nos.json +184 -0
- teradataml/data/jsons/tableoperator/17.10/write_nos.json +195 -0
- teradataml/data/jsons/tableoperator/17.20/IMAGE2MATRIX.json +53 -0
- teradataml/data/jsons/tableoperator/17.20/read_nos.json +183 -0
- teradataml/data/jsons/tableoperator/17.20/write_nos.json +224 -0
- teradataml/data/jsons/uaf/17.20/TD_ACF.json +132 -0
- teradataml/data/jsons/uaf/17.20/TD_ARIMAESTIMATE.json +396 -0
- teradataml/data/jsons/uaf/17.20/TD_ARIMAFORECAST.json +77 -0
- teradataml/data/jsons/uaf/17.20/TD_ARIMAVALIDATE.json +153 -0
- 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 +107 -0
- teradataml/data/jsons/uaf/17.20/TD_BINARYSERIESOP.json +106 -0
- teradataml/data/jsons/uaf/17.20/TD_BREUSCH_GODFREY.json +89 -0
- teradataml/data/jsons/uaf/17.20/TD_BREUSCH_PAGAN_GODFREY.json +104 -0
- teradataml/data/jsons/uaf/17.20/TD_CONVOLVE.json +78 -0
- teradataml/data/jsons/uaf/17.20/TD_CONVOLVE2.json +66 -0
- teradataml/data/jsons/uaf/17.20/TD_CUMUL_PERIODOGRAM.json +87 -0
- teradataml/data/jsons/uaf/17.20/TD_DFFT.json +134 -0
- teradataml/data/jsons/uaf/17.20/TD_DFFT2.json +144 -0
- teradataml/data/jsons/uaf/17.20/TD_DFFT2CONV.json +108 -0
- teradataml/data/jsons/uaf/17.20/TD_DFFTCONV.json +108 -0
- teradataml/data/jsons/uaf/17.20/TD_DICKEY_FULLER.json +78 -0
- teradataml/data/jsons/uaf/17.20/TD_DIFF.json +92 -0
- teradataml/data/jsons/uaf/17.20/TD_DTW.json +114 -0
- teradataml/data/jsons/uaf/17.20/TD_DURBIN_WATSON.json +101 -0
- 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_EXTRACT_RESULTS.json +39 -0
- teradataml/data/jsons/uaf/17.20/TD_FITMETRICS.json +101 -0
- teradataml/data/jsons/uaf/17.20/TD_GENSERIES4FORMULA.json +85 -0
- teradataml/data/jsons/uaf/17.20/TD_GENSERIES4SINUSOIDS.json +71 -0
- teradataml/data/jsons/uaf/17.20/TD_GOLDFELD_QUANDT.json +139 -0
- teradataml/data/jsons/uaf/17.20/TD_HOLT_WINTERS_FORECASTER.json +313 -0
- teradataml/data/jsons/uaf/17.20/TD_IDFFT.json +58 -0
- teradataml/data/jsons/uaf/17.20/TD_IDFFT2.json +81 -0
- 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_INPUTVALIDATOR.json +64 -0
- teradataml/data/jsons/uaf/17.20/TD_IQR.json +117 -0
- teradataml/data/jsons/uaf/17.20/TD_LINEAR_REGR.json +182 -0
- teradataml/data/jsons/uaf/17.20/TD_LINESPEC.json +103 -0
- teradataml/data/jsons/uaf/17.20/TD_MAMEAN.json +181 -0
- teradataml/data/jsons/uaf/17.20/TD_MATRIX2IMAGE.json +209 -0
- teradataml/data/jsons/uaf/17.20/TD_MATRIXMULTIPLY.json +68 -0
- teradataml/data/jsons/uaf/17.20/TD_MINFO.json +67 -0
- teradataml/data/jsons/uaf/17.20/TD_MULTIVAR_REGR.json +179 -0
- teradataml/data/jsons/uaf/17.20/TD_PACF.json +114 -0
- teradataml/data/jsons/uaf/17.20/TD_PORTMAN.json +119 -0
- teradataml/data/jsons/uaf/17.20/TD_POWERSPEC.json +175 -0
- teradataml/data/jsons/uaf/17.20/TD_POWERTRANSFORM.json +98 -0
- teradataml/data/jsons/uaf/17.20/TD_RESAMPLE.json +194 -0
- teradataml/data/jsons/uaf/17.20/TD_SAX.json +210 -0
- teradataml/data/jsons/uaf/17.20/TD_SEASONALNORMALIZE.json +143 -0
- teradataml/data/jsons/uaf/17.20/TD_SELECTION_CRITERIA.json +90 -0
- teradataml/data/jsons/uaf/17.20/TD_SIGNIF_PERIODICITIES.json +80 -0
- teradataml/data/jsons/uaf/17.20/TD_SIGNIF_RESIDMEAN.json +68 -0
- teradataml/data/jsons/uaf/17.20/TD_SIMPLEEXP.json +184 -0
- teradataml/data/jsons/uaf/17.20/TD_SINFO.json +58 -0
- teradataml/data/jsons/uaf/17.20/TD_SMOOTHMA.json +163 -0
- teradataml/data/jsons/uaf/17.20/TD_TRACKINGOP.json +101 -0
- teradataml/data/jsons/uaf/17.20/TD_UNDIFF.json +112 -0
- teradataml/data/jsons/uaf/17.20/TD_UNNORMALIZE.json +95 -0
- teradataml/data/jsons/uaf/17.20/TD_WHITES_GENERAL.json +78 -0
- teradataml/data/jsons/uaf/17.20/TD_WINDOWDFFT.json +410 -0
- teradataml/data/kmeans_example.json +23 -0
- teradataml/data/kmeans_table.csv +10 -0
- teradataml/data/kmeans_us_arrests_data.csv +51 -0
- teradataml/data/knn_example.json +19 -0
- teradataml/data/knnrecommender_example.json +7 -0
- teradataml/data/knnrecommenderpredict_example.json +12 -0
- teradataml/data/lar_example.json +17 -0
- teradataml/data/larpredict_example.json +30 -0
- teradataml/data/lc_new_predictors.csv +5 -0
- teradataml/data/lc_new_reference.csv +9 -0
- teradataml/data/lda_example.json +9 -0
- teradataml/data/ldainference_example.json +15 -0
- teradataml/data/ldatopicsummary_example.json +9 -0
- teradataml/data/levendist_input.csv +13 -0
- teradataml/data/levenshteindistance_example.json +10 -0
- teradataml/data/linreg_example.json +10 -0
- teradataml/data/load_example_data.py +350 -0
- teradataml/data/loan_prediction.csv +295 -0
- teradataml/data/lungcancer.csv +138 -0
- teradataml/data/mappingdata.csv +12 -0
- teradataml/data/medical_readings.csv +101 -0
- teradataml/data/milk_timeseries.csv +157 -0
- teradataml/data/min_max_titanic.csv +4 -0
- teradataml/data/minhash_example.json +6 -0
- teradataml/data/ml_ratings.csv +7547 -0
- teradataml/data/ml_ratings_10.csv +2445 -0
- teradataml/data/mobile_data.csv +13 -0
- teradataml/data/model1_table.csv +5 -0
- teradataml/data/model2_table.csv +5 -0
- teradataml/data/models/License_file.txt +1 -0
- teradataml/data/models/License_file_empty.txt +0 -0
- teradataml/data/models/dataiku_iris_data_ann_thin +0 -0
- teradataml/data/models/dr_iris_rf +0 -0
- teradataml/data/models/iris_db_dt_model_sklearn.onnx +0 -0
- teradataml/data/models/iris_db_dt_model_sklearn_floattensor.onnx +0 -0
- teradataml/data/models/iris_db_glm_model.pmml +57 -0
- teradataml/data/models/iris_db_xgb_model.pmml +4471 -0
- teradataml/data/models/iris_kmeans_model +0 -0
- teradataml/data/models/iris_mojo_glm_h2o_model +0 -0
- teradataml/data/models/iris_mojo_xgb_h2o_model +0 -0
- teradataml/data/modularity_example.json +12 -0
- teradataml/data/movavg_example.json +8 -0
- teradataml/data/mtx1.csv +7 -0
- teradataml/data/mtx2.csv +13 -0
- teradataml/data/multi_model_classification.csv +401 -0
- teradataml/data/multi_model_regression.csv +401 -0
- teradataml/data/mvdfft8.csv +9 -0
- teradataml/data/naivebayes_example.json +10 -0
- teradataml/data/naivebayespredict_example.json +19 -0
- teradataml/data/naivebayestextclassifier2_example.json +7 -0
- teradataml/data/naivebayestextclassifier_example.json +8 -0
- teradataml/data/naivebayestextclassifierpredict_example.json +32 -0
- teradataml/data/name_Find_configure.csv +10 -0
- teradataml/data/namedentityfinder_example.json +14 -0
- teradataml/data/namedentityfinderevaluator_example.json +10 -0
- teradataml/data/namedentityfindertrainer_example.json +6 -0
- teradataml/data/nb_iris_input_test.csv +31 -0
- teradataml/data/nb_iris_input_train.csv +121 -0
- teradataml/data/nbp_iris_model.csv +13 -0
- teradataml/data/ner_dict.csv +8 -0
- teradataml/data/ner_extractor_text.csv +2 -0
- teradataml/data/ner_input_eng.csv +7 -0
- teradataml/data/ner_rule.csv +5 -0
- teradataml/data/ner_sports_test2.csv +29 -0
- teradataml/data/ner_sports_train.csv +501 -0
- teradataml/data/nerevaluator_example.json +6 -0
- teradataml/data/nerextractor_example.json +18 -0
- teradataml/data/nermem_sports_test.csv +18 -0
- teradataml/data/nermem_sports_train.csv +51 -0
- teradataml/data/nertrainer_example.json +7 -0
- teradataml/data/ngrams_example.json +7 -0
- teradataml/data/notebooks/__init__.py +0 -0
- teradataml/data/notebooks/sqlalchemy/Teradata Vantage Aggregate Functions using SQLAlchemy.ipynb +1455 -0
- teradataml/data/notebooks/sqlalchemy/Teradata Vantage Arithmetic Functions Using SQLAlchemy.ipynb +1993 -0
- teradataml/data/notebooks/sqlalchemy/Teradata Vantage Bit-Byte Manipulation Functions using SQLAlchemy.ipynb +1492 -0
- teradataml/data/notebooks/sqlalchemy/Teradata Vantage Built-in functions using SQLAlchemy.ipynb +536 -0
- teradataml/data/notebooks/sqlalchemy/Teradata Vantage Regular Expressions Using SQLAlchemy.ipynb +570 -0
- teradataml/data/notebooks/sqlalchemy/Teradata Vantage String Functions Using SQLAlchemy.ipynb +2559 -0
- teradataml/data/notebooks/sqlalchemy/Teradata Vantage Window Aggregate Functions using SQLAlchemy.ipynb +2911 -0
- teradataml/data/notebooks/sqlalchemy/Using Generic SQLAlchemy ClauseElements teradataml DataFrame assign method.ipynb +698 -0
- teradataml/data/notebooks/sqlalchemy/__init__.py +0 -0
- teradataml/data/notebooks/sqlalchemy/teradataml filtering using SQLAlchemy ClauseElements.ipynb +784 -0
- teradataml/data/npath_example.json +23 -0
- teradataml/data/ntree_example.json +14 -0
- teradataml/data/numeric_strings.csv +5 -0
- teradataml/data/numerics.csv +4 -0
- teradataml/data/ocean_buoy.csv +17 -0
- teradataml/data/ocean_buoy2.csv +17 -0
- teradataml/data/ocean_buoys.csv +28 -0
- teradataml/data/ocean_buoys2.csv +10 -0
- teradataml/data/ocean_buoys_nonpti.csv +28 -0
- teradataml/data/ocean_buoys_seq.csv +29 -0
- teradataml/data/onehot_encoder_train.csv +4 -0
- teradataml/data/openml_example.json +92 -0
- teradataml/data/optional_event_table.csv +4 -0
- teradataml/data/orders1.csv +11 -0
- teradataml/data/orders1_12.csv +13 -0
- teradataml/data/orders_ex.csv +4 -0
- teradataml/data/pack_example.json +9 -0
- teradataml/data/package_tracking.csv +19 -0
- teradataml/data/package_tracking_pti.csv +19 -0
- teradataml/data/pagerank_example.json +13 -0
- teradataml/data/paragraphs_input.csv +6 -0
- teradataml/data/pathanalyzer_example.json +8 -0
- teradataml/data/pathgenerator_example.json +8 -0
- teradataml/data/patient_profile.csv +101 -0
- teradataml/data/pattern_matching_data.csv +11 -0
- teradataml/data/payment_fraud_dataset.csv +10001 -0
- teradataml/data/peppers.png +0 -0
- teradataml/data/phrases.csv +7 -0
- teradataml/data/pivot_example.json +9 -0
- teradataml/data/pivot_input.csv +22 -0
- teradataml/data/playerRating.csv +31 -0
- teradataml/data/pos_input.csv +40 -0
- teradataml/data/postagger_example.json +7 -0
- teradataml/data/posttagger_output.csv +44 -0
- teradataml/data/production_data.csv +17 -0
- teradataml/data/production_data2.csv +7 -0
- teradataml/data/randomsample_example.json +32 -0
- teradataml/data/randomwalksample_example.json +9 -0
- teradataml/data/rank_table.csv +6 -0
- teradataml/data/real_values.csv +14 -0
- teradataml/data/ref_mobile_data.csv +4 -0
- teradataml/data/ref_mobile_data_dense.csv +2 -0
- teradataml/data/ref_url.csv +17 -0
- teradataml/data/restaurant_reviews.csv +7 -0
- teradataml/data/retail_churn_table.csv +27772 -0
- teradataml/data/river_data.csv +145 -0
- teradataml/data/roc_example.json +8 -0
- teradataml/data/roc_input.csv +101 -0
- teradataml/data/rule_inputs.csv +6 -0
- teradataml/data/rule_table.csv +2 -0
- teradataml/data/sales.csv +7 -0
- teradataml/data/sales_transaction.csv +501 -0
- teradataml/data/salesdata.csv +342 -0
- teradataml/data/sample_cities.csv +3 -0
- teradataml/data/sample_shapes.csv +11 -0
- teradataml/data/sample_streets.csv +3 -0
- teradataml/data/sampling_example.json +16 -0
- teradataml/data/sax_example.json +17 -0
- teradataml/data/scale_attributes.csv +3 -0
- teradataml/data/scale_example.json +74 -0
- teradataml/data/scale_housing.csv +11 -0
- teradataml/data/scale_housing_test.csv +6 -0
- 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/scale_stat.csv +11 -0
- teradataml/data/scalebypartition_example.json +13 -0
- teradataml/data/scalemap_example.json +13 -0
- teradataml/data/scalesummary_example.json +12 -0
- teradataml/data/score_category.csv +101 -0
- teradataml/data/score_summary.csv +4 -0
- teradataml/data/script_example.json +10 -0
- teradataml/data/scripts/deploy_script.py +84 -0
- teradataml/data/scripts/lightgbm/dataset.template +175 -0
- teradataml/data/scripts/lightgbm/lightgbm_class_functions.template +264 -0
- teradataml/data/scripts/lightgbm/lightgbm_function.template +234 -0
- teradataml/data/scripts/lightgbm/lightgbm_sklearn.template +177 -0
- teradataml/data/scripts/mapper.R +20 -0
- teradataml/data/scripts/mapper.py +16 -0
- teradataml/data/scripts/mapper_replace.py +16 -0
- teradataml/data/scripts/sklearn/__init__.py +0 -0
- teradataml/data/scripts/sklearn/sklearn_fit.py +205 -0
- teradataml/data/scripts/sklearn/sklearn_fit_predict.py +148 -0
- teradataml/data/scripts/sklearn/sklearn_function.template +144 -0
- teradataml/data/scripts/sklearn/sklearn_model_selection_split.py +166 -0
- teradataml/data/scripts/sklearn/sklearn_neighbors.py +161 -0
- teradataml/data/scripts/sklearn/sklearn_score.py +145 -0
- teradataml/data/scripts/sklearn/sklearn_transform.py +327 -0
- teradataml/data/sdk/modelops/modelops_spec.json +101737 -0
- teradataml/data/seeds.csv +10 -0
- teradataml/data/sentenceextractor_example.json +7 -0
- teradataml/data/sentiment_extract_input.csv +11 -0
- teradataml/data/sentiment_train.csv +16 -0
- teradataml/data/sentiment_word.csv +20 -0
- teradataml/data/sentiment_word_input.csv +20 -0
- teradataml/data/sentimentextractor_example.json +24 -0
- teradataml/data/sentimenttrainer_example.json +8 -0
- teradataml/data/sequence_table.csv +10 -0
- teradataml/data/seriessplitter_example.json +8 -0
- teradataml/data/sessionize_example.json +17 -0
- teradataml/data/sessionize_table.csv +116 -0
- teradataml/data/setop_test1.csv +24 -0
- teradataml/data/setop_test2.csv +22 -0
- teradataml/data/soc_nw_edges.csv +11 -0
- teradataml/data/soc_nw_vertices.csv +8 -0
- teradataml/data/souvenir_timeseries.csv +168 -0
- teradataml/data/sparse_iris_attribute.csv +5 -0
- teradataml/data/sparse_iris_test.csv +121 -0
- teradataml/data/sparse_iris_train.csv +601 -0
- teradataml/data/star1.csv +6 -0
- teradataml/data/star_pivot.csv +8 -0
- teradataml/data/state_transition.csv +5 -0
- teradataml/data/stock_data.csv +53 -0
- teradataml/data/stock_movement.csv +11 -0
- teradataml/data/stock_vol.csv +76 -0
- teradataml/data/stop_words.csv +8 -0
- teradataml/data/store_sales.csv +37 -0
- teradataml/data/stringsimilarity_example.json +8 -0
- teradataml/data/strsimilarity_input.csv +13 -0
- teradataml/data/students.csv +101 -0
- teradataml/data/svm_iris_input_test.csv +121 -0
- teradataml/data/svm_iris_input_train.csv +481 -0
- teradataml/data/svm_iris_model.csv +7 -0
- teradataml/data/svmdense_example.json +10 -0
- teradataml/data/svmdensepredict_example.json +19 -0
- teradataml/data/svmsparse_example.json +8 -0
- teradataml/data/svmsparsepredict_example.json +14 -0
- teradataml/data/svmsparsesummary_example.json +8 -0
- teradataml/data/target_mobile_data.csv +13 -0
- teradataml/data/target_mobile_data_dense.csv +5 -0
- teradataml/data/target_udt_data.csv +8 -0
- teradataml/data/tdnerextractor_example.json +14 -0
- teradataml/data/templatedata.csv +1201 -0
- teradataml/data/templates/open_source_ml.json +11 -0
- teradataml/data/teradata_icon.ico +0 -0
- teradataml/data/teradataml_example.json +1473 -0
- teradataml/data/test_classification.csv +101 -0
- teradataml/data/test_loan_prediction.csv +53 -0
- teradataml/data/test_pacf_12.csv +37 -0
- teradataml/data/test_prediction.csv +101 -0
- teradataml/data/test_regression.csv +101 -0
- teradataml/data/test_river2.csv +109 -0
- teradataml/data/text_inputs.csv +6 -0
- teradataml/data/textchunker_example.json +8 -0
- teradataml/data/textclassifier_example.json +7 -0
- teradataml/data/textclassifier_input.csv +7 -0
- teradataml/data/textclassifiertrainer_example.json +7 -0
- teradataml/data/textmorph_example.json +11 -0
- teradataml/data/textparser_example.json +15 -0
- teradataml/data/texttagger_example.json +12 -0
- teradataml/data/texttokenizer_example.json +7 -0
- teradataml/data/texttrainer_input.csv +11 -0
- teradataml/data/tf_example.json +7 -0
- teradataml/data/tfidf_example.json +14 -0
- teradataml/data/tfidf_input1.csv +201 -0
- teradataml/data/tfidf_train.csv +6 -0
- teradataml/data/time_table1.csv +535 -0
- teradataml/data/time_table2.csv +14 -0
- teradataml/data/timeseriesdata.csv +1601 -0
- teradataml/data/timeseriesdatasetsd4.csv +105 -0
- teradataml/data/timestamp_data.csv +4 -0
- teradataml/data/titanic.csv +892 -0
- teradataml/data/titanic_dataset_unpivoted.csv +19 -0
- teradataml/data/to_num_data.csv +4 -0
- teradataml/data/tochar_data.csv +5 -0
- teradataml/data/token_table.csv +696 -0
- teradataml/data/train_multiclass.csv +101 -0
- teradataml/data/train_regression.csv +101 -0
- teradataml/data/train_regression_multiple_labels.csv +101 -0
- teradataml/data/train_tracking.csv +28 -0
- teradataml/data/trans_dense.csv +16 -0
- teradataml/data/trans_sparse.csv +55 -0
- teradataml/data/transformation_table.csv +6 -0
- teradataml/data/transformation_table_new.csv +2 -0
- teradataml/data/tv_spots.csv +16 -0
- teradataml/data/twod_climate_data.csv +117 -0
- teradataml/data/uaf_example.json +529 -0
- teradataml/data/univariatestatistics_example.json +9 -0
- teradataml/data/unpack_example.json +10 -0
- teradataml/data/unpivot_example.json +25 -0
- teradataml/data/unpivot_input.csv +8 -0
- teradataml/data/url_data.csv +10 -0
- teradataml/data/us_air_pass.csv +37 -0
- teradataml/data/us_population.csv +624 -0
- teradataml/data/us_states_shapes.csv +52 -0
- teradataml/data/varmax_example.json +18 -0
- teradataml/data/vectordistance_example.json +30 -0
- teradataml/data/ville_climatedata.csv +121 -0
- teradataml/data/ville_tempdata.csv +12 -0
- teradataml/data/ville_tempdata1.csv +12 -0
- teradataml/data/ville_temperature.csv +11 -0
- teradataml/data/waveletTable.csv +1605 -0
- teradataml/data/waveletTable2.csv +1605 -0
- teradataml/data/weightedmovavg_example.json +9 -0
- teradataml/data/wft_testing.csv +5 -0
- teradataml/data/windowdfft.csv +16 -0
- teradataml/data/wine_data.csv +1600 -0
- teradataml/data/word_embed_input_table1.csv +6 -0
- teradataml/data/word_embed_input_table2.csv +5 -0
- teradataml/data/word_embed_model.csv +23 -0
- teradataml/data/words_input.csv +13 -0
- teradataml/data/xconvolve_complex_left.csv +6 -0
- teradataml/data/xconvolve_complex_leftmulti.csv +6 -0
- teradataml/data/xgboost_example.json +36 -0
- teradataml/data/xgboostpredict_example.json +32 -0
- teradataml/data/ztest_example.json +16 -0
- teradataml/dataframe/__init__.py +0 -0
- teradataml/dataframe/copy_to.py +2446 -0
- teradataml/dataframe/data_transfer.py +2840 -0
- teradataml/dataframe/dataframe.py +20908 -0
- teradataml/dataframe/dataframe_utils.py +2114 -0
- teradataml/dataframe/fastload.py +794 -0
- teradataml/dataframe/functions.py +2110 -0
- teradataml/dataframe/indexer.py +424 -0
- teradataml/dataframe/row.py +160 -0
- teradataml/dataframe/setop.py +1171 -0
- teradataml/dataframe/sql.py +10904 -0
- teradataml/dataframe/sql_function_parameters.py +440 -0
- teradataml/dataframe/sql_functions.py +652 -0
- teradataml/dataframe/sql_interfaces.py +220 -0
- teradataml/dataframe/vantage_function_types.py +675 -0
- teradataml/dataframe/window.py +694 -0
- teradataml/dbutils/__init__.py +3 -0
- teradataml/dbutils/dbutils.py +2871 -0
- teradataml/dbutils/filemgr.py +318 -0
- teradataml/gen_ai/__init__.py +2 -0
- teradataml/gen_ai/convAI.py +473 -0
- teradataml/geospatial/__init__.py +4 -0
- teradataml/geospatial/geodataframe.py +1105 -0
- teradataml/geospatial/geodataframecolumn.py +392 -0
- teradataml/geospatial/geometry_types.py +926 -0
- teradataml/hyperparameter_tuner/__init__.py +1 -0
- teradataml/hyperparameter_tuner/optimizer.py +4115 -0
- teradataml/hyperparameter_tuner/utils.py +303 -0
- teradataml/lib/__init__.py +0 -0
- teradataml/lib/aed_0_1.dll +0 -0
- teradataml/lib/libaed_0_1.dylib +0 -0
- teradataml/lib/libaed_0_1.so +0 -0
- teradataml/lib/libaed_0_1_aarch64.so +0 -0
- teradataml/lib/libaed_0_1_ppc64le.so +0 -0
- teradataml/opensource/__init__.py +1 -0
- teradataml/opensource/_base.py +1321 -0
- teradataml/opensource/_class.py +464 -0
- teradataml/opensource/_constants.py +61 -0
- teradataml/opensource/_lightgbm.py +949 -0
- teradataml/opensource/_sklearn.py +1008 -0
- teradataml/opensource/_wrapper_utils.py +267 -0
- teradataml/options/__init__.py +148 -0
- teradataml/options/configure.py +489 -0
- teradataml/options/display.py +187 -0
- teradataml/plot/__init__.py +3 -0
- teradataml/plot/axis.py +1427 -0
- teradataml/plot/constants.py +15 -0
- teradataml/plot/figure.py +431 -0
- teradataml/plot/plot.py +810 -0
- teradataml/plot/query_generator.py +83 -0
- teradataml/plot/subplot.py +216 -0
- teradataml/scriptmgmt/UserEnv.py +4273 -0
- teradataml/scriptmgmt/__init__.py +3 -0
- teradataml/scriptmgmt/lls_utils.py +2157 -0
- teradataml/sdk/README.md +79 -0
- teradataml/sdk/__init__.py +4 -0
- teradataml/sdk/_auth_modes.py +422 -0
- teradataml/sdk/_func_params.py +487 -0
- teradataml/sdk/_json_parser.py +453 -0
- teradataml/sdk/_openapi_spec_constants.py +249 -0
- teradataml/sdk/_utils.py +236 -0
- teradataml/sdk/api_client.py +900 -0
- teradataml/sdk/constants.py +62 -0
- teradataml/sdk/modelops/__init__.py +98 -0
- teradataml/sdk/modelops/_client.py +409 -0
- teradataml/sdk/modelops/_constants.py +304 -0
- teradataml/sdk/modelops/models.py +2308 -0
- teradataml/sdk/spinner.py +107 -0
- teradataml/series/__init__.py +0 -0
- teradataml/series/series.py +537 -0
- teradataml/series/series_utils.py +71 -0
- teradataml/store/__init__.py +12 -0
- teradataml/store/feature_store/__init__.py +0 -0
- teradataml/store/feature_store/constants.py +658 -0
- teradataml/store/feature_store/feature_store.py +4814 -0
- teradataml/store/feature_store/mind_map.py +639 -0
- teradataml/store/feature_store/models.py +7330 -0
- teradataml/store/feature_store/utils.py +390 -0
- teradataml/table_operators/Apply.py +979 -0
- teradataml/table_operators/Script.py +1739 -0
- teradataml/table_operators/TableOperator.py +1343 -0
- teradataml/table_operators/__init__.py +2 -0
- teradataml/table_operators/apply_query_generator.py +262 -0
- teradataml/table_operators/query_generator.py +493 -0
- teradataml/table_operators/table_operator_query_generator.py +462 -0
- teradataml/table_operators/table_operator_util.py +726 -0
- teradataml/table_operators/templates/dataframe_apply.template +184 -0
- teradataml/table_operators/templates/dataframe_map.template +176 -0
- teradataml/table_operators/templates/dataframe_register.template +73 -0
- teradataml/table_operators/templates/dataframe_udf.template +67 -0
- teradataml/table_operators/templates/script_executor.template +170 -0
- teradataml/telemetry_utils/__init__.py +0 -0
- teradataml/telemetry_utils/queryband.py +53 -0
- teradataml/utils/__init__.py +0 -0
- teradataml/utils/docstring.py +527 -0
- teradataml/utils/dtypes.py +943 -0
- teradataml/utils/internal_buffer.py +122 -0
- teradataml/utils/print_versions.py +206 -0
- teradataml/utils/utils.py +451 -0
- teradataml/utils/validators.py +3305 -0
- teradataml-20.0.0.8.dist-info/METADATA +2804 -0
- teradataml-20.0.0.8.dist-info/RECORD +1208 -0
- teradataml-20.0.0.8.dist-info/WHEEL +5 -0
- teradataml-20.0.0.8.dist-info/top_level.txt +1 -0
- teradataml-20.0.0.8.dist-info/zip-safe +1 -0
|
@@ -0,0 +1,3166 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Unpublished work.
|
|
4
|
+
Copyright (c) 2018 by Teradata Corporation. All rights reserved.
|
|
5
|
+
TERADATA CORPORATION CONFIDENTIAL AND TRADE SECRET
|
|
6
|
+
|
|
7
|
+
Primary Owner: mounika.kotha@teradata.com
|
|
8
|
+
Secondary Owner:
|
|
9
|
+
|
|
10
|
+
This is a common class to include common functionality required
|
|
11
|
+
by other classes which can be reused according to the need.
|
|
12
|
+
|
|
13
|
+
Add all the common functions in this class like creating temporary table names, getting
|
|
14
|
+
the datatypes etc.
|
|
15
|
+
"""
|
|
16
|
+
import datetime
|
|
17
|
+
import json
|
|
18
|
+
import os
|
|
19
|
+
import re
|
|
20
|
+
import time
|
|
21
|
+
import uuid, hashlib
|
|
22
|
+
import warnings
|
|
23
|
+
from functools import reduce
|
|
24
|
+
from inspect import getsource
|
|
25
|
+
from math import floor
|
|
26
|
+
|
|
27
|
+
import requests
|
|
28
|
+
import sqlalchemy
|
|
29
|
+
from numpy import number
|
|
30
|
+
from sqlalchemy import Column, MetaData, Table
|
|
31
|
+
from sqlalchemy.exc import OperationalError as sqlachemyOperationalError
|
|
32
|
+
from teradatasql import OperationalError
|
|
33
|
+
from teradatasqlalchemy.dialect import dialect as td_dialect
|
|
34
|
+
from teradatasqlalchemy.dialect import preparer
|
|
35
|
+
from teradatasqlalchemy.types import (BIGINT, BLOB, BYTE, BYTEINT, CHAR, CLOB,
|
|
36
|
+
DATE, DECIMAL, FLOAT, INTEGER, NUMBER,
|
|
37
|
+
SMALLINT, TIME, TIMESTAMP, VARBYTE,
|
|
38
|
+
VARCHAR, _TDType)
|
|
39
|
+
|
|
40
|
+
from teradataml import _version
|
|
41
|
+
from teradataml.common import td_coltype_code_to_tdtype
|
|
42
|
+
from teradataml.common.constants import (HTTPRequest, PTITableConstants,
|
|
43
|
+
PythonTypes, SQLConstants,
|
|
44
|
+
TeradataConstants,
|
|
45
|
+
TeradataReservedKeywords, TeradataTableKindConstants,
|
|
46
|
+
TeradataTypes)
|
|
47
|
+
from teradataml.common.exceptions import TeradataMlException
|
|
48
|
+
from teradataml.common.garbagecollector import GarbageCollector
|
|
49
|
+
from teradataml.common.messagecodes import MessageCodes
|
|
50
|
+
from teradataml.common.messages import Messages
|
|
51
|
+
from teradataml.common.sqlbundle import SQLBundle
|
|
52
|
+
from teradataml.common.warnings import (OneTimeUserWarning,
|
|
53
|
+
VantageRuntimeWarning)
|
|
54
|
+
from teradataml.common.logger import get_td_logger
|
|
55
|
+
from teradataml.context import context as tdmlctx
|
|
56
|
+
from teradataml.options.configure import configure
|
|
57
|
+
from teradataml.options.display import display
|
|
58
|
+
from teradataml.telemetry_utils.queryband import collect_queryband
|
|
59
|
+
from teradataml.utils.utils import execute_sql
|
|
60
|
+
from teradataml.utils.validators import _Validators
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class UtilFuncs():
|
|
64
|
+
def _get_numeric_datatypes(self):
|
|
65
|
+
"""
|
|
66
|
+
Returns the numeric data types used in Teradata Vantage
|
|
67
|
+
**From : https://www.info.teradata.com/HTMLPubs/DB_TTU_16_00/
|
|
68
|
+
index.html#page/General_Reference/B035-1091-160K/psa1472241434371.html
|
|
69
|
+
|
|
70
|
+
PARAMETERS:
|
|
71
|
+
None
|
|
72
|
+
|
|
73
|
+
RAISES:
|
|
74
|
+
None
|
|
75
|
+
|
|
76
|
+
RETURNS:
|
|
77
|
+
List of numeric data types used in Teradata Vantage
|
|
78
|
+
"""
|
|
79
|
+
return [BYTEINT, SMALLINT, INTEGER, BIGINT, DECIMAL, FLOAT, NUMBER]
|
|
80
|
+
|
|
81
|
+
def _get_timedate_datatypes(self):
|
|
82
|
+
"""
|
|
83
|
+
Returns a list of TimeDate data types.
|
|
84
|
+
|
|
85
|
+
PARAMETERS:
|
|
86
|
+
None
|
|
87
|
+
|
|
88
|
+
RAISES:
|
|
89
|
+
None
|
|
90
|
+
|
|
91
|
+
RETURNS:
|
|
92
|
+
List of TimeDate data types used in Teradata Vantage
|
|
93
|
+
"""
|
|
94
|
+
return [TIMESTAMP, DATE, TIME]
|
|
95
|
+
|
|
96
|
+
def _get_character_datatypes(self):
|
|
97
|
+
"""
|
|
98
|
+
Returns a list of Character data types.
|
|
99
|
+
|
|
100
|
+
PARAMETERS:
|
|
101
|
+
None
|
|
102
|
+
|
|
103
|
+
RAISES:
|
|
104
|
+
None
|
|
105
|
+
|
|
106
|
+
RETURNS:
|
|
107
|
+
List of Character data types used in Teradata Vantage
|
|
108
|
+
"""
|
|
109
|
+
return [CHAR, VARCHAR, CLOB]
|
|
110
|
+
|
|
111
|
+
def _get_byte_datatypes(self):
|
|
112
|
+
"""
|
|
113
|
+
Returns a list of byte like data types.
|
|
114
|
+
|
|
115
|
+
PARAMETERS:
|
|
116
|
+
None
|
|
117
|
+
|
|
118
|
+
RAISES:
|
|
119
|
+
None
|
|
120
|
+
|
|
121
|
+
RETURNS:
|
|
122
|
+
List of Byte data types used in Teradata Vantage
|
|
123
|
+
"""
|
|
124
|
+
return [BYTE, VARBYTE, BLOB]
|
|
125
|
+
|
|
126
|
+
def _get_categorical_datatypes(self):
|
|
127
|
+
"""
|
|
128
|
+
Returns a list of containing Character and TimeDate data types.
|
|
129
|
+
|
|
130
|
+
PARAMETERS:
|
|
131
|
+
None
|
|
132
|
+
|
|
133
|
+
RAISES:
|
|
134
|
+
None
|
|
135
|
+
|
|
136
|
+
RETURNS:
|
|
137
|
+
List of Character and TimeDate data types used in Teradata Vantage
|
|
138
|
+
"""
|
|
139
|
+
return list.__add__(self._get_character_datatypes(), self._get_timedate_datatypes())
|
|
140
|
+
|
|
141
|
+
def _get_all_datatypes(self):
|
|
142
|
+
"""
|
|
143
|
+
Returns a list of Character, Numeric and TimeDate data types.
|
|
144
|
+
|
|
145
|
+
PARAMETERS:
|
|
146
|
+
None
|
|
147
|
+
|
|
148
|
+
RAISES:
|
|
149
|
+
None
|
|
150
|
+
|
|
151
|
+
RETURNS:
|
|
152
|
+
List of Character, Numeric and TimeDate data types used in Teradata Vantage
|
|
153
|
+
"""
|
|
154
|
+
return list.__add__(self._get_categorical_datatypes(), self._get_numeric_datatypes())
|
|
155
|
+
|
|
156
|
+
def _get_db_name_from_dataframe(self, df):
|
|
157
|
+
"""
|
|
158
|
+
DESCRIPTION:
|
|
159
|
+
Function to get database name from teradataml DataFrame.
|
|
160
|
+
|
|
161
|
+
PARAMETERS:
|
|
162
|
+
df:
|
|
163
|
+
Required Argument.
|
|
164
|
+
Specifies the input teradataml DataFrame.
|
|
165
|
+
Types: teradataml DataFrame
|
|
166
|
+
|
|
167
|
+
RETURNS:
|
|
168
|
+
Database name.
|
|
169
|
+
|
|
170
|
+
RAISES:
|
|
171
|
+
None.
|
|
172
|
+
|
|
173
|
+
EXAMPLES:
|
|
174
|
+
UtilFuncs()._get_db_name_from_dataframe(df)
|
|
175
|
+
"""
|
|
176
|
+
if df._table_name is None:
|
|
177
|
+
from teradataml.dataframe.dataframe_utils import DataFrameUtils
|
|
178
|
+
df._table_name = DataFrameUtils()._execute_node_return_db_object_name(df._nodeid,
|
|
179
|
+
df._metaexpr)
|
|
180
|
+
|
|
181
|
+
db_name = self._extract_db_name(df._table_name)
|
|
182
|
+
if db_name is None or db_name == "":
|
|
183
|
+
# Extract db_name from SQLAlchemy Engine URL.
|
|
184
|
+
if 'DATABASE' in tdmlctx.get_context().url.query:
|
|
185
|
+
db_name = tdmlctx.get_context().url.query['DATABASE']
|
|
186
|
+
else:
|
|
187
|
+
db_name = tdmlctx._get_current_databasename()
|
|
188
|
+
else:
|
|
189
|
+
db_name = db_name.replace("\"", "")
|
|
190
|
+
|
|
191
|
+
return db_name
|
|
192
|
+
|
|
193
|
+
@staticmethod
|
|
194
|
+
def _get_valid_aggregate_operations():
|
|
195
|
+
"""
|
|
196
|
+
Returns the list of valid aggregate operations on Teradata Vantage
|
|
197
|
+
|
|
198
|
+
PARAMETERS:
|
|
199
|
+
None
|
|
200
|
+
|
|
201
|
+
RAISES:
|
|
202
|
+
None
|
|
203
|
+
|
|
204
|
+
RETURNS:
|
|
205
|
+
List of valid aggregate operations possible on Teradata Vantage
|
|
206
|
+
"""
|
|
207
|
+
return ['count', 'kurtosis', 'max', 'mean', 'median', 'min', 'percentile', 'skew', 'std',
|
|
208
|
+
'sum', 'unique', 'var']
|
|
209
|
+
|
|
210
|
+
@staticmethod
|
|
211
|
+
def _get_valid_time_series_aggregate_operations():
|
|
212
|
+
"""
|
|
213
|
+
Returns the list of valid aggregate operations on Teradata Vantage
|
|
214
|
+
|
|
215
|
+
PARAMETERS:
|
|
216
|
+
None
|
|
217
|
+
|
|
218
|
+
RAISES:
|
|
219
|
+
None
|
|
220
|
+
|
|
221
|
+
RETURNS:
|
|
222
|
+
List of valid aggregate operations possible on Teradata Vantage
|
|
223
|
+
"""
|
|
224
|
+
return ['bottom', 'bottom with ties', 'delta_t', 'first', 'last', 'mad', 'mode', 'top',
|
|
225
|
+
'top with ties']
|
|
226
|
+
|
|
227
|
+
@staticmethod
|
|
228
|
+
def _generate_temp_table_name(databasename=None, user=None, prefix=None,
|
|
229
|
+
use_default_database=False, gc_on_quit=True, quote=True,
|
|
230
|
+
table_type=TeradataConstants.TERADATA_VIEW):
|
|
231
|
+
"""
|
|
232
|
+
DESCRIPTION:
|
|
233
|
+
Function to return the random string for temporary table names.
|
|
234
|
+
|
|
235
|
+
PARAMETERS:
|
|
236
|
+
databasename:
|
|
237
|
+
Optional Argument.
|
|
238
|
+
Specifies the database name to use while generating the script.
|
|
239
|
+
Types: str
|
|
240
|
+
|
|
241
|
+
user:
|
|
242
|
+
Optional Argument.
|
|
243
|
+
Specifies the current username or database name on which user logged on to Teradata Vantage.
|
|
244
|
+
Types: str
|
|
245
|
+
|
|
246
|
+
prefix:
|
|
247
|
+
Optional Argument.
|
|
248
|
+
Specifies the prefix of the module from which table/view name is requested.
|
|
249
|
+
Types: str
|
|
250
|
+
|
|
251
|
+
use_default_database:
|
|
252
|
+
Optional Argument.
|
|
253
|
+
Specifies whether to create a table or view in the default database when
|
|
254
|
+
"databasename" is not provided.
|
|
255
|
+
Default value: False
|
|
256
|
+
Types: str
|
|
257
|
+
|
|
258
|
+
gc_on_quit:
|
|
259
|
+
Optional Argument.
|
|
260
|
+
Specifies whether to garbage collect the table/view with the generated name
|
|
261
|
+
at the end of the session.
|
|
262
|
+
When 'True', the objects created with the generated name will be garbage
|
|
263
|
+
collected at the end of the session.
|
|
264
|
+
Default value: True
|
|
265
|
+
Types: bool
|
|
266
|
+
|
|
267
|
+
quote:
|
|
268
|
+
Optional Argument.
|
|
269
|
+
Specifies whether to quote the database name and table/view name.
|
|
270
|
+
When 'True', quotes are added around the database name and the table/view name.
|
|
271
|
+
Default value: True
|
|
272
|
+
Types: bool
|
|
273
|
+
|
|
274
|
+
table_type:
|
|
275
|
+
Optional Argument.
|
|
276
|
+
Specifies the type of objects - table or view.
|
|
277
|
+
Default value: TeradataConstants.TERADATA_VIEW
|
|
278
|
+
Types: TeradataConstant
|
|
279
|
+
|
|
280
|
+
RETURNS:
|
|
281
|
+
Temporary table name.
|
|
282
|
+
|
|
283
|
+
RAISES:
|
|
284
|
+
|
|
285
|
+
EXAMPLES:
|
|
286
|
+
>>> new_table_name = UtilFuncs._generate_temp_table_name(user='tdqg', prefix="from_pandas")
|
|
287
|
+
>>> new_table_name = UtilFuncs._generate_temp_table_name(user='tdqg', prefix="from_pandas",
|
|
288
|
+
table_type = TeradataConstants.TERADATA_VIEW)
|
|
289
|
+
>>> new_table_name = UtilFuncs._generate_temp_table_name(user='tdqg', prefix="from_pandas",
|
|
290
|
+
table_type = TeradataConstants.TERADATA_TABLE)
|
|
291
|
+
# Example when use_short_object_name is set to True
|
|
292
|
+
>>> from teradataml.options.configure import configure
|
|
293
|
+
>>> configure.use_short_object_name = True
|
|
294
|
+
>>> new_table_name = UtilFuncs._generate_temp_table_name(user='tdqg', prefix="from_pandas")
|
|
295
|
+
|
|
296
|
+
Output:
|
|
297
|
+
tdml_temp_table__1517501990393350 (or)
|
|
298
|
+
tdqg.tdml_temp_table__1517501990393350 (or)
|
|
299
|
+
tdml_temp_table__from_pandas_1517501990393350 (or)
|
|
300
|
+
tdqg.tdml_temp_table__from_pandas_1517501990393350 (or)
|
|
301
|
+
ml__1749637109887272
|
|
302
|
+
"""
|
|
303
|
+
# Number of seconds since Jan 1, 1970 00:00:00
|
|
304
|
+
timestamp = time.time()
|
|
305
|
+
use_short_name = configure.use_short_object_name
|
|
306
|
+
tabname = "ml_"
|
|
307
|
+
random_string = "{}{}".format(floor(timestamp / 1000000),
|
|
308
|
+
floor(timestamp % 1000000 * 1000000 +
|
|
309
|
+
int(str(uuid.uuid4().fields[-1])[:10])))
|
|
310
|
+
|
|
311
|
+
# Append prefix only if use_short_object_name is False and prefix is provided.
|
|
312
|
+
if (not use_short_name) and (prefix is not None):
|
|
313
|
+
tabname = "{}_{}".format(tabname, prefix)
|
|
314
|
+
# Append prefix "tdml" when use_short_object_name is True and random string is of length 15.
|
|
315
|
+
elif use_short_name and (len(random_string)==15):
|
|
316
|
+
tabname = "tdml"
|
|
317
|
+
|
|
318
|
+
tabname = "{}_{}".format(tabname, random_string)
|
|
319
|
+
|
|
320
|
+
# ELE-6710 - Use database user associated with the current context for volatile tables.
|
|
321
|
+
if table_type == TeradataConstants.TERADATA_VOLATILE_TABLE:
|
|
322
|
+
from teradataml.context.context import _get_user
|
|
323
|
+
tabname = "\"{}\".\"{}\"".format(_get_user(), tabname)
|
|
324
|
+
return tabname
|
|
325
|
+
|
|
326
|
+
if (not use_short_name) and (configure.temp_object_type == TeradataConstants.
|
|
327
|
+
TERADATA_VOLATILE_TABLE):
|
|
328
|
+
from teradataml.context.context import _get_user
|
|
329
|
+
return "\"{}\".\"{}_{}\"".format(_get_user(), "vt", tabname)
|
|
330
|
+
|
|
331
|
+
if use_default_database and databasename is None:
|
|
332
|
+
tabname = "\"{}\".\"{}\"".format(tdmlctx._get_context_temp_databasename(
|
|
333
|
+
table_type=table_type), tabname)
|
|
334
|
+
|
|
335
|
+
if user is not None:
|
|
336
|
+
tabname = "\"{}\".\"{}\"".format(user, tabname)
|
|
337
|
+
|
|
338
|
+
if databasename is not None:
|
|
339
|
+
tabname = "\"{}\".\"{}\"".format(databasename, tabname)
|
|
340
|
+
|
|
341
|
+
# Enable garbage collection for the temporary view & table created while transformations.
|
|
342
|
+
if gc_on_quit:
|
|
343
|
+
GarbageCollector._add_to_garbagecollector(tabname, table_type)
|
|
344
|
+
|
|
345
|
+
return tabname
|
|
346
|
+
|
|
347
|
+
@staticmethod
|
|
348
|
+
def _generate_temp_script_name(database_name=None, prefix=None, use_default_database=True,
|
|
349
|
+
gc_on_quit=True, quote=True,
|
|
350
|
+
script_type=TeradataConstants.TERADATA_SCRIPT,
|
|
351
|
+
extension=None):
|
|
352
|
+
"""
|
|
353
|
+
DESCRIPTION:
|
|
354
|
+
Function to return the random string for temporary script names.
|
|
355
|
+
|
|
356
|
+
PARAMETERS:
|
|
357
|
+
database_name:
|
|
358
|
+
Optional Argument:
|
|
359
|
+
Specifies the database name on which user logged on to Teradata Vantage.
|
|
360
|
+
Types: str
|
|
361
|
+
|
|
362
|
+
prefix:
|
|
363
|
+
Optional Argument.
|
|
364
|
+
Specifies the prefix of the module or function from which script name is requested.
|
|
365
|
+
Types: str
|
|
366
|
+
|
|
367
|
+
use_default_database:
|
|
368
|
+
Optional Argument.
|
|
369
|
+
Specifies whether the script will be installed in the default/connected database.
|
|
370
|
+
When 'True', the current/default database name will be used for generating the name.
|
|
371
|
+
Default value: True
|
|
372
|
+
Types: bool
|
|
373
|
+
|
|
374
|
+
gc_on_quit:
|
|
375
|
+
Optional Argument.
|
|
376
|
+
Specifies whether to garbage collect the object with the generated name
|
|
377
|
+
at the end of the session.
|
|
378
|
+
When 'True', the objects created with the generated name will be garbage
|
|
379
|
+
collected at the end of the session.
|
|
380
|
+
Default value: True
|
|
381
|
+
Types: bool
|
|
382
|
+
|
|
383
|
+
quote:
|
|
384
|
+
Optional Argument.
|
|
385
|
+
Specifies whether to quote the database name and script name.
|
|
386
|
+
When 'True', quotes are added around the database name and the script name.
|
|
387
|
+
Default value: True
|
|
388
|
+
Types: bool
|
|
389
|
+
|
|
390
|
+
script_type:
|
|
391
|
+
Optional Argument.
|
|
392
|
+
Specifies the type of script.
|
|
393
|
+
Default value: TeradataConstants.TERADATA_SCRIPT
|
|
394
|
+
Types: TeradataConstant
|
|
395
|
+
|
|
396
|
+
extension:
|
|
397
|
+
Optional Argument.
|
|
398
|
+
Specifies the extension of the script.
|
|
399
|
+
Default value: None
|
|
400
|
+
Types: str
|
|
401
|
+
|
|
402
|
+
RETURNS:
|
|
403
|
+
Temporary script name.
|
|
404
|
+
|
|
405
|
+
RAISES:
|
|
406
|
+
None.
|
|
407
|
+
|
|
408
|
+
EXAMPLES:
|
|
409
|
+
new_script_name = UtilFuncs._generate_temp_script_name(use_default_database=True,
|
|
410
|
+
script_type = TeradataConstants.TERADATA_SCRIPT)
|
|
411
|
+
"""
|
|
412
|
+
# NOTE:
|
|
413
|
+
# 1. There can be other types of scripts going forward which may require their own type (like for Apply).
|
|
414
|
+
# Hence, we have a 'script_type' argument which currently has only one possible value.
|
|
415
|
+
# 2. Currently map_row and map_partition use only default database, but going forward this can be changed
|
|
416
|
+
# to use other databases for installation of script, using 'database_name'.
|
|
417
|
+
|
|
418
|
+
timestamp = time.time()
|
|
419
|
+
script_name = "ml_"
|
|
420
|
+
|
|
421
|
+
random_string = "{}{}".format(floor(timestamp / 1000000),
|
|
422
|
+
floor(timestamp % 1000000 * 1000000 +
|
|
423
|
+
int(str(uuid.uuid4().fields[-1])[:10])))
|
|
424
|
+
|
|
425
|
+
if prefix is not None:
|
|
426
|
+
script_name = "{}_{}".format(script_name, prefix)
|
|
427
|
+
|
|
428
|
+
script_name = "{}_{}".format(script_name, random_string)
|
|
429
|
+
|
|
430
|
+
if extension is not None:
|
|
431
|
+
script_name = "{}.{}".format(script_name, extension)
|
|
432
|
+
|
|
433
|
+
dbname_to_use = tdmlctx._get_current_databasename()
|
|
434
|
+
if not use_default_database and database_name is not None:
|
|
435
|
+
dbname_to_use = database_name
|
|
436
|
+
|
|
437
|
+
script_name = "\"{}\".\"{}\"".format(dbname_to_use, script_name)
|
|
438
|
+
|
|
439
|
+
# Enable garbage collection for the temporary script created.
|
|
440
|
+
if gc_on_quit:
|
|
441
|
+
GarbageCollector._add_to_garbagecollector(script_name, script_type)
|
|
442
|
+
|
|
443
|
+
return script_name
|
|
444
|
+
|
|
445
|
+
@staticmethod
|
|
446
|
+
def _serialize_and_encode(obj):
|
|
447
|
+
"""
|
|
448
|
+
DESCRIPTION:
|
|
449
|
+
Internal utility to serialize any Python object (including functions)
|
|
450
|
+
using dill and encode using base64.
|
|
451
|
+
|
|
452
|
+
PARAMETERS:
|
|
453
|
+
obj:
|
|
454
|
+
Specifies the Python object to serialize and encode.
|
|
455
|
+
Types: object
|
|
456
|
+
|
|
457
|
+
RAISES:
|
|
458
|
+
None.
|
|
459
|
+
|
|
460
|
+
RETURNS:
|
|
461
|
+
An encoded byte string representing the serialized object 'obj'.
|
|
462
|
+
|
|
463
|
+
EXAMPLES:
|
|
464
|
+
>>> # Serializing and encoding a literal value
|
|
465
|
+
>>> literal = UtilFuncs._serialize_and_encode('literal value')
|
|
466
|
+
>>> # Serializing and encoding a function
|
|
467
|
+
>>> def udf(a, b): return a + b
|
|
468
|
+
>>> func = UtilFuncs._serialize_and_encode(udf)
|
|
469
|
+
"""
|
|
470
|
+
from base64 import b64encode as base64_b64encode
|
|
471
|
+
|
|
472
|
+
from dill import dumps as dill_dumps
|
|
473
|
+
|
|
474
|
+
return base64_b64encode(dill_dumps(obj, recurse=True))
|
|
475
|
+
|
|
476
|
+
@staticmethod
|
|
477
|
+
def _quote_table_names(table_name):
|
|
478
|
+
"""
|
|
479
|
+
Quotes table names or view names.
|
|
480
|
+
If the table name is in the format schema.table_name, it will quote the
|
|
481
|
+
schema name and table name.
|
|
482
|
+
|
|
483
|
+
Example:
|
|
484
|
+
mytab -> "my.tab"
|
|
485
|
+
schema.mytable -> "schema"."my.tab"
|
|
486
|
+
myview -> "myview"
|
|
487
|
+
|
|
488
|
+
PARAMETERS:
|
|
489
|
+
table_name - The name of table or view. The name can include the schema (e.g. schema.table_name)
|
|
490
|
+
|
|
491
|
+
RETURNS:
|
|
492
|
+
returns the quoted table name.
|
|
493
|
+
|
|
494
|
+
RAISES:
|
|
495
|
+
|
|
496
|
+
EXAMPLES:
|
|
497
|
+
table_name = UtilFuncs._quote_table_names(table_name)
|
|
498
|
+
|
|
499
|
+
"""
|
|
500
|
+
table_name_list = re.findall('".+?"', table_name)
|
|
501
|
+
if table_name_list:
|
|
502
|
+
for i in range(0, len(table_name_list)):
|
|
503
|
+
if not (table_name_list[i].startswith("\"") and table_name_list[i].endswith("\"")):
|
|
504
|
+
table_name_list[i] = UtilFuncs._teradata_quote_arg(table_name_list[i], "\"", False)
|
|
505
|
+
|
|
506
|
+
return ".".join(table_name_list)
|
|
507
|
+
else:
|
|
508
|
+
return "\"{}\"".format(table_name)
|
|
509
|
+
|
|
510
|
+
@staticmethod
|
|
511
|
+
def _execute_ddl_statement(ddl_statement):
|
|
512
|
+
"""
|
|
513
|
+
Executes a DDL statment and commits transaction
|
|
514
|
+
This is an internal function.
|
|
515
|
+
|
|
516
|
+
PARAMETERS:
|
|
517
|
+
ddl_statement - Teradata DDL statement.
|
|
518
|
+
|
|
519
|
+
RETURNS:
|
|
520
|
+
|
|
521
|
+
RAISES:
|
|
522
|
+
Database error if an error occurred while executing the DDL statement.
|
|
523
|
+
|
|
524
|
+
EXAMPLES:
|
|
525
|
+
UtilFuncs._execute_ddl_statement('create table mytab (col1 int, col2 varchar(20))')
|
|
526
|
+
|
|
527
|
+
"""
|
|
528
|
+
# Empty queryband buffer before SQL call.
|
|
529
|
+
UtilFuncs._set_queryband()
|
|
530
|
+
# Let's execute our DDL statement with escape function '{fn teradata_fake_result_sets}'
|
|
531
|
+
# offered by teradatasql driver. This function will allow us catch any warnings thrown
|
|
532
|
+
# from the Vantage. Hence, executing the DDL statement with this escape function.
|
|
533
|
+
ddl_statement = "{fn teradata_fake_result_sets} " + ddl_statement
|
|
534
|
+
|
|
535
|
+
if tdmlctx.td_connection is not None:
|
|
536
|
+
cursor = None
|
|
537
|
+
try:
|
|
538
|
+
conn = tdmlctx.td_connection.connection
|
|
539
|
+
cursor = conn.cursor()
|
|
540
|
+
get_td_logger().debug("Executing DDL statement: {0}".format(ddl_statement))
|
|
541
|
+
cursor.execute(ddl_statement)
|
|
542
|
+
|
|
543
|
+
# Warnings are displayed when the "suppress_vantage_runtime_warnings" attribute is set to 'False'.
|
|
544
|
+
if not display.suppress_vantage_runtime_warnings:
|
|
545
|
+
# Fetch the result set just to check whether we have received any warnings or not.
|
|
546
|
+
warnRes = cursor.fetchone()
|
|
547
|
+
# Check for "display.suppress_vantage_runtime_warnings" set to 'True'.
|
|
548
|
+
# Check for warning code and warning message
|
|
549
|
+
# warnRes[5] contains the Warning Code
|
|
550
|
+
# warnRes[6] contains the actual Warning Message
|
|
551
|
+
if warnRes[5] != 0 and warnRes[6] != "":
|
|
552
|
+
# Raise warning raised from Vantage as is.
|
|
553
|
+
warnings.simplefilter("always")
|
|
554
|
+
msg_ = Messages.get_message(MessageCodes.VANTAGE_WARNING)
|
|
555
|
+
warnings.warn(msg_.format(warnRes[5], warnRes[6]), VantageRuntimeWarning)
|
|
556
|
+
|
|
557
|
+
conn.commit()
|
|
558
|
+
except:
|
|
559
|
+
# logger.debug("Got exception while executing ({0})".format(teradataSQL))
|
|
560
|
+
raise
|
|
561
|
+
finally:
|
|
562
|
+
if cursor:
|
|
563
|
+
cursor.close()
|
|
564
|
+
else:
|
|
565
|
+
raise TeradataMlException(Messages.get_message(MessageCodes.CONNECTION_FAILURE),
|
|
566
|
+
MessageCodes.CONNECTION_FAILURE)
|
|
567
|
+
|
|
568
|
+
@staticmethod
|
|
569
|
+
def _execute_query(query, fetchWarnings=False, expect_none_result=False):
|
|
570
|
+
"""
|
|
571
|
+
Retrieves result set data from query.
|
|
572
|
+
|
|
573
|
+
PARAMETERS:
|
|
574
|
+
query:
|
|
575
|
+
Required Argument.
|
|
576
|
+
Specifies the SQL query to execute.
|
|
577
|
+
Types: str
|
|
578
|
+
|
|
579
|
+
fetchWarnings:
|
|
580
|
+
Optional Argument.
|
|
581
|
+
Specifies a flag that decides whether to raise warnings thrown from Vanatge or not.
|
|
582
|
+
Default Values: False
|
|
583
|
+
Types: bool
|
|
584
|
+
|
|
585
|
+
expect_none_result:
|
|
586
|
+
Optional Argument.
|
|
587
|
+
When set to True, warnings will not be fetched and only result set is fetched.
|
|
588
|
+
Returns None if no result set is received from the backend.
|
|
589
|
+
When fetchWarnings is set to True this option is ignored.
|
|
590
|
+
Default Values: False
|
|
591
|
+
Types: bool
|
|
592
|
+
|
|
593
|
+
RETURNS:
|
|
594
|
+
Returns only result set from query if 'fetchWarnings' is False. If set to True, then
|
|
595
|
+
return result set and columns for the result set.
|
|
596
|
+
|
|
597
|
+
RAISES:
|
|
598
|
+
Database error if an error occurred while executing query.
|
|
599
|
+
|
|
600
|
+
EXAMPLES:
|
|
601
|
+
result = UtilFuncs._execute_query('select col1, col2 from mytab')
|
|
602
|
+
result = UtilFuncs._execute_query('help column mytab.*')
|
|
603
|
+
|
|
604
|
+
result = UtilFuncs._execute_query('help column mytab.*')
|
|
605
|
+
|
|
606
|
+
# Execute the stored procedure using fetchWarnings.
|
|
607
|
+
UtilFuncs._execute_query("call SYSUIF.INSTALL_FILE('myfile',
|
|
608
|
+
'filename.py',
|
|
609
|
+
'cb!/Documents/filename.py')",
|
|
610
|
+
True, False)
|
|
611
|
+
|
|
612
|
+
# Execute the stored procedure without fetchWarnings but still needs resultsets.
|
|
613
|
+
UtilFuncs._execute_query("call SYSUIF.list_base_environments()", False, True)
|
|
614
|
+
|
|
615
|
+
"""
|
|
616
|
+
# Empty queryband buffer before SQL call.
|
|
617
|
+
UtilFuncs._set_queryband()
|
|
618
|
+
|
|
619
|
+
if fetchWarnings:
|
|
620
|
+
# Let's execute our DDL statement with escape function '{fn teradata_fake_result_sets}'
|
|
621
|
+
# offered by teradatasql driver. This function will allow us catch any warnings thrown
|
|
622
|
+
# from the Vantage. Hence, executing the DDL statement with this escape function.
|
|
623
|
+
query = "{fn teradata_fake_result_sets} " + query
|
|
624
|
+
|
|
625
|
+
if tdmlctx.td_connection is not None:
|
|
626
|
+
cursor = None
|
|
627
|
+
try:
|
|
628
|
+
conn = tdmlctx.td_connection.connection
|
|
629
|
+
cursor = conn.cursor()
|
|
630
|
+
get_td_logger().debug("Executing query: {0}\nfetchWarnings: {1}\nexpect_none_result: {2}".format(query, fetchWarnings, expect_none_result))
|
|
631
|
+
cursor.execute(query)
|
|
632
|
+
|
|
633
|
+
if fetchWarnings:
|
|
634
|
+
# Fetch the result set just to check whether we have received any warnings or not.
|
|
635
|
+
warnRes = cursor.fetchone()
|
|
636
|
+
# Check for warning code and warning message
|
|
637
|
+
# warnRes[5] contains the Warning Code
|
|
638
|
+
# warnRes[6] contains the actual Warning Message
|
|
639
|
+
if (warnRes[5] != 0 and warnRes[6] != "") and not display.suppress_vantage_runtime_warnings:
|
|
640
|
+
# Raise warning raised from Vantage as is.
|
|
641
|
+
warnings.simplefilter("always")
|
|
642
|
+
msg_ = Messages.get_message(MessageCodes.VANTAGE_WARNING)
|
|
643
|
+
warnings.warn(msg_.format(warnRes[5], warnRes[6]), VantageRuntimeWarning)
|
|
644
|
+
|
|
645
|
+
cursor.nextset()
|
|
646
|
+
|
|
647
|
+
return cursor.fetchall(), [col_desc[0] for col_desc in cursor.description]
|
|
648
|
+
|
|
649
|
+
# This check may be removed if DBS side stored procedure are fixed to return empty
|
|
650
|
+
# result sets with columns in cursor.description
|
|
651
|
+
elif expect_none_result:
|
|
652
|
+
cursor.nextset()
|
|
653
|
+
# Some stored procedure returns None if result set has no rows.
|
|
654
|
+
# cannot use fetchall call in such cases. If SPs are fixed to support result sets with zero
|
|
655
|
+
# rows then below call may be removed in the future.
|
|
656
|
+
if cursor.rowcount <= 0:
|
|
657
|
+
return None, None
|
|
658
|
+
return cursor.fetchall(), [col_desc[0] for col_desc in cursor.description]
|
|
659
|
+
|
|
660
|
+
else:
|
|
661
|
+
return cursor.fetchall()
|
|
662
|
+
except:
|
|
663
|
+
raise
|
|
664
|
+
finally:
|
|
665
|
+
if cursor:
|
|
666
|
+
cursor.close()
|
|
667
|
+
else:
|
|
668
|
+
raise TeradataMlException(Messages.get_message(MessageCodes.CONNECTION_FAILURE),
|
|
669
|
+
MessageCodes.CONNECTION_FAILURE)
|
|
670
|
+
|
|
671
|
+
@staticmethod
|
|
672
|
+
@collect_queryband(queryband='CreateView')
|
|
673
|
+
def _create_view(view_name, query, lock_rows=False):
|
|
674
|
+
"""
|
|
675
|
+
Create a view from the given query.
|
|
676
|
+
|
|
677
|
+
PARAMETERS:
|
|
678
|
+
view_name - View name
|
|
679
|
+
query - SQL query
|
|
680
|
+
lock_rows - When set to True, teradataml DataFrame locks the corresponding row(s)
|
|
681
|
+
in underlying table(s) while accessing the data. Otherwise,
|
|
682
|
+
teradataml DataFrame access the data without locking the rows.
|
|
683
|
+
Default is False.
|
|
684
|
+
|
|
685
|
+
RAISES
|
|
686
|
+
|
|
687
|
+
RETURNS:
|
|
688
|
+
True if success.
|
|
689
|
+
|
|
690
|
+
EXAMPLES:
|
|
691
|
+
UtilFuncs._create_view(view_name, "select * from table_name")
|
|
692
|
+
"""
|
|
693
|
+
|
|
694
|
+
crt_view = SQLBundle._build_create_view(view_name, query, lock_rows)
|
|
695
|
+
try:
|
|
696
|
+
get_td_logger().debug("Creating view: {0}".format(crt_view))
|
|
697
|
+
UtilFuncs._execute_ddl_statement(crt_view)
|
|
698
|
+
return True
|
|
699
|
+
except:
|
|
700
|
+
raise
|
|
701
|
+
|
|
702
|
+
@staticmethod
|
|
703
|
+
@collect_queryband(queryband='CreateTbl')
|
|
704
|
+
def _create_table(table_name, query, volatile=False):
|
|
705
|
+
"""
|
|
706
|
+
Create a table from the given query.
|
|
707
|
+
|
|
708
|
+
PARAMETERS:
|
|
709
|
+
table_name - Fully qualified quoted table name.
|
|
710
|
+
query - SQL query
|
|
711
|
+
volatile - Specifies whether to create volatile table or not.
|
|
712
|
+
When set to True, volatile table is created, otherwise
|
|
713
|
+
permanent table is created.
|
|
714
|
+
|
|
715
|
+
RAISES
|
|
716
|
+
|
|
717
|
+
RETURNS:
|
|
718
|
+
True if success, false if fails
|
|
719
|
+
|
|
720
|
+
EXAMPLES:
|
|
721
|
+
UtilFuncs._create_table('"dbname"."table_name"', "select * from table_name")
|
|
722
|
+
"""
|
|
723
|
+
|
|
724
|
+
crt_table = SQLBundle._build_create_table_with_data(table_name, query)
|
|
725
|
+
if volatile:
|
|
726
|
+
crt_table = SQLBundle._build_create_volatile_table_with_data(table_name, query)
|
|
727
|
+
|
|
728
|
+
get_td_logger().debug("Creating table: {0}\nVolatile: {1}".format(crt_table, volatile))
|
|
729
|
+
UtilFuncs._execute_ddl_statement(crt_table)
|
|
730
|
+
return True
|
|
731
|
+
|
|
732
|
+
@staticmethod
|
|
733
|
+
def _get_non_null_counts(col_names, table_name):
|
|
734
|
+
"""
|
|
735
|
+
Returns a list of non-null count for each column in col_names from table table_name.
|
|
736
|
+
|
|
737
|
+
PARAMETERS:
|
|
738
|
+
col_names - list of column names for table table_name.
|
|
739
|
+
table_name - table name.
|
|
740
|
+
|
|
741
|
+
RETURNS:
|
|
742
|
+
returns a list of non-null counts for each column.
|
|
743
|
+
|
|
744
|
+
RAISES:
|
|
745
|
+
|
|
746
|
+
EXAMPLES:
|
|
747
|
+
UtilFuncs._get_non_null_counts(col_names, 'mytab')
|
|
748
|
+
|
|
749
|
+
"""
|
|
750
|
+
count_col_names = ["count(\"{0}\")".format(name) for name in col_names]
|
|
751
|
+
select_count = "select {0} from {1}".format(", ".join(count_col_names), table_name)
|
|
752
|
+
result = UtilFuncs._execute_query(select_count)
|
|
753
|
+
return [str(i) for i in result[0]]
|
|
754
|
+
|
|
755
|
+
@staticmethod
|
|
756
|
+
@collect_queryband(queryband='CreateVolaTbl')
|
|
757
|
+
def _get_volatile_table(query, with_data=False):
|
|
758
|
+
"""
|
|
759
|
+
Creates a volatile table as query.
|
|
760
|
+
If with_data is True, creates the volatile table with data.
|
|
761
|
+
Else, creates the volatile table without data.
|
|
762
|
+
|
|
763
|
+
PARAMETERS:
|
|
764
|
+
query - The query used to create the volatile table.
|
|
765
|
+
with_data(optional) - True, creates table with data.
|
|
766
|
+
False, creates table without data. Default is False
|
|
767
|
+
|
|
768
|
+
RETURNS:
|
|
769
|
+
returns the temporary name of the volatile table.
|
|
770
|
+
|
|
771
|
+
RAISES:
|
|
772
|
+
Database error if an error occurred while creating the volatile table.
|
|
773
|
+
|
|
774
|
+
EXAMPLES:
|
|
775
|
+
UtilFuncs._get_volatile_table('select col1, col2, from mytab')
|
|
776
|
+
UtilFuncs._get_volatile_table('select col1, col2, from mytab', with_data=True)
|
|
777
|
+
|
|
778
|
+
"""
|
|
779
|
+
vtab_name = UtilFuncs._generate_temp_table_name()
|
|
780
|
+
if with_data:
|
|
781
|
+
create_vtab_ddl = SQLBundle._build_create_volatile_table_with_data(vtab_name, query)
|
|
782
|
+
else:
|
|
783
|
+
create_vtab_ddl = SQLBundle._build_create_volatile_table_without_data(vtab_name, query)
|
|
784
|
+
UtilFuncs._execute_ddl_statement(create_vtab_ddl)
|
|
785
|
+
return vtab_name
|
|
786
|
+
|
|
787
|
+
@staticmethod
|
|
788
|
+
def _drop_table(table_name, check_table_exist=True, purge_clause=None):
|
|
789
|
+
"""
|
|
790
|
+
Drops a table.
|
|
791
|
+
|
|
792
|
+
PARAMETERS:
|
|
793
|
+
table_name - The table to drop.
|
|
794
|
+
check_table_exist - Checks if the table exist before dropping the table.
|
|
795
|
+
purge_clause - Specifies string representing purge clause to be appended to drop table query.
|
|
796
|
+
|
|
797
|
+
RETURNS:
|
|
798
|
+
True - if the table is dropped.
|
|
799
|
+
|
|
800
|
+
RAISES:
|
|
801
|
+
Database error if an error occurred while dropping the table.
|
|
802
|
+
|
|
803
|
+
EXAMPLES:
|
|
804
|
+
UtilFuncs._drop_table('mytab')
|
|
805
|
+
UtilFuncs._drop_table('mytab', check_table_exist = False)
|
|
806
|
+
UtilFuncs._drop_table('mydb.mytab', check_table_exist = False)
|
|
807
|
+
UtilFuncs._drop_table("mydb"."mytab", check_table_exist = True)
|
|
808
|
+
UtilFuncs._drop_table("my_lake"."my_db"."my_tab", purge_clause='PURGE ALL')
|
|
809
|
+
UtilFuncs._drop_table("my_lake"."my_db"."my_tab", purge_clause='NO PURGE')
|
|
810
|
+
|
|
811
|
+
"""
|
|
812
|
+
drop_tab = SQLBundle._build_drop_table(table_name, purge_clause)
|
|
813
|
+
if check_table_exist is True:
|
|
814
|
+
helptable = UtilFuncs._get_help_tablename(table_name)
|
|
815
|
+
if helptable:
|
|
816
|
+
UtilFuncs._execute_ddl_statement(drop_tab)
|
|
817
|
+
return True
|
|
818
|
+
else:
|
|
819
|
+
UtilFuncs._execute_ddl_statement(drop_tab)
|
|
820
|
+
return True
|
|
821
|
+
|
|
822
|
+
return False
|
|
823
|
+
|
|
824
|
+
@staticmethod
|
|
825
|
+
def _drop_view(view_name, check_view_exist=True):
|
|
826
|
+
"""
|
|
827
|
+
Drops a view.
|
|
828
|
+
|
|
829
|
+
PARAMETERS:
|
|
830
|
+
view_name - The view to drop.
|
|
831
|
+
check_view_exist - Checks if the view exist before dropping the view.
|
|
832
|
+
|
|
833
|
+
RETURNS:
|
|
834
|
+
True - if the view is dropped.
|
|
835
|
+
|
|
836
|
+
RAISES:
|
|
837
|
+
Database error if an error occurred while dropping the view.
|
|
838
|
+
|
|
839
|
+
EXAMPLES:
|
|
840
|
+
UtilFuncs._drop_view('myview')
|
|
841
|
+
UtilFuncs._drop_view('myview', check_view_exist = False)
|
|
842
|
+
UtilFuncs._drop_view('mydb.myview', check_view_exist = False)
|
|
843
|
+
UtilFuncs._drop_view("mydb"."myview", check_view_exist = True)
|
|
844
|
+
"""
|
|
845
|
+
drop_view = SQLBundle._build_drop_view(view_name)
|
|
846
|
+
if check_view_exist is True:
|
|
847
|
+
viewdetails = UtilFuncs._get_help_viewname(view_name)
|
|
848
|
+
if viewdetails:
|
|
849
|
+
UtilFuncs._execute_ddl_statement(drop_view)
|
|
850
|
+
return True
|
|
851
|
+
else:
|
|
852
|
+
UtilFuncs._execute_ddl_statement(drop_view)
|
|
853
|
+
return True
|
|
854
|
+
|
|
855
|
+
return False
|
|
856
|
+
|
|
857
|
+
@staticmethod
|
|
858
|
+
def _delete_script(script_name, file_type=TeradataConstants.TERADATA_SCRIPT,
|
|
859
|
+
check_script_exist=True):
|
|
860
|
+
"""
|
|
861
|
+
DESCRIPTION:
|
|
862
|
+
Function to remove a user-installed file/script.
|
|
863
|
+
|
|
864
|
+
PARAMETERS:
|
|
865
|
+
script_name:
|
|
866
|
+
Required Argument.
|
|
867
|
+
Specifies the name of the script to remove.
|
|
868
|
+
Types: str
|
|
869
|
+
|
|
870
|
+
file_type:
|
|
871
|
+
Optional Argument.
|
|
872
|
+
Specifies the type of the file to remove, whether it is from
|
|
873
|
+
Enterpise (TeradataConstants.TERADATA_SCRIPT) or from Lake
|
|
874
|
+
(TeradataConstants.TERADATA_APPLY).
|
|
875
|
+
Default value: TeradataConstants.TERADATA_SCRIPT
|
|
876
|
+
Permitted Values: TeradataConstants.TERADATA_SCRIPT, TeradataConstants.TERADATA_APPLY
|
|
877
|
+
Types: TeradataConstants
|
|
878
|
+
|
|
879
|
+
check_script_exist:
|
|
880
|
+
Required Argument. Applicable only when "file_type" is
|
|
881
|
+
TeradataConstants.TERADATA_SCRIPT. Ignored otherwise.
|
|
882
|
+
Specifies whether to check if the script exists or not before removing it.
|
|
883
|
+
When 'True', the presence of the script will be check for.
|
|
884
|
+
Default value: True
|
|
885
|
+
Types: bool
|
|
886
|
+
|
|
887
|
+
RETURNS:
|
|
888
|
+
True - if the script is removed.
|
|
889
|
+
|
|
890
|
+
RAISES:
|
|
891
|
+
Database error if an error occurred while dropping the view.
|
|
892
|
+
|
|
893
|
+
EXAMPLES:
|
|
894
|
+
UtilFuncs._delete_script('myview')
|
|
895
|
+
UtilFuncs._delete_script('myview', check_script_exist = False)
|
|
896
|
+
UtilFuncs._delete_script('mydb.myview', check_script_exist = False)
|
|
897
|
+
UtilFuncs._delete_script("mydb"."myview", check_script_exist = True)
|
|
898
|
+
"""
|
|
899
|
+
dbname = UtilFuncs._teradata_unquote_arg(UtilFuncs._extract_db_name(script_name),
|
|
900
|
+
quote='"')
|
|
901
|
+
script_alias = UtilFuncs._teradata_unquote_arg(UtilFuncs._extract_table_name(script_name),
|
|
902
|
+
quote='"')
|
|
903
|
+
current_db = tdmlctx._get_current_databasename()
|
|
904
|
+
|
|
905
|
+
if file_type == TeradataConstants.TERADATA_SCRIPT:
|
|
906
|
+
script_exists = False
|
|
907
|
+
if check_script_exist:
|
|
908
|
+
query = "select count(*) from dbc.tablesV " \
|
|
909
|
+
"where databasename = '{}' and tablename = '{}' " \
|
|
910
|
+
"and tablekind = 'Z'".format(dbname, script_alias)
|
|
911
|
+
|
|
912
|
+
script_exists = True if UtilFuncs._execute_query(query)[0][0] == 1 else False
|
|
913
|
+
|
|
914
|
+
if script_exists or not check_script_exist:
|
|
915
|
+
try:
|
|
916
|
+
# If the database is not the current/default database, we need to
|
|
917
|
+
# set that as the session database to be able to remove the file.
|
|
918
|
+
if dbname and dbname.lower() != current_db.lower():
|
|
919
|
+
execute_sql('database {}'.format(dbname))
|
|
920
|
+
|
|
921
|
+
# Strip off the file extension and extract the base name.
|
|
922
|
+
from pathlib import Path
|
|
923
|
+
script_base_name = Path(script_alias).stem
|
|
924
|
+
|
|
925
|
+
# Remove the file.
|
|
926
|
+
remove_file(script_base_name, force_remove=True, suppress_output=True)
|
|
927
|
+
return True
|
|
928
|
+
except:
|
|
929
|
+
raise
|
|
930
|
+
finally:
|
|
931
|
+
# Reset the database if it was set to something else.
|
|
932
|
+
if dbname and dbname.lower() != current_db.lower():
|
|
933
|
+
execute_sql('database {}'.format(current_db))
|
|
934
|
+
else:
|
|
935
|
+
# environment name and file name are separated by '::'
|
|
936
|
+
# like <user_env_name(str)>::<apply_script_name>
|
|
937
|
+
env_name, script_alias = script_alias.split('::')
|
|
938
|
+
|
|
939
|
+
from teradataml.scriptmgmt.lls_utils import get_env
|
|
940
|
+
env = get_env(env_name)
|
|
941
|
+
env.remove_file(script_alias, suppress_output=True)
|
|
942
|
+
return True
|
|
943
|
+
|
|
944
|
+
@staticmethod
|
|
945
|
+
def _get_help_vtablenames():
|
|
946
|
+
"""
|
|
947
|
+
Function to get list of volatile tables.
|
|
948
|
+
|
|
949
|
+
RETURNS:
|
|
950
|
+
List of volatile tablenames.
|
|
951
|
+
|
|
952
|
+
EXAMPLES:
|
|
953
|
+
UtilFuncs._get_help_vtablenames()
|
|
954
|
+
"""
|
|
955
|
+
vtables = UtilFuncs._execute_query(SQLBundle._build_help_volatile_table(), fetchWarnings=True)
|
|
956
|
+
if vtables and vtables[0] and vtables[1]:
|
|
957
|
+
rows, columns = vtables
|
|
958
|
+
key = TeradataTableKindConstants.VOLATILE_TABLE_NAME.value
|
|
959
|
+
# Find the index of the column matching the table name
|
|
960
|
+
col_idx = columns.index(key)
|
|
961
|
+
return [row[col_idx].strip() for row in rows if row[col_idx]]
|
|
962
|
+
return []
|
|
963
|
+
|
|
964
|
+
@staticmethod
|
|
965
|
+
def _get_help_viewname(view_name):
|
|
966
|
+
"""
|
|
967
|
+
Function to get help of the view.
|
|
968
|
+
|
|
969
|
+
PARAMETERS:
|
|
970
|
+
view_name - The name of the view.
|
|
971
|
+
|
|
972
|
+
RETURNS:
|
|
973
|
+
The help information of the view specified by view_name.
|
|
974
|
+
|
|
975
|
+
EXAMPLES:
|
|
976
|
+
UtilFuncs._get_help_viewname(myview)
|
|
977
|
+
"""
|
|
978
|
+
return UtilFuncs._execute_query(SQLBundle._build_help_view(view_name))
|
|
979
|
+
|
|
980
|
+
@staticmethod
|
|
981
|
+
def _get_help_tablename(table_name):
|
|
982
|
+
"""
|
|
983
|
+
Function to get help of the table.
|
|
984
|
+
|
|
985
|
+
PARAMETERS:
|
|
986
|
+
table_name - The name of the table.
|
|
987
|
+
|
|
988
|
+
RETURNS:
|
|
989
|
+
The help information of the table specified by table_name.
|
|
990
|
+
|
|
991
|
+
EXAMPLES:
|
|
992
|
+
UtilFuncs._get_help_tablename(mytable)
|
|
993
|
+
"""
|
|
994
|
+
return UtilFuncs._execute_query(SQLBundle._build_help_table(table_name))
|
|
995
|
+
|
|
996
|
+
@staticmethod
|
|
997
|
+
def _get_help_datalakename(datalake_name):
|
|
998
|
+
"""
|
|
999
|
+
Function to get help of the datalake.
|
|
1000
|
+
|
|
1001
|
+
PARAMETERS:
|
|
1002
|
+
datalake_name - The name of the datalake.
|
|
1003
|
+
|
|
1004
|
+
RETURNS:
|
|
1005
|
+
The help information of the datalake specified by datalake_name.
|
|
1006
|
+
|
|
1007
|
+
EXAMPLES:
|
|
1008
|
+
UtilFuncs._get_help_datalakename(mydatalake)
|
|
1009
|
+
"""
|
|
1010
|
+
return UtilFuncs._execute_query(SQLBundle._build_help_datalake(datalake_name))
|
|
1011
|
+
|
|
1012
|
+
@staticmethod
|
|
1013
|
+
def _get_select_table(table_name):
|
|
1014
|
+
"""
|
|
1015
|
+
Function to get a table if exists.
|
|
1016
|
+
|
|
1017
|
+
PARAMETERS:
|
|
1018
|
+
table_name - Table name to check if exists in the database.
|
|
1019
|
+
|
|
1020
|
+
RETURNS:
|
|
1021
|
+
Table name in a list.
|
|
1022
|
+
|
|
1023
|
+
EXAMPLES:
|
|
1024
|
+
UtilFuncs._get_select_table('mytab')
|
|
1025
|
+
|
|
1026
|
+
"""
|
|
1027
|
+
table = UtilFuncs._execute_query(SQLBundle._build_select_table_name(table_name))
|
|
1028
|
+
if table:
|
|
1029
|
+
return table[0]
|
|
1030
|
+
return []
|
|
1031
|
+
|
|
1032
|
+
@staticmethod
|
|
1033
|
+
def _describe_column(metadata, to_type=None):
|
|
1034
|
+
"""
|
|
1035
|
+
This is an internal function to retrieve
|
|
1036
|
+
column names and column types for the table or view.
|
|
1037
|
+
|
|
1038
|
+
PARAMETERS:
|
|
1039
|
+
metadata:
|
|
1040
|
+
The result set from the HELP COLUMN command.
|
|
1041
|
+
|
|
1042
|
+
RETURNS:
|
|
1043
|
+
A list of tuples (column_names, column_types).
|
|
1044
|
+
|
|
1045
|
+
RAISES:
|
|
1046
|
+
Database errors if a problem occurs while trying to retrieve the column information.
|
|
1047
|
+
|
|
1048
|
+
EXAMPLES:
|
|
1049
|
+
column_names_and_types = UtilFuncs._describe_column()
|
|
1050
|
+
|
|
1051
|
+
"""
|
|
1052
|
+
column_names_and_types = []
|
|
1053
|
+
for row in metadata:
|
|
1054
|
+
# logger.debug("Retrieving Teradata type for {0}".format(row[31]))
|
|
1055
|
+
# row[31] corresponds to 'Column Dictionary Name' column in the result of 'HELP COLUMN' SQL commands result.
|
|
1056
|
+
column_name = row[31]
|
|
1057
|
+
# We also need to check if the column is a TD_TIMEBUCKET column, in which case we can ignore it.
|
|
1058
|
+
# We do so by checking the column name, and row[48] which corresponds to the 'Time Series Column Type'
|
|
1059
|
+
# column in the 'HELP COLUMN' command to make sure it is indeed the TD_TIMEBUCKET column in the PTI table,
|
|
1060
|
+
# and not just a column with the same name in a PTI/non-PTI table.
|
|
1061
|
+
# TD_TIMEBUCKET column is ignored since it is not functionally available to any user.
|
|
1062
|
+
if column_name == PTITableConstants.TD_TIMEBUCKET.value and \
|
|
1063
|
+
len(row) > 48 and row[48] is not None and \
|
|
1064
|
+
row[48].strip() == PTITableConstants.TSCOLTYPE_TIMEBUCKET.value:
|
|
1065
|
+
continue
|
|
1066
|
+
if to_type == "TD":
|
|
1067
|
+
# row[18] corresponds to the 'UDT Name' in the 'HELP COLUMN' SQL commands result.
|
|
1068
|
+
# row[1] corresponds to the 'Type' in the 'HELP COLUMN' commands result.
|
|
1069
|
+
column_names_and_types.append((column_name,
|
|
1070
|
+
UtilFuncs._help_col_to_td_type(row[1].strip(),
|
|
1071
|
+
row[18],
|
|
1072
|
+
row[44])))
|
|
1073
|
+
else:
|
|
1074
|
+
column_names_and_types.append((column_name,
|
|
1075
|
+
UtilFuncs._help_col_to_python_type(row[1].strip(),
|
|
1076
|
+
row[44])))
|
|
1077
|
+
|
|
1078
|
+
return column_names_and_types
|
|
1079
|
+
|
|
1080
|
+
@staticmethod
|
|
1081
|
+
def _get_pandas_converters(col_types):
|
|
1082
|
+
"""
|
|
1083
|
+
DESCRIPTION:
|
|
1084
|
+
Internal util function to get a dictionary of Python type names of columns
|
|
1085
|
+
in a teradataml DataFrame mapped to lambda functions to process the
|
|
1086
|
+
data to convert it to the type, which can be readily used with pandas'
|
|
1087
|
+
read_csv() function's 'converters' argument.
|
|
1088
|
+
|
|
1089
|
+
Note: This utility provides converter functions only for values of type
|
|
1090
|
+
int, float, and decimal.Decimal.
|
|
1091
|
+
For types that don't expect empty strings in input
|
|
1092
|
+
i.e. for 'datetime.datetime', 'datetime.date' and 'datetime.time',
|
|
1093
|
+
the converter function returns None for empty string input.
|
|
1094
|
+
|
|
1095
|
+
PARAMETERS:
|
|
1096
|
+
col_types:
|
|
1097
|
+
Required Argument.
|
|
1098
|
+
The list of Python types names corresponding to the columns in the input data.
|
|
1099
|
+
Types: list
|
|
1100
|
+
|
|
1101
|
+
RAISES:
|
|
1102
|
+
None
|
|
1103
|
+
|
|
1104
|
+
RETURNS:
|
|
1105
|
+
dict
|
|
1106
|
+
|
|
1107
|
+
EXAMPLES:
|
|
1108
|
+
>>> pandas_converters = UtilFuncs._get_pandas_converters(["int", "str"])
|
|
1109
|
+
"""
|
|
1110
|
+
pandas_converters = dict()
|
|
1111
|
+
for i, type_ in enumerate(col_types):
|
|
1112
|
+
# Add a functions that converts the string values to float or int when
|
|
1113
|
+
# the value is not empty string, else return None.
|
|
1114
|
+
if type_ in (PythonTypes.PY_FLOAT_TYPE.value,
|
|
1115
|
+
PythonTypes.PY_DECIMAL_TYPE.value):
|
|
1116
|
+
pandas_converters[i] = lambda x: float(x) \
|
|
1117
|
+
if isinstance(x, (bytes, number, int, float)) \
|
|
1118
|
+
else float("".join(x.split())) if len(x.strip()) > 0 else None
|
|
1119
|
+
|
|
1120
|
+
elif type_ == PythonTypes.PY_INT_TYPE.value:
|
|
1121
|
+
pandas_converters[i] = lambda x: int(x) \
|
|
1122
|
+
if isinstance(x, (bytes, number, int, float)) \
|
|
1123
|
+
else int(float("".join(x.split()))) if len(x.strip()) > 0 else None
|
|
1124
|
+
|
|
1125
|
+
elif type_ in (PythonTypes.PY_DATETIME_TYPE.value,
|
|
1126
|
+
PythonTypes.PY_DATE_TYPE.value,
|
|
1127
|
+
PythonTypes.PY_TIME_TYPE.value):
|
|
1128
|
+
# For types that do not expect empty strings, add function to
|
|
1129
|
+
# set them to None when value received is empty string.
|
|
1130
|
+
pandas_converters[i] = lambda x: x if len(x.strip()) > 0 else None
|
|
1131
|
+
|
|
1132
|
+
else:
|
|
1133
|
+
# For 'str' and 'bytes' types, add function that returns value as is.
|
|
1134
|
+
pandas_converters[i] = lambda x: x
|
|
1135
|
+
|
|
1136
|
+
return pandas_converters
|
|
1137
|
+
|
|
1138
|
+
@staticmethod
|
|
1139
|
+
def _teradata_type_to_python_type(td_type):
|
|
1140
|
+
"""
|
|
1141
|
+
Translate the Teradata type from metaexpr to Python types.
|
|
1142
|
+
PARAMETERS:
|
|
1143
|
+
td_type - The Teradata type from metaexpr.
|
|
1144
|
+
|
|
1145
|
+
RETURNS:
|
|
1146
|
+
The Python type for the given td_type.
|
|
1147
|
+
|
|
1148
|
+
RAISES:
|
|
1149
|
+
|
|
1150
|
+
EXAMPLES:
|
|
1151
|
+
# o is an instance of INTEGER
|
|
1152
|
+
pytype = UtilFuncs._teradata_type_to_python_type(o)
|
|
1153
|
+
|
|
1154
|
+
"""
|
|
1155
|
+
|
|
1156
|
+
# loggerlogger.debug("_help_col_to_python_type td_type = {0} ".format(td_type))
|
|
1157
|
+
if type(td_type) in TeradataTypes.TD_INTEGER_TYPES.value:
|
|
1158
|
+
return PythonTypes.PY_INT_TYPE.value
|
|
1159
|
+
elif type(td_type) in TeradataTypes.TD_FLOAT_TYPES.value:
|
|
1160
|
+
return PythonTypes.PY_FLOAT_TYPE.value
|
|
1161
|
+
elif type(td_type) in TeradataTypes.TD_DECIMAL_TYPES.value:
|
|
1162
|
+
return PythonTypes.PY_DECIMAL_TYPE.value
|
|
1163
|
+
elif type(td_type) in TeradataTypes.TD_BYTE_TYPES.value:
|
|
1164
|
+
return PythonTypes.PY_BYTES_TYPE.value
|
|
1165
|
+
elif type(td_type) in TeradataTypes.TD_DATETIME_TYPES.value:
|
|
1166
|
+
return PythonTypes.PY_DATETIME_TYPE.value
|
|
1167
|
+
elif type(td_type) in TeradataTypes.TD_TIME_TYPES.value:
|
|
1168
|
+
return PythonTypes.PY_TIME_TYPE.value
|
|
1169
|
+
elif type(td_type) in TeradataTypes.TD_DATE_TYPES.value:
|
|
1170
|
+
return PythonTypes.PY_DATE_TYPE.value
|
|
1171
|
+
|
|
1172
|
+
return PythonTypes.PY_STRING_TYPE.value
|
|
1173
|
+
|
|
1174
|
+
@staticmethod
|
|
1175
|
+
def _help_col_to_python_type(col_type, storage_format):
|
|
1176
|
+
"""
|
|
1177
|
+
Translate the 1 or 2 character TD type codes from HELP COLUMN to Python types.
|
|
1178
|
+
PARAMETERS:
|
|
1179
|
+
col_type - The 1 or 2 character type code from HELP COLUMN command.
|
|
1180
|
+
storage_format - The storage format from HELP COLUMN command.
|
|
1181
|
+
|
|
1182
|
+
RETURNS:
|
|
1183
|
+
The Python type for the given col_type.
|
|
1184
|
+
|
|
1185
|
+
RAISES:
|
|
1186
|
+
|
|
1187
|
+
EXAMPLES:
|
|
1188
|
+
pytype = UtilFuncs._help_col_to_python_type('CV', None)
|
|
1189
|
+
pytype = UtilFuncs._help_col_to_python_type('DT', 'CSV')
|
|
1190
|
+
|
|
1191
|
+
"""
|
|
1192
|
+
if col_type in TeradataTypes.TD_INTEGER_CODES.value:
|
|
1193
|
+
return PythonTypes.PY_INT_TYPE.value
|
|
1194
|
+
elif col_type in TeradataTypes.TD_FLOAT_CODES.value:
|
|
1195
|
+
return PythonTypes.PY_FLOAT_TYPE.value
|
|
1196
|
+
elif col_type in TeradataTypes.TD_DECIMAL_CODES.value:
|
|
1197
|
+
return PythonTypes.PY_DECIMAL_TYPE.value
|
|
1198
|
+
elif col_type in TeradataTypes.TD_BYTE_CODES.value:
|
|
1199
|
+
return PythonTypes.PY_BYTES_TYPE.value
|
|
1200
|
+
elif col_type in TeradataTypes.TD_DATETIME_CODES.value:
|
|
1201
|
+
return PythonTypes.PY_DATETIME_TYPE.value
|
|
1202
|
+
elif col_type in TeradataTypes.TD_TIME_CODES.value:
|
|
1203
|
+
return PythonTypes.PY_TIME_TYPE.value
|
|
1204
|
+
elif col_type in TeradataTypes.TD_DATE_CODES.value:
|
|
1205
|
+
return PythonTypes.PY_DATE_TYPE.value
|
|
1206
|
+
elif col_type == "DT":
|
|
1207
|
+
sfmt = storage_format.strip()
|
|
1208
|
+
if sfmt == "CSV":
|
|
1209
|
+
return PythonTypes.PY_STRING_TYPE.value
|
|
1210
|
+
elif sfmt == "AVRO":
|
|
1211
|
+
return PythonTypes.PY_BYTES_TYPE.value
|
|
1212
|
+
|
|
1213
|
+
return PythonTypes.PY_STRING_TYPE.value
|
|
1214
|
+
|
|
1215
|
+
@staticmethod
|
|
1216
|
+
def _help_col_to_td_type(col_type, udt_name, storage_format):
|
|
1217
|
+
"""
|
|
1218
|
+
Translate the 2 character TD type codes from HELP COLUMN to Teradata types.
|
|
1219
|
+
PARAMETERS:
|
|
1220
|
+
col_type - The 2 character type code from HELP COLUMN command.
|
|
1221
|
+
udt_name - The UDT name from the HELP COLUMN command.
|
|
1222
|
+
storage_format - The storage format from HELP COLUMN command.
|
|
1223
|
+
|
|
1224
|
+
RETURNS:
|
|
1225
|
+
The Teradata type for the given colType.
|
|
1226
|
+
|
|
1227
|
+
RAISES:
|
|
1228
|
+
|
|
1229
|
+
EXAMPLES:
|
|
1230
|
+
tdtype = UtilFuncs._help_col_to_td_type('CV', None, None)
|
|
1231
|
+
|
|
1232
|
+
"""
|
|
1233
|
+
# logger.debug("helpColumnToTeradataTypeName colType = {0} udtName = {1}
|
|
1234
|
+
# storageFormat {2}".format(colType, udtName, storageFormat))
|
|
1235
|
+
if col_type in td_coltype_code_to_tdtype.HELP_COL_TYPE_TO_TDTYPE:
|
|
1236
|
+
return td_coltype_code_to_tdtype.HELP_COL_TYPE_TO_TDTYPE[col_type]
|
|
1237
|
+
|
|
1238
|
+
if col_type == "DT":
|
|
1239
|
+
return "DATASET STORAGE FORMAT {0}".format(storage_format.strip())
|
|
1240
|
+
|
|
1241
|
+
if col_type in ["UD", "US", "UT", "A1", "AN"]:
|
|
1242
|
+
if udt_name:
|
|
1243
|
+
return udt_name
|
|
1244
|
+
|
|
1245
|
+
return col_type
|
|
1246
|
+
|
|
1247
|
+
@staticmethod
|
|
1248
|
+
def _convert_date_to_string(date_obj):
|
|
1249
|
+
"""
|
|
1250
|
+
Converts the date from datetime.date object to String type in the format "DATE 1987-06-09".
|
|
1251
|
+
PARAMETERS:
|
|
1252
|
+
date_obj:
|
|
1253
|
+
Required Argument.
|
|
1254
|
+
Specifies the date object to convert to string type.
|
|
1255
|
+
Types: datetime.date
|
|
1256
|
+
|
|
1257
|
+
RETURNS:
|
|
1258
|
+
The String reresentation for the given datetime.date object in the format "DATE 1987-06-09"
|
|
1259
|
+
|
|
1260
|
+
RAISES:
|
|
1261
|
+
None
|
|
1262
|
+
|
|
1263
|
+
Examples:
|
|
1264
|
+
date_str = UtilFuncs._convert_date_to_string(date_obj)
|
|
1265
|
+
|
|
1266
|
+
"""
|
|
1267
|
+
date_str = 'DATE {}'.format(date_obj.strftime('%Y-%m-%d'))
|
|
1268
|
+
return date_str
|
|
1269
|
+
|
|
1270
|
+
@staticmethod
|
|
1271
|
+
def _process_for_teradata_keyword(keyword):
|
|
1272
|
+
"""
|
|
1273
|
+
Processing the Teradata Reserved keywords.
|
|
1274
|
+
If keyword is in list of Teradata Reserved keywords, then it'll be quoted in double quotes "keyword".
|
|
1275
|
+
|
|
1276
|
+
PARAMETERS:
|
|
1277
|
+
keyword - A string or a list of strings to check whether it belongs to Teradata Reserved
|
|
1278
|
+
Keywords or not.
|
|
1279
|
+
|
|
1280
|
+
RETURNS:
|
|
1281
|
+
A quoted string or list of quoted strings, if keyword is one of the Teradata Reserved Keyword,
|
|
1282
|
+
else same object as is.
|
|
1283
|
+
|
|
1284
|
+
RAISES:
|
|
1285
|
+
None.
|
|
1286
|
+
|
|
1287
|
+
EXAMPLES:
|
|
1288
|
+
# Passing non-reserved returns "xyz" as is.
|
|
1289
|
+
keyword = self.__process_for_teradata_keyword("xyz")
|
|
1290
|
+
print(keyword)
|
|
1291
|
+
# Passing reserved str returns double-quoted str, i.e., "\"threshold\"".
|
|
1292
|
+
keyword = self.__process_for_teradata_keyword("threshold")
|
|
1293
|
+
print(keyword)
|
|
1294
|
+
"""
|
|
1295
|
+
# If the input keyword is a list, then call the same function again for every
|
|
1296
|
+
# element in the list.
|
|
1297
|
+
if isinstance(keyword, list):
|
|
1298
|
+
return [UtilFuncs._process_for_teradata_keyword(col) for col in keyword]
|
|
1299
|
+
|
|
1300
|
+
if isinstance(keyword, str) and keyword.upper() in \
|
|
1301
|
+
TeradataReservedKeywords.TERADATA_RESERVED_WORDS.value:
|
|
1302
|
+
return UtilFuncs._teradata_quote_arg(keyword, "\"", False)
|
|
1303
|
+
|
|
1304
|
+
return keyword
|
|
1305
|
+
|
|
1306
|
+
def _contains_space(item):
|
|
1307
|
+
"""
|
|
1308
|
+
Check if the specified string in item has spaces or tabs in it.
|
|
1309
|
+
|
|
1310
|
+
PARAMETERS:
|
|
1311
|
+
item:
|
|
1312
|
+
Required Argument.
|
|
1313
|
+
Specifies a string to check for spaces or tabs.
|
|
1314
|
+
Types: str
|
|
1315
|
+
|
|
1316
|
+
RETURNS:
|
|
1317
|
+
True, if the specified string has spaces or tabs in it, else False.
|
|
1318
|
+
|
|
1319
|
+
RAISES:
|
|
1320
|
+
None.
|
|
1321
|
+
|
|
1322
|
+
EXAMPLES:
|
|
1323
|
+
# Passing column name with spaces returns True.
|
|
1324
|
+
is_space = UtilFuncs._contains_space("col name")
|
|
1325
|
+
print(is_space)
|
|
1326
|
+
# Passing column name without spaces returns False.
|
|
1327
|
+
is_space = UtilFuncs._contains_space("colname")
|
|
1328
|
+
print(is_space)
|
|
1329
|
+
"""
|
|
1330
|
+
# Check if the input is a string and look for spaces or tabs
|
|
1331
|
+
if isinstance(item, str):
|
|
1332
|
+
return any(char in {' ', '\t'} for char in item)
|
|
1333
|
+
|
|
1334
|
+
# If the input is a list, check each element
|
|
1335
|
+
if isinstance(item, list):
|
|
1336
|
+
# Check each item in the list
|
|
1337
|
+
return any(UtilFuncs._contains_space(col) for col in item)
|
|
1338
|
+
|
|
1339
|
+
return False
|
|
1340
|
+
|
|
1341
|
+
@staticmethod
|
|
1342
|
+
def _is_non_ascii(col_lst):
|
|
1343
|
+
"""
|
|
1344
|
+
Description:
|
|
1345
|
+
Check if the specified string in col_lst has non-ASCII characters in it.
|
|
1346
|
+
|
|
1347
|
+
PARAMETERS:
|
|
1348
|
+
col_lst:
|
|
1349
|
+
Required Argument.
|
|
1350
|
+
Specifies a list of strings to check for non-ASCII characters.
|
|
1351
|
+
Types: list
|
|
1352
|
+
|
|
1353
|
+
RETURNS:
|
|
1354
|
+
True, if the specified string has non-ASCII characters in it, else False.
|
|
1355
|
+
|
|
1356
|
+
RAISES:
|
|
1357
|
+
None.
|
|
1358
|
+
|
|
1359
|
+
EXAMPLES:
|
|
1360
|
+
# Passing column name with non-ASCII characters returns True.
|
|
1361
|
+
>>> is_non_ascii = UtilFuncs._is_ascii(["col name", "がく片の長さ@name"])
|
|
1362
|
+
>>> print(is_non_ascii)
|
|
1363
|
+
>>> True
|
|
1364
|
+
# Passing column name without non-ASCII characters returns False.
|
|
1365
|
+
>>> is_non_ascii = UtilFuncs._is_ascii(["colname", "col_name"])
|
|
1366
|
+
>>> print(is_non_ascii)
|
|
1367
|
+
>>> False
|
|
1368
|
+
"""
|
|
1369
|
+
if isinstance(col_lst, str):
|
|
1370
|
+
# Check if the input is a string and look for non-ASCII characters
|
|
1371
|
+
return not col_lst.isascii()
|
|
1372
|
+
|
|
1373
|
+
if isinstance(col_lst, list):
|
|
1374
|
+
for item in col_lst:
|
|
1375
|
+
if isinstance(item, str) and not item.isascii():
|
|
1376
|
+
return True
|
|
1377
|
+
return False
|
|
1378
|
+
|
|
1379
|
+
@staticmethod
|
|
1380
|
+
def __get_dot_separated_names(full_qualified_name):
|
|
1381
|
+
"""
|
|
1382
|
+
Takes in fully qualified name of the table/view (db.table), and returns
|
|
1383
|
+
a dot separated name from the same.
|
|
1384
|
+
|
|
1385
|
+
PARAMETERS:
|
|
1386
|
+
full_qualified_name - Name of the table/view
|
|
1387
|
+
|
|
1388
|
+
EXAMPLES:
|
|
1389
|
+
UtilFuncs._extract_db_name('"db1"."tablename"')
|
|
1390
|
+
UtilFuncs._extract_db_name('"Icebergs"."db1"."tablename"')
|
|
1391
|
+
|
|
1392
|
+
RETURNS:
|
|
1393
|
+
List of dot separated name from the provided name.
|
|
1394
|
+
|
|
1395
|
+
"""
|
|
1396
|
+
# If condition to handle the quoted name.
|
|
1397
|
+
if '"' in full_qualified_name:
|
|
1398
|
+
# Extract the double quoted strings.
|
|
1399
|
+
names = re.findall(r'["](.*?)["]', full_qualified_name)
|
|
1400
|
+
# Remove quotes around the string.
|
|
1401
|
+
names = [i.replace('"', '') for i in names]
|
|
1402
|
+
# Handle non-quoted string with dot separated name.
|
|
1403
|
+
else:
|
|
1404
|
+
names = full_qualified_name.split(".")
|
|
1405
|
+
return names
|
|
1406
|
+
|
|
1407
|
+
@staticmethod
|
|
1408
|
+
def _extract_db_name(full_qualified_name):
|
|
1409
|
+
"""
|
|
1410
|
+
Takes in fully qualified name of the table/view (db.table), and returns
|
|
1411
|
+
a database name from the same.
|
|
1412
|
+
|
|
1413
|
+
PARAMETERS:
|
|
1414
|
+
full_qualified_name - Name of the table/view
|
|
1415
|
+
|
|
1416
|
+
EXAMPLES:
|
|
1417
|
+
UtilFuncs._extract_db_name('"db1"."tablename"')
|
|
1418
|
+
UtilFuncs._extract_db_name('"Icebergs"."db1"."tablename"')
|
|
1419
|
+
|
|
1420
|
+
RETURNS:
|
|
1421
|
+
Database name from the provided name.
|
|
1422
|
+
|
|
1423
|
+
"""
|
|
1424
|
+
names = UtilFuncs.__get_dot_separated_names(full_qualified_name)
|
|
1425
|
+
if names:
|
|
1426
|
+
if len(names) == 2:
|
|
1427
|
+
return names[0]
|
|
1428
|
+
elif len(names) == 3:
|
|
1429
|
+
return names[1]
|
|
1430
|
+
else:
|
|
1431
|
+
return None
|
|
1432
|
+
|
|
1433
|
+
@staticmethod
|
|
1434
|
+
def _extract_table_name(full_qualified_name):
|
|
1435
|
+
"""
|
|
1436
|
+
Takes in fully qualified name of the table/view (db.table), and returns
|
|
1437
|
+
a table/view name from the same.
|
|
1438
|
+
|
|
1439
|
+
PARAMETERS:
|
|
1440
|
+
full_qualified_name - Name of the table/view
|
|
1441
|
+
|
|
1442
|
+
EXAMPLES:
|
|
1443
|
+
UtilFuncs._extract_table_name('"db1"."tablename"')
|
|
1444
|
+
UtilFuncs._extract_table_name('"Icebergs"."db1"."tablename"')
|
|
1445
|
+
|
|
1446
|
+
RETURNS:
|
|
1447
|
+
Table/View name from the provided name.
|
|
1448
|
+
|
|
1449
|
+
"""
|
|
1450
|
+
names = UtilFuncs.__get_dot_separated_names(full_qualified_name)
|
|
1451
|
+
if names:
|
|
1452
|
+
if len(names) == 2:
|
|
1453
|
+
return names[1]
|
|
1454
|
+
elif len(names) == 3:
|
|
1455
|
+
return names[2]
|
|
1456
|
+
else:
|
|
1457
|
+
return names[0]
|
|
1458
|
+
return full_qualified_name
|
|
1459
|
+
|
|
1460
|
+
@staticmethod
|
|
1461
|
+
def _extract_datalake_name(full_qualified_name):
|
|
1462
|
+
"""
|
|
1463
|
+
Takes in fully qualified name of the table/view (db.table), and returns
|
|
1464
|
+
a datalake name from the same.
|
|
1465
|
+
|
|
1466
|
+
PARAMETERS:
|
|
1467
|
+
full_qualified_name - Name of the table/view
|
|
1468
|
+
|
|
1469
|
+
EXAMPLES:
|
|
1470
|
+
UtilFuncs._extract_datalake_name('"db1"."tablename"')
|
|
1471
|
+
UtilFuncs._extract_datalake_name('"Icebergs"."db1"."tablename"')
|
|
1472
|
+
|
|
1473
|
+
RETURNS:
|
|
1474
|
+
Database name from the provided name.
|
|
1475
|
+
|
|
1476
|
+
"""
|
|
1477
|
+
names = UtilFuncs.__get_dot_separated_names(full_qualified_name)
|
|
1478
|
+
if names and len(names) == 3:
|
|
1479
|
+
return names[0]
|
|
1480
|
+
return None
|
|
1481
|
+
|
|
1482
|
+
@staticmethod
|
|
1483
|
+
def _teradata_quote_arg(args, quote="'", call_from_wrapper=True):
|
|
1484
|
+
"""
|
|
1485
|
+
Function to quote argument value.
|
|
1486
|
+
PARAMETERS:
|
|
1487
|
+
args : Argument to be quoted.
|
|
1488
|
+
quote : Type of quote to be used for quoting. Default is
|
|
1489
|
+
single quote (').
|
|
1490
|
+
RETURNS:
|
|
1491
|
+
Argument with quotes as a string.
|
|
1492
|
+
|
|
1493
|
+
EXAMPLES:
|
|
1494
|
+
When a call is being made from wrapper:
|
|
1495
|
+
UtilFuncs._teradata_quote_arg(family, "'")
|
|
1496
|
+
When a call is being made from non-wrapper function.
|
|
1497
|
+
UtilFuncs._teradata_quote_arg(family, "'", False)
|
|
1498
|
+
"""
|
|
1499
|
+
if call_from_wrapper and not configure.column_casesensitive_handler:
|
|
1500
|
+
quote = ""
|
|
1501
|
+
return args
|
|
1502
|
+
|
|
1503
|
+
# Returning same string if it already quoted. Applicable only for strings.
|
|
1504
|
+
if isinstance(args, str) and args.startswith(quote) and args.endswith(quote):
|
|
1505
|
+
return args
|
|
1506
|
+
if args is None:
|
|
1507
|
+
return None
|
|
1508
|
+
if isinstance(args, list):
|
|
1509
|
+
return ["{0}{1}{0}".format(quote, arg) for arg in args]
|
|
1510
|
+
|
|
1511
|
+
return "{0}{1}{0}".format(quote, args)
|
|
1512
|
+
|
|
1513
|
+
@staticmethod
|
|
1514
|
+
def _teradata_unquote_arg(quoted_string, quote="'"):
|
|
1515
|
+
"""
|
|
1516
|
+
Function to unquote argument value.
|
|
1517
|
+
PARAMETERS:
|
|
1518
|
+
quoted_string : String to be unquoted.
|
|
1519
|
+
quote : Type of quote to be used for unquoting. Default is
|
|
1520
|
+
single quote (').
|
|
1521
|
+
RETURNS:
|
|
1522
|
+
None if 'quoted_string' is not a string,
|
|
1523
|
+
else Argument without quotes as a string.
|
|
1524
|
+
|
|
1525
|
+
EXAMPLES:
|
|
1526
|
+
UtilFuncs._teradata_unquote_arg(family, "'")
|
|
1527
|
+
"""
|
|
1528
|
+
|
|
1529
|
+
if not isinstance(quoted_string, str):
|
|
1530
|
+
return None
|
|
1531
|
+
|
|
1532
|
+
# Returning same string if it already unquoted.
|
|
1533
|
+
if not quoted_string.startswith(quote) and not quoted_string.endswith(quote):
|
|
1534
|
+
return quoted_string
|
|
1535
|
+
|
|
1536
|
+
return quoted_string[1:-1]
|
|
1537
|
+
|
|
1538
|
+
@staticmethod
|
|
1539
|
+
def _teradata_collapse_arglist(args_list, quote="'"):
|
|
1540
|
+
"""
|
|
1541
|
+
Given a list as an argument this will single quote all the
|
|
1542
|
+
list elements and combine them into a single string separated by
|
|
1543
|
+
commas.
|
|
1544
|
+
|
|
1545
|
+
PARAMETERS:
|
|
1546
|
+
args_list: List containing string/s to be quoted.
|
|
1547
|
+
quote: Type of quote to be used for quoting. Default is single quote (').
|
|
1548
|
+
|
|
1549
|
+
RETURNS:
|
|
1550
|
+
Single string separated by commas.
|
|
1551
|
+
|
|
1552
|
+
EXAMPLES:
|
|
1553
|
+
UtilFuncs._teradata_collapse_arglist(family, "'")
|
|
1554
|
+
|
|
1555
|
+
"""
|
|
1556
|
+
expr = r"([\"'][\d.\d\w]+\s*[\"'][,]*\s*)+([\"']\s*[\d.\d\w]+[\"']$)"
|
|
1557
|
+
|
|
1558
|
+
# # return None if list is empty
|
|
1559
|
+
# if not args_list and not isinstance(args_list, bool):
|
|
1560
|
+
# return args_list
|
|
1561
|
+
|
|
1562
|
+
# if args_list is a list quote all values of the list
|
|
1563
|
+
if isinstance(args_list, list):
|
|
1564
|
+
'''
|
|
1565
|
+
EXAMPLE:
|
|
1566
|
+
arg = ['admitted', 'masters', 'gpa', 'stats', 'programming']
|
|
1567
|
+
UtilFuncs._teradata_collapse_arglist(arg, "\"")
|
|
1568
|
+
RETURNS:
|
|
1569
|
+
'"admitted","masters","gpa","stats","programming"'
|
|
1570
|
+
|
|
1571
|
+
'''
|
|
1572
|
+
return ",".join("{0}{1}{0}".format(quote, arg) for arg in args_list)
|
|
1573
|
+
elif (isinstance(args_list, str)) and (bool(re.match(expr, args_list)) is True):
|
|
1574
|
+
'''
|
|
1575
|
+
Quotes the arguments which is string of strings with the provided quote variable
|
|
1576
|
+
value.
|
|
1577
|
+
The expr should be strings separeted by commas. The string values can be digits or
|
|
1578
|
+
alphabets.
|
|
1579
|
+
For example:
|
|
1580
|
+
args_list = '"masters","gpa","stats"'
|
|
1581
|
+
quote = "'"
|
|
1582
|
+
The args_list is quoted as below based on the quote argument provided:
|
|
1583
|
+
strQuotes = '"masters"','"gpa"','"stats"'
|
|
1584
|
+
RETURNS:
|
|
1585
|
+
quoted string
|
|
1586
|
+
|
|
1587
|
+
The quoted value is added to list in the functions with other arguments as:
|
|
1588
|
+
funcOtherArgs = ["'2.0'", "'POISSON'", "'IDENTITY'", "'0.05'", "'10'", "'False'", "'True'",
|
|
1589
|
+
'\'"masters"\',\'"gpa"\',\'"stats"\',\'"programming"\',\'"admitted"\'',
|
|
1590
|
+
'\'"masters"\',\'"stats"\',\'"programming"\'']
|
|
1591
|
+
|
|
1592
|
+
'''
|
|
1593
|
+
str_val = re.sub(r"\s+", "", args_list)
|
|
1594
|
+
args_list = str_val.split(",")
|
|
1595
|
+
return ",".join("{0}{1}{0}".format(quote, arg) for arg in args_list)
|
|
1596
|
+
# if argVector is any value of int/str/bool type, quote the value
|
|
1597
|
+
else:
|
|
1598
|
+
return UtilFuncs._teradata_quote_arg(args_list, quote, False)
|
|
1599
|
+
|
|
1600
|
+
@staticmethod
|
|
1601
|
+
def _get_metaexpr_using_columns(nodeid, column_info, with_engine=False, is_persist=False, **kw):
|
|
1602
|
+
"""
|
|
1603
|
+
This internal function takes in input node ID and column information in zipped lists format
|
|
1604
|
+
to return metaexpr with or without engine.
|
|
1605
|
+
|
|
1606
|
+
PARAMETERS:
|
|
1607
|
+
nodeid - AED DAG node id for which a metaexpr is to be generated.
|
|
1608
|
+
column_info - This contains zipped lists of column names and corresponding column types.
|
|
1609
|
+
with_engine - A bool parameter, deciding whether to generate metaexpr with engine or not.
|
|
1610
|
+
Default is False.
|
|
1611
|
+
is_persist - A bool parameter, deciding whether to persist the result or not.
|
|
1612
|
+
Default is False.
|
|
1613
|
+
|
|
1614
|
+
RAISES:
|
|
1615
|
+
|
|
1616
|
+
RETURNS:
|
|
1617
|
+
metaexpr for the provided node ID and with column inforamtion.
|
|
1618
|
+
|
|
1619
|
+
EXAMPLES:
|
|
1620
|
+
node_id_list = self.__aed_utils._aed_ml_query(self.__input_nodeids, self.sqlmr_query, self.__func_output_args, "NaiveBayesMap")
|
|
1621
|
+
stdout_column_info = zip(stdout_column_names, stdout_column_types)
|
|
1622
|
+
UtilFuncs._get_metaexpr_using_columns(node_id_list[0], stdout_column_info)
|
|
1623
|
+
"""
|
|
1624
|
+
from teradataml.dataframe.sql import _MetaExpression
|
|
1625
|
+
if with_engine:
|
|
1626
|
+
eng = tdmlctx.get_context()
|
|
1627
|
+
meta = sqlalchemy.MetaData(eng)
|
|
1628
|
+
else:
|
|
1629
|
+
meta = sqlalchemy.MetaData()
|
|
1630
|
+
|
|
1631
|
+
# Get the output table name for node_id from AED
|
|
1632
|
+
aed_utils = AedUtils()
|
|
1633
|
+
|
|
1634
|
+
table_name = aed_utils._aed_get_tablename(nodeid)
|
|
1635
|
+
db_schema = UtilFuncs._extract_db_name(table_name)
|
|
1636
|
+
db_table_name = UtilFuncs._extract_table_name(table_name)
|
|
1637
|
+
|
|
1638
|
+
# Constructing new Metadata (_metaexpr) without DB; _MetaExpression
|
|
1639
|
+
ouptut_table = Table(db_table_name, meta,
|
|
1640
|
+
*(Column(col_name, col_type) for col_name, col_type in column_info),
|
|
1641
|
+
schema=db_schema)
|
|
1642
|
+
return _MetaExpression(ouptut_table, is_persist=is_persist, **kw)
|
|
1643
|
+
|
|
1644
|
+
@staticmethod
|
|
1645
|
+
def _get_metaexpr_using_parent_metaexpr(nodeid, metaexpr):
|
|
1646
|
+
"""
|
|
1647
|
+
This internal function takes in input node ID and metaexpr (parents)
|
|
1648
|
+
to return metaexpr with or without engine.
|
|
1649
|
+
|
|
1650
|
+
PARAMETERS:
|
|
1651
|
+
nodeid:
|
|
1652
|
+
Required Argument.
|
|
1653
|
+
Specifies AED DAG node id for which a metaexpr is to be generated.
|
|
1654
|
+
|
|
1655
|
+
metaexpr:
|
|
1656
|
+
Required Argument.
|
|
1657
|
+
_MetaExpression() of a DataFrame objects which is to be used to extract and
|
|
1658
|
+
create a new _MetaExpression.
|
|
1659
|
+
|
|
1660
|
+
RAISES:
|
|
1661
|
+
None.
|
|
1662
|
+
|
|
1663
|
+
RETURNS:
|
|
1664
|
+
metaexpr for the provided node ID and with metaexpr inforamtion.
|
|
1665
|
+
|
|
1666
|
+
EXAMPLES:
|
|
1667
|
+
node_id_list = self.__aed_utils._aed_ml_query(self.__input_nodeids, self.sqlmr_query, self.__func_output_args, "NaiveBayesMap")
|
|
1668
|
+
UtilFuncs._get_metaexpr_using_parent_metaexpr(node_id_list[0], parent_metaexpr)
|
|
1669
|
+
"""
|
|
1670
|
+
meta_cols = metaexpr.t.c
|
|
1671
|
+
meta_columns = [c.name for c in meta_cols]
|
|
1672
|
+
col_names = []
|
|
1673
|
+
col_types = []
|
|
1674
|
+
|
|
1675
|
+
# When column list to retrieve is not provided, return meta-data for all columns.
|
|
1676
|
+
for col_name in meta_columns:
|
|
1677
|
+
col_names.append(meta_cols[col_name].name)
|
|
1678
|
+
col_types.append(meta_cols[col_name].type)
|
|
1679
|
+
|
|
1680
|
+
return UtilFuncs._get_metaexpr_using_columns(nodeid, zip(col_names, col_types),
|
|
1681
|
+
datalake=metaexpr.datalake)
|
|
1682
|
+
|
|
1683
|
+
@staticmethod
|
|
1684
|
+
def _create_table_using_columns(table_name, columns_datatypes, pti_clause=None, storage=None):
|
|
1685
|
+
"""
|
|
1686
|
+
Create a table with columns.
|
|
1687
|
+
|
|
1688
|
+
PARAMETERS:
|
|
1689
|
+
table_name - Fully qualified quoted table name.
|
|
1690
|
+
columns_datatypes - Column names and dattypes for the table
|
|
1691
|
+
pti_clause - Specifies the string for the primary time index.
|
|
1692
|
+
storage - Specifies the storage for the table.
|
|
1693
|
+
|
|
1694
|
+
RAISES
|
|
1695
|
+
|
|
1696
|
+
RETURNS:
|
|
1697
|
+
True if success, false if fails
|
|
1698
|
+
|
|
1699
|
+
EXAMPLES:
|
|
1700
|
+
UtilFuncs._create_table_using_columns('"dbname"."table_name"',
|
|
1701
|
+
"col1 varchar(10), col2 integer, col3 timestamp")
|
|
1702
|
+
"""
|
|
1703
|
+
# If storage option is specified, add the storage clause in the create table statement.
|
|
1704
|
+
if storage:
|
|
1705
|
+
table_name = "{}, STORAGE={}".format(table_name, storage)
|
|
1706
|
+
|
|
1707
|
+
crt_table = SQLBundle._build_create_table_using_columns(table_name, columns_datatypes)
|
|
1708
|
+
|
|
1709
|
+
if pti_clause is not None:
|
|
1710
|
+
crt_table = "{} PRIMARY TIME INDEX {}".format(crt_table, pti_clause)
|
|
1711
|
+
|
|
1712
|
+
try:
|
|
1713
|
+
UtilFuncs._execute_ddl_statement(crt_table)
|
|
1714
|
+
return True
|
|
1715
|
+
except Exception:
|
|
1716
|
+
raise
|
|
1717
|
+
|
|
1718
|
+
@staticmethod
|
|
1719
|
+
def _get_engine_name(engine):
|
|
1720
|
+
"""
|
|
1721
|
+
Function to return the name of the engine mapped to the
|
|
1722
|
+
argument 'engine' in function mapped dictionary.
|
|
1723
|
+
|
|
1724
|
+
PARAMETERS:
|
|
1725
|
+
engine:
|
|
1726
|
+
Required Argument.
|
|
1727
|
+
Specifies the type of the engine.
|
|
1728
|
+
|
|
1729
|
+
RETURNS:
|
|
1730
|
+
Name of the engine.
|
|
1731
|
+
|
|
1732
|
+
RAISES:
|
|
1733
|
+
TeradataMLException
|
|
1734
|
+
|
|
1735
|
+
EXAMPLES:
|
|
1736
|
+
UtilFuncs._get_engine_name("ENGINE_SQL")
|
|
1737
|
+
|
|
1738
|
+
"""
|
|
1739
|
+
_Validators._validate_engine(engine)
|
|
1740
|
+
supported_engines = TeradataConstants.SUPPORTED_ENGINES.value
|
|
1741
|
+
return supported_engines[engine]['name']
|
|
1742
|
+
|
|
1743
|
+
@staticmethod
|
|
1744
|
+
def _as_list(obj):
|
|
1745
|
+
"""
|
|
1746
|
+
Function to convert an object to list, i.e., just enclose the value passed to the
|
|
1747
|
+
function in a list and return the same, if it is not of list type.
|
|
1748
|
+
PARAMETERS:
|
|
1749
|
+
obj:
|
|
1750
|
+
Required Argument.
|
|
1751
|
+
Specifies the object to be enclosed in a list.
|
|
1752
|
+
Types: Any type except list.
|
|
1753
|
+
RETURNS:
|
|
1754
|
+
list
|
|
1755
|
+
RAISES:
|
|
1756
|
+
None.
|
|
1757
|
+
EXAMPLES:
|
|
1758
|
+
obj = UtilFuncs._as_list("vantage1.0")
|
|
1759
|
+
"""
|
|
1760
|
+
return obj if isinstance(obj, list) else [obj]
|
|
1761
|
+
|
|
1762
|
+
@staticmethod
|
|
1763
|
+
def _get_all_columns(object, is_object_type_tdml_column):
|
|
1764
|
+
"""
|
|
1765
|
+
Function to get all columns from a given teradataml DataFrame
|
|
1766
|
+
or teradataml DataFrame column.
|
|
1767
|
+
|
|
1768
|
+
PARAMETERS:
|
|
1769
|
+
object:
|
|
1770
|
+
Required Argument.
|
|
1771
|
+
Specifies either teradataml DataFrame or teradataml DataFrame
|
|
1772
|
+
Column.
|
|
1773
|
+
Types: teradataml DataFrame, _SQLColumnExpression
|
|
1774
|
+
|
|
1775
|
+
is_object_type_tdml_column:
|
|
1776
|
+
Required Argument.
|
|
1777
|
+
Specifies whether "object" is a teradataml DataFrame or
|
|
1778
|
+
teradataml DataFrame Column.
|
|
1779
|
+
If True, "object" treats as teradataml DataFrame Column.
|
|
1780
|
+
If False, "object" treats as teradataml DataFrame.
|
|
1781
|
+
Types: bool
|
|
1782
|
+
|
|
1783
|
+
RETURNS:
|
|
1784
|
+
An iterator and each element in the iterator represents a Column
|
|
1785
|
+
|
|
1786
|
+
RAISES:
|
|
1787
|
+
None.
|
|
1788
|
+
|
|
1789
|
+
EXAMPLES:
|
|
1790
|
+
obj = UtilFuncs._get_all_columns(df.col, True)
|
|
1791
|
+
obj = UtilFuncs._get_all_columns(df, False)
|
|
1792
|
+
"""
|
|
1793
|
+
if is_object_type_tdml_column:
|
|
1794
|
+
return UtilFuncs._all_df_column_expressions(object)
|
|
1795
|
+
# object._metaexpr.c extracts the data to a list. And, the caller of
|
|
1796
|
+
# this function will again iterate through the list, to process the
|
|
1797
|
+
# list i.e. object._metaexpr.c is being iterated twice. To avoid this,
|
|
1798
|
+
# a generator object is being constructed and returned.
|
|
1799
|
+
return (c for c in object._metaexpr.c)
|
|
1800
|
+
|
|
1801
|
+
@staticmethod
|
|
1802
|
+
def _get_file_contents(file_path, read_in_binary_mode=False):
|
|
1803
|
+
"""
|
|
1804
|
+
Description:
|
|
1805
|
+
Function to get the file content from a file, given absolute
|
|
1806
|
+
file path.
|
|
1807
|
+
|
|
1808
|
+
PARAMETERS:
|
|
1809
|
+
file_path:
|
|
1810
|
+
Required Argument.
|
|
1811
|
+
Specifies absolute file path of the file.
|
|
1812
|
+
Types: str
|
|
1813
|
+
|
|
1814
|
+
read_in_binary_mode:
|
|
1815
|
+
Optional Argument.
|
|
1816
|
+
Specifies whether to read the file in binary format or not.
|
|
1817
|
+
If True, read the file in binary mode.
|
|
1818
|
+
If False, read the file in ASCII mode.
|
|
1819
|
+
Default value: False
|
|
1820
|
+
Types: bool
|
|
1821
|
+
|
|
1822
|
+
RETURNS:
|
|
1823
|
+
str OR bytes
|
|
1824
|
+
|
|
1825
|
+
RAISES:
|
|
1826
|
+
TeradataMlException
|
|
1827
|
+
|
|
1828
|
+
EXAMPLES:
|
|
1829
|
+
obj = UtilFuncs._get_file_contents("/abc/xyz.txt")
|
|
1830
|
+
obj = UtilFuncs._get_file_contents("/abc/xyz.txt", True)
|
|
1831
|
+
"""
|
|
1832
|
+
try:
|
|
1833
|
+
mode = 'r'
|
|
1834
|
+
if read_in_binary_mode:
|
|
1835
|
+
mode = 'rb'
|
|
1836
|
+
with open(file_path, mode) as file_data:
|
|
1837
|
+
_Validators._check_empty_file(file_path)
|
|
1838
|
+
return file_data.read()
|
|
1839
|
+
except TeradataMlException:
|
|
1840
|
+
raise
|
|
1841
|
+
except FileNotFoundError:
|
|
1842
|
+
raise
|
|
1843
|
+
except Exception as err:
|
|
1844
|
+
msg_code = MessageCodes.EXECUTION_FAILED
|
|
1845
|
+
raise TeradataMlException(
|
|
1846
|
+
Messages.get_message(msg_code, "read contents of file '{}'".format(file_path), str(err)), msg_code)
|
|
1847
|
+
|
|
1848
|
+
@staticmethod
|
|
1849
|
+
def _create_table_using_table_object(table_obj):
|
|
1850
|
+
"""
|
|
1851
|
+
DESCRIPTION:
|
|
1852
|
+
This function creates the table in Vantage using table object.
|
|
1853
|
+
|
|
1854
|
+
PARAMETERS:
|
|
1855
|
+
table_obj:
|
|
1856
|
+
Specifies the table object.
|
|
1857
|
+
Types: sqlalchemy.sql.schema.Table
|
|
1858
|
+
|
|
1859
|
+
RETURNS:
|
|
1860
|
+
None.
|
|
1861
|
+
|
|
1862
|
+
RAISES:
|
|
1863
|
+
TeradataMlException
|
|
1864
|
+
|
|
1865
|
+
EXAMPLES:
|
|
1866
|
+
from sqlalchemy import Table, MetaData, Column
|
|
1867
|
+
|
|
1868
|
+
meta = MetaData()
|
|
1869
|
+
# Create default Table construct with parameter dictionary
|
|
1870
|
+
table_obj = Table(table_name, meta,
|
|
1871
|
+
*(Column(col_name, col_type)
|
|
1872
|
+
for col_name, col_type in
|
|
1873
|
+
zip(col_names, col_types)),
|
|
1874
|
+
teradatasql_post_create=pti,
|
|
1875
|
+
prefixes=prefix,
|
|
1876
|
+
schema=schema_name
|
|
1877
|
+
)
|
|
1878
|
+
|
|
1879
|
+
_create_table_using_table_object(table_obj)
|
|
1880
|
+
"""
|
|
1881
|
+
if table_obj is not None:
|
|
1882
|
+
try:
|
|
1883
|
+
table_obj.create(bind=tdmlctx.get_context())
|
|
1884
|
+
except sqlachemyOperationalError as err:
|
|
1885
|
+
raise TeradataMlException(Messages.get_message(MessageCodes.TABLE_OBJECT_CREATION_FAILED) +
|
|
1886
|
+
'\n' + str(err),
|
|
1887
|
+
MessageCodes.TABLE_OBJECT_CREATION_FAILED)
|
|
1888
|
+
else:
|
|
1889
|
+
raise TeradataMlException(Messages.get_message(MessageCodes.TABLE_OBJECT_CREATION_FAILED),
|
|
1890
|
+
MessageCodes.TABLE_OBJECT_CREATION_FAILED)
|
|
1891
|
+
|
|
1892
|
+
@staticmethod
|
|
1893
|
+
def _extract_table_object_column_info(table_obj):
|
|
1894
|
+
"""
|
|
1895
|
+
Internal function to extract the column name and column types from
|
|
1896
|
+
table object.
|
|
1897
|
+
|
|
1898
|
+
PARAMETERS:
|
|
1899
|
+
table_obj:
|
|
1900
|
+
Required Argument.
|
|
1901
|
+
Specifies the table object.
|
|
1902
|
+
Types: sqlalchemy.sql
|
|
1903
|
+
|
|
1904
|
+
RETURNS:
|
|
1905
|
+
Tuple
|
|
1906
|
+
|
|
1907
|
+
RAISES:
|
|
1908
|
+
None
|
|
1909
|
+
|
|
1910
|
+
EXAMPLE:
|
|
1911
|
+
meta = MetaData()
|
|
1912
|
+
table = Table(table_name, meta, schema=schema_name, autoload_with=eng)
|
|
1913
|
+
_extract_table_object_column_info(table.c)
|
|
1914
|
+
"""
|
|
1915
|
+
col_names = []
|
|
1916
|
+
col_types = []
|
|
1917
|
+
|
|
1918
|
+
for col in table_obj:
|
|
1919
|
+
col_names.append(col.name)
|
|
1920
|
+
col_types.append(col.type)
|
|
1921
|
+
|
|
1922
|
+
return col_names, col_types
|
|
1923
|
+
|
|
1924
|
+
@staticmethod
|
|
1925
|
+
def _get_warnings(argument_name, argument_value, specified_argument_name, specified_argument_value):
|
|
1926
|
+
"""
|
|
1927
|
+
Internal function to print the warning.
|
|
1928
|
+
|
|
1929
|
+
PARAMETERS:
|
|
1930
|
+
argument_name:
|
|
1931
|
+
Required Argument.
|
|
1932
|
+
Specifies the argument name to check.
|
|
1933
|
+
Types: str
|
|
1934
|
+
|
|
1935
|
+
argument_value:
|
|
1936
|
+
Required Argument.
|
|
1937
|
+
Specifies the argument value to check.
|
|
1938
|
+
Types: bool
|
|
1939
|
+
|
|
1940
|
+
specified_argument_name:
|
|
1941
|
+
Required Argument.
|
|
1942
|
+
Specifies the argument name to use in warning message.
|
|
1943
|
+
Types: str
|
|
1944
|
+
|
|
1945
|
+
specified_argument_value:
|
|
1946
|
+
Required Argument.
|
|
1947
|
+
Specifies the argument value to use in warning message.
|
|
1948
|
+
Types: str
|
|
1949
|
+
|
|
1950
|
+
RETURNS:
|
|
1951
|
+
None
|
|
1952
|
+
|
|
1953
|
+
RAISES:
|
|
1954
|
+
None
|
|
1955
|
+
|
|
1956
|
+
EXAMPLE:
|
|
1957
|
+
_get_warnings(argument_name, argument_value, specified_argument_name, specified_argument_value)
|
|
1958
|
+
"""
|
|
1959
|
+
if argument_value:
|
|
1960
|
+
warnings.warn(Messages.get_message(MessageCodes.IGNORE_ARGS_WARN,
|
|
1961
|
+
'{0}',
|
|
1962
|
+
"{1}='{2}'",
|
|
1963
|
+
'specified').format(argument_name,
|
|
1964
|
+
specified_argument_name,
|
|
1965
|
+
specified_argument_value))
|
|
1966
|
+
|
|
1967
|
+
@staticmethod
|
|
1968
|
+
def _get_sqlalchemy_table(table_name, schema_name=None, check_table_exists=False):
|
|
1969
|
+
"""
|
|
1970
|
+
Internal function returns the SQLAlchemy table object for a table.
|
|
1971
|
+
If check_table_exists specified, function also checks for table existence.
|
|
1972
|
+
|
|
1973
|
+
PARAMETERS:
|
|
1974
|
+
table_name:
|
|
1975
|
+
Required Argument.
|
|
1976
|
+
Specifies the table name.
|
|
1977
|
+
Types: str
|
|
1978
|
+
|
|
1979
|
+
schema_name:
|
|
1980
|
+
Optional Argument.
|
|
1981
|
+
Specifies schema name.
|
|
1982
|
+
Types: str
|
|
1983
|
+
|
|
1984
|
+
check_table_exists:
|
|
1985
|
+
Optional Argument.
|
|
1986
|
+
Specifies whether to check table exists or not.
|
|
1987
|
+
Default Value: False
|
|
1988
|
+
Types: bool
|
|
1989
|
+
|
|
1990
|
+
RETURNS:
|
|
1991
|
+
sqlalchemy.sql.schema.Table
|
|
1992
|
+
|
|
1993
|
+
RAISES:
|
|
1994
|
+
None
|
|
1995
|
+
|
|
1996
|
+
EXAMPLE:
|
|
1997
|
+
_get_sqlalchemy_table(table_name='my_table')
|
|
1998
|
+
"""
|
|
1999
|
+
con = tdmlctx.get_connection()
|
|
2000
|
+
|
|
2001
|
+
if check_table_exists:
|
|
2002
|
+
table_exists = con.dialect.has_table(con, table_name, schema_name, table_only=True)
|
|
2003
|
+
|
|
2004
|
+
if not table_exists:
|
|
2005
|
+
raise TeradataMlException(Messages.get_message(MessageCodes.TABLE_DOES_NOT_EXIST, table_name),
|
|
2006
|
+
MessageCodes.TABLE_DOES_NOT_EXIST)
|
|
2007
|
+
|
|
2008
|
+
meta = MetaData()
|
|
2009
|
+
return Table(table_name, meta,
|
|
2010
|
+
schema=schema_name,
|
|
2011
|
+
autoload_with=tdmlctx.get_context())
|
|
2012
|
+
|
|
2013
|
+
@staticmethod
|
|
2014
|
+
def _extract_table_object_index_info(table_obj):
|
|
2015
|
+
"""
|
|
2016
|
+
Internal function to extract primary index information of existing table.
|
|
2017
|
+
|
|
2018
|
+
PARAMETERS:
|
|
2019
|
+
table_obj:
|
|
2020
|
+
Required Argument.
|
|
2021
|
+
Specifies the sqlalchemy table object.
|
|
2022
|
+
Types: sqlalchemy.sql.schema.Table.
|
|
2023
|
+
|
|
2024
|
+
RETURNS:
|
|
2025
|
+
list.
|
|
2026
|
+
|
|
2027
|
+
RAISES:
|
|
2028
|
+
None.
|
|
2029
|
+
|
|
2030
|
+
EXAMPLE:
|
|
2031
|
+
_extract_table_object_index_info(table_object)
|
|
2032
|
+
"""
|
|
2033
|
+
sqlalchemy_table_primary_index = table_obj.indexes
|
|
2034
|
+
primary_index_list = []
|
|
2035
|
+
for index in sqlalchemy_table_primary_index:
|
|
2036
|
+
primary_index_list = index.columns.keys()
|
|
2037
|
+
return primary_index_list
|
|
2038
|
+
|
|
2039
|
+
@staticmethod
|
|
2040
|
+
def _get_positive_infinity():
|
|
2041
|
+
"""
|
|
2042
|
+
Description:
|
|
2043
|
+
Function to get the positive infinity.
|
|
2044
|
+
|
|
2045
|
+
RETURNS:
|
|
2046
|
+
float
|
|
2047
|
+
|
|
2048
|
+
RAISES:
|
|
2049
|
+
None
|
|
2050
|
+
|
|
2051
|
+
EXAMPLES:
|
|
2052
|
+
inf = UtilFuncs._get_positive_infinity()
|
|
2053
|
+
"""
|
|
2054
|
+
return float("inf")
|
|
2055
|
+
|
|
2056
|
+
@staticmethod
|
|
2057
|
+
def _get_negative_infinity():
|
|
2058
|
+
"""
|
|
2059
|
+
Description:
|
|
2060
|
+
Function to get the negative infinity.
|
|
2061
|
+
|
|
2062
|
+
RETURNS:
|
|
2063
|
+
float
|
|
2064
|
+
|
|
2065
|
+
RAISES:
|
|
2066
|
+
None
|
|
2067
|
+
|
|
2068
|
+
EXAMPLES:
|
|
2069
|
+
inf = UtilFuncs._get_negative_infinity()
|
|
2070
|
+
"""
|
|
2071
|
+
return -1 * UtilFuncs._get_positive_infinity()
|
|
2072
|
+
|
|
2073
|
+
@staticmethod
|
|
2074
|
+
def _get_class(class_name, supress_isinstance_check=False):
|
|
2075
|
+
"""
|
|
2076
|
+
Description:
|
|
2077
|
+
Function to get the class dynamically with the name as 'class_name'.
|
|
2078
|
+
|
|
2079
|
+
PARAMETERS:
|
|
2080
|
+
class_name:
|
|
2081
|
+
Required Parameter.
|
|
2082
|
+
Specifies the name of the class generated to be.
|
|
2083
|
+
Types: str
|
|
2084
|
+
|
|
2085
|
+
supress_isinstance_check:
|
|
2086
|
+
Optional Parameter.
|
|
2087
|
+
Specifies whether the dynamically created class should overwrite the
|
|
2088
|
+
isinstance method or not. When set to True, if the class generated from
|
|
2089
|
+
this function is passed to isinstance method, instead of verifying the
|
|
2090
|
+
actual type, it tries to match the name of object's class with 'class_name'.
|
|
2091
|
+
Default value: False
|
|
2092
|
+
Types: bool
|
|
2093
|
+
|
|
2094
|
+
RETURNS:
|
|
2095
|
+
type
|
|
2096
|
+
|
|
2097
|
+
RAISES:
|
|
2098
|
+
None
|
|
2099
|
+
|
|
2100
|
+
EXAMPLES:
|
|
2101
|
+
inf = UtilFuncs._get_class("test")
|
|
2102
|
+
"""
|
|
2103
|
+
parent_object = object
|
|
2104
|
+
if supress_isinstance_check:
|
|
2105
|
+
|
|
2106
|
+
# isinstance function is governed by the dunder method __instancecheck__.
|
|
2107
|
+
# However, unlike other dunder method's, __instancecheck__ should be overwritten
|
|
2108
|
+
# for a class, instead of object ,i.e., while creating the class itself, __instancecheck__
|
|
2109
|
+
# should be overwritten.
|
|
2110
|
+
# Note that, python's type accepts either object or any other class as a parent class.
|
|
2111
|
+
# Since, other than object, one should pass only a class to a python type, creating a
|
|
2112
|
+
# dummy class and specifying the metaclass as SupressInstanceCheck so that the dummy class
|
|
2113
|
+
# has updated __instancecheck__ dunder method.
|
|
2114
|
+
class SupressInstanceCheck(type):
|
|
2115
|
+
def __instancecheck__(self, instance):
|
|
2116
|
+
try:
|
|
2117
|
+
return self.__name__ == instance.__class__.__name__
|
|
2118
|
+
except Exception:
|
|
2119
|
+
return False
|
|
2120
|
+
|
|
2121
|
+
class temp(metaclass=SupressInstanceCheck):
|
|
2122
|
+
pass
|
|
2123
|
+
|
|
2124
|
+
parent_object = temp
|
|
2125
|
+
|
|
2126
|
+
return type(class_name, (parent_object, ), {})
|
|
2127
|
+
|
|
2128
|
+
@staticmethod
|
|
2129
|
+
def _get_file_size(file_path, in_mb=True):
|
|
2130
|
+
"""
|
|
2131
|
+
Description:
|
|
2132
|
+
Function to get the size of file, given absolute file path.
|
|
2133
|
+
|
|
2134
|
+
PARAMETERS:
|
|
2135
|
+
file_path:
|
|
2136
|
+
Required Argument.
|
|
2137
|
+
Specifies absolute file path of the file.
|
|
2138
|
+
Types: str
|
|
2139
|
+
|
|
2140
|
+
in_mb:
|
|
2141
|
+
Optional Argument.
|
|
2142
|
+
Specifies whether to get the file size in mega bytes or not.
|
|
2143
|
+
If True, size of the file returns in MB's. Otherwise, returns
|
|
2144
|
+
in bytes.
|
|
2145
|
+
Default value: True
|
|
2146
|
+
Types: bool
|
|
2147
|
+
|
|
2148
|
+
RETURNS:
|
|
2149
|
+
int OR float
|
|
2150
|
+
|
|
2151
|
+
RAISES:
|
|
2152
|
+
TeradataMlException
|
|
2153
|
+
|
|
2154
|
+
EXAMPLES:
|
|
2155
|
+
file_size = UtilFuncs._get_file_size("/abc/xyz.txt")
|
|
2156
|
+
"""
|
|
2157
|
+
size_in_bytes = os.path.getsize(file_path)
|
|
2158
|
+
|
|
2159
|
+
return size_in_bytes/(1024*1024.0) if in_mb else size_in_bytes
|
|
2160
|
+
|
|
2161
|
+
@staticmethod
|
|
2162
|
+
def _http_request(url, method_type=HTTPRequest.GET, **kwargs):
|
|
2163
|
+
"""
|
|
2164
|
+
Description:
|
|
2165
|
+
Function to initiate HTTP(S) request.
|
|
2166
|
+
|
|
2167
|
+
PARAMETERS:
|
|
2168
|
+
url:
|
|
2169
|
+
Required Argument.
|
|
2170
|
+
Specifies the url to initiate http request.
|
|
2171
|
+
Types: str
|
|
2172
|
+
|
|
2173
|
+
method_type:
|
|
2174
|
+
Optional Argument.
|
|
2175
|
+
Specifies the type of HTTP request.
|
|
2176
|
+
Default value: HTTPREquest.GET
|
|
2177
|
+
Types: HTTPRequest enum
|
|
2178
|
+
|
|
2179
|
+
**kwargs:
|
|
2180
|
+
Specifies the keyword arguments required for HTTP Request.
|
|
2181
|
+
Below are the expected arguments as a part of kwargs:
|
|
2182
|
+
json:
|
|
2183
|
+
Optional Argument.
|
|
2184
|
+
Specifies the payload for HTTP request in a dictionary.
|
|
2185
|
+
Types: dict
|
|
2186
|
+
|
|
2187
|
+
data:
|
|
2188
|
+
Optional Argument.
|
|
2189
|
+
Specifies the payload for HTTP request in a string format.
|
|
2190
|
+
Types: str
|
|
2191
|
+
|
|
2192
|
+
headers:
|
|
2193
|
+
Optional Argument.
|
|
2194
|
+
Specifies the headers for HTTP request.
|
|
2195
|
+
Types: dict
|
|
2196
|
+
|
|
2197
|
+
verify:
|
|
2198
|
+
Optional Argument.
|
|
2199
|
+
Specifies whether to verify the certificate or not in a HTTPS request.
|
|
2200
|
+
One can specify either False to suppress the certificate verification or
|
|
2201
|
+
path to certificate to verify the certificate.
|
|
2202
|
+
Types: str OR bool
|
|
2203
|
+
|
|
2204
|
+
files:
|
|
2205
|
+
Optional Argument.
|
|
2206
|
+
Specifies the file to be uploaded with a HTTP Request.
|
|
2207
|
+
Types: tuple
|
|
2208
|
+
|
|
2209
|
+
RETURNS:
|
|
2210
|
+
Response object.
|
|
2211
|
+
|
|
2212
|
+
RAISES:
|
|
2213
|
+
None
|
|
2214
|
+
|
|
2215
|
+
EXAMPLES:
|
|
2216
|
+
resp = UtilFuncs._http_request("http://abc/xyz.teradata")
|
|
2217
|
+
"""
|
|
2218
|
+
kwargs["verify"] = configure.certificate_file
|
|
2219
|
+
|
|
2220
|
+
if not configure.certificate_file:
|
|
2221
|
+
warnings.filterwarnings("ignore", message="Unverified HTTPS request is being made to host[ a-zA-Z0-9'-.]*")
|
|
2222
|
+
|
|
2223
|
+
return getattr(requests, method_type.value)(url=url, **kwargs)
|
|
2224
|
+
|
|
2225
|
+
@staticmethod
|
|
2226
|
+
def _get_tdml_directory():
|
|
2227
|
+
"""
|
|
2228
|
+
DESCRIPTION:
|
|
2229
|
+
Function to get the directory of teradataml module.
|
|
2230
|
+
|
|
2231
|
+
PARAMETERS:
|
|
2232
|
+
None.
|
|
2233
|
+
|
|
2234
|
+
RETURNS:
|
|
2235
|
+
str.
|
|
2236
|
+
|
|
2237
|
+
EXAMPLES:
|
|
2238
|
+
>>> tdml_path = UtilFuncs._get_tdml_directory()
|
|
2239
|
+
"""
|
|
2240
|
+
# Get the directory of teradataml module.
|
|
2241
|
+
return os.path.dirname(_version.__file__)
|
|
2242
|
+
|
|
2243
|
+
@staticmethod
|
|
2244
|
+
def _get_data_directory(dir_name=None, func_type=None, version=None):
|
|
2245
|
+
"""
|
|
2246
|
+
DESCRIPTION:
|
|
2247
|
+
Function to get the directory for jsons or docs from teradataml/data.
|
|
2248
|
+
|
|
2249
|
+
PARAMETERS:
|
|
2250
|
+
dir_name:
|
|
2251
|
+
Optional Argument.
|
|
2252
|
+
Specifies the name of directory required from teradataml/data directory.
|
|
2253
|
+
Permitted values : ["jsons", "docs"]
|
|
2254
|
+
Types: str
|
|
2255
|
+
|
|
2256
|
+
func_type
|
|
2257
|
+
Optional Argument.
|
|
2258
|
+
Specifies the type of function for which jsons or docs directory is required.
|
|
2259
|
+
Types: TeradataAnalyticFunctionInfo
|
|
2260
|
+
|
|
2261
|
+
version:
|
|
2262
|
+
Optional Argument.
|
|
2263
|
+
Specifies the version of directory for which jsons or docs directory is required.
|
|
2264
|
+
Types: str
|
|
2265
|
+
|
|
2266
|
+
RETURNS:
|
|
2267
|
+
path to desired directory.
|
|
2268
|
+
|
|
2269
|
+
EXAMPLES:
|
|
2270
|
+
>>> json_dir = UtilFuncs._get_data_directory(dir_name="jsons",
|
|
2271
|
+
... func_type=TeradataAnalyticFunctionInfo.FASTPATH,
|
|
2272
|
+
... version="17.10")
|
|
2273
|
+
|
|
2274
|
+
"""
|
|
2275
|
+
if func_type:
|
|
2276
|
+
func_type = func_type.value["func_type"]
|
|
2277
|
+
dir_path = os.path.join(UtilFuncs._get_tdml_directory(), "data")
|
|
2278
|
+
levels = [dir_name, func_type, version]
|
|
2279
|
+
for level in levels:
|
|
2280
|
+
if level:
|
|
2281
|
+
dir_path = os.path.join(dir_path, level)
|
|
2282
|
+
else:
|
|
2283
|
+
break
|
|
2284
|
+
if os.path.exists(dir_path):
|
|
2285
|
+
return dir_path
|
|
2286
|
+
|
|
2287
|
+
@staticmethod
|
|
2288
|
+
def _replace_special_chars(str_value, replace_char="_", addon=None):
|
|
2289
|
+
"""
|
|
2290
|
+
DESCRIPTION:
|
|
2291
|
+
Function to replace any special character with a underscore(_).
|
|
2292
|
+
|
|
2293
|
+
PARAMETERS:
|
|
2294
|
+
str_value:
|
|
2295
|
+
Required Argument.
|
|
2296
|
+
Specifies the value of string which has special characters.
|
|
2297
|
+
Types: str
|
|
2298
|
+
|
|
2299
|
+
replace_char:
|
|
2300
|
+
Optional Argument.
|
|
2301
|
+
Specifies the value to be replaced for any special character.
|
|
2302
|
+
Types: str
|
|
2303
|
+
|
|
2304
|
+
addon
|
|
2305
|
+
Optional Argument.
|
|
2306
|
+
Specifies a dictionary with key as value to be checked in "s" and value
|
|
2307
|
+
to be replaced in "s".
|
|
2308
|
+
Types: dict
|
|
2309
|
+
|
|
2310
|
+
RETURNS:
|
|
2311
|
+
str
|
|
2312
|
+
|
|
2313
|
+
EXAMPLES:
|
|
2314
|
+
>>> json_dir = UtilFuncs._replace_special_chars("123$%.", addon={"$": "#"})
|
|
2315
|
+
"""
|
|
2316
|
+
char_dict = {'A': 'A',
|
|
2317
|
+
'B': 'B',
|
|
2318
|
+
'C': 'C',
|
|
2319
|
+
'D': 'D',
|
|
2320
|
+
'E': 'E',
|
|
2321
|
+
'F': 'F',
|
|
2322
|
+
'G': 'G',
|
|
2323
|
+
'H': 'H',
|
|
2324
|
+
'I': 'I',
|
|
2325
|
+
'J': 'J',
|
|
2326
|
+
'K': 'K',
|
|
2327
|
+
'L': 'L',
|
|
2328
|
+
'M': 'M',
|
|
2329
|
+
'N': 'N',
|
|
2330
|
+
'O': 'O',
|
|
2331
|
+
'P': 'P',
|
|
2332
|
+
'Q': 'Q',
|
|
2333
|
+
'R': 'R',
|
|
2334
|
+
'S': 'S',
|
|
2335
|
+
'T': 'T',
|
|
2336
|
+
'U': 'U',
|
|
2337
|
+
'V': 'V',
|
|
2338
|
+
'W': 'W',
|
|
2339
|
+
'X': 'X',
|
|
2340
|
+
'Y': 'Y',
|
|
2341
|
+
'Z': 'Z',
|
|
2342
|
+
'a': 'a',
|
|
2343
|
+
'b': 'b',
|
|
2344
|
+
'c': 'c',
|
|
2345
|
+
'd': 'd',
|
|
2346
|
+
'e': 'e',
|
|
2347
|
+
'f': 'f',
|
|
2348
|
+
'g': 'g',
|
|
2349
|
+
'h': 'h',
|
|
2350
|
+
'i': 'i',
|
|
2351
|
+
'j': 'j',
|
|
2352
|
+
'k': 'k',
|
|
2353
|
+
'l': 'l',
|
|
2354
|
+
'm': 'm',
|
|
2355
|
+
'n': 'n',
|
|
2356
|
+
'o': 'o',
|
|
2357
|
+
'p': 'p',
|
|
2358
|
+
'q': 'q',
|
|
2359
|
+
'r': 'r',
|
|
2360
|
+
's': 's',
|
|
2361
|
+
't': 't',
|
|
2362
|
+
'u': 'u',
|
|
2363
|
+
'v': 'v',
|
|
2364
|
+
'w': 'w',
|
|
2365
|
+
'x': 'x',
|
|
2366
|
+
'y': 'y',
|
|
2367
|
+
'z': 'z',
|
|
2368
|
+
'0': '0',
|
|
2369
|
+
'1': '1',
|
|
2370
|
+
'2': '2',
|
|
2371
|
+
'3': '3',
|
|
2372
|
+
'4': '4',
|
|
2373
|
+
'5': '5',
|
|
2374
|
+
'6': '6',
|
|
2375
|
+
'7': '7',
|
|
2376
|
+
'8': '8',
|
|
2377
|
+
'9': '9'}
|
|
2378
|
+
char_dict.update({" ": "", "_": "_", "\"": ""})
|
|
2379
|
+
if addon:
|
|
2380
|
+
char_dict.update(addon)
|
|
2381
|
+
return reduce(lambda x,y: x+y, (char_dict.get(c, replace_char) for c in str_value))
|
|
2382
|
+
|
|
2383
|
+
@staticmethod
|
|
2384
|
+
def _get_dict_from_libs(lib_name):
|
|
2385
|
+
"""
|
|
2386
|
+
DESCRIPTION:
|
|
2387
|
+
Function to format the list of library version string to a dictionary,
|
|
2388
|
+
on the basis of regex.
|
|
2389
|
+
|
|
2390
|
+
PARAMETERS:
|
|
2391
|
+
lib_name:
|
|
2392
|
+
Required Argument.
|
|
2393
|
+
Specifies the libs the user wants to format to a dictionary with
|
|
2394
|
+
key as lib_name and value as lib_version.
|
|
2395
|
+
Types: str, list of str
|
|
2396
|
+
|
|
2397
|
+
RETURNS:
|
|
2398
|
+
dict
|
|
2399
|
+
"""
|
|
2400
|
+
result = {}
|
|
2401
|
+
if isinstance(lib_name, str):
|
|
2402
|
+
lib_name = UtilFuncs._as_list(lib_name)
|
|
2403
|
+
for lib in lib_name:
|
|
2404
|
+
matches = re.findall(r'([^<>=]+)([<>=].*)', lib)
|
|
2405
|
+
if matches:
|
|
2406
|
+
for key, value in matches:
|
|
2407
|
+
result[key] = value
|
|
2408
|
+
else:
|
|
2409
|
+
result[lib] = ''
|
|
2410
|
+
return result
|
|
2411
|
+
|
|
2412
|
+
@staticmethod
|
|
2413
|
+
def _is_valid_td_type(type_):
|
|
2414
|
+
"""
|
|
2415
|
+
DESCRIPTION:
|
|
2416
|
+
Function to check whether it is valid teradatasqlalchemy type or not.
|
|
2417
|
+
|
|
2418
|
+
PARAMETERS:
|
|
2419
|
+
type_:
|
|
2420
|
+
Required Argument.
|
|
2421
|
+
Specifies any value which needs to be validated for teradatasqlalchemy type.
|
|
2422
|
+
Types: Any python object
|
|
2423
|
+
|
|
2424
|
+
RETURNS:
|
|
2425
|
+
bool
|
|
2426
|
+
"""
|
|
2427
|
+
if isinstance(type_, _TDType):
|
|
2428
|
+
return True
|
|
2429
|
+
if isinstance(type_, type) and issubclass(type_, _TDType):
|
|
2430
|
+
return True
|
|
2431
|
+
return False
|
|
2432
|
+
|
|
2433
|
+
@staticmethod
|
|
2434
|
+
def _all_df_column_expressions(df_column):
|
|
2435
|
+
"""
|
|
2436
|
+
DESCRIPTION:
|
|
2437
|
+
A method to get all the SQLALchemy Columns involved in corresponding DataFrame.
|
|
2438
|
+
|
|
2439
|
+
PARAMETERS:
|
|
2440
|
+
df_column:
|
|
2441
|
+
Required Argument.
|
|
2442
|
+
Specifies teradataml DataFrame ColumnExpression.
|
|
2443
|
+
Types: teradataml DataFrame ColumnExpression
|
|
2444
|
+
|
|
2445
|
+
RAISES:
|
|
2446
|
+
None
|
|
2447
|
+
|
|
2448
|
+
RETURNS:
|
|
2449
|
+
list
|
|
2450
|
+
|
|
2451
|
+
EXAMPLES:
|
|
2452
|
+
>>> self._all_df_column_expressions
|
|
2453
|
+
"""
|
|
2454
|
+
cols = []
|
|
2455
|
+
for table_ in df_column._get_sqlalchemy_tables(df_column.expression):
|
|
2456
|
+
cols = cols + list(table_.columns)
|
|
2457
|
+
return cols
|
|
2458
|
+
|
|
2459
|
+
@staticmethod
|
|
2460
|
+
def _all_df_columns(df_column):
|
|
2461
|
+
"""
|
|
2462
|
+
DESCRIPTION:
|
|
2463
|
+
A method to get all the column names involved in corresponding DataFrame.
|
|
2464
|
+
|
|
2465
|
+
PARAMETERS:
|
|
2466
|
+
df_column:
|
|
2467
|
+
Required Argument.
|
|
2468
|
+
Specifies teradataml DataFrame ColumnExpression.
|
|
2469
|
+
Types: teradataml DataFrame ColumnExpression
|
|
2470
|
+
|
|
2471
|
+
RAISES:
|
|
2472
|
+
None
|
|
2473
|
+
|
|
2474
|
+
RETURNS:
|
|
2475
|
+
list
|
|
2476
|
+
|
|
2477
|
+
EXAMPLES:
|
|
2478
|
+
>>> self._all_df_columns
|
|
2479
|
+
"""
|
|
2480
|
+
return [col.name for col in UtilFuncs._all_df_column_expressions(df_column)]
|
|
2481
|
+
|
|
2482
|
+
@staticmethod
|
|
2483
|
+
def _is_lake():
|
|
2484
|
+
"""
|
|
2485
|
+
DESCRIPTION:
|
|
2486
|
+
An internal function to check whether system is Lake or enterprise.
|
|
2487
|
+
|
|
2488
|
+
PARAMETERS:
|
|
2489
|
+
None.
|
|
2490
|
+
|
|
2491
|
+
RAISES:
|
|
2492
|
+
None
|
|
2493
|
+
|
|
2494
|
+
RETURNS:
|
|
2495
|
+
bool
|
|
2496
|
+
|
|
2497
|
+
EXAMPLES:
|
|
2498
|
+
>>> self._is_lake()
|
|
2499
|
+
"""
|
|
2500
|
+
|
|
2501
|
+
tbl_operator = configure.table_operator.lower() \
|
|
2502
|
+
if configure.table_operator else None
|
|
2503
|
+
|
|
2504
|
+
# If the user does not provide a table_operator, check the database version
|
|
2505
|
+
# and determine the system type accordingly.
|
|
2506
|
+
if tbl_operator is None:
|
|
2507
|
+
from teradataml.context.context import _get_database_version
|
|
2508
|
+
if int(_get_database_version().split(".")[0]) < 20:
|
|
2509
|
+
return False
|
|
2510
|
+
# If the database version is 20 or higher, check if the system is VCL or not.
|
|
2511
|
+
try:
|
|
2512
|
+
res = UtilFuncs._execute_query("SELECT 1 WHERE TD_GetSystemType('PRODUCT') = 'VCL';")
|
|
2513
|
+
return True if res else False
|
|
2514
|
+
except OperationalError:
|
|
2515
|
+
return True
|
|
2516
|
+
|
|
2517
|
+
return tbl_operator == "apply"
|
|
2518
|
+
|
|
2519
|
+
@staticmethod
|
|
2520
|
+
def _get_python_execution_path():
|
|
2521
|
+
"""
|
|
2522
|
+
DESCRIPTION:
|
|
2523
|
+
An internal function to get the python execution path.
|
|
2524
|
+
|
|
2525
|
+
PARAMETERS:
|
|
2526
|
+
None.
|
|
2527
|
+
|
|
2528
|
+
RAISES:
|
|
2529
|
+
None
|
|
2530
|
+
|
|
2531
|
+
RETURNS:
|
|
2532
|
+
bool
|
|
2533
|
+
|
|
2534
|
+
EXAMPLES:
|
|
2535
|
+
>>> self._get_python_execution_path()
|
|
2536
|
+
"""
|
|
2537
|
+
# 'indb_install_location' expects python installation directory path.
|
|
2538
|
+
# Hence, postfixing python binary path.
|
|
2539
|
+
return "python" if UtilFuncs._is_lake() else \
|
|
2540
|
+
'{}/bin/python3'.format(configure.indb_install_location)
|
|
2541
|
+
|
|
2542
|
+
def _is_view(tablename):
|
|
2543
|
+
"""
|
|
2544
|
+
DESCRIPTION:
|
|
2545
|
+
Internal function to check whether the object is view or not.
|
|
2546
|
+
PARAMETERS:
|
|
2547
|
+
tablename:
|
|
2548
|
+
Required Argument.
|
|
2549
|
+
Table name or view name to be checked.
|
|
2550
|
+
Types: str
|
|
2551
|
+
RAISES:
|
|
2552
|
+
None.
|
|
2553
|
+
RETURNS:
|
|
2554
|
+
True when the tablename is view, else false.
|
|
2555
|
+
EXAMPLES:
|
|
2556
|
+
>>> _is_view('"dbname"."tablename"')
|
|
2557
|
+
"""
|
|
2558
|
+
db_name = UtilFuncs._teradata_unquote_arg(UtilFuncs._extract_db_name(tablename), "\"")
|
|
2559
|
+
table_view_name = UtilFuncs._teradata_unquote_arg(UtilFuncs._extract_table_name(tablename), "\"")
|
|
2560
|
+
query = SQLBundle._build_select_table_kind(db_name, "'{0}'".format(table_view_name), "'V'")
|
|
2561
|
+
|
|
2562
|
+
df = UtilFuncs._execute_query(query)
|
|
2563
|
+
if len(df) > 0:
|
|
2564
|
+
return True
|
|
2565
|
+
else:
|
|
2566
|
+
return False
|
|
2567
|
+
|
|
2568
|
+
@staticmethod
|
|
2569
|
+
def _set_queryband(force_flush=False):
|
|
2570
|
+
"""
|
|
2571
|
+
DESCRIPTION:
|
|
2572
|
+
Internal function to execute SET QUERYBAND queries.
|
|
2573
|
+
|
|
2574
|
+
PARAMETERS:
|
|
2575
|
+
force_flush:
|
|
2576
|
+
Optional Argument.
|
|
2577
|
+
Specifies flag to consume all entries in queryband buffer.
|
|
2578
|
+
Types: bool
|
|
2579
|
+
|
|
2580
|
+
RAISES:
|
|
2581
|
+
None.
|
|
2582
|
+
|
|
2583
|
+
RETURNS:
|
|
2584
|
+
None.
|
|
2585
|
+
|
|
2586
|
+
EXAMPLES:
|
|
2587
|
+
>>> UtilFuncs._set_queryband(force_flush=True)
|
|
2588
|
+
"""
|
|
2589
|
+
from teradataml import session_queryband
|
|
2590
|
+
try:
|
|
2591
|
+
# Trigger SET queryband only when
|
|
2592
|
+
# queryband string has reached to max char limit of 256 chars
|
|
2593
|
+
# and has been moved to unflushed_buffer or
|
|
2594
|
+
# it is called explicitly.
|
|
2595
|
+
if session_queryband._unflushed_buffers or force_flush:
|
|
2596
|
+
qb_queries = session_queryband.generate_set_queryband_queries(consume_all=force_flush)
|
|
2597
|
+
for qb_query in qb_queries:
|
|
2598
|
+
execute_sql(qb_query)
|
|
2599
|
+
except Exception as _set_queryband_err:
|
|
2600
|
+
pass
|
|
2601
|
+
|
|
2602
|
+
def _create_or_get_env(template):
|
|
2603
|
+
"""
|
|
2604
|
+
DESCRIPTION:
|
|
2605
|
+
Internal function to return the environment if already exists else
|
|
2606
|
+
creates the environment using template file and return the environment.
|
|
2607
|
+
|
|
2608
|
+
PARAMETERS:
|
|
2609
|
+
template:
|
|
2610
|
+
Required Argument.
|
|
2611
|
+
Template json file name containing details of environment(s) to be created.
|
|
2612
|
+
Types: str
|
|
2613
|
+
|
|
2614
|
+
RAISES:
|
|
2615
|
+
TeradataMLException
|
|
2616
|
+
|
|
2617
|
+
RETURNS:
|
|
2618
|
+
An object of class UserEnv representing the user environment.
|
|
2619
|
+
|
|
2620
|
+
EXAMPLES:
|
|
2621
|
+
>>> self._create_or_get_env("open_source_ml.json")
|
|
2622
|
+
"""
|
|
2623
|
+
# Get the template file path.
|
|
2624
|
+
from teradataml import _TDML_DIRECTORY
|
|
2625
|
+
from teradataml.scriptmgmt.lls_utils import create_env, get_env
|
|
2626
|
+
template_dir_path = os.path.join(_TDML_DIRECTORY, "data", "templates", template)
|
|
2627
|
+
|
|
2628
|
+
# Read template file.
|
|
2629
|
+
with open(template_dir_path, "r") as r_file:
|
|
2630
|
+
data = json.load(r_file)
|
|
2631
|
+
|
|
2632
|
+
# Get env_name.
|
|
2633
|
+
_env_name = data["env_specs"][0]["env_name"]
|
|
2634
|
+
|
|
2635
|
+
try:
|
|
2636
|
+
# Call function to get env.
|
|
2637
|
+
return get_env(_env_name)
|
|
2638
|
+
except TeradataMlException as tdml_e:
|
|
2639
|
+
# We will get here when error says, env does not exist otherwise raise the exception as is.
|
|
2640
|
+
# Env does not exist so create one.
|
|
2641
|
+
|
|
2642
|
+
exc_msg = "Failed to execute get_env(). User environment '{}' not " \
|
|
2643
|
+
"found.".format(_env_name)
|
|
2644
|
+
if exc_msg in tdml_e.args[0]:
|
|
2645
|
+
print(f"No OpenAF environment with name '{_env_name}' found. Creating one with "\
|
|
2646
|
+
"latest supported python and required packages.")
|
|
2647
|
+
return create_env(template=template_dir_path)
|
|
2648
|
+
else:
|
|
2649
|
+
raise tdml_e
|
|
2650
|
+
except Exception as exc:
|
|
2651
|
+
raise exc
|
|
2652
|
+
|
|
2653
|
+
def _get_env_name(col=None):
|
|
2654
|
+
"""
|
|
2655
|
+
DESCRIPTION:
|
|
2656
|
+
Internal function to get the env name if passed with ColumnExpression
|
|
2657
|
+
else the default "openml_env".
|
|
2658
|
+
|
|
2659
|
+
PARAMETERS:
|
|
2660
|
+
col:
|
|
2661
|
+
Optional Argument.
|
|
2662
|
+
Specifies teradataml DataFrame ColumnExpression.
|
|
2663
|
+
Types: teradataml DataFrame ColumnExpression
|
|
2664
|
+
Default Value: None
|
|
2665
|
+
|
|
2666
|
+
RAISES:
|
|
2667
|
+
None.
|
|
2668
|
+
|
|
2669
|
+
RETURNS:
|
|
2670
|
+
string
|
|
2671
|
+
|
|
2672
|
+
EXAMPLES:
|
|
2673
|
+
>>> self._get_env_name(col)
|
|
2674
|
+
"""
|
|
2675
|
+
|
|
2676
|
+
# If ColumnExpression is passed and env_name is passed with it fetch the env name,
|
|
2677
|
+
# else check if default "openml_user_env" env is configured or not,
|
|
2678
|
+
# else get the default "openml_env" env if exists or create new deafult env.
|
|
2679
|
+
if col and col._env_name is not None:
|
|
2680
|
+
from teradataml.scriptmgmt.UserEnv import UserEnv
|
|
2681
|
+
env = col._env_name
|
|
2682
|
+
env_name = env.env_name if isinstance(col._env_name, UserEnv) else env
|
|
2683
|
+
elif configure.openml_user_env is not None:
|
|
2684
|
+
env_name = configure.openml_user_env.env_name
|
|
2685
|
+
else:
|
|
2686
|
+
env_name = UtilFuncs._create_or_get_env("open_source_ml.json").env_name
|
|
2687
|
+
return env_name
|
|
2688
|
+
|
|
2689
|
+
def _func_to_string(user_functions):
|
|
2690
|
+
"""
|
|
2691
|
+
DESCRIPTION:
|
|
2692
|
+
Internal function to get the user functions in a single string format.
|
|
2693
|
+
|
|
2694
|
+
PARAMETERS:
|
|
2695
|
+
user_functions:
|
|
2696
|
+
Required Argument.
|
|
2697
|
+
List of user functions.
|
|
2698
|
+
Types: list
|
|
2699
|
+
|
|
2700
|
+
RAISES:
|
|
2701
|
+
None.
|
|
2702
|
+
|
|
2703
|
+
RETURNS:
|
|
2704
|
+
string
|
|
2705
|
+
|
|
2706
|
+
EXAMPLES:
|
|
2707
|
+
>>> from teradataml.dataframe.functions import udf
|
|
2708
|
+
>>> @udf(returns=VARCHAR())
|
|
2709
|
+
... def sum(x, y):
|
|
2710
|
+
... return x+y
|
|
2711
|
+
>>>
|
|
2712
|
+
>>> def to_upper(s):
|
|
2713
|
+
... return s.upper()
|
|
2714
|
+
>>> user_functions = [sum(1,2)._udf, to_upper]
|
|
2715
|
+
>>> res = self._func_to_string(user_functions)
|
|
2716
|
+
>>> print(res)
|
|
2717
|
+
def sum(x, y):
|
|
2718
|
+
return x+y
|
|
2719
|
+
|
|
2720
|
+
def to_upper(s):
|
|
2721
|
+
return s.upper()
|
|
2722
|
+
|
|
2723
|
+
>>>
|
|
2724
|
+
"""
|
|
2725
|
+
user_function_code = ""
|
|
2726
|
+
for func in user_functions:
|
|
2727
|
+
# Get the source code of the user function.
|
|
2728
|
+
# Note that, checking for lambda function is required for teradatamlspk UDFs
|
|
2729
|
+
# If the function is a lambda function, get the source code from __source__.
|
|
2730
|
+
func = getsource(func) if func.__code__.co_name != "<lambda>" else func.__source__
|
|
2731
|
+
|
|
2732
|
+
# If the function have any extra space in the beginning remove it.
|
|
2733
|
+
func = func.lstrip()
|
|
2734
|
+
# Function can have decorator,e.g. udf as decorator, remove it.
|
|
2735
|
+
if func.startswith("@"):
|
|
2736
|
+
func = func[func.find("\n")+1: ].lstrip()
|
|
2737
|
+
# If multiple functions are passed, separate them with new line.
|
|
2738
|
+
user_function_code += func + '\n'
|
|
2739
|
+
return user_function_code
|
|
2740
|
+
|
|
2741
|
+
@staticmethod
|
|
2742
|
+
def _get_qualified_table_name(schema_name, table_name):
|
|
2743
|
+
"""
|
|
2744
|
+
DESCRIPTION:
|
|
2745
|
+
Internal function to get the fully qualified name of table.
|
|
2746
|
+
|
|
2747
|
+
PARAMETERS:
|
|
2748
|
+
schema_name:
|
|
2749
|
+
Required Argument.
|
|
2750
|
+
Specifies the name of the schema.
|
|
2751
|
+
Types: str
|
|
2752
|
+
|
|
2753
|
+
table_name:
|
|
2754
|
+
Required Argument.
|
|
2755
|
+
Specifies the name of the table.
|
|
2756
|
+
Types: str
|
|
2757
|
+
|
|
2758
|
+
RAISES:
|
|
2759
|
+
None.
|
|
2760
|
+
|
|
2761
|
+
RETURNS:
|
|
2762
|
+
string
|
|
2763
|
+
|
|
2764
|
+
EXAMPLES:
|
|
2765
|
+
>>> UtilFuncs._get_qualified_table_name("schema_name", "table_name")
|
|
2766
|
+
'"schema_name"."table_name"'
|
|
2767
|
+
"""
|
|
2768
|
+
return '"{}"."{}"'.format(schema_name, table_name)
|
|
2769
|
+
|
|
2770
|
+
def _check_python_version_diff(env = None):
|
|
2771
|
+
"""
|
|
2772
|
+
DESCRIPTION:
|
|
2773
|
+
Internal function to check the python version difference between Vantage and local.
|
|
2774
|
+
|
|
2775
|
+
PARAMETERS:
|
|
2776
|
+
env:
|
|
2777
|
+
Optional Argument.
|
|
2778
|
+
Specifies the user environment for Vantage Cloud Lake.
|
|
2779
|
+
Types: str, object of class UserEnv
|
|
2780
|
+
Default Value: None
|
|
2781
|
+
|
|
2782
|
+
RAISES:
|
|
2783
|
+
TeradataMlException
|
|
2784
|
+
|
|
2785
|
+
RETURNS:
|
|
2786
|
+
None.
|
|
2787
|
+
|
|
2788
|
+
EXAMPLES:
|
|
2789
|
+
>>> self._check_python_version_diff(env)
|
|
2790
|
+
"""
|
|
2791
|
+
if env:
|
|
2792
|
+
# Get the Python interpreter version of the user environment.
|
|
2793
|
+
from teradataml.scriptmgmt.lls_utils import list_user_envs
|
|
2794
|
+
from teradataml.scriptmgmt.UserEnv import UserEnv
|
|
2795
|
+
env_list = list_user_envs()
|
|
2796
|
+
user_env_name = env.env_name if isinstance(env, UserEnv) else env
|
|
2797
|
+
env_base_version = env_list[env_list['env_name'] == user_env_name].base_env_name.values
|
|
2798
|
+
# Check if the user environment is not found, then return.
|
|
2799
|
+
if len(env_base_version) == 0:
|
|
2800
|
+
return
|
|
2801
|
+
python_env = env_base_version[0].split("_")[1]
|
|
2802
|
+
|
|
2803
|
+
# Get the Python interpreter version of the local environment.
|
|
2804
|
+
from teradataml.context import context as tdmlctx
|
|
2805
|
+
python_local = tdmlctx.python_version_local.rsplit(".", 1)[0]
|
|
2806
|
+
# Check if the Python interpreter major versions are consistent between Lake user environment and local.
|
|
2807
|
+
# If not, raise an exception.
|
|
2808
|
+
if python_env != python_local:
|
|
2809
|
+
raise TeradataMlException(Messages.get_message(MessageCodes.PYTHON_VERSION_MISMATCH_OAF,
|
|
2810
|
+
python_env, python_local),
|
|
2811
|
+
MessageCodes.PYTHON_VERSION_MISMATCH_OAF)
|
|
2812
|
+
else:
|
|
2813
|
+
from teradataml.context import context as tdmlctx
|
|
2814
|
+
from teradataml.dbutils.dbutils import (db_python_version_diff,
|
|
2815
|
+
set_session_param)
|
|
2816
|
+
set_session_param("searchuifdbpath",
|
|
2817
|
+
UtilFuncs._get_dialect_quoted_name(tdmlctx._get_current_databasename()))
|
|
2818
|
+
if len(db_python_version_diff()) > 0:
|
|
2819
|
+
# Raise exception when python versions don't match between Vantage and local.
|
|
2820
|
+
py_major_vantage_version = tdmlctx.python_version_vantage.rsplit(".", 1)[0]
|
|
2821
|
+
raise TeradataMlException(Messages.get_message(MessageCodes.PYTHON_VERSION_MISMATCH,
|
|
2822
|
+
tdmlctx.python_version_vantage, py_major_vantage_version),
|
|
2823
|
+
MessageCodes.PYTHON_VERSION_MISMATCH)
|
|
2824
|
+
|
|
2825
|
+
def _check_package_version_diff(func, packages, env=None):
|
|
2826
|
+
"""
|
|
2827
|
+
DESCRIPTION:
|
|
2828
|
+
Internal function to process packages differences between Vantage and local.
|
|
2829
|
+
Note:
|
|
2830
|
+
* Raises a warning if the versions of certain Python packages are not consistent between Vantage and local.
|
|
2831
|
+
|
|
2832
|
+
PARAMETERS:
|
|
2833
|
+
func:
|
|
2834
|
+
Required Argument.
|
|
2835
|
+
Specifies the function name.
|
|
2836
|
+
Types: str
|
|
2837
|
+
|
|
2838
|
+
packages:
|
|
2839
|
+
Required Argument.
|
|
2840
|
+
Specifies the list of package names.
|
|
2841
|
+
Types: list of str
|
|
2842
|
+
|
|
2843
|
+
env:
|
|
2844
|
+
Optional Argument.
|
|
2845
|
+
Specifies the user environment for Vantage Cloud Lake.
|
|
2846
|
+
Types: str, object of class UserEnv
|
|
2847
|
+
Default Value: None
|
|
2848
|
+
|
|
2849
|
+
RETURNS:
|
|
2850
|
+
None
|
|
2851
|
+
|
|
2852
|
+
RAISES:
|
|
2853
|
+
OneTimeUserWarning
|
|
2854
|
+
|
|
2855
|
+
EXAMPLES:
|
|
2856
|
+
self._process_package_differences("apply", ["dill"], env)
|
|
2857
|
+
"""
|
|
2858
|
+
|
|
2859
|
+
# Check if OSML required packages are verified or not.
|
|
2860
|
+
from teradataml.opensource._constants import \
|
|
2861
|
+
_packages_verified_in_vantage
|
|
2862
|
+
_is_packages_verfied_in_vantage = _packages_verified_in_vantage.get(
|
|
2863
|
+
func, None)
|
|
2864
|
+
if _is_packages_verfied_in_vantage:
|
|
2865
|
+
return
|
|
2866
|
+
|
|
2867
|
+
if env:
|
|
2868
|
+
from teradataml.scriptmgmt.lls_utils import get_env
|
|
2869
|
+
from teradataml.scriptmgmt.UserEnv import UserEnv
|
|
2870
|
+
env = env if isinstance(env, UserEnv) else get_env(env)
|
|
2871
|
+
env_pkg_df = env.libs
|
|
2872
|
+
pkgs_dict = dict(zip(env_pkg_df['name'], env_pkg_df['version']))
|
|
2873
|
+
|
|
2874
|
+
from importlib.metadata import version
|
|
2875
|
+
warning_raised = False
|
|
2876
|
+
strr = []
|
|
2877
|
+
for pkg in packages:
|
|
2878
|
+
env_version = pkgs_dict.get(pkg)
|
|
2879
|
+
local_version = version(pkg)
|
|
2880
|
+
# Write the requirements file listing all the related packages and their versions
|
|
2881
|
+
# if the versions Python packages are not consistent between Vantage and local.
|
|
2882
|
+
if env_version != local_version:
|
|
2883
|
+
warning_raised = True
|
|
2884
|
+
strr.append(f"{pkg}=={local_version}")
|
|
2885
|
+
|
|
2886
|
+
# If there are differences in package versions, display a warning message to the user.
|
|
2887
|
+
# about the package differences and the requirements file created for the user to install the packages
|
|
2888
|
+
if warning_raised:
|
|
2889
|
+
file_name = f"requirements_{func}.txt"
|
|
2890
|
+
req_file = os.path.join(GarbageCollector._get_temp_dir_name(), file_name)
|
|
2891
|
+
with open(req_file, "w") as f:
|
|
2892
|
+
f.write("\n".join(strr))
|
|
2893
|
+
|
|
2894
|
+
packages = "{}".format(packages[0]) if len(packages) == 1 else\
|
|
2895
|
+
"', '".join(packages[:-1]) + "' and '" + packages[-1]
|
|
2896
|
+
|
|
2897
|
+
if func == "apply":
|
|
2898
|
+
warning_msg = f"The version of certain Python packages are not consistent between Lake "\
|
|
2899
|
+
f"user environment and local. Teradata recommends to maintain same version of '{packages}' "\
|
|
2900
|
+
f"between Lake user environment and local for '{func}'."
|
|
2901
|
+
else:
|
|
2902
|
+
_packages_verified_in_vantage[func] = True
|
|
2903
|
+
warning_msg = "The versions of certain Python packages are not consistent between "\
|
|
2904
|
+
"Lake user environment and local. OpenSourceML compares the versions of '{}' "\
|
|
2905
|
+
f"(and also matches the patterns of these packages) used by 'td_{func}'. "\
|
|
2906
|
+
"Teradata recommends same versions for all the Python packages between Lake "\
|
|
2907
|
+
"user environment and local."
|
|
2908
|
+
|
|
2909
|
+
req = f"\nA requirements file listing all '{func}' " + \
|
|
2910
|
+
f"related packages and their versions has been written to '{req_file}'. "+ \
|
|
2911
|
+
"Update the Lake user environment with the required packages.\n"
|
|
2912
|
+
|
|
2913
|
+
warning_msg += req
|
|
2914
|
+
warnings.warn(warning_msg.format(packages), category=OneTimeUserWarning)
|
|
2915
|
+
|
|
2916
|
+
else:
|
|
2917
|
+
# Check if the versions of Python packages are consistent between Vantage and local.
|
|
2918
|
+
from teradataml.dbutils.dbutils import \
|
|
2919
|
+
_db_python_package_version_diff
|
|
2920
|
+
all_package_versions = _db_python_package_version_diff(packages, only_diff=False)
|
|
2921
|
+
package_difference = \
|
|
2922
|
+
all_package_versions[all_package_versions.vantage != all_package_versions.local]
|
|
2923
|
+
# If there are differences in package versions, raise a warning.
|
|
2924
|
+
if package_difference.shape[0] > 0:
|
|
2925
|
+
strr = []
|
|
2926
|
+
# Write the requirements file listing all the related packages and their versions.
|
|
2927
|
+
for rec in all_package_versions.to_records():
|
|
2928
|
+
strr.append(f"{rec[1]}=={rec[2]}")
|
|
2929
|
+
file_name = f"requirements_{func}.txt"
|
|
2930
|
+
req_file = os.path.join(GarbageCollector._get_temp_dir_name(), file_name)
|
|
2931
|
+
with open(req_file, "w") as f:
|
|
2932
|
+
f.write("\n".join(strr))
|
|
2933
|
+
|
|
2934
|
+
packages = "{}".format(packages[0]) if len(packages) == 1 else\
|
|
2935
|
+
"', '".join(packages[:-1]) + "' and '" + packages[-1]
|
|
2936
|
+
|
|
2937
|
+
if func in ["map_row", "map_partition"]:
|
|
2938
|
+
warning_msg = f"The version of certain Python packages are not consistent between "\
|
|
2939
|
+
"Vantage and local. User can identify them using db_python_package_version_diff() "\
|
|
2940
|
+
f"function. Teradata recommends to maintain same version of '{packages}' "\
|
|
2941
|
+
f"between Vantage and local for '{func}'."
|
|
2942
|
+
else:
|
|
2943
|
+
_packages_verified_in_vantage[func] = True
|
|
2944
|
+
warning_msg = "The versions of certain Python packages are not consistent between "\
|
|
2945
|
+
"Vantage and local. User can identify them using db_python_package_version_diff() "\
|
|
2946
|
+
"function. OpenSourceML compares the versions of '{}' (and also matches the "\
|
|
2947
|
+
f"patterns of these packages) used by 'td_{func}'. Teradata "\
|
|
2948
|
+
"recommends to maintain same versions for all the Python packages between Vantage "\
|
|
2949
|
+
"and local."
|
|
2950
|
+
|
|
2951
|
+
# Display a warning message to the user about the package differences
|
|
2952
|
+
# and the requirements file created for the user to install the packages.
|
|
2953
|
+
req = f"\nA requirements file listing all '{func}' " + \
|
|
2954
|
+
f"related packages and their versions has been written to '{req_file}'.\n"
|
|
2955
|
+
|
|
2956
|
+
warning_msg += req
|
|
2957
|
+
warnings.warn(warning_msg.format(packages), category=OneTimeUserWarning)
|
|
2958
|
+
|
|
2959
|
+
@staticmethod
|
|
2960
|
+
def _get_dialect_quoted_name(object_name):
|
|
2961
|
+
"""
|
|
2962
|
+
DESCRIPTION:
|
|
2963
|
+
Function to quote the SQL identifiers as per teradatasqlalchemy's quoting rules.
|
|
2964
|
+
|
|
2965
|
+
PARAMETERS:
|
|
2966
|
+
object_name
|
|
2967
|
+
Required Argument.
|
|
2968
|
+
Specifies the name of the SQL identifier to be quoted.
|
|
2969
|
+
Type: str
|
|
2970
|
+
|
|
2971
|
+
RAISES:
|
|
2972
|
+
None
|
|
2973
|
+
|
|
2974
|
+
RETURNS:
|
|
2975
|
+
Quoted object name.
|
|
2976
|
+
|
|
2977
|
+
EXAMPLES:
|
|
2978
|
+
_get_dialect_quoted_name(object_name = "tdml.alice")
|
|
2979
|
+
|
|
2980
|
+
OUTPUT:
|
|
2981
|
+
'"tdml.alice"'
|
|
2982
|
+
"""
|
|
2983
|
+
tdp = preparer(td_dialect)
|
|
2984
|
+
return tdp.quote(object_name)
|
|
2985
|
+
|
|
2986
|
+
@staticmethod
|
|
2987
|
+
def _get_hash_value(identifier):
|
|
2988
|
+
"""
|
|
2989
|
+
DESCRIPTION:
|
|
2990
|
+
Function to get the hash value of the identifier.
|
|
2991
|
+
|
|
2992
|
+
PARAMETERS:
|
|
2993
|
+
identifier
|
|
2994
|
+
Required Argument.
|
|
2995
|
+
Specifies the identifier to be hashed.
|
|
2996
|
+
Type: str
|
|
2997
|
+
|
|
2998
|
+
RAISES:
|
|
2999
|
+
None
|
|
3000
|
+
|
|
3001
|
+
RETURNS:
|
|
3002
|
+
Hash value of the identifier.
|
|
3003
|
+
|
|
3004
|
+
EXAMPLES:
|
|
3005
|
+
>>> UtilFuncs._get_hash_value(identifier = "tdml.alice")
|
|
3006
|
+
a6c64c2c_58e9_5060_b811_00839ea493ed
|
|
3007
|
+
"""
|
|
3008
|
+
# Generate a hash value using SHA-256
|
|
3009
|
+
hash_object = hashlib.sha256(identifier.encode())
|
|
3010
|
+
hash_hex = hash_object.hexdigest()
|
|
3011
|
+
|
|
3012
|
+
# Format the hash value to match the desired format
|
|
3013
|
+
formatted_hash = f"{hash_hex[:8]}_{hash_hex[8:12]}_{hash_hex[12:16]}_{hash_hex[16:20]}_{hash_hex[20:32]}"
|
|
3014
|
+
|
|
3015
|
+
return formatted_hash
|
|
3016
|
+
|
|
3017
|
+
@staticmethod
|
|
3018
|
+
def _get_http_status_phrases_description():
|
|
3019
|
+
"""
|
|
3020
|
+
DESCRIPTION:
|
|
3021
|
+
Function to get phrases and description for all HTTP status codes.
|
|
3022
|
+
|
|
3023
|
+
PARAMETERS:
|
|
3024
|
+
None
|
|
3025
|
+
|
|
3026
|
+
RETURNS:
|
|
3027
|
+
dict
|
|
3028
|
+
|
|
3029
|
+
EXAMPLES:
|
|
3030
|
+
>>> UtilFuncs._get_http_status_phrases_description()
|
|
3031
|
+
"""
|
|
3032
|
+
from http import HTTPStatus
|
|
3033
|
+
return {status.value: {"phrase": status.phrase, "description": status.description} \
|
|
3034
|
+
for status in HTTPStatus}
|
|
3035
|
+
|
|
3036
|
+
@staticmethod
|
|
3037
|
+
def _get_time_formatted_string(period):
|
|
3038
|
+
"""
|
|
3039
|
+
DESCRIPTION:
|
|
3040
|
+
Converts a string representing Period to the formatted TIMESTAMP/DATE string for snapshot queries.
|
|
3041
|
+
|
|
3042
|
+
PARAMETERS:
|
|
3043
|
+
period:
|
|
3044
|
+
Required Argument.
|
|
3045
|
+
Specifies the period string to be converted.
|
|
3046
|
+
Types: str
|
|
3047
|
+
|
|
3048
|
+
RETURNS:
|
|
3049
|
+
The formatted TIMESTAMP/DATE string.
|
|
3050
|
+
|
|
3051
|
+
RAISES:
|
|
3052
|
+
ValueError.
|
|
3053
|
+
|
|
3054
|
+
EXAMPLES:
|
|
3055
|
+
>>> UtilFuncs._get_time_formatted_string('2025-06-01 12:00:00.123')
|
|
3056
|
+
"""
|
|
3057
|
+
# Try to parse as datetime string
|
|
3058
|
+
try:
|
|
3059
|
+
for fmt in ["%Y-%m-%d %H:%M:%S.%f", "%Y-%m-%d %H:%M:%S", "%Y-%m-%d"]:
|
|
3060
|
+
try:
|
|
3061
|
+
dt = datetime.datetime.strptime(period, fmt)
|
|
3062
|
+
# If input had microseconds, preserve them
|
|
3063
|
+
if "%f" in fmt and "." in period:
|
|
3064
|
+
# Remove trailing zeros and dot if needed
|
|
3065
|
+
result = "TIMESTAMP'{}'".format(dt.strftime("%Y-%m-%d %H:%M:%S.%f").rstrip("0").rstrip("."))
|
|
3066
|
+
elif "%S" in fmt:
|
|
3067
|
+
result = "TIMESTAMP'{}'".format(dt.strftime("%Y-%m-%d %H:%M:%S"))
|
|
3068
|
+
else:
|
|
3069
|
+
result = "DATE'{}'".format(dt.strftime("%Y-%m-%d"))
|
|
3070
|
+
return result
|
|
3071
|
+
except ValueError:
|
|
3072
|
+
continue
|
|
3073
|
+
raise ValueError(f"Unrecognized period format: {period}")
|
|
3074
|
+
except Exception as e:
|
|
3075
|
+
raise ValueError(f"Could not convert period: {period}") from e
|
|
3076
|
+
|
|
3077
|
+
@staticmethod
|
|
3078
|
+
def extract_table_names_from_query(query):
|
|
3079
|
+
"""
|
|
3080
|
+
DESCRIPTION:
|
|
3081
|
+
Extracts all table/view names from FROM, JOIN, and ON-AS clauses in a SQL query.
|
|
3082
|
+
Handles nested queries and captures subqueries in ON (...), and ON <table> AS <alias>.
|
|
3083
|
+
|
|
3084
|
+
PARAMETERS:
|
|
3085
|
+
query:
|
|
3086
|
+
Required Argument.
|
|
3087
|
+
Specifies the SQL query string to extract table names from.
|
|
3088
|
+
Types: str
|
|
3089
|
+
|
|
3090
|
+
RAISES:
|
|
3091
|
+
None
|
|
3092
|
+
|
|
3093
|
+
RETURNS:
|
|
3094
|
+
list of str
|
|
3095
|
+
|
|
3096
|
+
EXAMPLES:
|
|
3097
|
+
>>> query = '''
|
|
3098
|
+
... SELECT a.col1, b.col2
|
|
3099
|
+
... FROM schema1.table1 AS a
|
|
3100
|
+
... JOIN (SELECT * FROM schema2.table2) AS b
|
|
3101
|
+
... ON (SELECT col3 FROM schema3.table3) AS c.col3 = a.col1
|
|
3102
|
+
... '''
|
|
3103
|
+
>>> UtilFuncs.extract_table_names_from_query(query)
|
|
3104
|
+
['schema1.table1', 'schema2.table2', 'schema3.table3']
|
|
3105
|
+
"""
|
|
3106
|
+
# Regex for FROM, JOIN, and ON ... AS ... clauses
|
|
3107
|
+
# This is a simplification; for production, use a SQL parser.
|
|
3108
|
+
table_names = set()
|
|
3109
|
+
# FROM ... (possibly with nested SELECT)
|
|
3110
|
+
for match in re.finditer(r'from\s+([^\s\(\)]+)', query, re.IGNORECASE):
|
|
3111
|
+
table_names.add(match.group(1).strip())
|
|
3112
|
+
# JOIN ... (possibly with nested SELECT)
|
|
3113
|
+
for match in re.finditer(r'join\s+([^\s\(\)]+)', query, re.IGNORECASE):
|
|
3114
|
+
table_names.add(match.group(1).strip())
|
|
3115
|
+
# ON ( ... ) AS ... Nested Query in ON Clause.
|
|
3116
|
+
for match in re.finditer(r'ON\s+\(([^)]+)\)\s+AS\s+["\']?\w+["\']?', query, re.IGNORECASE):
|
|
3117
|
+
table_names.update(UtilFuncs.extract_table_names_from_query(match.group(1)))
|
|
3118
|
+
# ON <table> AS <alias> (no parentheses)
|
|
3119
|
+
for match in re.finditer(r'ON\s+(["\']?\w+["\']?(?:\.["\']?\w+["\']?)*)\s+AS\s+["\']?\w+["\']?', query, re.IGNORECASE):
|
|
3120
|
+
table_names.add(match.group(1).strip())
|
|
3121
|
+
return list(table_names)
|
|
3122
|
+
|
|
3123
|
+
@staticmethod
|
|
3124
|
+
def _get_normalize_and_deduplicate_columns(columns):
|
|
3125
|
+
"""
|
|
3126
|
+
DESCRIPTION:
|
|
3127
|
+
Function that normalizes and deduplicates a list of column names.
|
|
3128
|
+
This function processes the "columns", which can be a list of column names
|
|
3129
|
+
as strings or ColumnExpression, or a single column name/ColumnExpression.
|
|
3130
|
+
It extracts the column names, removes duplicates while preserving order,
|
|
3131
|
+
and returns the resulting list of unique column names.
|
|
3132
|
+
|
|
3133
|
+
PARAMETERS:
|
|
3134
|
+
columns:
|
|
3135
|
+
Required Argument.
|
|
3136
|
+
Specifies the column.
|
|
3137
|
+
Types: str, ColumnExpression, list of str or ColumnExpression
|
|
3138
|
+
|
|
3139
|
+
RAISES:
|
|
3140
|
+
None
|
|
3141
|
+
|
|
3142
|
+
RETURNS:
|
|
3143
|
+
list
|
|
3144
|
+
|
|
3145
|
+
EXAMPLES:
|
|
3146
|
+
>>> load_examples_data('dataframe', 'sales')
|
|
3147
|
+
>>> df = DataFrame('sales')
|
|
3148
|
+
>>> columns = [df.Jan, 'Jan', 'Feb', df.Feb, 'Mar']
|
|
3149
|
+
>>> UtilFuncs._get_normalize_and_deduplicate_columns(columns)
|
|
3150
|
+
['Jan', 'Feb', 'Mar']
|
|
3151
|
+
|
|
3152
|
+
"""
|
|
3153
|
+
columns_list = []
|
|
3154
|
+
seen = set()
|
|
3155
|
+
|
|
3156
|
+
for column in (columns if isinstance(columns, list) else [columns]):
|
|
3157
|
+
name = column if isinstance(column, str) else column.name
|
|
3158
|
+
if name not in seen:
|
|
3159
|
+
seen.add(name)
|
|
3160
|
+
columns_list.append(name)
|
|
3161
|
+
|
|
3162
|
+
return columns_list
|
|
3163
|
+
|
|
3164
|
+
# Keeping at the end to avoid circular dependency
|
|
3165
|
+
from teradataml.common.aed_utils import AedUtils
|
|
3166
|
+
from teradataml.dbutils.filemgr import remove_file
|