teradataml 17.20.0.7__py3-none-any.whl → 20.0.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of teradataml might be problematic. Click here for more details.

Files changed (1285) hide show
  1. teradataml/LICENSE-3RD-PARTY.pdf +0 -0
  2. teradataml/LICENSE.pdf +0 -0
  3. teradataml/README.md +1864 -1640
  4. teradataml/__init__.py +70 -60
  5. teradataml/_version.py +11 -11
  6. teradataml/analytics/Transformations.py +2995 -2995
  7. teradataml/analytics/__init__.py +81 -83
  8. teradataml/analytics/analytic_function_executor.py +2013 -2010
  9. teradataml/analytics/analytic_query_generator.py +958 -958
  10. teradataml/analytics/byom/H2OPredict.py +514 -514
  11. teradataml/analytics/byom/PMMLPredict.py +437 -437
  12. teradataml/analytics/byom/__init__.py +14 -14
  13. teradataml/analytics/json_parser/__init__.py +130 -130
  14. teradataml/analytics/json_parser/analytic_functions_argument.py +1707 -1707
  15. teradataml/analytics/json_parser/json_store.py +191 -191
  16. teradataml/analytics/json_parser/metadata.py +1637 -1637
  17. teradataml/analytics/json_parser/utils.py +804 -803
  18. teradataml/analytics/meta_class.py +196 -196
  19. teradataml/analytics/sqle/DecisionTreePredict.py +455 -470
  20. teradataml/analytics/sqle/NaiveBayesPredict.py +419 -428
  21. teradataml/analytics/sqle/__init__.py +97 -110
  22. teradataml/analytics/sqle/json/decisiontreepredict_sqle.json +78 -78
  23. teradataml/analytics/sqle/json/naivebayespredict_sqle.json +62 -62
  24. teradataml/analytics/table_operator/__init__.py +10 -10
  25. teradataml/analytics/uaf/__init__.py +63 -63
  26. teradataml/analytics/utils.py +693 -692
  27. teradataml/analytics/valib.py +1603 -1600
  28. teradataml/automl/__init__.py +1628 -0
  29. teradataml/automl/custom_json_utils.py +1270 -0
  30. teradataml/automl/data_preparation.py +993 -0
  31. teradataml/automl/data_transformation.py +727 -0
  32. teradataml/automl/feature_engineering.py +1648 -0
  33. teradataml/automl/feature_exploration.py +547 -0
  34. teradataml/automl/model_evaluation.py +163 -0
  35. teradataml/automl/model_training.py +887 -0
  36. teradataml/catalog/__init__.py +1 -3
  37. teradataml/catalog/byom.py +1759 -1716
  38. teradataml/catalog/function_argument_mapper.py +859 -861
  39. teradataml/catalog/model_cataloging_utils.py +491 -1510
  40. teradataml/clients/pkce_client.py +481 -481
  41. teradataml/common/aed_utils.py +6 -2
  42. teradataml/common/bulk_exposed_utils.py +111 -111
  43. teradataml/common/constants.py +1433 -1441
  44. teradataml/common/deprecations.py +160 -0
  45. teradataml/common/exceptions.py +73 -73
  46. teradataml/common/formula.py +742 -742
  47. teradataml/common/garbagecollector.py +592 -635
  48. teradataml/common/messagecodes.py +422 -431
  49. teradataml/common/messages.py +227 -231
  50. teradataml/common/sqlbundle.py +693 -693
  51. teradataml/common/td_coltype_code_to_tdtype.py +48 -48
  52. teradataml/common/utils.py +2418 -2500
  53. teradataml/common/warnings.py +25 -25
  54. teradataml/common/wrapper_utils.py +1 -110
  55. teradataml/config/dummy_file1.cfg +4 -4
  56. teradataml/config/dummy_file2.cfg +2 -2
  57. teradataml/config/sqlengine_alias_definitions_v1.0 +13 -13
  58. teradataml/config/sqlengine_alias_definitions_v1.1 +19 -19
  59. teradataml/config/sqlengine_alias_definitions_v1.3 +18 -18
  60. teradataml/context/aed_context.py +217 -217
  61. teradataml/context/context.py +1071 -999
  62. teradataml/data/A_loan.csv +19 -19
  63. teradataml/data/BINARY_REALS_LEFT.csv +11 -11
  64. teradataml/data/BINARY_REALS_RIGHT.csv +11 -11
  65. teradataml/data/B_loan.csv +49 -49
  66. teradataml/data/BuoyData2.csv +17 -17
  67. teradataml/data/CONVOLVE2_COMPLEX_LEFT.csv +5 -5
  68. teradataml/data/CONVOLVE2_COMPLEX_RIGHT.csv +5 -5
  69. teradataml/data/Convolve2RealsLeft.csv +5 -5
  70. teradataml/data/Convolve2RealsRight.csv +5 -5
  71. teradataml/data/Convolve2ValidLeft.csv +11 -11
  72. teradataml/data/Convolve2ValidRight.csv +11 -11
  73. teradataml/data/DFFTConv_Real_8_8.csv +65 -65
  74. teradataml/data/Orders1_12mf.csv +24 -24
  75. teradataml/data/Pi_loan.csv +7 -7
  76. teradataml/data/SMOOTHED_DATA.csv +7 -7
  77. teradataml/data/TestDFFT8.csv +9 -9
  78. teradataml/data/TestRiver.csv +109 -109
  79. teradataml/data/Traindata.csv +28 -28
  80. teradataml/data/acf.csv +17 -17
  81. teradataml/data/adaboost_example.json +34 -34
  82. teradataml/data/adaboostpredict_example.json +24 -24
  83. teradataml/data/additional_table.csv +10 -10
  84. teradataml/data/admissions_test.csv +21 -21
  85. teradataml/data/admissions_train.csv +41 -41
  86. teradataml/data/admissions_train_nulls.csv +41 -41
  87. teradataml/data/ageandheight.csv +13 -13
  88. teradataml/data/ageandpressure.csv +31 -31
  89. teradataml/data/antiselect_example.json +36 -36
  90. teradataml/data/antiselect_input.csv +8 -8
  91. teradataml/data/antiselect_input_mixed_case.csv +8 -8
  92. teradataml/data/applicant_external.csv +6 -6
  93. teradataml/data/applicant_reference.csv +6 -6
  94. teradataml/data/arima_example.json +9 -9
  95. teradataml/data/assortedtext_input.csv +8 -8
  96. teradataml/data/attribution_example.json +33 -33
  97. teradataml/data/attribution_sample_table.csv +27 -27
  98. teradataml/data/attribution_sample_table1.csv +6 -6
  99. teradataml/data/attribution_sample_table2.csv +11 -11
  100. teradataml/data/bank_churn.csv +10001 -0
  101. teradataml/data/bank_web_clicks1.csv +42 -42
  102. teradataml/data/bank_web_clicks2.csv +91 -91
  103. teradataml/data/bank_web_url.csv +85 -85
  104. teradataml/data/barrier.csv +2 -2
  105. teradataml/data/barrier_new.csv +3 -3
  106. teradataml/data/betweenness_example.json +13 -13
  107. teradataml/data/bin_breaks.csv +8 -8
  108. teradataml/data/bin_fit_ip.csv +3 -3
  109. teradataml/data/binary_complex_left.csv +11 -11
  110. teradataml/data/binary_complex_right.csv +11 -11
  111. teradataml/data/binary_matrix_complex_left.csv +21 -21
  112. teradataml/data/binary_matrix_complex_right.csv +21 -21
  113. teradataml/data/binary_matrix_real_left.csv +21 -21
  114. teradataml/data/binary_matrix_real_right.csv +21 -21
  115. teradataml/data/blood2ageandweight.csv +26 -26
  116. teradataml/data/bmi.csv +501 -0
  117. teradataml/data/boston.csv +507 -507
  118. teradataml/data/buoydata_mix.csv +11 -11
  119. teradataml/data/burst_data.csv +5 -5
  120. teradataml/data/burst_example.json +20 -20
  121. teradataml/data/byom_example.json +17 -17
  122. teradataml/data/bytes_table.csv +3 -3
  123. teradataml/data/cal_housing_ex_raw.csv +70 -70
  124. teradataml/data/callers.csv +7 -7
  125. teradataml/data/calls.csv +10 -10
  126. teradataml/data/cars_hist.csv +33 -33
  127. teradataml/data/cat_table.csv +24 -24
  128. teradataml/data/ccm_example.json +31 -31
  129. teradataml/data/ccm_input.csv +91 -91
  130. teradataml/data/ccm_input2.csv +13 -13
  131. teradataml/data/ccmexample.csv +101 -101
  132. teradataml/data/ccmprepare_example.json +8 -8
  133. teradataml/data/ccmprepare_input.csv +91 -91
  134. teradataml/data/cfilter_example.json +12 -12
  135. teradataml/data/changepointdetection_example.json +18 -18
  136. teradataml/data/changepointdetectionrt_example.json +8 -8
  137. teradataml/data/chi_sq.csv +2 -2
  138. teradataml/data/churn_data.csv +14 -14
  139. teradataml/data/churn_emission.csv +35 -35
  140. teradataml/data/churn_initial.csv +3 -3
  141. teradataml/data/churn_state_transition.csv +5 -5
  142. teradataml/data/citedges_2.csv +745 -745
  143. teradataml/data/citvertices_2.csv +1210 -1210
  144. teradataml/data/clicks2.csv +16 -16
  145. teradataml/data/clickstream.csv +12 -12
  146. teradataml/data/clickstream1.csv +11 -11
  147. teradataml/data/closeness_example.json +15 -15
  148. teradataml/data/complaints.csv +21 -21
  149. teradataml/data/complaints_mini.csv +3 -3
  150. teradataml/data/complaints_testtoken.csv +224 -224
  151. teradataml/data/complaints_tokens_test.csv +353 -353
  152. teradataml/data/complaints_traintoken.csv +472 -472
  153. teradataml/data/computers_category.csv +1001 -1001
  154. teradataml/data/computers_test1.csv +1252 -1252
  155. teradataml/data/computers_train1.csv +5009 -5009
  156. teradataml/data/computers_train1_clustered.csv +5009 -5009
  157. teradataml/data/confusionmatrix_example.json +9 -9
  158. teradataml/data/conversion_event_table.csv +3 -3
  159. teradataml/data/corr_input.csv +17 -17
  160. teradataml/data/correlation_example.json +11 -11
  161. teradataml/data/coxhazardratio_example.json +39 -39
  162. teradataml/data/coxph_example.json +15 -15
  163. teradataml/data/coxsurvival_example.json +28 -28
  164. teradataml/data/cpt.csv +41 -41
  165. teradataml/data/credit_ex_merged.csv +45 -45
  166. teradataml/data/customer_loyalty.csv +301 -301
  167. teradataml/data/customer_loyalty_newseq.csv +31 -31
  168. teradataml/data/dataframe_example.json +146 -146
  169. teradataml/data/decisionforest_example.json +37 -37
  170. teradataml/data/decisionforestpredict_example.json +38 -38
  171. teradataml/data/decisiontree_example.json +21 -21
  172. teradataml/data/decisiontreepredict_example.json +45 -45
  173. teradataml/data/dfft2_size4_real.csv +17 -17
  174. teradataml/data/dfft2_test_matrix16.csv +17 -17
  175. teradataml/data/dfft2conv_real_4_4.csv +65 -65
  176. teradataml/data/diabetes.csv +443 -443
  177. teradataml/data/diabetes_test.csv +89 -89
  178. teradataml/data/dict_table.csv +5 -5
  179. teradataml/data/docperterm_table.csv +4 -4
  180. teradataml/data/docs/__init__.py +1 -1
  181. teradataml/data/docs/byom/docs/DataRobotPredict.py +180 -180
  182. teradataml/data/docs/byom/docs/DataikuPredict.py +177 -177
  183. teradataml/data/docs/byom/docs/H2OPredict.py +324 -324
  184. teradataml/data/docs/byom/docs/ONNXPredict.py +283 -283
  185. teradataml/data/docs/byom/docs/PMMLPredict.py +277 -277
  186. teradataml/data/docs/sqle/docs_17_10/Antiselect.py +82 -82
  187. teradataml/data/docs/sqle/docs_17_10/Attribution.py +199 -199
  188. teradataml/data/docs/sqle/docs_17_10/BincodeFit.py +171 -171
  189. teradataml/data/docs/sqle/docs_17_10/BincodeTransform.py +131 -130
  190. teradataml/data/docs/sqle/docs_17_10/CategoricalSummary.py +86 -86
  191. teradataml/data/docs/sqle/docs_17_10/ChiSq.py +90 -90
  192. teradataml/data/docs/sqle/docs_17_10/ColumnSummary.py +85 -85
  193. teradataml/data/docs/sqle/docs_17_10/ConvertTo.py +95 -95
  194. teradataml/data/docs/sqle/docs_17_10/DecisionForestPredict.py +139 -139
  195. teradataml/data/docs/sqle/docs_17_10/DecisionTreePredict.py +151 -151
  196. teradataml/data/docs/sqle/docs_17_10/FTest.py +160 -160
  197. teradataml/data/docs/sqle/docs_17_10/FillRowId.py +82 -82
  198. teradataml/data/docs/sqle/docs_17_10/Fit.py +87 -87
  199. teradataml/data/docs/sqle/docs_17_10/GLMPredict.py +144 -144
  200. teradataml/data/docs/sqle/docs_17_10/GetRowsWithMissingValues.py +84 -84
  201. teradataml/data/docs/sqle/docs_17_10/GetRowsWithoutMissingValues.py +81 -81
  202. teradataml/data/docs/sqle/docs_17_10/Histogram.py +164 -164
  203. teradataml/data/docs/sqle/docs_17_10/MovingAverage.py +134 -134
  204. teradataml/data/docs/sqle/docs_17_10/NGramSplitter.py +208 -208
  205. teradataml/data/docs/sqle/docs_17_10/NPath.py +265 -265
  206. teradataml/data/docs/sqle/docs_17_10/NaiveBayesPredict.py +116 -116
  207. teradataml/data/docs/sqle/docs_17_10/NaiveBayesTextClassifierPredict.py +176 -176
  208. teradataml/data/docs/sqle/docs_17_10/NumApply.py +147 -147
  209. teradataml/data/docs/sqle/docs_17_10/OneHotEncodingFit.py +132 -132
  210. teradataml/data/docs/sqle/docs_17_10/OneHotEncodingTransform.py +103 -103
  211. teradataml/data/docs/sqle/docs_17_10/OutlierFilterFit.py +165 -165
  212. teradataml/data/docs/sqle/docs_17_10/OutlierFilterTransform.py +101 -101
  213. teradataml/data/docs/sqle/docs_17_10/Pack.py +128 -128
  214. teradataml/data/docs/sqle/docs_17_10/PolynomialFeaturesFit.py +111 -111
  215. teradataml/data/docs/sqle/docs_17_10/PolynomialFeaturesTransform.py +102 -102
  216. teradataml/data/docs/sqle/docs_17_10/QQNorm.py +104 -104
  217. teradataml/data/docs/sqle/docs_17_10/RoundColumns.py +109 -109
  218. teradataml/data/docs/sqle/docs_17_10/RowNormalizeFit.py +117 -117
  219. teradataml/data/docs/sqle/docs_17_10/RowNormalizeTransform.py +99 -98
  220. teradataml/data/docs/sqle/docs_17_10/SVMSparsePredict.py +152 -152
  221. teradataml/data/docs/sqle/docs_17_10/ScaleFit.py +197 -197
  222. teradataml/data/docs/sqle/docs_17_10/ScaleTransform.py +99 -98
  223. teradataml/data/docs/sqle/docs_17_10/Sessionize.py +113 -113
  224. teradataml/data/docs/sqle/docs_17_10/SimpleImputeFit.py +116 -116
  225. teradataml/data/docs/sqle/docs_17_10/SimpleImputeTransform.py +98 -98
  226. teradataml/data/docs/sqle/docs_17_10/StrApply.py +187 -187
  227. teradataml/data/docs/sqle/docs_17_10/StringSimilarity.py +145 -145
  228. teradataml/data/docs/sqle/docs_17_10/Transform.py +105 -104
  229. teradataml/data/docs/sqle/docs_17_10/UnivariateStatistics.py +141 -141
  230. teradataml/data/docs/sqle/docs_17_10/Unpack.py +214 -214
  231. teradataml/data/docs/sqle/docs_17_10/WhichMax.py +83 -83
  232. teradataml/data/docs/sqle/docs_17_10/WhichMin.py +83 -83
  233. teradataml/data/docs/sqle/docs_17_10/ZTest.py +155 -155
  234. teradataml/data/docs/sqle/docs_17_20/ANOVA.py +126 -126
  235. teradataml/data/docs/sqle/docs_17_20/Antiselect.py +82 -82
  236. teradataml/data/docs/sqle/docs_17_20/Attribution.py +200 -200
  237. teradataml/data/docs/sqle/docs_17_20/BincodeFit.py +171 -171
  238. teradataml/data/docs/sqle/docs_17_20/BincodeTransform.py +139 -138
  239. teradataml/data/docs/sqle/docs_17_20/CategoricalSummary.py +86 -86
  240. teradataml/data/docs/sqle/docs_17_20/ChiSq.py +90 -90
  241. teradataml/data/docs/sqle/docs_17_20/ClassificationEvaluator.py +166 -166
  242. teradataml/data/docs/sqle/docs_17_20/ColumnSummary.py +85 -85
  243. teradataml/data/docs/sqle/docs_17_20/ColumnTransformer.py +243 -243
  244. teradataml/data/docs/sqle/docs_17_20/ConvertTo.py +113 -113
  245. teradataml/data/docs/sqle/docs_17_20/DecisionForest.py +279 -279
  246. teradataml/data/docs/sqle/docs_17_20/DecisionForestPredict.py +144 -144
  247. teradataml/data/docs/sqle/docs_17_20/DecisionTreePredict.py +135 -135
  248. teradataml/data/docs/sqle/docs_17_20/FTest.py +160 -160
  249. teradataml/data/docs/sqle/docs_17_20/FillRowId.py +82 -82
  250. teradataml/data/docs/sqle/docs_17_20/Fit.py +87 -87
  251. teradataml/data/docs/sqle/docs_17_20/GLM.py +380 -380
  252. teradataml/data/docs/sqle/docs_17_20/GLMPerSegment.py +414 -414
  253. teradataml/data/docs/sqle/docs_17_20/GLMPredict.py +144 -144
  254. teradataml/data/docs/sqle/docs_17_20/GLMPredictPerSegment.py +233 -234
  255. teradataml/data/docs/sqle/docs_17_20/GetFutileColumns.py +123 -123
  256. teradataml/data/docs/sqle/docs_17_20/GetRowsWithMissingValues.py +108 -108
  257. teradataml/data/docs/sqle/docs_17_20/GetRowsWithoutMissingValues.py +105 -105
  258. teradataml/data/docs/sqle/docs_17_20/Histogram.py +223 -223
  259. teradataml/data/docs/sqle/docs_17_20/KMeans.py +204 -204
  260. teradataml/data/docs/sqle/docs_17_20/KMeansPredict.py +144 -143
  261. teradataml/data/docs/sqle/docs_17_20/KNN.py +214 -214
  262. teradataml/data/docs/sqle/docs_17_20/MovingAverage.py +134 -134
  263. teradataml/data/docs/sqle/docs_17_20/NGramSplitter.py +208 -208
  264. teradataml/data/docs/sqle/docs_17_20/NPath.py +265 -265
  265. teradataml/data/docs/sqle/docs_17_20/NaiveBayesPredict.py +116 -116
  266. teradataml/data/docs/sqle/docs_17_20/NaiveBayesTextClassifierPredict.py +177 -176
  267. teradataml/data/docs/sqle/docs_17_20/NaiveBayesTextClassifierTrainer.py +126 -126
  268. teradataml/data/docs/sqle/docs_17_20/NonLinearCombineFit.py +117 -117
  269. teradataml/data/docs/sqle/docs_17_20/NonLinearCombineTransform.py +112 -112
  270. teradataml/data/docs/sqle/docs_17_20/NumApply.py +147 -147
  271. teradataml/data/docs/sqle/docs_17_20/OneClassSVM.py +307 -307
  272. teradataml/data/docs/sqle/docs_17_20/OneClassSVMPredict.py +185 -184
  273. teradataml/data/docs/sqle/docs_17_20/OneHotEncodingFit.py +225 -225
  274. teradataml/data/docs/sqle/docs_17_20/OneHotEncodingTransform.py +115 -115
  275. teradataml/data/docs/sqle/docs_17_20/OrdinalEncodingFit.py +219 -219
  276. teradataml/data/docs/sqle/docs_17_20/OrdinalEncodingTransform.py +127 -127
  277. teradataml/data/docs/sqle/docs_17_20/OutlierFilterFit.py +189 -189
  278. teradataml/data/docs/sqle/docs_17_20/OutlierFilterTransform.py +117 -112
  279. teradataml/data/docs/sqle/docs_17_20/Pack.py +128 -128
  280. teradataml/data/docs/sqle/docs_17_20/PolynomialFeaturesFit.py +111 -111
  281. teradataml/data/docs/sqle/docs_17_20/PolynomialFeaturesTransform.py +112 -111
  282. teradataml/data/docs/sqle/docs_17_20/QQNorm.py +104 -104
  283. teradataml/data/docs/sqle/docs_17_20/ROC.py +163 -163
  284. teradataml/data/docs/sqle/docs_17_20/RandomProjectionFit.py +154 -154
  285. teradataml/data/docs/sqle/docs_17_20/RandomProjectionMinComponents.py +106 -106
  286. teradataml/data/docs/sqle/docs_17_20/RandomProjectionTransform.py +120 -120
  287. teradataml/data/docs/sqle/docs_17_20/RegressionEvaluator.py +211 -211
  288. teradataml/data/docs/sqle/docs_17_20/RoundColumns.py +108 -108
  289. teradataml/data/docs/sqle/docs_17_20/RowNormalizeFit.py +117 -117
  290. teradataml/data/docs/sqle/docs_17_20/RowNormalizeTransform.py +111 -110
  291. teradataml/data/docs/sqle/docs_17_20/SVM.py +413 -413
  292. teradataml/data/docs/sqle/docs_17_20/SVMPredict.py +202 -202
  293. teradataml/data/docs/sqle/docs_17_20/SVMSparsePredict.py +152 -152
  294. teradataml/data/docs/sqle/docs_17_20/ScaleFit.py +197 -197
  295. teradataml/data/docs/sqle/docs_17_20/ScaleTransform.py +110 -109
  296. teradataml/data/docs/sqle/docs_17_20/SentimentExtractor.py +206 -206
  297. teradataml/data/docs/sqle/docs_17_20/Sessionize.py +113 -113
  298. teradataml/data/docs/sqle/docs_17_20/Silhouette.py +152 -152
  299. teradataml/data/docs/sqle/docs_17_20/SimpleImputeFit.py +116 -116
  300. teradataml/data/docs/sqle/docs_17_20/SimpleImputeTransform.py +109 -108
  301. teradataml/data/docs/sqle/docs_17_20/StrApply.py +187 -187
  302. teradataml/data/docs/sqle/docs_17_20/StringSimilarity.py +145 -145
  303. teradataml/data/docs/sqle/docs_17_20/TDDecisionForestPredict.py +207 -207
  304. teradataml/data/docs/sqle/docs_17_20/TDGLMPredict.py +171 -171
  305. teradataml/data/docs/sqle/docs_17_20/TargetEncodingFit.py +266 -266
  306. teradataml/data/docs/sqle/docs_17_20/TargetEncodingTransform.py +141 -140
  307. teradataml/data/docs/sqle/docs_17_20/TextParser.py +172 -172
  308. teradataml/data/docs/sqle/docs_17_20/TrainTestSplit.py +159 -159
  309. teradataml/data/docs/sqle/docs_17_20/Transform.py +123 -123
  310. teradataml/data/docs/sqle/docs_17_20/UnivariateStatistics.py +141 -141
  311. teradataml/data/docs/sqle/docs_17_20/Unpack.py +214 -214
  312. teradataml/data/docs/sqle/docs_17_20/VectorDistance.py +168 -168
  313. teradataml/data/docs/sqle/docs_17_20/WhichMax.py +83 -83
  314. teradataml/data/docs/sqle/docs_17_20/WhichMin.py +83 -83
  315. teradataml/data/docs/sqle/docs_17_20/WordEmbeddings.py +236 -236
  316. teradataml/data/docs/sqle/docs_17_20/XGBoost.py +353 -353
  317. teradataml/data/docs/sqle/docs_17_20/XGBoostPredict.py +275 -275
  318. teradataml/data/docs/sqle/docs_17_20/ZTest.py +155 -155
  319. teradataml/data/docs/tableoperator/docs_17_00/ReadNOS.py +429 -429
  320. teradataml/data/docs/tableoperator/docs_17_05/ReadNOS.py +429 -429
  321. teradataml/data/docs/tableoperator/docs_17_05/WriteNOS.py +347 -347
  322. teradataml/data/docs/tableoperator/docs_17_10/ReadNOS.py +428 -428
  323. teradataml/data/docs/tableoperator/docs_17_10/WriteNOS.py +347 -347
  324. teradataml/data/docs/tableoperator/docs_17_20/ReadNOS.py +439 -439
  325. teradataml/data/docs/tableoperator/docs_17_20/WriteNOS.py +386 -386
  326. teradataml/data/docs/uaf/docs_17_20/ACF.py +195 -195
  327. teradataml/data/docs/uaf/docs_17_20/ArimaEstimate.py +369 -369
  328. teradataml/data/docs/uaf/docs_17_20/ArimaForecast.py +142 -142
  329. teradataml/data/docs/uaf/docs_17_20/ArimaValidate.py +159 -159
  330. teradataml/data/docs/uaf/docs_17_20/BinaryMatrixOp.py +247 -247
  331. teradataml/data/docs/uaf/docs_17_20/BinarySeriesOp.py +252 -252
  332. teradataml/data/docs/uaf/docs_17_20/BreuschGodfrey.py +177 -177
  333. teradataml/data/docs/uaf/docs_17_20/BreuschPaganGodfrey.py +174 -174
  334. teradataml/data/docs/uaf/docs_17_20/Convolve.py +226 -226
  335. teradataml/data/docs/uaf/docs_17_20/Convolve2.py +214 -214
  336. teradataml/data/docs/uaf/docs_17_20/CumulPeriodogram.py +183 -183
  337. teradataml/data/docs/uaf/docs_17_20/DFFT.py +203 -203
  338. teradataml/data/docs/uaf/docs_17_20/DFFT2.py +216 -216
  339. teradataml/data/docs/uaf/docs_17_20/DFFT2Conv.py +215 -215
  340. teradataml/data/docs/uaf/docs_17_20/DFFTConv.py +191 -191
  341. teradataml/data/docs/uaf/docs_17_20/DTW.py +179 -179
  342. teradataml/data/docs/uaf/docs_17_20/DickeyFuller.py +144 -144
  343. teradataml/data/docs/uaf/docs_17_20/DurbinWatson.py +183 -183
  344. teradataml/data/docs/uaf/docs_17_20/ExtractResults.py +184 -184
  345. teradataml/data/docs/uaf/docs_17_20/FitMetrics.py +172 -172
  346. teradataml/data/docs/uaf/docs_17_20/GenseriesFormula.py +205 -205
  347. teradataml/data/docs/uaf/docs_17_20/GenseriesSinusoids.py +142 -142
  348. teradataml/data/docs/uaf/docs_17_20/HoltWintersForecaster.py +258 -258
  349. teradataml/data/docs/uaf/docs_17_20/IDFFT.py +164 -164
  350. teradataml/data/docs/uaf/docs_17_20/IDFFT2.py +198 -198
  351. teradataml/data/docs/uaf/docs_17_20/InputValidator.py +120 -120
  352. teradataml/data/docs/uaf/docs_17_20/LineSpec.py +155 -155
  353. teradataml/data/docs/uaf/docs_17_20/LinearRegr.py +214 -214
  354. teradataml/data/docs/uaf/docs_17_20/MAMean.py +173 -173
  355. teradataml/data/docs/uaf/docs_17_20/MInfo.py +133 -133
  356. teradataml/data/docs/uaf/docs_17_20/MatrixMultiply.py +135 -135
  357. teradataml/data/docs/uaf/docs_17_20/MultivarRegr.py +190 -190
  358. teradataml/data/docs/uaf/docs_17_20/PACF.py +158 -158
  359. teradataml/data/docs/uaf/docs_17_20/Portman.py +216 -216
  360. teradataml/data/docs/uaf/docs_17_20/PowerTransform.py +154 -154
  361. teradataml/data/docs/uaf/docs_17_20/Resample.py +228 -228
  362. teradataml/data/docs/uaf/docs_17_20/SInfo.py +122 -122
  363. teradataml/data/docs/uaf/docs_17_20/SeasonalNormalize.py +165 -165
  364. teradataml/data/docs/uaf/docs_17_20/SelectionCriteria.py +173 -173
  365. teradataml/data/docs/uaf/docs_17_20/SignifPeriodicities.py +170 -170
  366. teradataml/data/docs/uaf/docs_17_20/SignifResidmean.py +163 -163
  367. teradataml/data/docs/uaf/docs_17_20/SimpleExp.py +179 -179
  368. teradataml/data/docs/uaf/docs_17_20/Smoothma.py +207 -207
  369. teradataml/data/docs/uaf/docs_17_20/TrackingOp.py +150 -150
  370. teradataml/data/docs/uaf/docs_17_20/UNDIFF.py +171 -171
  371. teradataml/data/docs/uaf/docs_17_20/Unnormalize.py +201 -201
  372. teradataml/data/docs/uaf/docs_17_20/WhitesGeneral.py +169 -169
  373. teradataml/data/dtw_example.json +17 -17
  374. teradataml/data/dtw_t1.csv +11 -11
  375. teradataml/data/dtw_t2.csv +4 -4
  376. teradataml/data/dwt2d_example.json +15 -15
  377. teradataml/data/dwt_example.json +14 -14
  378. teradataml/data/dwt_filter_dim.csv +5 -5
  379. teradataml/data/emission.csv +9 -9
  380. teradataml/data/emp_table_by_dept.csv +19 -19
  381. teradataml/data/employee_info.csv +4 -4
  382. teradataml/data/employee_table.csv +6 -6
  383. teradataml/data/excluding_event_table.csv +2 -2
  384. teradataml/data/finance_data.csv +6 -6
  385. teradataml/data/finance_data2.csv +61 -61
  386. teradataml/data/finance_data3.csv +93 -93
  387. teradataml/data/fish.csv +160 -0
  388. teradataml/data/fm_blood2ageandweight.csv +26 -26
  389. teradataml/data/fmeasure_example.json +11 -11
  390. teradataml/data/followers_leaders.csv +10 -10
  391. teradataml/data/fpgrowth_example.json +12 -12
  392. teradataml/data/frequentpaths_example.json +29 -29
  393. teradataml/data/friends.csv +9 -9
  394. teradataml/data/fs_input.csv +33 -33
  395. teradataml/data/fs_input1.csv +33 -33
  396. teradataml/data/genData.csv +513 -513
  397. teradataml/data/geodataframe_example.json +39 -39
  398. teradataml/data/glass_types.csv +215 -0
  399. teradataml/data/glm_admissions_model.csv +12 -12
  400. teradataml/data/glm_example.json +29 -29
  401. teradataml/data/glml1l2_example.json +28 -28
  402. teradataml/data/glml1l2predict_example.json +54 -54
  403. teradataml/data/glmpredict_example.json +54 -54
  404. teradataml/data/gq_t1.csv +21 -21
  405. teradataml/data/hconvolve_complex_right.csv +5 -5
  406. teradataml/data/hconvolve_complex_rightmulti.csv +5 -5
  407. teradataml/data/histogram_example.json +11 -11
  408. teradataml/data/hmmdecoder_example.json +78 -78
  409. teradataml/data/hmmevaluator_example.json +24 -24
  410. teradataml/data/hmmsupervised_example.json +10 -10
  411. teradataml/data/hmmunsupervised_example.json +7 -7
  412. teradataml/data/house_values.csv +12 -12
  413. teradataml/data/house_values2.csv +13 -13
  414. teradataml/data/housing_cat.csv +7 -7
  415. teradataml/data/housing_data.csv +9 -9
  416. teradataml/data/housing_test.csv +47 -47
  417. teradataml/data/housing_test_binary.csv +47 -47
  418. teradataml/data/housing_train.csv +493 -493
  419. teradataml/data/housing_train_attribute.csv +4 -4
  420. teradataml/data/housing_train_binary.csv +437 -437
  421. teradataml/data/housing_train_parameter.csv +2 -2
  422. teradataml/data/housing_train_response.csv +493 -493
  423. teradataml/data/ibm_stock.csv +370 -370
  424. teradataml/data/ibm_stock1.csv +370 -370
  425. teradataml/data/identitymatch_example.json +21 -21
  426. teradataml/data/idf_table.csv +4 -4
  427. teradataml/data/impressions.csv +101 -101
  428. teradataml/data/inflation.csv +21 -21
  429. teradataml/data/initial.csv +3 -3
  430. teradataml/data/insect_sprays.csv +12 -12
  431. teradataml/data/insurance.csv +1339 -1339
  432. teradataml/data/interpolator_example.json +12 -12
  433. teradataml/data/iris_altinput.csv +481 -481
  434. teradataml/data/iris_attribute_output.csv +8 -8
  435. teradataml/data/iris_attribute_test.csv +121 -121
  436. teradataml/data/iris_attribute_train.csv +481 -481
  437. teradataml/data/iris_category_expect_predict.csv +31 -31
  438. teradataml/data/iris_data.csv +151 -0
  439. teradataml/data/iris_input.csv +151 -151
  440. teradataml/data/iris_response_train.csv +121 -121
  441. teradataml/data/iris_test.csv +31 -31
  442. teradataml/data/iris_train.csv +121 -121
  443. teradataml/data/join_table1.csv +4 -4
  444. teradataml/data/join_table2.csv +4 -4
  445. teradataml/data/jsons/anly_function_name.json +6 -6
  446. teradataml/data/jsons/byom/dataikupredict.json +147 -147
  447. teradataml/data/jsons/byom/datarobotpredict.json +146 -146
  448. teradataml/data/jsons/byom/h2opredict.json +194 -194
  449. teradataml/data/jsons/byom/onnxpredict.json +186 -186
  450. teradataml/data/jsons/byom/pmmlpredict.json +146 -146
  451. teradataml/data/jsons/paired_functions.json +435 -435
  452. teradataml/data/jsons/sqle/16.20/Antiselect.json +56 -56
  453. teradataml/data/jsons/sqle/16.20/Attribution.json +249 -249
  454. teradataml/data/jsons/sqle/16.20/DecisionForestPredict.json +156 -156
  455. teradataml/data/jsons/sqle/16.20/DecisionTreePredict.json +170 -170
  456. teradataml/data/jsons/sqle/16.20/GLMPredict.json +122 -122
  457. teradataml/data/jsons/sqle/16.20/MovingAverage.json +367 -367
  458. teradataml/data/jsons/sqle/16.20/NGramSplitter.json +239 -239
  459. teradataml/data/jsons/sqle/16.20/NaiveBayesPredict.json +136 -136
  460. teradataml/data/jsons/sqle/16.20/NaiveBayesTextClassifierPredict.json +235 -235
  461. teradataml/data/jsons/sqle/16.20/Pack.json +98 -98
  462. teradataml/data/jsons/sqle/16.20/SVMSparsePredict.json +162 -162
  463. teradataml/data/jsons/sqle/16.20/Sessionize.json +105 -105
  464. teradataml/data/jsons/sqle/16.20/StringSimilarity.json +86 -86
  465. teradataml/data/jsons/sqle/16.20/Unpack.json +166 -166
  466. teradataml/data/jsons/sqle/16.20/nPath.json +269 -269
  467. teradataml/data/jsons/sqle/17.00/Antiselect.json +56 -56
  468. teradataml/data/jsons/sqle/17.00/Attribution.json +249 -249
  469. teradataml/data/jsons/sqle/17.00/DecisionForestPredict.json +156 -156
  470. teradataml/data/jsons/sqle/17.00/DecisionTreePredict.json +170 -170
  471. teradataml/data/jsons/sqle/17.00/GLMPredict.json +122 -122
  472. teradataml/data/jsons/sqle/17.00/MovingAverage.json +367 -367
  473. teradataml/data/jsons/sqle/17.00/NGramSplitter.json +239 -239
  474. teradataml/data/jsons/sqle/17.00/NaiveBayesPredict.json +136 -136
  475. teradataml/data/jsons/sqle/17.00/NaiveBayesTextClassifierPredict.json +235 -235
  476. teradataml/data/jsons/sqle/17.00/Pack.json +98 -98
  477. teradataml/data/jsons/sqle/17.00/SVMSparsePredict.json +162 -162
  478. teradataml/data/jsons/sqle/17.00/Sessionize.json +105 -105
  479. teradataml/data/jsons/sqle/17.00/StringSimilarity.json +86 -86
  480. teradataml/data/jsons/sqle/17.00/Unpack.json +166 -166
  481. teradataml/data/jsons/sqle/17.00/nPath.json +269 -269
  482. teradataml/data/jsons/sqle/17.05/Antiselect.json +56 -56
  483. teradataml/data/jsons/sqle/17.05/Attribution.json +249 -249
  484. teradataml/data/jsons/sqle/17.05/DecisionForestPredict.json +156 -156
  485. teradataml/data/jsons/sqle/17.05/DecisionTreePredict.json +170 -170
  486. teradataml/data/jsons/sqle/17.05/GLMPredict.json +122 -122
  487. teradataml/data/jsons/sqle/17.05/MovingAverage.json +367 -367
  488. teradataml/data/jsons/sqle/17.05/NGramSplitter.json +239 -239
  489. teradataml/data/jsons/sqle/17.05/NaiveBayesPredict.json +136 -136
  490. teradataml/data/jsons/sqle/17.05/NaiveBayesTextClassifierPredict.json +235 -235
  491. teradataml/data/jsons/sqle/17.05/Pack.json +98 -98
  492. teradataml/data/jsons/sqle/17.05/SVMSparsePredict.json +162 -162
  493. teradataml/data/jsons/sqle/17.05/Sessionize.json +105 -105
  494. teradataml/data/jsons/sqle/17.05/StringSimilarity.json +86 -86
  495. teradataml/data/jsons/sqle/17.05/Unpack.json +166 -166
  496. teradataml/data/jsons/sqle/17.05/nPath.json +269 -269
  497. teradataml/data/jsons/sqle/17.10/Antiselect.json +56 -56
  498. teradataml/data/jsons/sqle/17.10/Attribution.json +249 -249
  499. teradataml/data/jsons/sqle/17.10/DecisionForestPredict.json +185 -185
  500. teradataml/data/jsons/sqle/17.10/DecisionTreePredict.json +171 -171
  501. teradataml/data/jsons/sqle/17.10/GLMPredict.json +151 -151
  502. teradataml/data/jsons/sqle/17.10/MovingAverage.json +368 -368
  503. teradataml/data/jsons/sqle/17.10/NGramSplitter.json +239 -239
  504. teradataml/data/jsons/sqle/17.10/NaiveBayesPredict.json +149 -149
  505. teradataml/data/jsons/sqle/17.10/NaiveBayesTextClassifierPredict.json +288 -288
  506. teradataml/data/jsons/sqle/17.10/Pack.json +133 -133
  507. teradataml/data/jsons/sqle/17.10/SVMSparsePredict.json +193 -193
  508. teradataml/data/jsons/sqle/17.10/Sessionize.json +105 -105
  509. teradataml/data/jsons/sqle/17.10/StringSimilarity.json +86 -86
  510. teradataml/data/jsons/sqle/17.10/TD_BinCodeFit.json +239 -239
  511. teradataml/data/jsons/sqle/17.10/TD_BinCodeTransform.json +70 -70
  512. teradataml/data/jsons/sqle/17.10/TD_CategoricalSummary.json +53 -53
  513. teradataml/data/jsons/sqle/17.10/TD_Chisq.json +67 -67
  514. teradataml/data/jsons/sqle/17.10/TD_ColumnSummary.json +53 -53
  515. teradataml/data/jsons/sqle/17.10/TD_ConvertTo.json +68 -68
  516. teradataml/data/jsons/sqle/17.10/TD_FTest.json +187 -187
  517. teradataml/data/jsons/sqle/17.10/TD_FillRowID.json +51 -51
  518. teradataml/data/jsons/sqle/17.10/TD_FunctionFit.json +46 -46
  519. teradataml/data/jsons/sqle/17.10/TD_FunctionTransform.json +72 -71
  520. teradataml/data/jsons/sqle/17.10/TD_GetRowsWithMissingValues.json +52 -52
  521. teradataml/data/jsons/sqle/17.10/TD_GetRowsWithoutMissingValues.json +52 -52
  522. teradataml/data/jsons/sqle/17.10/TD_Histogram.json +132 -132
  523. teradataml/data/jsons/sqle/17.10/TD_NumApply.json +147 -147
  524. teradataml/data/jsons/sqle/17.10/TD_OneHotEncodingFit.json +182 -182
  525. teradataml/data/jsons/sqle/17.10/TD_OneHotEncodingTransform.json +65 -64
  526. teradataml/data/jsons/sqle/17.10/TD_OutlierFilterFit.json +196 -196
  527. teradataml/data/jsons/sqle/17.10/TD_OutlierFilterTransform.json +48 -47
  528. teradataml/data/jsons/sqle/17.10/TD_PolynomialFeaturesFit.json +114 -114
  529. teradataml/data/jsons/sqle/17.10/TD_PolynomialFeaturesTransform.json +72 -71
  530. teradataml/data/jsons/sqle/17.10/TD_QQNorm.json +111 -111
  531. teradataml/data/jsons/sqle/17.10/TD_RoundColumns.json +93 -93
  532. teradataml/data/jsons/sqle/17.10/TD_RowNormalizeFit.json +127 -127
  533. teradataml/data/jsons/sqle/17.10/TD_RowNormalizeTransform.json +70 -69
  534. teradataml/data/jsons/sqle/17.10/TD_ScaleFit.json +156 -156
  535. teradataml/data/jsons/sqle/17.10/TD_ScaleTransform.json +70 -69
  536. teradataml/data/jsons/sqle/17.10/TD_SimpleImputeFit.json +147 -147
  537. teradataml/data/jsons/sqle/17.10/TD_SimpleImputeTransform.json +48 -47
  538. teradataml/data/jsons/sqle/17.10/TD_StrApply.json +240 -240
  539. teradataml/data/jsons/sqle/17.10/TD_UnivariateStatistics.json +118 -118
  540. teradataml/data/jsons/sqle/17.10/TD_WhichMax.json +52 -52
  541. teradataml/data/jsons/sqle/17.10/TD_WhichMin.json +52 -52
  542. teradataml/data/jsons/sqle/17.10/TD_ZTest.json +171 -171
  543. teradataml/data/jsons/sqle/17.10/Unpack.json +188 -188
  544. teradataml/data/jsons/sqle/17.10/nPath.json +269 -269
  545. teradataml/data/jsons/sqle/17.20/Antiselect.json +56 -56
  546. teradataml/data/jsons/sqle/17.20/Attribution.json +249 -249
  547. teradataml/data/jsons/sqle/17.20/DecisionForestPredict.json +185 -185
  548. teradataml/data/jsons/sqle/17.20/DecisionTreePredict.json +172 -172
  549. teradataml/data/jsons/sqle/17.20/GLMPredict.json +151 -151
  550. teradataml/data/jsons/sqle/17.20/MovingAverage.json +367 -367
  551. teradataml/data/jsons/sqle/17.20/NGramSplitter.json +239 -239
  552. teradataml/data/jsons/sqle/17.20/NaiveBayesPredict.json +149 -149
  553. teradataml/data/jsons/sqle/17.20/NaiveBayesTextClassifierPredict.json +287 -287
  554. teradataml/data/jsons/sqle/17.20/Pack.json +133 -133
  555. teradataml/data/jsons/sqle/17.20/SVMSparsePredict.json +192 -192
  556. teradataml/data/jsons/sqle/17.20/Sessionize.json +105 -105
  557. teradataml/data/jsons/sqle/17.20/StringSimilarity.json +86 -86
  558. teradataml/data/jsons/sqle/17.20/TD_ANOVA.json +76 -76
  559. teradataml/data/jsons/sqle/17.20/TD_BinCodeFit.json +239 -239
  560. teradataml/data/jsons/sqle/17.20/TD_BinCodeTransform.json +71 -71
  561. teradataml/data/jsons/sqle/17.20/TD_CategoricalSummary.json +53 -53
  562. teradataml/data/jsons/sqle/17.20/TD_Chisq.json +67 -67
  563. teradataml/data/jsons/sqle/17.20/TD_ClassificationEvaluator.json +145 -145
  564. teradataml/data/jsons/sqle/17.20/TD_ColumnSummary.json +53 -53
  565. teradataml/data/jsons/sqle/17.20/TD_ColumnTransformer.json +218 -218
  566. teradataml/data/jsons/sqle/17.20/TD_ConvertTo.json +92 -92
  567. teradataml/data/jsons/sqle/17.20/TD_DecisionForest.json +259 -259
  568. teradataml/data/jsons/sqle/17.20/TD_DecisionForestPredict.json +139 -139
  569. teradataml/data/jsons/sqle/17.20/TD_FTest.json +186 -186
  570. teradataml/data/jsons/sqle/17.20/TD_FillRowID.json +52 -52
  571. teradataml/data/jsons/sqle/17.20/TD_FunctionFit.json +46 -46
  572. teradataml/data/jsons/sqle/17.20/TD_FunctionTransform.json +72 -72
  573. teradataml/data/jsons/sqle/17.20/TD_GLM.json +431 -431
  574. teradataml/data/jsons/sqle/17.20/TD_GLMPREDICT.json +125 -125
  575. teradataml/data/jsons/sqle/17.20/TD_GLMPerSegment.json +411 -411
  576. teradataml/data/jsons/sqle/17.20/TD_GLMPredictPerSegment.json +146 -146
  577. teradataml/data/jsons/sqle/17.20/TD_GetFutileColumns.json +91 -91
  578. teradataml/data/jsons/sqle/17.20/TD_GetRowsWithMissingValues.json +76 -76
  579. teradataml/data/jsons/sqle/17.20/TD_GetRowsWithoutMissingValues.json +76 -76
  580. teradataml/data/jsons/sqle/17.20/TD_Histogram.json +152 -152
  581. teradataml/data/jsons/sqle/17.20/TD_KMeans.json +211 -211
  582. teradataml/data/jsons/sqle/17.20/TD_KMeansPredict.json +86 -86
  583. teradataml/data/jsons/sqle/17.20/TD_KNN.json +262 -262
  584. teradataml/data/jsons/sqle/17.20/TD_NaiveBayesTextClassifierTrainer.json +137 -137
  585. teradataml/data/jsons/sqle/17.20/TD_NonLinearCombineFit.json +101 -101
  586. teradataml/data/jsons/sqle/17.20/TD_NonLinearCombineTransform.json +71 -71
  587. teradataml/data/jsons/sqle/17.20/TD_NumApply.json +147 -147
  588. teradataml/data/jsons/sqle/17.20/TD_OneClassSVM.json +315 -315
  589. teradataml/data/jsons/sqle/17.20/TD_OneClassSVMPredict.json +123 -123
  590. teradataml/data/jsons/sqle/17.20/TD_OneHotEncodingFit.json +271 -271
  591. teradataml/data/jsons/sqle/17.20/TD_OneHotEncodingTransform.json +65 -65
  592. teradataml/data/jsons/sqle/17.20/TD_OrdinalEncodingFit.json +229 -229
  593. teradataml/data/jsons/sqle/17.20/TD_OrdinalEncodingTransform.json +75 -75
  594. teradataml/data/jsons/sqle/17.20/TD_OutlierFilterFit.json +217 -217
  595. teradataml/data/jsons/sqle/17.20/TD_OutlierFilterTransform.json +48 -48
  596. teradataml/data/jsons/sqle/17.20/TD_PolynomialFeaturesFit.json +114 -114
  597. teradataml/data/jsons/sqle/17.20/TD_PolynomialFeaturesTransform.json +72 -72
  598. teradataml/data/jsons/sqle/17.20/TD_QQNorm.json +111 -111
  599. teradataml/data/jsons/sqle/17.20/TD_ROC.json +177 -177
  600. teradataml/data/jsons/sqle/17.20/TD_RandomProjectionFit.json +178 -178
  601. teradataml/data/jsons/sqle/17.20/TD_RandomProjectionMinComponents.json +73 -73
  602. teradataml/data/jsons/sqle/17.20/TD_RandomProjectionTransform.json +74 -74
  603. teradataml/data/jsons/sqle/17.20/TD_RegressionEvaluator.json +137 -137
  604. teradataml/data/jsons/sqle/17.20/TD_RoundColumns.json +93 -93
  605. teradataml/data/jsons/sqle/17.20/TD_RowNormalizeFit.json +127 -127
  606. teradataml/data/jsons/sqle/17.20/TD_RowNormalizeTransform.json +70 -70
  607. teradataml/data/jsons/sqle/17.20/TD_SVM.json +389 -389
  608. teradataml/data/jsons/sqle/17.20/TD_SVMPredict.json +124 -124
  609. teradataml/data/jsons/sqle/17.20/TD_ScaleFit.json +156 -156
  610. teradataml/data/jsons/sqle/17.20/TD_ScaleTransform.json +70 -70
  611. teradataml/data/jsons/sqle/17.20/TD_SentimentExtractor.json +193 -193
  612. teradataml/data/jsons/sqle/17.20/TD_Silhouette.json +142 -142
  613. teradataml/data/jsons/sqle/17.20/TD_SimpleImputeFit.json +147 -147
  614. teradataml/data/jsons/sqle/17.20/TD_SimpleImputeTransform.json +48 -48
  615. teradataml/data/jsons/sqle/17.20/TD_StrApply.json +240 -240
  616. teradataml/data/jsons/sqle/17.20/TD_TargetEncodingFit.json +248 -248
  617. teradataml/data/jsons/sqle/17.20/TD_TargetEncodingTransform.json +75 -75
  618. teradataml/data/jsons/sqle/17.20/TD_TextParser.json +192 -192
  619. teradataml/data/jsons/sqle/17.20/TD_TrainTestSplit.json +142 -142
  620. teradataml/data/jsons/sqle/17.20/TD_UnivariateStatistics.json +117 -117
  621. teradataml/data/jsons/sqle/17.20/TD_VectorDistance.json +182 -182
  622. teradataml/data/jsons/sqle/17.20/TD_WhichMax.json +52 -52
  623. teradataml/data/jsons/sqle/17.20/TD_WhichMin.json +52 -52
  624. teradataml/data/jsons/sqle/17.20/TD_WordEmbeddings.json +241 -241
  625. teradataml/data/jsons/sqle/17.20/TD_XGBoost.json +312 -312
  626. teradataml/data/jsons/sqle/17.20/TD_XGBoostPredict.json +182 -182
  627. teradataml/data/jsons/sqle/17.20/TD_ZTest.json +170 -170
  628. teradataml/data/jsons/sqle/17.20/Unpack.json +188 -188
  629. teradataml/data/jsons/sqle/17.20/nPath.json +269 -269
  630. teradataml/data/jsons/tableoperator/17.00/read_nos.json +197 -197
  631. teradataml/data/jsons/tableoperator/17.05/read_nos.json +197 -197
  632. teradataml/data/jsons/tableoperator/17.05/write_nos.json +194 -194
  633. teradataml/data/jsons/tableoperator/17.10/read_nos.json +183 -183
  634. teradataml/data/jsons/tableoperator/17.10/write_nos.json +194 -194
  635. teradataml/data/jsons/tableoperator/17.20/read_nos.json +182 -182
  636. teradataml/data/jsons/tableoperator/17.20/write_nos.json +223 -223
  637. teradataml/data/jsons/uaf/17.20/TD_ACF.json +149 -149
  638. teradataml/data/jsons/uaf/17.20/TD_ARIMAESTIMATE.json +409 -409
  639. teradataml/data/jsons/uaf/17.20/TD_ARIMAFORECAST.json +79 -79
  640. teradataml/data/jsons/uaf/17.20/TD_ARIMAVALIDATE.json +151 -151
  641. teradataml/data/jsons/uaf/17.20/TD_BINARYMATRIXOP.json +109 -109
  642. teradataml/data/jsons/uaf/17.20/TD_BINARYSERIESOP.json +107 -107
  643. teradataml/data/jsons/uaf/17.20/TD_BREUSCH_GODFREY.json +87 -87
  644. teradataml/data/jsons/uaf/17.20/TD_BREUSCH_PAGAN_GODFREY.json +106 -106
  645. teradataml/data/jsons/uaf/17.20/TD_CONVOLVE.json +80 -80
  646. teradataml/data/jsons/uaf/17.20/TD_CONVOLVE2.json +67 -67
  647. teradataml/data/jsons/uaf/17.20/TD_CUMUL_PERIODOGRAM.json +91 -91
  648. teradataml/data/jsons/uaf/17.20/TD_DFFT.json +136 -136
  649. teradataml/data/jsons/uaf/17.20/TD_DFFT2.json +148 -148
  650. teradataml/data/jsons/uaf/17.20/TD_DFFT2CONV.json +108 -108
  651. teradataml/data/jsons/uaf/17.20/TD_DFFTCONV.json +109 -109
  652. teradataml/data/jsons/uaf/17.20/TD_DICKEY_FULLER.json +86 -86
  653. teradataml/data/jsons/uaf/17.20/TD_DIFF.json +91 -91
  654. teradataml/data/jsons/uaf/17.20/TD_DTW.json +116 -116
  655. teradataml/data/jsons/uaf/17.20/TD_DURBIN_WATSON.json +100 -100
  656. teradataml/data/jsons/uaf/17.20/TD_EXTRACT_RESULTS.json +38 -38
  657. teradataml/data/jsons/uaf/17.20/TD_FITMETRICS.json +100 -100
  658. teradataml/data/jsons/uaf/17.20/TD_GENSERIES4FORMULA.json +84 -84
  659. teradataml/data/jsons/uaf/17.20/TD_GENSERIES4SINUSOIDS.json +70 -70
  660. teradataml/data/jsons/uaf/17.20/TD_GOLDFELD_QUANDT.json +152 -152
  661. teradataml/data/jsons/uaf/17.20/TD_HOLT_WINTERS_FORECAST.json +313 -313
  662. teradataml/data/jsons/uaf/17.20/TD_IDFFT.json +57 -57
  663. teradataml/data/jsons/uaf/17.20/TD_IDFFT2.json +94 -94
  664. teradataml/data/jsons/uaf/17.20/TD_INPUTVALIDATOR.json +63 -63
  665. teradataml/data/jsons/uaf/17.20/TD_LINEAR_REGR.json +181 -181
  666. teradataml/data/jsons/uaf/17.20/TD_LINESPEC.json +102 -102
  667. teradataml/data/jsons/uaf/17.20/TD_MAMEAN.json +182 -182
  668. teradataml/data/jsons/uaf/17.20/TD_MATRIXMULTIPLY.json +67 -67
  669. teradataml/data/jsons/uaf/17.20/TD_MINFO.json +66 -66
  670. teradataml/data/jsons/uaf/17.20/TD_MULTIVAR_REGR.json +178 -178
  671. teradataml/data/jsons/uaf/17.20/TD_PACF.json +114 -114
  672. teradataml/data/jsons/uaf/17.20/TD_PORTMAN.json +118 -118
  673. teradataml/data/jsons/uaf/17.20/TD_POWERSPEC.json +175 -175
  674. teradataml/data/jsons/uaf/17.20/TD_POWERTRANSFORM.json +97 -97
  675. teradataml/data/jsons/uaf/17.20/TD_RESAMPLE.json +173 -173
  676. teradataml/data/jsons/uaf/17.20/TD_SEASONALNORMALIZE.json +136 -136
  677. teradataml/data/jsons/uaf/17.20/TD_SELECTION_CRITERIA.json +89 -89
  678. teradataml/data/jsons/uaf/17.20/TD_SIGNIF_PERIODICITIES.json +79 -79
  679. teradataml/data/jsons/uaf/17.20/TD_SIGNIF_RESIDMEAN.json +67 -67
  680. teradataml/data/jsons/uaf/17.20/TD_SIMPLEEXP.json +184 -184
  681. teradataml/data/jsons/uaf/17.20/TD_SINFO.json +57 -57
  682. teradataml/data/jsons/uaf/17.20/TD_SMOOTHMA.json +162 -162
  683. teradataml/data/jsons/uaf/17.20/TD_TRACKINGOP.json +100 -100
  684. teradataml/data/jsons/uaf/17.20/TD_UNDIFF.json +111 -111
  685. teradataml/data/jsons/uaf/17.20/TD_UNNORMALIZE.json +95 -95
  686. teradataml/data/jsons/uaf/17.20/TD_WHITES_GENERAL.json +77 -77
  687. teradataml/data/kmeans_example.json +17 -17
  688. teradataml/data/kmeans_us_arrests_data.csv +0 -0
  689. teradataml/data/knn_example.json +18 -18
  690. teradataml/data/knnrecommender_example.json +6 -6
  691. teradataml/data/knnrecommenderpredict_example.json +12 -12
  692. teradataml/data/lar_example.json +17 -17
  693. teradataml/data/larpredict_example.json +30 -30
  694. teradataml/data/lc_new_predictors.csv +5 -5
  695. teradataml/data/lc_new_reference.csv +9 -9
  696. teradataml/data/lda_example.json +8 -8
  697. teradataml/data/ldainference_example.json +14 -14
  698. teradataml/data/ldatopicsummary_example.json +8 -8
  699. teradataml/data/levendist_input.csv +13 -13
  700. teradataml/data/levenshteindistance_example.json +10 -10
  701. teradataml/data/linreg_example.json +9 -9
  702. teradataml/data/load_example_data.py +326 -323
  703. teradataml/data/loan_prediction.csv +295 -295
  704. teradataml/data/lungcancer.csv +138 -138
  705. teradataml/data/mappingdata.csv +12 -12
  706. teradataml/data/milk_timeseries.csv +157 -157
  707. teradataml/data/min_max_titanic.csv +4 -4
  708. teradataml/data/minhash_example.json +6 -6
  709. teradataml/data/ml_ratings.csv +7547 -7547
  710. teradataml/data/ml_ratings_10.csv +2445 -2445
  711. teradataml/data/model1_table.csv +5 -5
  712. teradataml/data/model2_table.csv +5 -5
  713. teradataml/data/models/iris_db_glm_model.pmml +56 -56
  714. teradataml/data/models/iris_db_xgb_model.pmml +4471 -4471
  715. teradataml/data/modularity_example.json +12 -12
  716. teradataml/data/movavg_example.json +7 -7
  717. teradataml/data/mtx1.csv +7 -7
  718. teradataml/data/mtx2.csv +13 -13
  719. teradataml/data/multi_model_classification.csv +401 -0
  720. teradataml/data/multi_model_regression.csv +401 -0
  721. teradataml/data/mvdfft8.csv +9 -9
  722. teradataml/data/naivebayes_example.json +9 -9
  723. teradataml/data/naivebayespredict_example.json +19 -19
  724. teradataml/data/naivebayestextclassifier2_example.json +6 -6
  725. teradataml/data/naivebayestextclassifier_example.json +8 -8
  726. teradataml/data/naivebayestextclassifierpredict_example.json +20 -20
  727. teradataml/data/name_Find_configure.csv +10 -10
  728. teradataml/data/namedentityfinder_example.json +14 -14
  729. teradataml/data/namedentityfinderevaluator_example.json +10 -10
  730. teradataml/data/namedentityfindertrainer_example.json +6 -6
  731. teradataml/data/nb_iris_input_test.csv +31 -31
  732. teradataml/data/nb_iris_input_train.csv +121 -121
  733. teradataml/data/nbp_iris_model.csv +13 -13
  734. teradataml/data/ner_extractor_text.csv +2 -2
  735. teradataml/data/ner_sports_test2.csv +29 -29
  736. teradataml/data/ner_sports_train.csv +501 -501
  737. teradataml/data/nerevaluator_example.json +5 -5
  738. teradataml/data/nerextractor_example.json +18 -18
  739. teradataml/data/nermem_sports_test.csv +17 -17
  740. teradataml/data/nermem_sports_train.csv +50 -50
  741. teradataml/data/nertrainer_example.json +6 -6
  742. teradataml/data/ngrams_example.json +6 -6
  743. teradataml/data/notebooks/sqlalchemy/Teradata Vantage Aggregate Functions using SQLAlchemy.ipynb +1455 -1455
  744. teradataml/data/notebooks/sqlalchemy/Teradata Vantage Arithmetic Functions Using SQLAlchemy.ipynb +1993 -1993
  745. teradataml/data/notebooks/sqlalchemy/Teradata Vantage Bit-Byte Manipulation Functions using SQLAlchemy.ipynb +1492 -1492
  746. teradataml/data/notebooks/sqlalchemy/Teradata Vantage Built-in functions using SQLAlchemy.ipynb +536 -536
  747. teradataml/data/notebooks/sqlalchemy/Teradata Vantage Regular Expressions Using SQLAlchemy.ipynb +570 -570
  748. teradataml/data/notebooks/sqlalchemy/Teradata Vantage String Functions Using SQLAlchemy.ipynb +2559 -2559
  749. teradataml/data/notebooks/sqlalchemy/Teradata Vantage Window Aggregate Functions using SQLAlchemy.ipynb +2911 -2911
  750. teradataml/data/notebooks/sqlalchemy/Using Generic SQLAlchemy ClauseElements teradataml DataFrame assign method.ipynb +698 -698
  751. teradataml/data/notebooks/sqlalchemy/teradataml filtering using SQLAlchemy ClauseElements.ipynb +784 -784
  752. teradataml/data/npath_example.json +23 -23
  753. teradataml/data/ntree_example.json +14 -14
  754. teradataml/data/numeric_strings.csv +4 -4
  755. teradataml/data/numerics.csv +4 -4
  756. teradataml/data/ocean_buoy.csv +17 -17
  757. teradataml/data/ocean_buoy2.csv +17 -17
  758. teradataml/data/ocean_buoys.csv +27 -27
  759. teradataml/data/ocean_buoys2.csv +10 -10
  760. teradataml/data/ocean_buoys_nonpti.csv +28 -28
  761. teradataml/data/ocean_buoys_seq.csv +29 -29
  762. teradataml/data/openml_example.json +63 -0
  763. teradataml/data/optional_event_table.csv +4 -4
  764. teradataml/data/orders1.csv +11 -11
  765. teradataml/data/orders1_12.csv +12 -12
  766. teradataml/data/orders_ex.csv +4 -4
  767. teradataml/data/pack_example.json +8 -8
  768. teradataml/data/package_tracking.csv +19 -19
  769. teradataml/data/package_tracking_pti.csv +18 -18
  770. teradataml/data/pagerank_example.json +13 -13
  771. teradataml/data/paragraphs_input.csv +6 -6
  772. teradataml/data/pathanalyzer_example.json +7 -7
  773. teradataml/data/pathgenerator_example.json +7 -7
  774. teradataml/data/phrases.csv +7 -7
  775. teradataml/data/pivot_example.json +8 -8
  776. teradataml/data/pivot_input.csv +22 -22
  777. teradataml/data/playerRating.csv +31 -31
  778. teradataml/data/postagger_example.json +6 -6
  779. teradataml/data/posttagger_output.csv +44 -44
  780. teradataml/data/production_data.csv +16 -16
  781. teradataml/data/production_data2.csv +7 -7
  782. teradataml/data/randomsample_example.json +31 -31
  783. teradataml/data/randomwalksample_example.json +8 -8
  784. teradataml/data/rank_table.csv +6 -6
  785. teradataml/data/ref_mobile_data.csv +4 -4
  786. teradataml/data/ref_mobile_data_dense.csv +2 -2
  787. teradataml/data/ref_url.csv +17 -17
  788. teradataml/data/restaurant_reviews.csv +7 -7
  789. teradataml/data/river_data.csv +145 -145
  790. teradataml/data/roc_example.json +7 -7
  791. teradataml/data/roc_input.csv +101 -101
  792. teradataml/data/rule_inputs.csv +6 -6
  793. teradataml/data/rule_table.csv +2 -2
  794. teradataml/data/sales.csv +7 -7
  795. teradataml/data/sales_transaction.csv +501 -501
  796. teradataml/data/salesdata.csv +342 -342
  797. teradataml/data/sample_cities.csv +2 -2
  798. teradataml/data/sample_shapes.csv +10 -10
  799. teradataml/data/sample_streets.csv +2 -2
  800. teradataml/data/sampling_example.json +15 -15
  801. teradataml/data/sax_example.json +8 -8
  802. teradataml/data/scale_example.json +23 -23
  803. teradataml/data/scale_housing.csv +11 -11
  804. teradataml/data/scale_housing_test.csv +6 -6
  805. teradataml/data/scale_stat.csv +11 -11
  806. teradataml/data/scalebypartition_example.json +13 -13
  807. teradataml/data/scalemap_example.json +13 -13
  808. teradataml/data/scalesummary_example.json +12 -12
  809. teradataml/data/score_category.csv +101 -101
  810. teradataml/data/score_summary.csv +4 -4
  811. teradataml/data/script_example.json +9 -9
  812. teradataml/data/scripts/deploy_script.py +65 -0
  813. teradataml/data/scripts/mapper.R +20 -0
  814. teradataml/data/scripts/mapper.py +15 -15
  815. teradataml/data/scripts/mapper_replace.py +15 -15
  816. teradataml/data/scripts/sklearn/__init__.py +0 -0
  817. teradataml/data/scripts/sklearn/sklearn_fit.py +175 -0
  818. teradataml/data/scripts/sklearn/sklearn_fit_predict.py +135 -0
  819. teradataml/data/scripts/sklearn/sklearn_function.template +113 -0
  820. teradataml/data/scripts/sklearn/sklearn_model_selection_split.py +158 -0
  821. teradataml/data/scripts/sklearn/sklearn_neighbors.py +152 -0
  822. teradataml/data/scripts/sklearn/sklearn_score.py +128 -0
  823. teradataml/data/scripts/sklearn/sklearn_transform.py +179 -0
  824. teradataml/data/seeds.csv +10 -10
  825. teradataml/data/sentenceextractor_example.json +6 -6
  826. teradataml/data/sentiment_extract_input.csv +11 -11
  827. teradataml/data/sentiment_train.csv +16 -16
  828. teradataml/data/sentiment_word.csv +20 -20
  829. teradataml/data/sentiment_word_input.csv +19 -19
  830. teradataml/data/sentimentextractor_example.json +24 -24
  831. teradataml/data/sentimenttrainer_example.json +8 -8
  832. teradataml/data/sequence_table.csv +10 -10
  833. teradataml/data/seriessplitter_example.json +7 -7
  834. teradataml/data/sessionize_example.json +17 -17
  835. teradataml/data/sessionize_table.csv +116 -116
  836. teradataml/data/setop_test1.csv +24 -24
  837. teradataml/data/setop_test2.csv +22 -22
  838. teradataml/data/soc_nw_edges.csv +10 -10
  839. teradataml/data/soc_nw_vertices.csv +7 -7
  840. teradataml/data/souvenir_timeseries.csv +167 -167
  841. teradataml/data/sparse_iris_attribute.csv +5 -5
  842. teradataml/data/sparse_iris_test.csv +121 -121
  843. teradataml/data/sparse_iris_train.csv +601 -601
  844. teradataml/data/star1.csv +6 -6
  845. teradataml/data/state_transition.csv +5 -5
  846. teradataml/data/stock_data.csv +53 -53
  847. teradataml/data/stock_movement.csv +11 -11
  848. teradataml/data/stock_vol.csv +76 -76
  849. teradataml/data/stop_words.csv +8 -8
  850. teradataml/data/store_sales.csv +37 -37
  851. teradataml/data/stringsimilarity_example.json +7 -7
  852. teradataml/data/strsimilarity_input.csv +13 -13
  853. teradataml/data/students.csv +101 -101
  854. teradataml/data/svm_iris_input_test.csv +121 -121
  855. teradataml/data/svm_iris_input_train.csv +481 -481
  856. teradataml/data/svm_iris_model.csv +7 -7
  857. teradataml/data/svmdense_example.json +9 -9
  858. teradataml/data/svmdensepredict_example.json +18 -18
  859. teradataml/data/svmsparse_example.json +7 -7
  860. teradataml/data/svmsparsepredict_example.json +13 -13
  861. teradataml/data/svmsparsesummary_example.json +7 -7
  862. teradataml/data/target_mobile_data.csv +13 -13
  863. teradataml/data/target_mobile_data_dense.csv +5 -5
  864. teradataml/data/templatedata.csv +1201 -1201
  865. teradataml/data/templates/open_source_ml.json +9 -0
  866. teradataml/data/teradataml_example.json +73 -1
  867. teradataml/data/test_classification.csv +101 -0
  868. teradataml/data/test_loan_prediction.csv +53 -53
  869. teradataml/data/test_pacf_12.csv +37 -37
  870. teradataml/data/test_prediction.csv +101 -0
  871. teradataml/data/test_regression.csv +101 -0
  872. teradataml/data/test_river2.csv +109 -109
  873. teradataml/data/text_inputs.csv +6 -6
  874. teradataml/data/textchunker_example.json +7 -7
  875. teradataml/data/textclassifier_example.json +6 -6
  876. teradataml/data/textclassifier_input.csv +7 -7
  877. teradataml/data/textclassifiertrainer_example.json +6 -6
  878. teradataml/data/textmorph_example.json +5 -5
  879. teradataml/data/textparser_example.json +15 -15
  880. teradataml/data/texttagger_example.json +11 -11
  881. teradataml/data/texttokenizer_example.json +6 -6
  882. teradataml/data/texttrainer_input.csv +11 -11
  883. teradataml/data/tf_example.json +6 -6
  884. teradataml/data/tfidf_example.json +13 -13
  885. teradataml/data/tfidf_input1.csv +201 -201
  886. teradataml/data/tfidf_train.csv +6 -6
  887. teradataml/data/time_table1.csv +535 -535
  888. teradataml/data/time_table2.csv +14 -14
  889. teradataml/data/timeseriesdata.csv +1601 -1601
  890. teradataml/data/timeseriesdatasetsd4.csv +105 -105
  891. teradataml/data/titanic.csv +892 -892
  892. teradataml/data/token_table.csv +696 -696
  893. teradataml/data/train_multiclass.csv +101 -0
  894. teradataml/data/train_regression.csv +101 -0
  895. teradataml/data/train_regression_multiple_labels.csv +101 -0
  896. teradataml/data/train_tracking.csv +27 -27
  897. teradataml/data/transformation_table.csv +5 -5
  898. teradataml/data/transformation_table_new.csv +1 -1
  899. teradataml/data/tv_spots.csv +16 -16
  900. teradataml/data/twod_climate_data.csv +117 -117
  901. teradataml/data/uaf_example.json +475 -475
  902. teradataml/data/univariatestatistics_example.json +8 -8
  903. teradataml/data/unpack_example.json +9 -9
  904. teradataml/data/unpivot_example.json +9 -9
  905. teradataml/data/unpivot_input.csv +8 -8
  906. teradataml/data/us_air_pass.csv +36 -36
  907. teradataml/data/us_population.csv +624 -624
  908. teradataml/data/us_states_shapes.csv +52 -52
  909. teradataml/data/varmax_example.json +17 -17
  910. teradataml/data/vectordistance_example.json +25 -25
  911. teradataml/data/ville_climatedata.csv +121 -121
  912. teradataml/data/ville_tempdata.csv +12 -12
  913. teradataml/data/ville_tempdata1.csv +12 -12
  914. teradataml/data/ville_temperature.csv +11 -11
  915. teradataml/data/waveletTable.csv +1605 -1605
  916. teradataml/data/waveletTable2.csv +1605 -1605
  917. teradataml/data/weightedmovavg_example.json +8 -8
  918. teradataml/data/wft_testing.csv +5 -5
  919. teradataml/data/wine_data.csv +1600 -0
  920. teradataml/data/word_embed_input_table1.csv +5 -5
  921. teradataml/data/word_embed_input_table2.csv +4 -4
  922. teradataml/data/word_embed_model.csv +22 -22
  923. teradataml/data/words_input.csv +13 -13
  924. teradataml/data/xconvolve_complex_left.csv +6 -6
  925. teradataml/data/xconvolve_complex_leftmulti.csv +6 -6
  926. teradataml/data/xgboost_example.json +35 -35
  927. teradataml/data/xgboostpredict_example.json +31 -31
  928. teradataml/dataframe/copy_to.py +1764 -1698
  929. teradataml/dataframe/data_transfer.py +2753 -2745
  930. teradataml/dataframe/dataframe.py +17545 -16946
  931. teradataml/dataframe/dataframe_utils.py +1837 -1740
  932. teradataml/dataframe/fastload.py +611 -603
  933. teradataml/dataframe/indexer.py +424 -424
  934. teradataml/dataframe/setop.py +1179 -1166
  935. teradataml/dataframe/sql.py +10090 -6432
  936. teradataml/dataframe/sql_function_parameters.py +439 -388
  937. teradataml/dataframe/sql_functions.py +652 -652
  938. teradataml/dataframe/sql_interfaces.py +220 -220
  939. teradataml/dataframe/vantage_function_types.py +674 -630
  940. teradataml/dataframe/window.py +693 -692
  941. teradataml/dbutils/__init__.py +3 -3
  942. teradataml/dbutils/dbutils.py +1167 -1150
  943. teradataml/dbutils/filemgr.py +267 -267
  944. teradataml/gen_ai/__init__.py +2 -2
  945. teradataml/gen_ai/convAI.py +472 -472
  946. teradataml/geospatial/__init__.py +3 -3
  947. teradataml/geospatial/geodataframe.py +1105 -1094
  948. teradataml/geospatial/geodataframecolumn.py +392 -387
  949. teradataml/geospatial/geometry_types.py +925 -925
  950. teradataml/hyperparameter_tuner/__init__.py +1 -1
  951. teradataml/hyperparameter_tuner/optimizer.py +3783 -2993
  952. teradataml/hyperparameter_tuner/utils.py +281 -187
  953. teradataml/lib/aed_0_1.dll +0 -0
  954. teradataml/lib/libaed_0_1.dylib +0 -0
  955. teradataml/lib/libaed_0_1.so +0 -0
  956. teradataml/libaed_0_1.dylib +0 -0
  957. teradataml/libaed_0_1.so +0 -0
  958. teradataml/opensource/__init__.py +1 -0
  959. teradataml/opensource/sklearn/__init__.py +1 -0
  960. teradataml/opensource/sklearn/_class.py +255 -0
  961. teradataml/opensource/sklearn/_sklearn_wrapper.py +1668 -0
  962. teradataml/opensource/sklearn/_wrapper_utils.py +268 -0
  963. teradataml/opensource/sklearn/constants.py +54 -0
  964. teradataml/options/__init__.py +121 -124
  965. teradataml/options/configure.py +337 -336
  966. teradataml/options/display.py +176 -176
  967. teradataml/plot/__init__.py +2 -2
  968. teradataml/plot/axis.py +1388 -1388
  969. teradataml/plot/constants.py +15 -15
  970. teradataml/plot/figure.py +398 -398
  971. teradataml/plot/plot.py +760 -760
  972. teradataml/plot/query_generator.py +83 -83
  973. teradataml/plot/subplot.py +216 -216
  974. teradataml/scriptmgmt/UserEnv.py +3788 -3761
  975. teradataml/scriptmgmt/__init__.py +3 -3
  976. teradataml/scriptmgmt/lls_utils.py +1616 -1604
  977. teradataml/series/series.py +532 -532
  978. teradataml/series/series_utils.py +71 -71
  979. teradataml/table_operators/Apply.py +949 -917
  980. teradataml/table_operators/Script.py +1719 -1982
  981. teradataml/table_operators/TableOperator.py +1207 -1616
  982. teradataml/table_operators/__init__.py +2 -3
  983. teradataml/table_operators/apply_query_generator.py +262 -262
  984. teradataml/table_operators/query_generator.py +507 -507
  985. teradataml/table_operators/table_operator_query_generator.py +460 -460
  986. teradataml/table_operators/table_operator_util.py +631 -639
  987. teradataml/table_operators/templates/dataframe_apply.template +184 -184
  988. teradataml/table_operators/templates/dataframe_map.template +176 -176
  989. teradataml/table_operators/templates/script_executor.template +170 -170
  990. teradataml/utils/dtypes.py +684 -684
  991. teradataml/utils/internal_buffer.py +84 -84
  992. teradataml/utils/print_versions.py +205 -205
  993. teradataml/utils/utils.py +410 -410
  994. teradataml/utils/validators.py +2239 -2115
  995. {teradataml-17.20.0.7.dist-info → teradataml-20.0.0.0.dist-info}/METADATA +270 -41
  996. teradataml-20.0.0.0.dist-info/RECORD +1038 -0
  997. {teradataml-17.20.0.7.dist-info → teradataml-20.0.0.0.dist-info}/WHEEL +1 -1
  998. {teradataml-17.20.0.7.dist-info → teradataml-20.0.0.0.dist-info}/zip-safe +1 -1
  999. teradataml/analytics/mle/AdaBoost.py +0 -651
  1000. teradataml/analytics/mle/AdaBoostPredict.py +0 -564
  1001. teradataml/analytics/mle/Antiselect.py +0 -342
  1002. teradataml/analytics/mle/Arima.py +0 -641
  1003. teradataml/analytics/mle/ArimaPredict.py +0 -477
  1004. teradataml/analytics/mle/Attribution.py +0 -1070
  1005. teradataml/analytics/mle/Betweenness.py +0 -658
  1006. teradataml/analytics/mle/Burst.py +0 -711
  1007. teradataml/analytics/mle/CCM.py +0 -600
  1008. teradataml/analytics/mle/CCMPrepare.py +0 -324
  1009. teradataml/analytics/mle/CFilter.py +0 -460
  1010. teradataml/analytics/mle/ChangePointDetection.py +0 -572
  1011. teradataml/analytics/mle/ChangePointDetectionRT.py +0 -477
  1012. teradataml/analytics/mle/Closeness.py +0 -737
  1013. teradataml/analytics/mle/ConfusionMatrix.py +0 -420
  1014. teradataml/analytics/mle/Correlation.py +0 -477
  1015. teradataml/analytics/mle/Correlation2.py +0 -573
  1016. teradataml/analytics/mle/CoxHazardRatio.py +0 -679
  1017. teradataml/analytics/mle/CoxPH.py +0 -556
  1018. teradataml/analytics/mle/CoxSurvival.py +0 -478
  1019. teradataml/analytics/mle/CumulativeMovAvg.py +0 -363
  1020. teradataml/analytics/mle/DTW.py +0 -623
  1021. teradataml/analytics/mle/DWT.py +0 -564
  1022. teradataml/analytics/mle/DWT2D.py +0 -599
  1023. teradataml/analytics/mle/DecisionForest.py +0 -716
  1024. teradataml/analytics/mle/DecisionForestEvaluator.py +0 -363
  1025. teradataml/analytics/mle/DecisionForestPredict.py +0 -561
  1026. teradataml/analytics/mle/DecisionTree.py +0 -830
  1027. teradataml/analytics/mle/DecisionTreePredict.py +0 -528
  1028. teradataml/analytics/mle/ExponentialMovAvg.py +0 -418
  1029. teradataml/analytics/mle/FMeasure.py +0 -402
  1030. teradataml/analytics/mle/FPGrowth.py +0 -734
  1031. teradataml/analytics/mle/FrequentPaths.py +0 -695
  1032. teradataml/analytics/mle/GLM.py +0 -558
  1033. teradataml/analytics/mle/GLML1L2.py +0 -547
  1034. teradataml/analytics/mle/GLML1L2Predict.py +0 -519
  1035. teradataml/analytics/mle/GLMPredict.py +0 -529
  1036. teradataml/analytics/mle/HMMDecoder.py +0 -945
  1037. teradataml/analytics/mle/HMMEvaluator.py +0 -901
  1038. teradataml/analytics/mle/HMMSupervised.py +0 -521
  1039. teradataml/analytics/mle/HMMUnsupervised.py +0 -572
  1040. teradataml/analytics/mle/Histogram.py +0 -561
  1041. teradataml/analytics/mle/IDWT.py +0 -476
  1042. teradataml/analytics/mle/IDWT2D.py +0 -493
  1043. teradataml/analytics/mle/IdentityMatch.py +0 -763
  1044. teradataml/analytics/mle/Interpolator.py +0 -918
  1045. teradataml/analytics/mle/KMeans.py +0 -485
  1046. teradataml/analytics/mle/KNN.py +0 -627
  1047. teradataml/analytics/mle/KNNRecommender.py +0 -488
  1048. teradataml/analytics/mle/KNNRecommenderPredict.py +0 -581
  1049. teradataml/analytics/mle/LAR.py +0 -439
  1050. teradataml/analytics/mle/LARPredict.py +0 -478
  1051. teradataml/analytics/mle/LDA.py +0 -548
  1052. teradataml/analytics/mle/LDAInference.py +0 -492
  1053. teradataml/analytics/mle/LDATopicSummary.py +0 -464
  1054. teradataml/analytics/mle/LevenshteinDistance.py +0 -450
  1055. teradataml/analytics/mle/LinReg.py +0 -433
  1056. teradataml/analytics/mle/LinRegPredict.py +0 -438
  1057. teradataml/analytics/mle/MinHash.py +0 -544
  1058. teradataml/analytics/mle/Modularity.py +0 -587
  1059. teradataml/analytics/mle/NEREvaluator.py +0 -410
  1060. teradataml/analytics/mle/NERExtractor.py +0 -595
  1061. teradataml/analytics/mle/NERTrainer.py +0 -458
  1062. teradataml/analytics/mle/NGrams.py +0 -570
  1063. teradataml/analytics/mle/NPath.py +0 -634
  1064. teradataml/analytics/mle/NTree.py +0 -549
  1065. teradataml/analytics/mle/NaiveBayes.py +0 -462
  1066. teradataml/analytics/mle/NaiveBayesPredict.py +0 -513
  1067. teradataml/analytics/mle/NaiveBayesTextClassifier.py +0 -607
  1068. teradataml/analytics/mle/NaiveBayesTextClassifier2.py +0 -531
  1069. teradataml/analytics/mle/NaiveBayesTextClassifierPredict.py +0 -799
  1070. teradataml/analytics/mle/NamedEntityFinder.py +0 -529
  1071. teradataml/analytics/mle/NamedEntityFinderEvaluator.py +0 -414
  1072. teradataml/analytics/mle/NamedEntityFinderTrainer.py +0 -396
  1073. teradataml/analytics/mle/POSTagger.py +0 -417
  1074. teradataml/analytics/mle/Pack.py +0 -411
  1075. teradataml/analytics/mle/PageRank.py +0 -535
  1076. teradataml/analytics/mle/PathAnalyzer.py +0 -426
  1077. teradataml/analytics/mle/PathGenerator.py +0 -367
  1078. teradataml/analytics/mle/PathStart.py +0 -464
  1079. teradataml/analytics/mle/PathSummarizer.py +0 -470
  1080. teradataml/analytics/mle/Pivot.py +0 -471
  1081. teradataml/analytics/mle/ROC.py +0 -425
  1082. teradataml/analytics/mle/RandomSample.py +0 -637
  1083. teradataml/analytics/mle/RandomWalkSample.py +0 -490
  1084. teradataml/analytics/mle/SAX.py +0 -779
  1085. teradataml/analytics/mle/SVMDense.py +0 -677
  1086. teradataml/analytics/mle/SVMDensePredict.py +0 -536
  1087. teradataml/analytics/mle/SVMDenseSummary.py +0 -437
  1088. teradataml/analytics/mle/SVMSparse.py +0 -557
  1089. teradataml/analytics/mle/SVMSparsePredict.py +0 -553
  1090. teradataml/analytics/mle/SVMSparseSummary.py +0 -435
  1091. teradataml/analytics/mle/Sampling.py +0 -549
  1092. teradataml/analytics/mle/Scale.py +0 -565
  1093. teradataml/analytics/mle/ScaleByPartition.py +0 -496
  1094. teradataml/analytics/mle/ScaleMap.py +0 -378
  1095. teradataml/analytics/mle/ScaleSummary.py +0 -320
  1096. teradataml/analytics/mle/SentenceExtractor.py +0 -363
  1097. teradataml/analytics/mle/SentimentEvaluator.py +0 -432
  1098. teradataml/analytics/mle/SentimentExtractor.py +0 -578
  1099. teradataml/analytics/mle/SentimentTrainer.py +0 -405
  1100. teradataml/analytics/mle/SeriesSplitter.py +0 -641
  1101. teradataml/analytics/mle/Sessionize.py +0 -475
  1102. teradataml/analytics/mle/SimpleMovAvg.py +0 -397
  1103. teradataml/analytics/mle/StringSimilarity.py +0 -425
  1104. teradataml/analytics/mle/TF.py +0 -389
  1105. teradataml/analytics/mle/TFIDF.py +0 -504
  1106. teradataml/analytics/mle/TextChunker.py +0 -414
  1107. teradataml/analytics/mle/TextClassifier.py +0 -399
  1108. teradataml/analytics/mle/TextClassifierEvaluator.py +0 -413
  1109. teradataml/analytics/mle/TextClassifierTrainer.py +0 -565
  1110. teradataml/analytics/mle/TextMorph.py +0 -494
  1111. teradataml/analytics/mle/TextParser.py +0 -623
  1112. teradataml/analytics/mle/TextTagger.py +0 -530
  1113. teradataml/analytics/mle/TextTokenizer.py +0 -502
  1114. teradataml/analytics/mle/UnivariateStatistics.py +0 -488
  1115. teradataml/analytics/mle/Unpack.py +0 -526
  1116. teradataml/analytics/mle/Unpivot.py +0 -438
  1117. teradataml/analytics/mle/VarMax.py +0 -776
  1118. teradataml/analytics/mle/VectorDistance.py +0 -762
  1119. teradataml/analytics/mle/WeightedMovAvg.py +0 -400
  1120. teradataml/analytics/mle/XGBoost.py +0 -842
  1121. teradataml/analytics/mle/XGBoostPredict.py +0 -627
  1122. teradataml/analytics/mle/__init__.py +0 -123
  1123. teradataml/analytics/mle/json/adaboost_mle.json +0 -135
  1124. teradataml/analytics/mle/json/adaboostpredict_mle.json +0 -85
  1125. teradataml/analytics/mle/json/antiselect_mle.json +0 -34
  1126. teradataml/analytics/mle/json/antiselect_mle_mle.json +0 -34
  1127. teradataml/analytics/mle/json/arima_mle.json +0 -172
  1128. teradataml/analytics/mle/json/arimapredict_mle.json +0 -52
  1129. teradataml/analytics/mle/json/attribution_mle_mle.json +0 -143
  1130. teradataml/analytics/mle/json/betweenness_mle.json +0 -97
  1131. teradataml/analytics/mle/json/burst_mle.json +0 -140
  1132. teradataml/analytics/mle/json/ccm_mle.json +0 -124
  1133. teradataml/analytics/mle/json/ccmprepare_mle.json +0 -14
  1134. teradataml/analytics/mle/json/cfilter_mle.json +0 -93
  1135. teradataml/analytics/mle/json/changepointdetection_mle.json +0 -92
  1136. teradataml/analytics/mle/json/changepointdetectionrt_mle.json +0 -78
  1137. teradataml/analytics/mle/json/closeness_mle.json +0 -104
  1138. teradataml/analytics/mle/json/confusionmatrix_mle.json +0 -79
  1139. teradataml/analytics/mle/json/correlation_mle.json +0 -86
  1140. teradataml/analytics/mle/json/correlationreduce_mle.json +0 -49
  1141. teradataml/analytics/mle/json/coxhazardratio_mle.json +0 -89
  1142. teradataml/analytics/mle/json/coxph_mle.json +0 -98
  1143. teradataml/analytics/mle/json/coxsurvival_mle.json +0 -79
  1144. teradataml/analytics/mle/json/cumulativemovavg_mle.json +0 -34
  1145. teradataml/analytics/mle/json/decisionforest_mle.json +0 -167
  1146. teradataml/analytics/mle/json/decisionforestevaluator_mle.json +0 -33
  1147. teradataml/analytics/mle/json/decisionforestpredict_mle_mle.json +0 -74
  1148. teradataml/analytics/mle/json/decisiontree_mle.json +0 -194
  1149. teradataml/analytics/mle/json/decisiontreepredict_mle_mle.json +0 -86
  1150. teradataml/analytics/mle/json/dtw_mle.json +0 -97
  1151. teradataml/analytics/mle/json/dwt2d_mle.json +0 -116
  1152. teradataml/analytics/mle/json/dwt_mle.json +0 -101
  1153. teradataml/analytics/mle/json/exponentialmovavg_mle.json +0 -55
  1154. teradataml/analytics/mle/json/fmeasure_mle.json +0 -58
  1155. teradataml/analytics/mle/json/fpgrowth_mle.json +0 -159
  1156. teradataml/analytics/mle/json/frequentpaths_mle.json +0 -129
  1157. teradataml/analytics/mle/json/glm_mle.json +0 -111
  1158. teradataml/analytics/mle/json/glml1l2_mle.json +0 -106
  1159. teradataml/analytics/mle/json/glml1l2predict_mle.json +0 -57
  1160. teradataml/analytics/mle/json/glmpredict_mle_mle.json +0 -74
  1161. teradataml/analytics/mle/json/histogram_mle.json +0 -100
  1162. teradataml/analytics/mle/json/hmmdecoder_mle.json +0 -192
  1163. teradataml/analytics/mle/json/hmmevaluator_mle.json +0 -206
  1164. teradataml/analytics/mle/json/hmmsupervised_mle.json +0 -91
  1165. teradataml/analytics/mle/json/hmmunsupervised_mle.json +0 -114
  1166. teradataml/analytics/mle/json/identitymatch_mle.json +0 -88
  1167. teradataml/analytics/mle/json/idwt2d_mle.json +0 -73
  1168. teradataml/analytics/mle/json/idwt_mle.json +0 -66
  1169. teradataml/analytics/mle/json/interpolator_mle.json +0 -151
  1170. teradataml/analytics/mle/json/kmeans_mle.json +0 -97
  1171. teradataml/analytics/mle/json/knn_mle.json +0 -141
  1172. teradataml/analytics/mle/json/knnrecommender_mle.json +0 -111
  1173. teradataml/analytics/mle/json/knnrecommenderpredict_mle.json +0 -75
  1174. teradataml/analytics/mle/json/lar_mle.json +0 -78
  1175. teradataml/analytics/mle/json/larpredict_mle.json +0 -69
  1176. teradataml/analytics/mle/json/lda_mle.json +0 -130
  1177. teradataml/analytics/mle/json/ldainference_mle.json +0 -78
  1178. teradataml/analytics/mle/json/ldatopicsummary_mle.json +0 -64
  1179. teradataml/analytics/mle/json/levenshteindistance_mle.json +0 -92
  1180. teradataml/analytics/mle/json/linreg_mle.json +0 -42
  1181. teradataml/analytics/mle/json/linregpredict_mle.json +0 -56
  1182. teradataml/analytics/mle/json/minhash_mle.json +0 -113
  1183. teradataml/analytics/mle/json/modularity_mle.json +0 -91
  1184. teradataml/analytics/mle/json/naivebayespredict_mle_mle.json +0 -85
  1185. teradataml/analytics/mle/json/naivebayesreduce_mle.json +0 -52
  1186. teradataml/analytics/mle/json/naivebayestextclassifierpredict_mle_mle.json +0 -147
  1187. teradataml/analytics/mle/json/naivebayestextclassifiertrainer2_mle.json +0 -108
  1188. teradataml/analytics/mle/json/naivebayestextclassifiertrainer_mle.json +0 -102
  1189. teradataml/analytics/mle/json/namedentityfinder_mle.json +0 -84
  1190. teradataml/analytics/mle/json/namedentityfinderevaluatorreduce_mle.json +0 -43
  1191. teradataml/analytics/mle/json/namedentityfindertrainer_mle.json +0 -64
  1192. teradataml/analytics/mle/json/nerevaluator_mle.json +0 -54
  1193. teradataml/analytics/mle/json/nerextractor_mle.json +0 -87
  1194. teradataml/analytics/mle/json/nertrainer_mle.json +0 -89
  1195. teradataml/analytics/mle/json/ngrams_mle.json +0 -137
  1196. teradataml/analytics/mle/json/ngramsplitter_mle_mle.json +0 -137
  1197. teradataml/analytics/mle/json/npath@coprocessor_mle.json +0 -73
  1198. teradataml/analytics/mle/json/ntree@coprocessor_mle.json +0 -123
  1199. teradataml/analytics/mle/json/pack_mle.json +0 -58
  1200. teradataml/analytics/mle/json/pack_mle_mle.json +0 -58
  1201. teradataml/analytics/mle/json/pagerank_mle.json +0 -81
  1202. teradataml/analytics/mle/json/pathanalyzer_mle.json +0 -63
  1203. teradataml/analytics/mle/json/pathgenerator_mle.json +0 -40
  1204. teradataml/analytics/mle/json/pathstart_mle.json +0 -62
  1205. teradataml/analytics/mle/json/pathsummarizer_mle.json +0 -72
  1206. teradataml/analytics/mle/json/pivoting_mle.json +0 -71
  1207. teradataml/analytics/mle/json/postagger_mle.json +0 -51
  1208. teradataml/analytics/mle/json/randomsample_mle.json +0 -131
  1209. teradataml/analytics/mle/json/randomwalksample_mle.json +0 -85
  1210. teradataml/analytics/mle/json/roc_mle.json +0 -73
  1211. teradataml/analytics/mle/json/sampling_mle.json +0 -75
  1212. teradataml/analytics/mle/json/sax_mle.json +0 -154
  1213. teradataml/analytics/mle/json/scale_mle.json +0 -93
  1214. teradataml/analytics/mle/json/scalebypartition_mle.json +0 -89
  1215. teradataml/analytics/mle/json/scalemap_mle.json +0 -44
  1216. teradataml/analytics/mle/json/scalesummary_mle.json +0 -14
  1217. teradataml/analytics/mle/json/sentenceextractor_mle.json +0 -41
  1218. teradataml/analytics/mle/json/sentimentevaluator_mle.json +0 -43
  1219. teradataml/analytics/mle/json/sentimentextractor_mle.json +0 -100
  1220. teradataml/analytics/mle/json/sentimenttrainer_mle.json +0 -68
  1221. teradataml/analytics/mle/json/seriessplitter_mle.json +0 -133
  1222. teradataml/analytics/mle/json/sessionize_mle_mle.json +0 -62
  1223. teradataml/analytics/mle/json/simplemovavg_mle.json +0 -48
  1224. teradataml/analytics/mle/json/stringsimilarity_mle.json +0 -50
  1225. teradataml/analytics/mle/json/stringsimilarity_mle_mle.json +0 -50
  1226. teradataml/analytics/mle/json/svmdense_mle.json +0 -165
  1227. teradataml/analytics/mle/json/svmdensepredict_mle.json +0 -95
  1228. teradataml/analytics/mle/json/svmdensesummary_mle.json +0 -58
  1229. teradataml/analytics/mle/json/svmsparse_mle.json +0 -148
  1230. teradataml/analytics/mle/json/svmsparsepredict_mle_mle.json +0 -103
  1231. teradataml/analytics/mle/json/svmsparsesummary_mle.json +0 -57
  1232. teradataml/analytics/mle/json/textchunker_mle.json +0 -40
  1233. teradataml/analytics/mle/json/textclassifier_mle.json +0 -51
  1234. teradataml/analytics/mle/json/textclassifierevaluator_mle.json +0 -43
  1235. teradataml/analytics/mle/json/textclassifiertrainer_mle.json +0 -103
  1236. teradataml/analytics/mle/json/textmorph_mle.json +0 -63
  1237. teradataml/analytics/mle/json/textparser_mle.json +0 -166
  1238. teradataml/analytics/mle/json/texttagger_mle.json +0 -81
  1239. teradataml/analytics/mle/json/texttokenizer_mle.json +0 -91
  1240. teradataml/analytics/mle/json/tf_mle.json +0 -33
  1241. teradataml/analytics/mle/json/tfidf_mle.json +0 -34
  1242. teradataml/analytics/mle/json/univariatestatistics_mle.json +0 -81
  1243. teradataml/analytics/mle/json/unpack_mle.json +0 -91
  1244. teradataml/analytics/mle/json/unpack_mle_mle.json +0 -91
  1245. teradataml/analytics/mle/json/unpivoting_mle.json +0 -63
  1246. teradataml/analytics/mle/json/varmax_mle.json +0 -176
  1247. teradataml/analytics/mle/json/vectordistance_mle.json +0 -179
  1248. teradataml/analytics/mle/json/weightedmovavg_mle.json +0 -48
  1249. teradataml/analytics/mle/json/xgboost_mle.json +0 -178
  1250. teradataml/analytics/mle/json/xgboostpredict_mle.json +0 -104
  1251. teradataml/analytics/sqle/Antiselect.py +0 -321
  1252. teradataml/analytics/sqle/Attribution.py +0 -603
  1253. teradataml/analytics/sqle/DecisionForestPredict.py +0 -408
  1254. teradataml/analytics/sqle/GLMPredict.py +0 -430
  1255. teradataml/analytics/sqle/MovingAverage.py +0 -543
  1256. teradataml/analytics/sqle/NGramSplitter.py +0 -548
  1257. teradataml/analytics/sqle/NPath.py +0 -632
  1258. teradataml/analytics/sqle/NaiveBayesTextClassifierPredict.py +0 -515
  1259. teradataml/analytics/sqle/Pack.py +0 -388
  1260. teradataml/analytics/sqle/SVMSparsePredict.py +0 -464
  1261. teradataml/analytics/sqle/Sessionize.py +0 -390
  1262. teradataml/analytics/sqle/StringSimilarity.py +0 -400
  1263. teradataml/analytics/sqle/Unpack.py +0 -503
  1264. teradataml/analytics/sqle/json/antiselect_sqle.json +0 -21
  1265. teradataml/analytics/sqle/json/attribution_sqle.json +0 -92
  1266. teradataml/analytics/sqle/json/decisionforestpredict_sqle.json +0 -48
  1267. teradataml/analytics/sqle/json/glmpredict_sqle.json +0 -48
  1268. teradataml/analytics/sqle/json/h2opredict_sqle.json +0 -63
  1269. teradataml/analytics/sqle/json/movingaverage_sqle.json +0 -58
  1270. teradataml/analytics/sqle/json/naivebayestextclassifierpredict_sqle.json +0 -76
  1271. teradataml/analytics/sqle/json/ngramsplitter_sqle.json +0 -126
  1272. teradataml/analytics/sqle/json/npath_sqle.json +0 -67
  1273. teradataml/analytics/sqle/json/pack_sqle.json +0 -47
  1274. teradataml/analytics/sqle/json/pmmlpredict_sqle.json +0 -55
  1275. teradataml/analytics/sqle/json/sessionize_sqle.json +0 -43
  1276. teradataml/analytics/sqle/json/stringsimilarity_sqle.json +0 -39
  1277. teradataml/analytics/sqle/json/svmsparsepredict_sqle.json +0 -74
  1278. teradataml/analytics/sqle/json/unpack_sqle.json +0 -80
  1279. teradataml/catalog/model_cataloging.py +0 -980
  1280. teradataml/config/mlengine_alias_definitions_v1.0 +0 -118
  1281. teradataml/config/mlengine_alias_definitions_v1.1 +0 -127
  1282. teradataml/config/mlengine_alias_definitions_v1.3 +0 -129
  1283. teradataml/table_operators/sandbox_container_util.py +0 -643
  1284. teradataml-17.20.0.7.dist-info/RECORD +0 -1280
  1285. {teradataml-17.20.0.7.dist-info → teradataml-20.0.0.0.dist-info}/top_level.txt +0 -0
@@ -1,2500 +1,2418 @@
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 uuid
17
- from math import floor
18
- import os, itertools
19
- import time
20
- import re, requests
21
- import sqlalchemy
22
- from pathlib import Path
23
- from numpy import number
24
- from sqlalchemy import Column, MetaData, Table
25
- from teradataml import _version
26
- from teradataml.context import context as tdmlctx
27
- from teradataml.common.exceptions import TeradataMlException
28
- from teradataml.common.messages import Messages
29
- from teradataml.common.messagecodes import MessageCodes
30
- from teradataml.common.sqlbundle import SQLBundle
31
- from teradataml.common import td_coltype_code_to_tdtype
32
- from teradataml.common.constants import PythonTypes
33
- from teradataml.common.constants import TeradataTypes
34
- from teradataml.common.garbagecollector import GarbageCollector
35
- from teradataml.common.constants import TeradataConstants, PTITableConstants, \
36
- TableOperatorConstants, HTTPRequest
37
- from teradataml.common.warnings import VantageRuntimeWarning
38
- from teradataml.options.configure import configure
39
- from teradataml.options.display import display
40
- from teradataml.common.constants import TeradataReservedKeywords
41
-
42
- from teradatasqlalchemy.types import _TDType
43
- from teradatasqlalchemy.types import (INTEGER, SMALLINT, BIGINT, BYTEINT,
44
- DECIMAL, FLOAT, NUMBER)
45
- from teradatasqlalchemy.types import (DATE, TIME, TIMESTAMP)
46
- from teradatasqlalchemy.types import (BYTE, VARBYTE, BLOB)
47
- from teradatasqlalchemy.types import (CHAR, VARCHAR, CLOB)
48
- from functools import wraps, reduce
49
- import warnings
50
- from teradataml.utils.utils import execute_sql
51
- from teradataml.utils.validators import _Validators
52
- from sqlalchemy.exc import OperationalError as sqlachemyOperationalError
53
-
54
- def package_deprecation(version, replacement=None, type="class"):
55
- """
56
- Define a deprecation decorator.
57
-
58
- PARAMETERS:
59
- replacement:
60
- Optional Argument.
61
- `replacement` should refer to the new API to be used instead.
62
-
63
- type:
64
- Optional Argument.
65
- Specifies the type of entity being deprecated.
66
- For example,
67
- class or function
68
-
69
- EXAMPLES:
70
- @package_deprecation('16.20.x.y')
71
- def old_func(): ...
72
- @package_deprecation('16.20.x.y', 'teradataml.analytics.mle')
73
- def old_func(): ..."""
74
-
75
- def decorator(func):
76
- def wrapper(*args, **kwargs):
77
- msg = "\nThe \"{}\" {} has moved to a new package in version {}."
78
- if replacement:
79
- msg += "\nImport from the teradataml package, or directly from the {} module." + \
80
- "\nSee the teradataml {} User Guide for more information."
81
- warnings.warn(msg.format('.'.join([func.__module__, func.__name__]), type, version,
82
- replacement + '.' + func.__name__, version),
83
- category=DeprecationWarning, stacklevel=2)
84
- return func(*args, **kwargs)
85
-
86
- return wraps(func)(wrapper)
87
-
88
- return decorator
89
-
90
- def argument_deprecation(tdml_version, deprecated_arguments, behaviour=False, alternatives=None):
91
- """
92
- Decorator for deprecating of argument(s) for a function or class constructor.
93
-
94
- PARAMETERS:
95
- tdml_version:
96
- Required Argument.
97
- Specifies the teradataml version when the argument will be deprecated.
98
- Types: str
99
-
100
- deprecated_arguments:
101
- Required Argument.
102
- Specifies the name(s) of the argument(s) to be deprecated.
103
- Types: str OR list of Strings (str)
104
-
105
- behaviour:
106
- Optional Argument.
107
- Specifies whether behaviour of the argument is deprecated.
108
- Types: bool
109
-
110
- alternatives:
111
- Optional Argument.
112
- Specifies the name(s) of the argument(s) that are alternative
113
- to the deprecate arguments.
114
- Types: str OR list of Strings (str)
115
-
116
-
117
- EXAMPLES:
118
- # Example 1: Deprecate behavior of arguments "arg1" and "arg2".
119
- @argument_deprecation("17.20.00.02", ["arg1", "arg2"], True)
120
- def old_func(self): ...
121
-
122
- # Example 2: Deprecate argument completely.
123
- @argument_deprecation("17.20.00.02", "old_arg")
124
- def old_func(self): ...
125
-
126
- # Example 3: Deprecate arguments completely with alternative.
127
- @argument_deprecation("17.20.00.02", ["arg1", "arg2"], False, ["new_arg"])
128
- def old_func(self): ...
129
-
130
- # Example 4: Deprecate behavior of arguments "old_arg1" and "old_arg2" and provide alternatives.
131
- @argument_deprecation("17.20.00.02", ["arg1", "arg2"], True, ["alt_arg1", "alt_arg2"])
132
- def old_func(self): ...
133
-
134
- """
135
- def decorator(func):
136
- def wrapper(*args, **kwargs):
137
- msg = "\nThe argument(s) \"{}\" will be deprecated in {}."
138
- if behaviour:
139
- msg = "\nBehaviour of the argument(s) \"{}\" will change in {}."
140
- msg = msg.format(deprecated_arguments, tdml_version)
141
- if alternatives is not None:
142
- msg += "\nUse argument(s) \"{}\" instead.".format(alternatives)
143
- warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
144
- return func(*args, **kwargs)
145
-
146
- return wraps(func)(wrapper)
147
- return decorator
148
-
149
- def function_deprecation(tdml_version, behaviour=False, alternatives=None):
150
- """
151
- Decorator for deprecating a function.
152
-
153
- PARAMETERS:
154
- tdml_version:
155
- Required Argument.
156
- Specifies the teradataml version when the function will be deprecated.
157
- Types: str
158
-
159
- behaviour:
160
- Optional Argument.
161
- Specifies whether behaviour of the function is deprecated.
162
- Default value: False
163
- Types: bool
164
-
165
-
166
- alternatives:
167
- Optional Argument.
168
- Specifies the name of the function that is alternative
169
- to the deprecate function.
170
- Default value: None
171
- Types: str
172
-
173
-
174
- EXAMPLES:
175
- # Example 1: Deprecate behavior of function "old_func".
176
- @function_deprecation("17.20.00.03", True)
177
- def old_func(self): ...
178
-
179
- # Example 2: Deprecate function "old_func" completely.
180
- @function_deprecation("17.20.00.03")
181
- def old_func(self): ...
182
-
183
- # Example 3: Deprecate function "old_func" completely with alternative function "new_func".
184
- @function_deprecation("17.20.00.03", False, "new_func")
185
- def old_func(self): ...
186
-
187
- # Example 4: Deprecate behavior of function "old_func".
188
- @function_deprecation("17.20.00.03", True)
189
- def old_func(self): ...
190
- """
191
- def decorator(func):
192
- def wrapper(*args, **kwargs):
193
- msg = "\nThe function \"{}\" will be deprecated in {}."
194
- if behaviour:
195
- msg = "\nBehaviour of the function \"{}\" will change in {}."
196
- msg = msg.format(func.__name__, tdml_version)
197
- if alternatives is not None:
198
- msg += "\nInstead, Use following function \"{}\".".format(alternatives)
199
- warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
200
- return func(*args, **kwargs)
201
- return wraps(func)(wrapper)
202
- return decorator
203
-
204
-
205
- class UtilFuncs():
206
- def _get_numeric_datatypes(self):
207
- """
208
- Returns the numeric data types used in Teradata Vantage
209
- **From : https://www.info.teradata.com/HTMLPubs/DB_TTU_16_00/
210
- index.html#page/General_Reference/B035-1091-160K/psa1472241434371.html
211
-
212
- PARAMETERS:
213
- None
214
-
215
- RAISES:
216
- None
217
-
218
- RETURNS:
219
- List of numeric data types used in Teradata Vantage
220
- """
221
- return [BYTEINT, SMALLINT, INTEGER, BIGINT, DECIMAL, FLOAT, NUMBER]
222
-
223
- def _get_timedate_datatypes(self):
224
- """
225
- Returns a list of TimeDate data types.
226
-
227
- PARAMETERS:
228
- None
229
-
230
- RAISES:
231
- None
232
-
233
- RETURNS:
234
- List of TimeDate data types used in Teradata Vantage
235
- """
236
- return [TIMESTAMP, DATE, TIME]
237
-
238
- def _get_character_datatypes(self):
239
- """
240
- Returns a list of Character data types.
241
-
242
- PARAMETERS:
243
- None
244
-
245
- RAISES:
246
- None
247
-
248
- RETURNS:
249
- List of Character data types used in Teradata Vantage
250
- """
251
- return [CHAR, VARCHAR, CLOB]
252
-
253
- def _get_byte_datatypes(self):
254
- """
255
- Returns a list of byte like data types.
256
-
257
- PARAMETERS:
258
- None
259
-
260
- RAISES:
261
- None
262
-
263
- RETURNS:
264
- List of Byte data types used in Teradata Vantage
265
- """
266
- return [BYTE, VARBYTE, BLOB]
267
-
268
- def _get_categorical_datatypes(self):
269
- """
270
- Returns a list of containing Character and TimeDate data types.
271
-
272
- PARAMETERS:
273
- None
274
-
275
- RAISES:
276
- None
277
-
278
- RETURNS:
279
- List of Character and TimeDate data types used in Teradata Vantage
280
- """
281
- return list.__add__(self._get_character_datatypes(), self._get_timedate_datatypes())
282
-
283
- def _get_all_datatypes(self):
284
- """
285
- Returns a list of Character, Numeric and TimeDate data types.
286
-
287
- PARAMETERS:
288
- None
289
-
290
- RAISES:
291
- None
292
-
293
- RETURNS:
294
- List of Character, Numeric and TimeDate data types used in Teradata Vantage
295
- """
296
- return list.__add__(self._get_categorical_datatypes(), self._get_numeric_datatypes())
297
-
298
- def _get_db_name_from_dataframe(self, df):
299
- """
300
- DESCRIPTION:
301
- Function to get database name from teradataml DataFrame.
302
-
303
- PARAMETERS:
304
- df:
305
- Required Argument.
306
- Specifies the input teradataml DataFrame.
307
- Types: teradataml DataFrame
308
-
309
- RETURNS:
310
- Database name.
311
-
312
- RAISES:
313
- None.
314
-
315
- EXAMPLES:
316
- UtilFuncs()._get_db_name_from_dataframe(df)
317
- """
318
- if df._table_name is None:
319
- from teradataml.dataframe.dataframe_utils import DataFrameUtils
320
- df._table_name = DataFrameUtils()._execute_node_return_db_object_name(df._nodeid,
321
- df._metaexpr)
322
-
323
- db_name = self._extract_db_name(df._table_name)
324
- if db_name is None or db_name == "":
325
- # Extract db_name from SQLAlchemy Engine URL.
326
- if 'DATABASE' in tdmlctx.get_context().url.query:
327
- db_name = tdmlctx.get_context().url.query['DATABASE']
328
- else:
329
- db_name = tdmlctx._get_current_databasename()
330
- else:
331
- db_name = db_name.replace("\"", "")
332
-
333
- return db_name
334
-
335
- @staticmethod
336
- def _get_valid_aggregate_operations():
337
- """
338
- Returns the list of valid aggregate operations on Teradata Vantage
339
-
340
- PARAMETERS:
341
- None
342
-
343
- RAISES:
344
- None
345
-
346
- RETURNS:
347
- List of valid aggregate operations possible on Teradata Vantage
348
- """
349
- return ['count', 'kurtosis', 'max', 'mean', 'median', 'min', 'percentile', 'skew', 'std',
350
- 'sum', 'unique', 'var']
351
-
352
- @staticmethod
353
- def _get_valid_time_series_aggregate_operations():
354
- """
355
- Returns the list of valid aggregate operations on Teradata Vantage
356
-
357
- PARAMETERS:
358
- None
359
-
360
- RAISES:
361
- None
362
-
363
- RETURNS:
364
- List of valid aggregate operations possible on Teradata Vantage
365
- """
366
- return ['bottom', 'bottom with ties', 'delta_t', 'first', 'last', 'mad', 'mode', 'top',
367
- 'top with ties']
368
-
369
- @staticmethod
370
- def _generate_temp_table_name(databasename=None, user=None, prefix=None,
371
- use_default_database=False, gc_on_quit=True, quote=True,
372
- table_type=TeradataConstants.TERADATA_VIEW):
373
- """
374
- DESCRIPTION:
375
- Function to return the random string for temporary table names.
376
-
377
- PARAMETERS:
378
- databasename:
379
- Optional Argument.
380
- Specifies the database name to use while generating the script.
381
- Types: str
382
-
383
- user:
384
- Optional Argument.
385
- Specifies the current username or database name on which user logged on to Teradata Vantage.
386
- Types: str
387
-
388
- prefix:
389
- Optional Argument.
390
- Specifies the prefix of the module from which table/view name is requested.
391
- Types: str
392
-
393
- use_default_database:
394
- Optional Argument.
395
- Specifies whether to create a table or view in the default database when
396
- "databasename" is not provided.
397
- Default value: False
398
- Types: str
399
-
400
- gc_on_quit:
401
- Optional Argument.
402
- Specifies whether to garbage collect the table/view with the generated name
403
- at the end of the session.
404
- When 'True', the objects created with the generated name will be garbage
405
- collected at the end of the session.
406
- Default value: True
407
- Types: bool
408
-
409
- quote:
410
- Optional Argument.
411
- Specifies whether to quote the database name and table/view name.
412
- When 'True', quotes are added around the database name and the table/view name.
413
- Default value: True
414
- Types: bool
415
-
416
- table_type:
417
- Optional Argument.
418
- Specifies the type of objects - table or view.
419
- Default value: TeradataConstants.TERADATA_VIEW
420
- Types: TeradataConstant
421
-
422
- RETURNS:
423
- Temporary table name.
424
-
425
- RAISES:
426
-
427
- EXAMPLES:
428
- new_table_name = UtilFuncs._generate_temp_table_name(user='tdqg', prefix="from_pandas")
429
- new_table_name = UtilFuncs._generate_temp_table_name(user='tdqg', prefix="from_pandas",
430
- table_type = TeradataConstants.TERADATA_VIEW)
431
- new_table_name = UtilFuncs._generate_temp_table_name(user='tdqg', prefix="from_pandas",
432
- table_type = TeradataConstants.TERADATA_TABLE)
433
-
434
- Output:
435
- tdml_temp_table__1517501990393350 (or)
436
- tdqg.tdml_temp_table__1517501990393350 (or)
437
- tdml_temp_table__from_pandas_1517501990393350 (or)
438
- tdqg.tdml_temp_table__from_pandas_1517501990393350
439
- """
440
- # Number of seconds since Jan 1, 1970 00:00:00
441
- timestamp = time.time()
442
- tabname = "ml_"
443
- random_string = "{}{}".format(floor(timestamp / 1000000),
444
- floor(timestamp % 1000000 * 1000000 +
445
- int(str(uuid.uuid4().fields[-1])[:10])))
446
- if prefix is not None:
447
- tabname = "{}_{}".format(tabname, prefix)
448
-
449
- tabname = "{}_{}".format(tabname, random_string)
450
-
451
- if use_default_database and databasename is None:
452
- tabname = "\"{}\".\"{}\"".format(tdmlctx._get_context_temp_databasename(
453
- table_type=table_type), tabname)
454
-
455
- if user is not None:
456
- tabname = "\"{}\".\"{}\"".format(user, tabname)
457
-
458
- if databasename is not None:
459
- tabname = "\"{}\".\"{}\"".format(databasename, tabname)
460
-
461
- # Enable garbage collection for the temporary view & table created while transformations.
462
- if gc_on_quit:
463
- GarbageCollector._add_to_garbagecollector(tabname, table_type)
464
-
465
- return tabname
466
-
467
- @staticmethod
468
- def _generate_temp_script_name(database_name=None, prefix=None, use_default_database=True,
469
- gc_on_quit=True, quote=True,
470
- script_type=TeradataConstants.TERADATA_SCRIPT):
471
- """
472
- DESCRIPTION:
473
- Function to return the random string for temporary script names.
474
-
475
- PARAMETERS:
476
- database_name:
477
- Optional Argument:
478
- Specifies the database name on which user logged on to Teradata Vantage.
479
- Types: str
480
-
481
- prefix:
482
- Optional Argument.
483
- Specifies the prefix of the module or function from which script name is requested.
484
- Types: str
485
-
486
- use_default_database:
487
- Optional Argument.
488
- Specifies whether the script will be installed in the default/connected database.
489
- When 'True', the current/default database name will be used for generating the name.
490
- Default value: True
491
- Types: bool
492
-
493
- gc_on_quit:
494
- Optional Argument.
495
- Specifies whether to garbage collect the object with the generated name
496
- at the end of the session.
497
- When 'True', the objects created with the generated name will be garbage
498
- collected at the end of the session.
499
- Default value: True
500
- Types: bool
501
-
502
- quote:
503
- Optional Argument.
504
- Specifies whether to quote the database name and script name.
505
- When 'True', quotes are added around the database name and the script name.
506
- Default value: True
507
- Types: bool
508
-
509
- script_type:
510
- Optional Argument.
511
- Specifies the type of script.
512
- Default value: TeradataConstants.TERADATA_SCRIPT
513
- Types: TeradataConstant
514
-
515
- RETURNS:
516
- Temporary script name.
517
-
518
- RAISES:
519
- None.
520
-
521
- EXAMPLES:
522
- new_script_name = UtilFuncs._generate_temp_script_name(use_default_database=True,
523
- script_type = TeradataConstants.TERADATA_SCRIPT)
524
- """
525
- # NOTE:
526
- # 1. There can be other types of scripts going forward which may require their own type (like for Apply).
527
- # Hence, we have a 'script_type' argument which currently has only one possible value.
528
- # 2. Currently map_row and map_partition use only default database, but going forward this can be changed
529
- # to use other databases for installation of script, using 'database_name'.
530
-
531
- timestamp = time.time()
532
- script_name = "ml_"
533
-
534
- random_string = "{}{}".format(floor(timestamp / 1000000),
535
- floor(timestamp % 1000000 * 1000000 +
536
- int(str(uuid.uuid4().fields[-1])[:10])))
537
-
538
- if prefix is not None:
539
- script_name = "{}_{}".format(script_name, prefix)
540
-
541
- script_name = "{}_{}".format(script_name, random_string)
542
-
543
- dbname_to_use = tdmlctx._get_current_databasename()
544
- if not use_default_database and database_name is not None:
545
- dbname_to_use = database_name
546
-
547
- script_name = "\"{}\".\"{}\"".format(dbname_to_use, script_name)
548
-
549
- # Enable garbage collection for the temporary script created.
550
- if gc_on_quit:
551
- GarbageCollector._add_to_garbagecollector(script_name, script_type)
552
-
553
- return script_name
554
-
555
- @staticmethod
556
- def _serialize_and_encode(obj):
557
- """
558
- DESCRIPTION:
559
- Internal utility to serialize any Python object (including functions)
560
- using dill and encode using base64.
561
-
562
- PARAMETERS:
563
- obj:
564
- Specifies the Python object to serialize and encode.
565
- Types: object
566
-
567
- RAISES:
568
- None.
569
-
570
- RETURNS:
571
- An encoded byte string representing the serialized object 'obj'.
572
-
573
- EXAMPLES:
574
- >>> # Serializing and encoding a literal value
575
- >>> literal = UtilFuncs._serialize_and_encode('literal value')
576
- >>> # Serializing and encoding a function
577
- >>> def udf(a, b): return a + b
578
- >>> func = UtilFuncs._serialize_and_encode(udf)
579
- """
580
- from dill import dumps as dill_dumps
581
- from base64 import b64encode as base64_b64encode
582
-
583
- return base64_b64encode(dill_dumps(obj, recurse=True))
584
-
585
- @staticmethod
586
- def _quote_table_names(table_name):
587
- """
588
- Quotes table names or view names.
589
- If the table name is in the format schema.table_name, it will quote the
590
- schema name and table name.
591
-
592
- Example:
593
- mytab -> "my.tab"
594
- schema.mytable -> "schema"."my.tab"
595
- myview -> "myview"
596
-
597
- PARAMETERS:
598
- table_name - The name of table or view. The name can include the schema (e.g. schema.table_name)
599
-
600
- RETURNS:
601
- returns the quoted table name.
602
-
603
- RAISES:
604
-
605
- EXAMPLES:
606
- table_name = UtilFuncs._quote_table_names(table_name)
607
-
608
- """
609
- table_name_list = re.findall('".+?"', table_name)
610
- if table_name_list:
611
- for i in range(0, len(table_name_list)):
612
- if not (table_name_list[i].startswith("\"") and table_name_list[i].endswith("\"")):
613
- table_name_list[i] = UtilFuncs._teradata_quote_arg(table_name_list[i], "\"", False)
614
-
615
- return ".".join(table_name_list)
616
- else:
617
- return "\"{}\"".format(table_name)
618
-
619
- @staticmethod
620
- def _execute_ddl_statement(ddl_statement):
621
- """
622
- Executes a DDL statment and commits transaction
623
- This is an internal function.
624
-
625
- PARAMETERS:
626
- ddl_statement - Teradata DDL statement.
627
-
628
- RETURNS:
629
-
630
- RAISES:
631
- Database error if an error occurred while executing the DDL statement.
632
-
633
- EXAMPLES:
634
- UtilFuncs._execute_ddl_statement('create table mytab (col1 int, col2 varchar(20))')
635
-
636
- """
637
- # Let's execute our DDL statement with escape function '{fn teradata_fake_result_sets}'
638
- # offered by teradatasql driver. This function will allow us catch any warnings thrown
639
- # from the Vantage. Hence, executing the DDL statement with this escape function.
640
- ddl_statement = "{fn teradata_fake_result_sets} " + ddl_statement
641
-
642
- if tdmlctx.td_connection is not None:
643
- cursor = None
644
- try:
645
- conn = tdmlctx.td_connection.connection
646
- cursor = conn.cursor()
647
- cursor.execute(ddl_statement)
648
-
649
- # Warnings are displayed when the "suppress_vantage_runtime_warnings" attribute is set to 'False'.
650
- if not display.suppress_vantage_runtime_warnings:
651
- # Fetch the result set just to check whether we have received any warnings or not.
652
- warnRes = cursor.fetchone()
653
- # Check for "display.suppress_vantage_runtime_warnings" set to 'True'.
654
- # Check for warning code and warning message
655
- # warnRes[5] contains the Warning Code
656
- # warnRes[6] contains the actual Warning Message
657
- if warnRes[5] != 0 and warnRes[6] != "":
658
- # Raise warning raised from Vantage as is.
659
- warnings.simplefilter("always")
660
- msg_ = Messages.get_message(MessageCodes.VANTAGE_WARNING)
661
- warnings.warn(msg_.format(warnRes[5], warnRes[6]), VantageRuntimeWarning)
662
-
663
- conn.commit()
664
- except:
665
- # logger.debug("Got exception while executing ({0})".format(teradataSQL))
666
- raise
667
- finally:
668
- if cursor:
669
- cursor.close()
670
- else:
671
- raise TeradataMlException(Messages.get_message(MessageCodes.CONNECTION_FAILURE),
672
- MessageCodes.CONNECTION_FAILURE)
673
-
674
- @staticmethod
675
- def _execute_query(query, fetchWarnings=False, expect_none_result=False):
676
- """
677
- Retrieves result set data from query.
678
-
679
- PARAMETERS:
680
- query:
681
- Required Argument.
682
- Specifies the SQL query to execute.
683
- Types: str
684
-
685
- fetchWarnings:
686
- Optional Argument.
687
- Specifies a flag that decides whether to raise warnings thrown from Vanatge or not.
688
- Default Values: False
689
- Types: bool
690
-
691
- expect_none_result:
692
- Optional Argument.
693
- When set to True, warnings will not be fetched and only result set is fetched.
694
- Returns None if no result set is received from the backend.
695
- When fetchWarnings is set to True this option is ignored.
696
- Default Values: False
697
- Types: bool
698
-
699
- RETURNS:
700
- Returns only result set from query if 'fetchWarnings' is False. If set to True, then
701
- return result set and columns for the result set.
702
-
703
- RAISES:
704
- Database error if an error occurred while executing query.
705
-
706
- EXAMPLES:
707
- result = UtilFuncs._execute_query('select col1, col2 from mytab')
708
- result = UtilFuncs._execute_query('help column mytab.*')
709
-
710
- result = UtilFuncs._execute_query('help column mytab.*')
711
-
712
- # Execute the stored procedure using fetchWarnings.
713
- UtilFuncs._execute_query("call SYSUIF.INSTALL_FILE('myfile',
714
- 'filename.py',
715
- 'cb!/Documents/filename.py')",
716
- True, False)
717
-
718
- # Execute the stored procedure without fetchWarnings but still needs resultsets.
719
- UtilFuncs._execute_query("call SYSUIF.list_base_environments()", False, True)
720
-
721
- """
722
-
723
- if fetchWarnings:
724
- # Let's execute our DDL statement with escape function '{fn teradata_fake_result_sets}'
725
- # offered by teradatasql driver. This function will allow us catch any warnings thrown
726
- # from the Vantage. Hence, executing the DDL statement with this escape function.
727
- query = "{fn teradata_fake_result_sets} " + query
728
-
729
- if tdmlctx.td_connection is not None:
730
- cursor = None
731
- try:
732
- conn = tdmlctx.td_connection.connection
733
- cursor = conn.cursor()
734
- cursor.execute(query)
735
-
736
- if fetchWarnings:
737
- # Fetch the result set just to check whether we have received any warnings or not.
738
- warnRes = cursor.fetchone()
739
- # Check for warning code and warning message
740
- # warnRes[5] contains the Warning Code
741
- # warnRes[6] contains the actual Warning Message
742
- if (warnRes[5] != 0 and warnRes[6] != "") and not display.suppress_vantage_runtime_warnings:
743
- # Raise warning raised from Vantage as is.
744
- warnings.simplefilter("always")
745
- msg_ = Messages.get_message(MessageCodes.VANTAGE_WARNING)
746
- warnings.warn(msg_.format(warnRes[5], warnRes[6]), VantageRuntimeWarning)
747
-
748
- cursor.nextset()
749
-
750
- return cursor.fetchall(), [col_desc[0] for col_desc in cursor.description]
751
-
752
- # This check may be removed if DBS side stored procedure are fixed to return empty
753
- # result sets with columns in cursor.description
754
- elif expect_none_result:
755
- cursor.nextset()
756
- # Some stored procedure returns None if result set has no rows.
757
- # cannot use fetchall call in such cases. If SPs are fixed to support result sets with zero
758
- # rows then below call may be removed in the future.
759
- if cursor.rowcount <= 0:
760
- return None, None
761
- return cursor.fetchall(), [col_desc[0] for col_desc in cursor.description]
762
-
763
- else:
764
- return cursor.fetchall()
765
- except:
766
- raise
767
- finally:
768
- if cursor:
769
- cursor.close()
770
- else:
771
- raise TeradataMlException(Messages.get_message(MessageCodes.CONNECTION_FAILURE),
772
- MessageCodes.CONNECTION_FAILURE)
773
-
774
- @staticmethod
775
- def _create_view(view_name, query):
776
- """
777
- Create a view from the given query.
778
-
779
- PARAMETERS:
780
- view_name - View name
781
- query - SQL query
782
-
783
- RAISES
784
-
785
- RETURNS:
786
- True if success.
787
-
788
- EXAMPLES:
789
- UtilFuncs._create_view(view_name, "select * from table_name")
790
- """
791
- crt_view = SQLBundle._build_create_view(view_name, query)
792
- try:
793
- UtilFuncs._execute_ddl_statement(crt_view)
794
- return True
795
- except:
796
- raise
797
-
798
- @staticmethod
799
- def _create_table(table_name, query, volatile=False):
800
- """
801
- Create a table from the given query.
802
-
803
- PARAMETERS:
804
- table_name - Fully qualified quoted table name.
805
- query - SQL query
806
- volatile - Specifies whether to create volatile table or not.
807
- When set to True, volatile table is created, otherwise
808
- permanent table is created.
809
-
810
- RAISES
811
-
812
- RETURNS:
813
- True if success, false if fails
814
-
815
- EXAMPLES:
816
- UtilFuncs._create_table('"dbname"."table_name"', "select * from table_name")
817
- """
818
- crt_table = SQLBundle._build_create_table_with_data(table_name, query)
819
- if volatile:
820
- crt_table = SQLBundle._build_create_volatile_table_with_data(table_name, query)
821
-
822
- UtilFuncs._execute_ddl_statement(crt_table)
823
- return True
824
-
825
- @staticmethod
826
- def _get_non_null_counts(col_names, table_name):
827
- """
828
- Returns a list of non-null count for each column in col_names from table table_name.
829
-
830
- PARAMETERS:
831
- col_names - list of column names for table table_name.
832
- table_name - table name.
833
-
834
- RETURNS:
835
- returns a list of non-null counts for each column.
836
-
837
- RAISES:
838
-
839
- EXAMPLES:
840
- UtilFuncs._get_non_null_counts(col_names, 'mytab')
841
-
842
- """
843
- count_col_names = ["count(\"{0}\")".format(name) for name in col_names]
844
- select_count = "select {0} from {1}".format(", ".join(count_col_names), table_name)
845
- result = UtilFuncs._execute_query(select_count)
846
- return [str(i) for i in result[0]]
847
-
848
- @staticmethod
849
- def _get_volatile_table(query, with_data=False):
850
- """
851
- Creates a volatile table as query.
852
- If with_data is True, creates the volatile table with data.
853
- Else, creates the volatile table without data.
854
-
855
- PARAMETERS:
856
- query - The query used to create the volatile table.
857
- with_data(optional) - True, creates table with data.
858
- False, creates table without data. Default is False
859
-
860
- RETURNS:
861
- returns the temporary name of the volatile table.
862
-
863
- RAISES:
864
- Database error if an error occurred while creating the volatile table.
865
-
866
- EXAMPLES:
867
- UtilFuncs._get_volatile_table('select col1, col2, from mytab')
868
- UtilFuncs._get_volatile_table('select col1, col2, from mytab', with_data=True)
869
-
870
- """
871
- vtab_name = UtilFuncs._generate_temp_table_name()
872
- if with_data:
873
- create_vtab_ddl = SQLBundle._build_create_volatile_table_with_data(vtab_name, query)
874
- else:
875
- create_vtab_ddl = SQLBundle._build_create_volatile_table_without_data(vtab_name, query)
876
- UtilFuncs._execute_ddl_statement(create_vtab_ddl)
877
- return vtab_name
878
-
879
- @staticmethod
880
- def _drop_table(table_name, check_table_exist=True):
881
- """
882
- Drops a table.
883
-
884
- PARAMETERS:
885
- table_name - The table to drop.
886
- check_table_exist - Checks if the table exist before dropping the table.
887
-
888
- RETURNS:
889
- True - if the table is dropped.
890
-
891
- RAISES:
892
- Database error if an error occurred while dropping the table.
893
-
894
- EXAMPLES:
895
- UtilFuncs._drop_table('mytab')
896
- UtilFuncs._drop_table('mytab', check_table_exist = False)
897
- UtilFuncs._drop_table('mydb.mytab', check_table_exist = False)
898
- UtilFuncs._drop_table("mydb"."mytab", check_table_exist = True)
899
-
900
- """
901
- drop_tab = SQLBundle._build_drop_table(table_name)
902
- if check_table_exist is True:
903
- helptable = UtilFuncs._get_help_tablename(table_name)
904
- if helptable:
905
- UtilFuncs._execute_ddl_statement(drop_tab)
906
- return True
907
- else:
908
- UtilFuncs._execute_ddl_statement(drop_tab)
909
- return True
910
-
911
- return False
912
-
913
- @staticmethod
914
- def _drop_view(view_name, check_view_exist=True):
915
- """
916
- Drops a view.
917
-
918
- PARAMETERS:
919
- view_name - The view to drop.
920
- check_view_exist - Checks if the view exist before dropping the view.
921
-
922
- RETURNS:
923
- True - if the view is dropped.
924
-
925
- RAISES:
926
- Database error if an error occurred while dropping the view.
927
-
928
- EXAMPLES:
929
- UtilFuncs._drop_view('myview')
930
- UtilFuncs._drop_view('myview', check_view_exist = False)
931
- UtilFuncs._drop_view('mydb.myview', check_view_exist = False)
932
- UtilFuncs._drop_view("mydb"."myview", check_view_exist = True)
933
- """
934
- drop_view = SQLBundle._build_drop_view(view_name)
935
- if check_view_exist is True:
936
- viewdetails = UtilFuncs._get_help_viewname(view_name)
937
- if viewdetails:
938
- UtilFuncs._execute_ddl_statement(drop_view)
939
- return True
940
- else:
941
- UtilFuncs._execute_ddl_statement(drop_view)
942
- return True
943
-
944
- return False
945
-
946
- @staticmethod
947
- def _delete_script(script_name, check_script_exist=True):
948
- """
949
- DESCRIPTION:
950
- Function to remove a user-installed file/script.
951
-
952
- PARAMETERS:
953
- script_name:
954
- Required Argument.
955
- Specifies the name of the script to remove.
956
- Types: str
957
-
958
- check_script_exist:
959
- Required Argument.
960
- Specifies whether to check if the script exists or not before removing it.
961
- When 'True', the presence of the script will be check for.
962
- Default value: True
963
- Types: bool
964
-
965
- RETURNS:
966
- True - if the script is removed.
967
-
968
- RAISES:
969
- Database error if an error occurred while dropping the view.
970
-
971
- EXAMPLES:
972
- UtilFuncs._delete_script('myview')
973
- UtilFuncs._delete_script('myview', check_script_exist = False)
974
- UtilFuncs._delete_script('mydb.myview', check_script_exist = False)
975
- UtilFuncs._delete_script("mydb"."myview", check_script_exist = True)
976
- """
977
- dbname = UtilFuncs._teradata_unquote_arg(UtilFuncs._extract_db_name(script_name),
978
- quote='"')
979
- script_alias = UtilFuncs._teradata_unquote_arg(UtilFuncs._extract_table_name(script_name),
980
- quote='"')
981
- current_db = tdmlctx._get_current_databasename()
982
-
983
- script_exists = False
984
- if check_script_exist:
985
- query = "select count(*) from dbc.tablesV " \
986
- "where databasename = '{}' and tablename = '{}' " \
987
- "and tablekind = 'Z'".format(dbname, script_alias)
988
-
989
- script_exists = True if UtilFuncs._execute_query(query)[0][0] == 1 else False
990
-
991
- if script_exists or not check_script_exist:
992
- try:
993
- # If the database is not the current/default database, we need to
994
- # set that as the session database to be able to remove the file.
995
- if dbname.lower() != current_db.lower():
996
- execute_sql('database {}'.format(dbname))
997
-
998
- # Remove the file.
999
- remove_file(script_alias, force_remove=True, suppress_output=True)
1000
- return True
1001
- except:
1002
- raise
1003
- finally:
1004
- # Reset the database if it was set to something else.
1005
- if dbname.lower() != current_db.lower():
1006
- execute_sql('database {}'.format(current_db))
1007
-
1008
- @staticmethod
1009
- def _get_help_vtablenames():
1010
- """
1011
- Function to get list of volatile tables.
1012
-
1013
- RETURNS:
1014
- List of volatile tablenames.
1015
-
1016
- EXAMPLES:
1017
- UtilFuncs._get_help_vtablenames()
1018
- """
1019
- vtables = UtilFuncs._execute_query(SQLBundle._build_help_volatile_table())
1020
- if vtables:
1021
- return list(map(str.strip, filter(None, vtables[0])))
1022
- return []
1023
-
1024
- @staticmethod
1025
- def _get_help_viewname(view_name):
1026
- """
1027
- Function to get help of the view.
1028
-
1029
- PARAMETERS:
1030
- view_name - The name of the view.
1031
-
1032
- RETURNS:
1033
- The help information of the view specified by view_name.
1034
-
1035
- EXAMPLES:
1036
- UtilFuncs._get_help_viewname(myview)
1037
- """
1038
- return UtilFuncs._execute_query(SQLBundle._build_help_view(view_name))
1039
-
1040
- @staticmethod
1041
- def _get_help_tablename(table_name):
1042
- """
1043
- Function to get help of the table.
1044
-
1045
- PARAMETERS:
1046
- table_name - The name of the table.
1047
-
1048
- RETURNS:
1049
- The help information of the table specified by table_name.
1050
-
1051
- EXAMPLES:
1052
- UtilFuncs._get_help_tablename(mytable)
1053
- """
1054
- return UtilFuncs._execute_query(SQLBundle._build_help_table(table_name))
1055
-
1056
- @staticmethod
1057
- def _get_select_table(table_name):
1058
- """
1059
- Function to get a table if exists.
1060
-
1061
- PARAMETERS:
1062
- table_name - Table name to check if exists in the database.
1063
-
1064
- RETURNS:
1065
- Table name in a list.
1066
-
1067
- EXAMPLES:
1068
- UtilFuncs._get_select_table('mytab')
1069
-
1070
- """
1071
- table = UtilFuncs._execute_query(SQLBundle._build_select_table_name(table_name))
1072
- if table:
1073
- return table[0]
1074
- return []
1075
-
1076
- @staticmethod
1077
- def _describe_column(metadata, to_type=None):
1078
- """
1079
- This is an internal function to retrieve
1080
- column names and column types for the table or view.
1081
-
1082
- PARAMETERS:
1083
- metadata:
1084
- The result set from the HELP COLUMN command.
1085
-
1086
- RETURNS:
1087
- A list of tuples (column_names, column_types).
1088
-
1089
- RAISES:
1090
- Database errors if a problem occurs while trying to retrieve the column information.
1091
-
1092
- EXAMPLES:
1093
- column_names_and_types = UtilFuncs._describe_column()
1094
-
1095
- """
1096
- column_names_and_types = []
1097
- for row in metadata:
1098
- # logger.debug("Retrieving Teradata type for {0}".format(row[31]))
1099
- # row[31] corresponds to 'Column Dictionary Name' column in the result of 'HELP COLUMN' SQL commands result.
1100
- column_name = row[31]
1101
- # We also need to check if the column is a TD_TIMEBUCKET column, in which case we can ignore it.
1102
- # We do so by checking the column name, and row[48] which corresponds to the 'Time Series Column Type'
1103
- # column in the 'HELP COLUMN' command to make sure it is indeed the TD_TIMEBUCKET column in the PTI table,
1104
- # and not just a column with the same name in a PTI/non-PTI table.
1105
- # TD_TIMEBUCKET column is ignored since it is not functionally available to any user.
1106
- if column_name == PTITableConstants.TD_TIMEBUCKET.value and \
1107
- len(row) > 48 and row[48] is not None and \
1108
- row[48].strip() == PTITableConstants.TSCOLTYPE_TIMEBUCKET.value:
1109
- continue
1110
- if to_type == "TD":
1111
- # row[18] corresponds to the 'UDT Name' in the 'HELP COLUMN' SQL commands result.
1112
- # row[1] corresponds to the 'Type' in the 'HELP COLUMN' commands result.
1113
- column_names_and_types.append((column_name,
1114
- UtilFuncs._help_col_to_td_type(row[1].strip(),
1115
- row[18],
1116
- row[44])))
1117
- else:
1118
- column_names_and_types.append((column_name,
1119
- UtilFuncs._help_col_to_python_type(row[1].strip(),
1120
- row[44])))
1121
-
1122
- return column_names_and_types
1123
-
1124
- @staticmethod
1125
- def _get_pandas_converters(col_types):
1126
- """
1127
- DESCRIPTION:
1128
- Internal util function to get a dictionary of Python type names of columns
1129
- in a teradataml DataFrame mapped to lambda functions to process the
1130
- data to convert it to the type, which can be readily used with pandas'
1131
- read_csv() function's 'converters' argument.
1132
-
1133
- Note: This utility provides converter functions only for values of type
1134
- int, float, and decimal.Decimal.
1135
- For types that don't expect empty strings in input
1136
- i.e. for 'datetime.datetime', 'datetime.date' and 'datetime.time',
1137
- the converter function returns None for empty string input.
1138
-
1139
- PARAMETERS:
1140
- col_types:
1141
- Required Argument.
1142
- The list of Python types names corresponding to the columns in the input data.
1143
- Types: list
1144
-
1145
- RAISES:
1146
- None
1147
-
1148
- RETURNS:
1149
- dict
1150
-
1151
- EXAMPLES:
1152
- >>> pandas_converters = UtilFuncs._get_pandas_converters(["int", "str"])
1153
- """
1154
- pandas_converters = dict()
1155
- for i, type_ in enumerate(col_types):
1156
- # Add a functions that converts the string values to float or int when
1157
- # the value is not empty string, else return None.
1158
- if type_ in (PythonTypes.PY_FLOAT_TYPE.value,
1159
- PythonTypes.PY_DECIMAL_TYPE.value):
1160
- pandas_converters[i] = lambda x: float(x) \
1161
- if isinstance(x, (bytes, number, int, float)) \
1162
- else float("".join(x.split())) if len(x.strip()) > 0 else None
1163
-
1164
- elif type_ == PythonTypes.PY_INT_TYPE.value:
1165
- pandas_converters[i] = lambda x: int(x) \
1166
- if isinstance(x, (bytes, number, int, float)) \
1167
- else int(float("".join(x.split()))) if len(x.strip()) > 0 else None
1168
-
1169
- elif type_ in (PythonTypes.PY_DATETIME_TYPE.value,
1170
- PythonTypes.PY_DATE_TYPE.value,
1171
- PythonTypes.PY_TIME_TYPE.value):
1172
- # For types that do not expect empty strings, add function to
1173
- # set them to None when value received is empty string.
1174
- pandas_converters[i] = lambda x: x if len(x.strip()) > 0 else None
1175
-
1176
- else:
1177
- # For 'str' and 'bytes' types, add function that returns value as is.
1178
- pandas_converters[i] = lambda x: x
1179
-
1180
- return pandas_converters
1181
-
1182
- @staticmethod
1183
- def _teradata_type_to_python_type(td_type):
1184
- """
1185
- Translate the Teradata type from metaexpr to Python types.
1186
- PARAMETERS:
1187
- td_type - The Teradata type from metaexpr.
1188
-
1189
- RETURNS:
1190
- The Python type for the given td_type.
1191
-
1192
- RAISES:
1193
-
1194
- EXAMPLES:
1195
- # o is an instance of INTEGER
1196
- pytype = UtilFuncs._teradata_type_to_python_type(o)
1197
-
1198
- """
1199
-
1200
- # loggerlogger.debug("_help_col_to_python_type td_type = {0} ".format(td_type))
1201
- if type(td_type) in TeradataTypes.TD_INTEGER_TYPES.value:
1202
- return PythonTypes.PY_INT_TYPE.value
1203
- elif type(td_type) in TeradataTypes.TD_FLOAT_TYPES.value:
1204
- return PythonTypes.PY_FLOAT_TYPE.value
1205
- elif type(td_type) in TeradataTypes.TD_DECIMAL_TYPES.value:
1206
- return PythonTypes.PY_DECIMAL_TYPE.value
1207
- elif type(td_type) in TeradataTypes.TD_BYTE_TYPES.value:
1208
- return PythonTypes.PY_BYTES_TYPE.value
1209
- elif type(td_type) in TeradataTypes.TD_DATETIME_TYPES.value:
1210
- return PythonTypes.PY_DATETIME_TYPE.value
1211
- elif type(td_type) in TeradataTypes.TD_TIME_TYPES.value:
1212
- return PythonTypes.PY_TIME_TYPE.value
1213
- elif type(td_type) in TeradataTypes.TD_DATE_TYPES.value:
1214
- return PythonTypes.PY_DATE_TYPE.value
1215
-
1216
- return PythonTypes.PY_STRING_TYPE.value
1217
-
1218
- @staticmethod
1219
- def _help_col_to_python_type(col_type, storage_format):
1220
- """
1221
- Translate the 1 or 2 character TD type codes from HELP COLUMN to Python types.
1222
- PARAMETERS:
1223
- col_type - The 1 or 2 character type code from HELP COLUMN command.
1224
- storage_format - The storage format from HELP COLUMN command.
1225
-
1226
- RETURNS:
1227
- The Python type for the given col_type.
1228
-
1229
- RAISES:
1230
-
1231
- EXAMPLES:
1232
- pytype = UtilFuncs._help_col_to_python_type('CV', None)
1233
- pytype = UtilFuncs._help_col_to_python_type('DT', 'CSV')
1234
-
1235
- """
1236
- if col_type in TeradataTypes.TD_INTEGER_CODES.value:
1237
- return PythonTypes.PY_INT_TYPE.value
1238
- elif col_type in TeradataTypes.TD_FLOAT_CODES.value:
1239
- return PythonTypes.PY_FLOAT_TYPE.value
1240
- elif col_type in TeradataTypes.TD_DECIMAL_CODES.value:
1241
- return PythonTypes.PY_DECIMAL_TYPE.value
1242
- elif col_type in TeradataTypes.TD_BYTE_CODES.value:
1243
- return PythonTypes.PY_BYTES_TYPE.value
1244
- elif col_type in TeradataTypes.TD_DATETIME_CODES.value:
1245
- return PythonTypes.PY_DATETIME_TYPE.value
1246
- elif col_type in TeradataTypes.TD_TIME_CODES.value:
1247
- return PythonTypes.PY_TIME_TYPE.value
1248
- elif col_type in TeradataTypes.TD_DATE_CODES.value:
1249
- return PythonTypes.PY_DATE_TYPE.value
1250
- elif col_type == "DT":
1251
- sfmt = storage_format.strip()
1252
- if sfmt == "CSV":
1253
- return PythonTypes.PY_STRING_TYPE.value
1254
- elif sfmt == "AVRO":
1255
- return PythonTypes.PY_BYTES_TYPE.value
1256
-
1257
- return PythonTypes.PY_STRING_TYPE.value
1258
-
1259
- @staticmethod
1260
- def _help_col_to_td_type(col_type, udt_name, storage_format):
1261
- """
1262
- Translate the 2 character TD type codes from HELP COLUMN to Teradata types.
1263
- PARAMETERS:
1264
- col_type - The 2 character type code from HELP COLUMN command.
1265
- udt_name - The UDT name from the HELP COLUMN command.
1266
- storage_format - The storage format from HELP COLUMN command.
1267
-
1268
- RETURNS:
1269
- The Teradata type for the given colType.
1270
-
1271
- RAISES:
1272
-
1273
- EXAMPLES:
1274
- tdtype = UtilFuncs._help_col_to_td_type('CV', None, None)
1275
-
1276
- """
1277
- # logger.debug("helpColumnToTeradataTypeName colType = {0} udtName = {1}
1278
- # storageFormat {2}".format(colType, udtName, storageFormat))
1279
- if col_type in td_coltype_code_to_tdtype.HELP_COL_TYPE_TO_TDTYPE:
1280
- return td_coltype_code_to_tdtype.HELP_COL_TYPE_TO_TDTYPE[col_type]
1281
-
1282
- if col_type == "DT":
1283
- return "DATASET STORAGE FORMAT {0}".format(storage_format.strip())
1284
-
1285
- if col_type in ["UD", "US", "UT", "A1", "AN"]:
1286
- if udt_name:
1287
- return udt_name
1288
-
1289
- return col_type
1290
-
1291
- @staticmethod
1292
- def _convert_date_to_string(date_obj):
1293
- """
1294
- Converts the date from datetime.date object to String type in the format "DATE 1987-06-09".
1295
- PARAMETERS:
1296
- date_obj:
1297
- Required Argument.
1298
- Specifies the date object to convert to string type.
1299
- Types: datetime.date
1300
-
1301
- RETURNS:
1302
- The String reresentation for the given datetime.date object in the format "DATE 1987-06-09"
1303
-
1304
- RAISES:
1305
- None
1306
-
1307
- Examples:
1308
- date_str = UtilFuncs._convert_date_to_string(date_obj)
1309
-
1310
- """
1311
- date_str = 'DATE {}'.format(date_obj.strftime('%Y-%m-%d'))
1312
- return date_str
1313
-
1314
- @staticmethod
1315
- def _process_for_teradata_keyword(keyword):
1316
- """
1317
- Processing the Teradata Reserved keywords.
1318
- If keyword is in list of Teradata Reserved keywords, then it'll be quoted in double quotes "keyword".
1319
-
1320
- PARAMETERS:
1321
- keyword - A string or a list of strings to check whether it belongs to Teradata Reserved
1322
- Keywords or not.
1323
-
1324
- RETURNS:
1325
- A quoted string or list of quoted strings, if keyword is one of the Teradata Reserved Keyword,
1326
- else same object as is.
1327
-
1328
- RAISES:
1329
- None.
1330
-
1331
- EXAMPLES:
1332
- # Passing non-reserved returns "xyz" as is.
1333
- keyword = self.__process_for_teradata_keyword("xyz")
1334
- print(keyword)
1335
- # Passing reserved str returns double-quoted str, i.e., "\"threshold\"".
1336
- keyword = self.__process_for_teradata_keyword("threshold")
1337
- print(keyword)
1338
- """
1339
- # If the input keyword is a list, then call the same function again for every
1340
- # element in the list.
1341
- if isinstance(keyword, list):
1342
- return [UtilFuncs._process_for_teradata_keyword(col) for col in keyword]
1343
-
1344
- if isinstance(keyword, str) and keyword.upper() in \
1345
- TeradataReservedKeywords.TERADATA_RESERVED_WORDS.value:
1346
- return UtilFuncs._teradata_quote_arg(keyword, "\"", False)
1347
-
1348
- return keyword
1349
-
1350
- @staticmethod
1351
- def _in_schema(schema_name, table_name):
1352
- """
1353
- Function takes a schema name and a table name and creates a database
1354
- object name in the format "schema"."table_name".
1355
- Note:
1356
- teradataml recommends to use this function to access table(s)/view(s),
1357
- from the database other than the default database.
1358
-
1359
- PARAMETERS:
1360
- schema_name:
1361
- Required Argument
1362
- Specifies the schema where the table resides in.
1363
- Types: str
1364
-
1365
- table_name:
1366
- Required Argument
1367
- Specifies the table name or view name in Vantage.
1368
- Types: str
1369
-
1370
- EXAMPLES:
1371
- from teradataml.dataframe.dataframe import in_schema, DataFrame
1372
-
1373
- # Example 1: The following example creates a DataFrame from the
1374
- # existing Vantage table "dbcinfo" in the non-default
1375
- # database "dbc" using the in_schema() function.
1376
- df = DataFrame(in_schema("dbc", "dbcinfo"))
1377
-
1378
- # Example 2: The following example uses from_table() function, existing
1379
- # Vantage table "dbcinfo" and non-default database "dbc" to
1380
- # create a teradataml DataFrame.
1381
- df = DataFrame.from_table(in_schema("dbc","dbcinfo"))
1382
-
1383
- """
1384
- return "{0}.{1}".format(UtilFuncs._teradata_quote_arg(schema_name, "\"", False),
1385
- UtilFuncs._teradata_quote_arg(table_name, "\"", False))
1386
-
1387
- @staticmethod
1388
- def _extract_db_name(full_qualified_name):
1389
- """
1390
- Takes in fully qualified name of the table/view (db.table), and returns
1391
- a database name from the same.
1392
-
1393
- PARAMETERS:
1394
- full_qualified_name - Name of the table/view
1395
-
1396
- EXAMPLES:
1397
- UtilFuncs._extract_db_name("db1"."tablename")
1398
-
1399
- RETURNS:
1400
- Database name from the provided name.
1401
-
1402
- """
1403
- # Extract the double quoted strings.
1404
- names = re.findall(r'["](.*?)["]', full_qualified_name)
1405
- # Remove quotes around the string.
1406
- names = [i.replace('"', '') for i in names]
1407
- if names:
1408
- if len(names) == 2:
1409
- return names[0]
1410
- else:
1411
- return None
1412
-
1413
- @staticmethod
1414
- def _extract_table_name(full_qualified_name):
1415
- """
1416
- Takes in fully qualified name of the table/view (db.table), and returns
1417
- a table/view name from the same.
1418
-
1419
- PARAMETERS:
1420
- full_qualified_name - Name of the table/view
1421
-
1422
- EXAMPLES:
1423
- UtilFuncs._extract_db_name("db1"."tablename")
1424
-
1425
- RETURNS:
1426
- Table/View name from the provided name.
1427
-
1428
- """
1429
- # Extract the double quoted strings.
1430
- names = re.findall(r'["](.*?)["]', full_qualified_name)
1431
- # Remove quotes around the string.
1432
- names = [i.replace('"', '') for i in names]
1433
- if names:
1434
- if len(names) == 2:
1435
- return names[1]
1436
- else:
1437
- return names[0]
1438
- return full_qualified_name
1439
-
1440
- @staticmethod
1441
- def _teradata_quote_arg(args, quote="'", call_from_wrapper=True):
1442
- """
1443
- Function to quote argument value.
1444
- PARAMETERS:
1445
- args : Argument to be quoted.
1446
- quote : Type of quote to be used for quoting. Default is
1447
- single quote (').
1448
- RETURNS:
1449
- Argument with quotes as a string.
1450
-
1451
- EXAMPLES:
1452
- When a call is being made from wrapper:
1453
- UtilFuncs._teradata_quote_arg(family, "'")
1454
- When a call is being made from non-wrapper function.
1455
- UtilFuncs._teradata_quote_arg(family, "'", False)
1456
- """
1457
- if call_from_wrapper and not configure.column_casesensitive_handler:
1458
- quote = ""
1459
- return args
1460
-
1461
- # Returning same string if it already quoted. Applicable only for strings.
1462
- if isinstance(args, str) and args.startswith(quote) and args.endswith(quote):
1463
- return args
1464
- if args is None:
1465
- return None
1466
- if isinstance(args, list):
1467
- return ["{0}{1}{0}".format(quote, arg) for arg in args]
1468
-
1469
- return "{0}{1}{0}".format(quote, args)
1470
-
1471
- @staticmethod
1472
- def _teradata_unquote_arg(quoted_string, quote="'"):
1473
- """
1474
- Function to unquote argument value.
1475
- PARAMETERS:
1476
- quoted_string : String to be unquoted.
1477
- quote : Type of quote to be used for unquoting. Default is
1478
- single quote (').
1479
- RETURNS:
1480
- None if 'quoted_string' is not a string,
1481
- else Argument without quotes as a string.
1482
-
1483
- EXAMPLES:
1484
- UtilFuncs._teradata_unquote_arg(family, "'")
1485
- """
1486
-
1487
- if not isinstance(quoted_string, str):
1488
- return None
1489
-
1490
- # Returning same string if it already unquoted.
1491
- if not quoted_string.startswith(quote) and not quoted_string.endswith(quote):
1492
- return quoted_string
1493
-
1494
- return quoted_string[1:-1]
1495
-
1496
- @staticmethod
1497
- def _teradata_collapse_arglist(args_list, quote="'"):
1498
- """
1499
- Given a list as an argument this will single quote all the
1500
- list elements and combine them into a single string separated by
1501
- commas.
1502
-
1503
- PARAMETERS:
1504
- args_list: List containing string/s to be quoted.
1505
- quote: Type of quote to be used for quoting. Default is single quote (').
1506
-
1507
- RETURNS:
1508
- Single string separated by commas.
1509
-
1510
- EXAMPLES:
1511
- UtilFuncs._teradata_collapse_arglist(family, "'")
1512
-
1513
- """
1514
- expr = r"([\"'][\d.\d\w]+\s*[\"'][,]*\s*)+([\"']\s*[\d.\d\w]+[\"']$)"
1515
-
1516
- # # return None if list is empty
1517
- # if not args_list and not isinstance(args_list, bool):
1518
- # return args_list
1519
-
1520
- # if args_list is a list quote all values of the list
1521
- if isinstance(args_list, list):
1522
- '''
1523
- EXAMPLE:
1524
- arg = ['admitted', 'masters', 'gpa', 'stats', 'programming']
1525
- UtilFuncs._teradata_collapse_arglist(arg, "\"")
1526
- RETURNS:
1527
- '"admitted","masters","gpa","stats","programming"'
1528
-
1529
- '''
1530
- return ",".join("{0}{1}{0}".format(quote, arg) for arg in args_list)
1531
- elif (isinstance(args_list, str)) and (bool(re.match(expr, args_list)) is True):
1532
- '''
1533
- Quotes the arguments which is string of strings with the provided quote variable
1534
- value.
1535
- The expr should be strings separeted by commas. The string values can be digits or
1536
- alphabets.
1537
- For example:
1538
- args_list = '"masters","gpa","stats"'
1539
- quote = "'"
1540
- The args_list is quoted as below based on the quote argument provided:
1541
- strQuotes = '"masters"','"gpa"','"stats"'
1542
- RETURNS:
1543
- quoted string
1544
-
1545
- The quoted value is added to list in the functions with other arguments as:
1546
- funcOtherArgs = ["'2.0'", "'POISSON'", "'IDENTITY'", "'0.05'", "'10'", "'False'", "'True'",
1547
- '\'"masters"\',\'"gpa"\',\'"stats"\',\'"programming"\',\'"admitted"\'',
1548
- '\'"masters"\',\'"stats"\',\'"programming"\'']
1549
-
1550
- '''
1551
- str_val = re.sub(r"\s+", "", args_list)
1552
- args_list = str_val.split(",")
1553
- return ",".join("{0}{1}{0}".format(quote, arg) for arg in args_list)
1554
- # if argVector is any value of int/str/bool type, quote the value
1555
- else:
1556
- return UtilFuncs._teradata_quote_arg(args_list, quote, False)
1557
-
1558
- @staticmethod
1559
- def _get_metaexpr_using_columns(nodeid, column_info, with_engine=False, is_persist=False):
1560
- """
1561
- This internal function takes in input node ID and column information in zipped lists format
1562
- to return metaexpr with or without engine.
1563
-
1564
- PARAMETERS:
1565
- nodeid - AED DAG node id for which a metaexpr is to be generated.
1566
- column_info - This contains zipped lists of column names and corresponding column types.
1567
- with_engine - A bool parameter, deciding whether to generate metaexpr with engine or not.
1568
- Default is False.
1569
- is_persist - A bool parameter, deciding whether to persist the result or not.
1570
- Default is False.
1571
-
1572
- RAISES:
1573
-
1574
- RETURNS:
1575
- metaexpr for the provided node ID and with column inforamtion.
1576
-
1577
- EXAMPLES:
1578
- node_id_list = self.__aed_utils._aed_ml_query(self.__input_nodeids, self.sqlmr_query, self.__func_output_args, "NaiveBayesMap")
1579
- stdout_column_info = zip(stdout_column_names, stdout_column_types)
1580
- UtilFuncs._get_metaexpr_using_columns(node_id_list[0], stdout_column_info)
1581
- """
1582
- from teradataml.dataframe.sql import _MetaExpression
1583
- if with_engine:
1584
- eng = tdmlctx.get_context()
1585
- meta = sqlalchemy.MetaData(eng)
1586
- else:
1587
- meta = sqlalchemy.MetaData()
1588
-
1589
- # Get the output table name for node_id from AED
1590
- aed_utils = AedUtils()
1591
-
1592
- table_name = aed_utils._aed_get_tablename(nodeid)
1593
- db_schema = UtilFuncs._extract_db_name(table_name)
1594
- db_table_name = UtilFuncs._extract_table_name(table_name)
1595
-
1596
- # Constructing new Metadata (_metaexpr) without DB; _MetaExpression
1597
- ouptut_table = Table(db_table_name, meta,
1598
- *(Column(col_name, col_type) for col_name, col_type in column_info),
1599
- schema=db_schema)
1600
- return _MetaExpression(ouptut_table, is_persist=is_persist)
1601
-
1602
- @staticmethod
1603
- def _get_metaexpr_using_parent_metaexpr(nodeid, metaexpr):
1604
- """
1605
- This internal function takes in input node ID and metaexpr (parents)
1606
- to return metaexpr with or without engine.
1607
-
1608
- PARAMETERS:
1609
- nodeid:
1610
- Required Argument.
1611
- Specifies AED DAG node id for which a metaexpr is to be generated.
1612
-
1613
- metaexpr:
1614
- Required Argument.
1615
- _MetaExpression() of a DataFrame objects which is to be used to extract and
1616
- create a new _MetaExpression.
1617
-
1618
- RAISES:
1619
- None.
1620
-
1621
- RETURNS:
1622
- metaexpr for the provided node ID and with metaexpr inforamtion.
1623
-
1624
- EXAMPLES:
1625
- node_id_list = self.__aed_utils._aed_ml_query(self.__input_nodeids, self.sqlmr_query, self.__func_output_args, "NaiveBayesMap")
1626
- UtilFuncs._get_metaexpr_using_parent_metaexpr(node_id_list[0], parent_metaexpr)
1627
- """
1628
- meta_cols = metaexpr.t.c
1629
- meta_columns = [c.name for c in meta_cols]
1630
- col_names = []
1631
- col_types = []
1632
-
1633
- # When column list to retrieve is not provided, return meta-data for all columns.
1634
- for col_name in meta_columns:
1635
- col_names.append(meta_cols[col_name].name)
1636
- col_types.append(meta_cols[col_name].type)
1637
-
1638
- return UtilFuncs._get_metaexpr_using_columns(nodeid, zip(col_names, col_types))
1639
-
1640
- @staticmethod
1641
- def _create_table_using_columns(table_name, columns_datatypes, pti_clause=None, storage=None):
1642
- """
1643
- Create a table with columns.
1644
-
1645
- PARAMETERS:
1646
- table_name - Fully qualified quoted table name.
1647
- columns_datatypes - Column names and dattypes for the table
1648
- pti_clause - Specifies the string for the primary time index.
1649
- storage - Specifies the storage for the table.
1650
-
1651
- RAISES
1652
-
1653
- RETURNS:
1654
- True if success, false if fails
1655
-
1656
- EXAMPLES:
1657
- UtilFuncs._create_table_using_columns('"dbname"."table_name"',
1658
- "col1 varchar(10), col2 integer, col3 timestamp")
1659
- """
1660
- # If storage option is specified, add the storage clause in the create table statement.
1661
- if storage:
1662
- table_name = "{}, STORAGE={}".format(table_name, storage)
1663
-
1664
- crt_table = SQLBundle._build_create_table_using_columns(table_name, columns_datatypes)
1665
-
1666
- if pti_clause is not None:
1667
- crt_table = "{} PRIMARY TIME INDEX {}".format(crt_table, pti_clause)
1668
-
1669
- try:
1670
- UtilFuncs._execute_ddl_statement(crt_table)
1671
- return True
1672
- except Exception:
1673
- raise
1674
-
1675
- @staticmethod
1676
- def _get_engine_name(engine):
1677
- """
1678
- Function to return the name of the engine mapped to the
1679
- argument 'engine' in function mapped dictionary.
1680
-
1681
- PARAMETERS:
1682
- engine:
1683
- Required Argument.
1684
- Specifies the type of the engine.
1685
-
1686
- RETURNS:
1687
- Name of the engine.
1688
-
1689
- RAISES:
1690
- TeradataMLException
1691
-
1692
- EXAMPLES:
1693
- UtilFuncs._get_engine_name("ENGINE_SQL")
1694
-
1695
- """
1696
- _Validators._validate_engine(engine)
1697
- supported_engines = TeradataConstants.SUPPORTED_ENGINES.value
1698
- return supported_engines[engine]['name']
1699
-
1700
- @staticmethod
1701
- def _get_function_mappings_from_config_file(alias_config_file):
1702
- """
1703
- Function to return the function mappings given the location of configuration file in
1704
- argument 'alias_config_file'.
1705
-
1706
- PARAMETERS:
1707
- alias_config_file:
1708
- Required Argument.
1709
- Specifies the location of configuration file to be read.
1710
-
1711
- RETURNS:
1712
- Function mappings as a dictionary of function_names to alias_names.
1713
-
1714
- RAISES:
1715
- TeradataMLException
1716
-
1717
- EXAMPLES:
1718
- UtilFuncs._get_function_mappings_from_config_file("config_file_location")
1719
-
1720
- """
1721
- repeated_function_names = []
1722
- function_mappings = {}
1723
- invalid_function_mappings = []
1724
- invalid_function_mappings_line_nos = []
1725
- # Reading configuration files
1726
- with open(alias_config_file, 'r') as fread:
1727
- for line_no, line in enumerate(fread.readlines()):
1728
- line = line.strip()
1729
-
1730
- # Ignoring empty lines in the config files.
1731
- if line == "":
1732
- continue
1733
-
1734
- # If the separator ":" is not present.
1735
- if ':' not in line:
1736
- invalid_function_mappings.append(line)
1737
- invalid_function_mappings_line_nos.append(str(line_no + 1))
1738
- else:
1739
- func_name, alias_name = line.split(":")
1740
- func_name = func_name.strip()
1741
- alias_name = alias_name.strip()
1742
-
1743
- # First line of 'alias_config_file' has header "functionName:aliasName".
1744
- if line_no == 0 and func_name == "functionName" and alias_name == "aliasName":
1745
- continue
1746
-
1747
- if func_name == "" or alias_name == "":
1748
- invalid_function_mappings.append(line)
1749
- invalid_function_mappings_line_nos.append(str(line_no + 1))
1750
- continue
1751
-
1752
- if func_name.lower() in function_mappings:
1753
- repeated_function_names.append(func_name.lower())
1754
-
1755
- # Loading function maps with lower values for key.
1756
- function_mappings[func_name.lower()] = alias_name
1757
-
1758
- # Presence of Invalid function mappings in the 'alias_config_file'.
1759
- if len(invalid_function_mappings) > 0:
1760
- err_ = Messages.get_message(MessageCodes.CONFIG_ALIAS_INVALID_FUNC_MAPPING)
1761
- err_ = err_.format("', '".join(invalid_function_mappings),
1762
- ", ".join(invalid_function_mappings_line_nos),
1763
- alias_config_file)
1764
- raise TeradataMlException(err_, MessageCodes.CONFIG_ALIAS_INVALID_FUNC_MAPPING)
1765
-
1766
- # Raising teradataml exception if there are any duplicates in function names.
1767
- if len(repeated_function_names) > 0:
1768
- raise TeradataMlException(Messages.get_message(
1769
- MessageCodes.CONFIG_ALIAS_DUPLICATES).format(alias_config_file,
1770
- ", ".join(repeated_function_names)),
1771
- MessageCodes.CONFIG_ALIAS_DUPLICATES)
1772
-
1773
- return function_mappings
1774
-
1775
- @staticmethod
1776
- def _check_alias_config_file_exists(vantage_version, alias_config_file):
1777
- """
1778
- Function to validate whether alias_config_file exists for the current vantage version.
1779
-
1780
- PARAMETERS:
1781
- vantage_version:
1782
- Required Argument.
1783
- Specifies the current vantage version.
1784
-
1785
- alias_config_file:
1786
- Required Argument.
1787
- Specifies the location of configuration file to be read.
1788
-
1789
- RETURNS:
1790
- True, if the file 'alias_config_file' is present in the
1791
- teradataml/config directory for the current vantage version.
1792
-
1793
- RAISES:
1794
- TeradataMLException
1795
-
1796
- EXAMPLES:
1797
- UtilFuncs._check_alias_config_file_exists("vantage1.0", "config_file_location")
1798
-
1799
- """
1800
- # Raise exception if alias config file is not defined.
1801
- if not Path(alias_config_file).exists():
1802
- raise TeradataMlException(Messages.get_message(
1803
- MessageCodes.CONFIG_ALIAS_CONFIG_FILE_NOT_FOUND).format(alias_config_file,
1804
- vantage_version),
1805
- MessageCodes.CONFIG_ALIAS_CONFIG_FILE_NOT_FOUND)
1806
- return True
1807
-
1808
- @staticmethod
1809
- def _as_list(obj):
1810
- """
1811
- Function to convert an object to list, i.e., just enclose the value passed to the
1812
- function in a list and return the same, if it is not of list type.
1813
- PARAMETERS:
1814
- obj:
1815
- Required Argument.
1816
- Specifies the object to be enclosed in a list.
1817
- Types: Any type except list.
1818
- RETURNS:
1819
- list
1820
- RAISES:
1821
- None.
1822
- EXAMPLES:
1823
- obj = UtilFuncs._as_list("vantage1.0")
1824
- """
1825
- return obj if isinstance(obj, list) else [obj]
1826
-
1827
- @staticmethod
1828
- def _get_all_columns(object, is_object_type_tdml_column):
1829
- """
1830
- Function to get all columns from a given teradataml DataFrame
1831
- or teradataml DataFrame column.
1832
-
1833
- PARAMETERS:
1834
- object:
1835
- Required Argument.
1836
- Specifies either teradataml DataFrame or teradataml DataFrame
1837
- Column.
1838
- Types: teradataml DataFrame, _SQLColumnExpression
1839
-
1840
- is_object_type_tdml_column:
1841
- Required Argument.
1842
- Specifies whether "object" is a teradataml DataFrame or
1843
- teradataml DataFrame Column.
1844
- If True, "object" treats as teradataml DataFrame Column.
1845
- If False, "object" treats as teradataml DataFrame.
1846
- Types: bool
1847
-
1848
- RETURNS:
1849
- An iterator and each element in the iterator represents a Column
1850
-
1851
- RAISES:
1852
- None.
1853
-
1854
- EXAMPLES:
1855
- obj = UtilFuncs._get_all_columns(df.col, True)
1856
- obj = UtilFuncs._get_all_columns(df, False)
1857
- """
1858
- if is_object_type_tdml_column:
1859
- return object.expression.table.columns
1860
- # object._metaexpr.c extracts the data to a list. And, the caller of
1861
- # this function will again iterate through the list, to process the
1862
- # list i.e. object._metaexpr.c is being iterated twice. To avoid this,
1863
- # a generator object is being constructed and returned.
1864
- return (c for c in object._metaexpr.c)
1865
-
1866
- @staticmethod
1867
- def _get_file_contents(file_path, read_in_binary_mode=False):
1868
- """
1869
- Description:
1870
- Function to get the file content from a file, given absolute
1871
- file path.
1872
-
1873
- PARAMETERS:
1874
- file_path:
1875
- Required Argument.
1876
- Specifies absolute file path of the file.
1877
- Types: str
1878
-
1879
- read_in_binary_mode:
1880
- Optional Argument.
1881
- Specifies whether to read the file in binary format or not.
1882
- If True, read the file in binary mode.
1883
- If False, read the file in ASCII mode.
1884
- Default value: False
1885
- Types: bool
1886
-
1887
- RETURNS:
1888
- str OR bytes
1889
-
1890
- RAISES:
1891
- TeradataMlException
1892
-
1893
- EXAMPLES:
1894
- obj = UtilFuncs._get_file_contents("/abc/xyz.txt")
1895
- obj = UtilFuncs._get_file_contents("/abc/xyz.txt", True)
1896
- """
1897
- try:
1898
- mode = 'r'
1899
- if read_in_binary_mode:
1900
- mode = 'rb'
1901
- with open(file_path, mode) as file_data:
1902
- _Validators._check_empty_file(file_path)
1903
- return file_data.read()
1904
- except TeradataMlException:
1905
- raise
1906
- except FileNotFoundError:
1907
- raise
1908
- except Exception as err:
1909
- msg_code = MessageCodes.EXECUTION_FAILED
1910
- raise TeradataMlException(
1911
- Messages.get_message(msg_code, "read contents of file '{}'".format(file_path), str(err)), msg_code)
1912
-
1913
- @staticmethod
1914
- def _create_table_using_table_object(table_obj):
1915
- """
1916
- DESCRIPTION:
1917
- This function creates the table in Vantage using table object.
1918
-
1919
- PARAMETERS:
1920
- table_obj:
1921
- Specifies the table object.
1922
- Types: sqlalchemy.sql.schema.Table
1923
-
1924
- RETURNS:
1925
- None.
1926
-
1927
- RAISES:
1928
- TeradataMlException
1929
-
1930
- EXAMPLES:
1931
- from sqlalchemy import Table, MetaData, Column
1932
-
1933
- meta = MetaData()
1934
- # Create default Table construct with parameter dictionary
1935
- table_obj = Table(table_name, meta,
1936
- *(Column(col_name, col_type)
1937
- for col_name, col_type in
1938
- zip(col_names, col_types)),
1939
- teradatasql_post_create=pti,
1940
- prefixes=prefix,
1941
- schema=schema_name
1942
- )
1943
-
1944
- _create_table_using_table_object(table_obj)
1945
- """
1946
- if table_obj is not None:
1947
- try:
1948
- table_obj.create(bind=tdmlctx.get_context())
1949
- except sqlachemyOperationalError as err:
1950
- raise TeradataMlException(Messages.get_message(MessageCodes.TABLE_OBJECT_CREATION_FAILED) +
1951
- '\n' + str(err),
1952
- MessageCodes.TABLE_OBJECT_CREATION_FAILED)
1953
- else:
1954
- raise TeradataMlException(Messages.get_message(MessageCodes.TABLE_OBJECT_CREATION_FAILED),
1955
- MessageCodes.TABLE_OBJECT_CREATION_FAILED)
1956
-
1957
- @staticmethod
1958
- def _extract_table_object_column_info(table_obj):
1959
- """
1960
- Internal function to extract the column name and column types from
1961
- table object.
1962
-
1963
- PARAMETERS:
1964
- table_obj:
1965
- Required Argument.
1966
- Specifies the table object.
1967
- Types: sqlalchemy.sql
1968
-
1969
- RETURNS:
1970
- Tuple
1971
-
1972
- RAISES:
1973
- None
1974
-
1975
- EXAMPLE:
1976
- meta = MetaData()
1977
- table = Table(table_name, meta, schema=schema_name, autoload_with=eng)
1978
- _extract_table_object_column_info(table.c)
1979
- """
1980
- col_names = []
1981
- col_types = []
1982
-
1983
- for col in table_obj:
1984
- col_names.append(col.name)
1985
- col_types.append(col.type)
1986
-
1987
- return col_names, col_types
1988
-
1989
- @staticmethod
1990
- def _get_warnings(argument_name, argument_value, specified_argument_name, specified_argument_value):
1991
- """
1992
- Internal function to print the warning.
1993
-
1994
- PARAMETERS:
1995
- argument_name:
1996
- Required Argument.
1997
- Specifies the argument name to check.
1998
- Types: str
1999
-
2000
- argument_value:
2001
- Required Argument.
2002
- Specifies the argument value to check.
2003
- Types: bool
2004
-
2005
- specified_argument_name:
2006
- Required Argument.
2007
- Specifies the argument name to use in warning message.
2008
- Types: str
2009
-
2010
- specified_argument_value:
2011
- Required Argument.
2012
- Specifies the argument value to use in warning message.
2013
- Types: str
2014
-
2015
- RETURNS:
2016
- None
2017
-
2018
- RAISES:
2019
- None
2020
-
2021
- EXAMPLE:
2022
- _get_warnings(argument_name, argument_value, specified_argument_name, specified_argument_value)
2023
- """
2024
- if argument_value:
2025
- warnings.warn(Messages.get_message(MessageCodes.IGNORE_ARGS_WARN,
2026
- '{0}',
2027
- "{1}='{2}'",
2028
- 'specified').format(argument_name,
2029
- specified_argument_name,
2030
- specified_argument_value))
2031
-
2032
- @staticmethod
2033
- def _get_sqlalchemy_table(table_name, schema_name=None, check_table_exists=False):
2034
- """
2035
- Internal function returns the SQLAlchemy table object for a table.
2036
- If check_table_exists specified, function also checks for table existence.
2037
-
2038
- PARAMETERS:
2039
- table_name:
2040
- Required Argument.
2041
- Specifies the table name.
2042
- Types: str
2043
-
2044
- schema_name:
2045
- Optional Argument.
2046
- Specifies schema name.
2047
- Types: str
2048
-
2049
- check_table_exists:
2050
- Optional Argument.
2051
- Specifies whether to check table exists or not.
2052
- Default Value: False
2053
- Types: bool
2054
-
2055
- RETURNS:
2056
- sqlalchemy.sql.schema.Table
2057
-
2058
- RAISES:
2059
- None
2060
-
2061
- EXAMPLE:
2062
- _get_sqlalchemy_table(table_name='my_table')
2063
- """
2064
- con = tdmlctx.get_connection()
2065
-
2066
- if check_table_exists:
2067
- table_exists = con.dialect.has_table(con, table_name, schema_name)
2068
-
2069
- if not table_exists:
2070
- raise TeradataMlException(Messages.get_message(MessageCodes.TABLE_DOES_NOT_EXIST, table_name),
2071
- MessageCodes.TABLE_DOES_NOT_EXIST)
2072
-
2073
- meta = MetaData()
2074
- return Table(table_name, meta,
2075
- schema=schema_name,
2076
- autoload_with=tdmlctx.get_context())
2077
-
2078
- @staticmethod
2079
- def _extract_table_object_index_info(table_obj):
2080
- """
2081
- Internal function to extract primary index information of existing table.
2082
-
2083
- PARAMETERS:
2084
- table_obj:
2085
- Required Argument.
2086
- Specifies the sqlalchemy table object.
2087
- Types: sqlalchemy.sql.schema.Table.
2088
-
2089
- RETURNS:
2090
- list.
2091
-
2092
- RAISES:
2093
- None.
2094
-
2095
- EXAMPLE:
2096
- _extract_table_object_index_info(table_object)
2097
- """
2098
- sqlalchemy_table_primary_index = table_obj.indexes
2099
- primary_index_list = []
2100
- for index in sqlalchemy_table_primary_index:
2101
- primary_index_list = index.columns.keys()
2102
- return primary_index_list
2103
-
2104
- @staticmethod
2105
- def _get_positive_infinity():
2106
- """
2107
- Description:
2108
- Function to get the positive infinity.
2109
-
2110
- RETURNS:
2111
- float
2112
-
2113
- RAISES:
2114
- None
2115
-
2116
- EXAMPLES:
2117
- inf = UtilFuncs._get_positive_infinity()
2118
- """
2119
- return float("inf")
2120
-
2121
- @staticmethod
2122
- def _get_negative_infinity():
2123
- """
2124
- Description:
2125
- Function to get the negative infinity.
2126
-
2127
- RETURNS:
2128
- float
2129
-
2130
- RAISES:
2131
- None
2132
-
2133
- EXAMPLES:
2134
- inf = UtilFuncs._get_negative_infinity()
2135
- """
2136
- return -1 * UtilFuncs._get_positive_infinity()
2137
-
2138
- @staticmethod
2139
- def _get_class(class_name, supress_isinstance_check=False):
2140
- """
2141
- Description:
2142
- Function to get the class dynamically with the name as 'class_name'.
2143
-
2144
- PARAMETERS:
2145
- class_name:
2146
- Required Parameter.
2147
- Specifies the name of the class generated to be.
2148
- Types: str
2149
-
2150
- supress_isinstance_check:
2151
- Optional Parameter.
2152
- Specifies whether the dynamically created class should overwrite the
2153
- isinstance method or not. When set to True, if the class generated from
2154
- this function is passed to isinstance method, instead of verifying the
2155
- actual type, it tries to match the name of object's class with 'class_name'.
2156
- Default value: False
2157
- Types: bool
2158
-
2159
- RETURNS:
2160
- type
2161
-
2162
- RAISES:
2163
- None
2164
-
2165
- EXAMPLES:
2166
- inf = UtilFuncs._get_class("test")
2167
- """
2168
- parent_object = object
2169
- if supress_isinstance_check:
2170
-
2171
- # isinstance function is governed by the dunder method __instancecheck__.
2172
- # However, unlike other dunder method's, __instancecheck__ should be overwritten
2173
- # for a class, instead of object ,i.e., while creating the class itself, __instancecheck__
2174
- # should be overwritten.
2175
- # Note that, python's type accepts either object or any other class as a parent class.
2176
- # Since, other than object, one should pass only a class to a python type, creating a
2177
- # dummy class and specifying the metaclass as SupressInstanceCheck so that the dummy class
2178
- # has updated __instancecheck__ dunder method.
2179
- class SupressInstanceCheck(type):
2180
- def __instancecheck__(self, instance):
2181
- try:
2182
- return self.__name__ == instance.__class__.__name__
2183
- except Exception:
2184
- return False
2185
-
2186
- class temp(metaclass=SupressInstanceCheck):
2187
- pass
2188
-
2189
- parent_object = temp
2190
-
2191
- return type(class_name, (parent_object, ), {})
2192
-
2193
- @staticmethod
2194
- def _get_file_size(file_path, in_mb=True):
2195
- """
2196
- Description:
2197
- Function to get the size of file, given absolute file path.
2198
-
2199
- PARAMETERS:
2200
- file_path:
2201
- Required Argument.
2202
- Specifies absolute file path of the file.
2203
- Types: str
2204
-
2205
- in_mb:
2206
- Optional Argument.
2207
- Specifies whether to get the file size in mega bytes or not.
2208
- If True, size of the file returns in MB's. Otherwise, returns
2209
- in bytes.
2210
- Default value: True
2211
- Types: bool
2212
-
2213
- RETURNS:
2214
- int OR float
2215
-
2216
- RAISES:
2217
- TeradataMlException
2218
-
2219
- EXAMPLES:
2220
- file_size = UtilFuncs._get_file_size("/abc/xyz.txt")
2221
- """
2222
- size_in_bytes = os.path.getsize(file_path)
2223
-
2224
- return size_in_bytes/(1024*1024.0) if in_mb else size_in_bytes
2225
-
2226
- @staticmethod
2227
- def _http_request(url, method_type=HTTPRequest.GET, **kwargs):
2228
- """
2229
- Description:
2230
- Function to initiate HTTP(S) request.
2231
-
2232
- PARAMETERS:
2233
- url:
2234
- Required Argument.
2235
- Specifies the url to initiate http request.
2236
- Types: str
2237
-
2238
- method_type:
2239
- Optional Argument.
2240
- Specifies the type of HTTP request.
2241
- Default value: HTTPREquest.GET
2242
- Types: HTTPRequest enum
2243
-
2244
- **kwargs:
2245
- Specifies the keyword arguments required for HTTP Request.
2246
- Below are the expected arguments as a part of kwargs:
2247
- json:
2248
- Optional Argument.
2249
- Specifies the payload for HTTP request in a dictionary.
2250
- Types: dict
2251
-
2252
- data:
2253
- Optional Argument.
2254
- Specifies the payload for HTTP request in a string format.
2255
- Types: str
2256
-
2257
- headers:
2258
- Optional Argument.
2259
- Specifies the headers for HTTP request.
2260
- Types: dict
2261
-
2262
- verify:
2263
- Optional Argument.
2264
- Specifies whether to verify the certificate or not in a HTTPS request.
2265
- One can specify either False to suppress the certificate verification or
2266
- path to certificate to verify the certificate.
2267
- Types: str OR bool
2268
-
2269
- files:
2270
- Optional Argument.
2271
- Specifies the file to be uploaded with a HTTP Request.
2272
- Types: tuple
2273
-
2274
- RETURNS:
2275
- Response object.
2276
-
2277
- RAISES:
2278
- None
2279
-
2280
- EXAMPLES:
2281
- resp = UtilFuncs._http_request("http://abc/xyz.teradata")
2282
- """
2283
- kwargs["verify"] = configure.certificate_file
2284
-
2285
- if not configure.certificate_file:
2286
- warnings.filterwarnings("ignore", message="Unverified HTTPS request is being made to host[ a-zA-Z0-9'-.]*")
2287
-
2288
- return getattr(requests, method_type.value)(url=url, **kwargs)
2289
-
2290
- @staticmethod
2291
- def _get_tdml_directory():
2292
- """
2293
- DESCRIPTION:
2294
- Function to get the directory of teradataml module.
2295
-
2296
- PARAMETERS:
2297
- None.
2298
-
2299
- RETURNS:
2300
- str.
2301
-
2302
- EXAMPLES:
2303
- >>> tdml_path = UtilFuncs._get_tdml_directory()
2304
- """
2305
- # Get the directory of teradataml module.
2306
- return os.path.dirname(_version.__file__)
2307
-
2308
- @staticmethod
2309
- def _get_data_directory(dir_name=None, func_type=None, version=None):
2310
- """
2311
- DESCRIPTION:
2312
- Function to get the directory for jsons or docs from teradataml/data.
2313
-
2314
- PARAMETERS:
2315
- dir_name:
2316
- Optional Argument.
2317
- Specifies the name of directory required from teradataml/data directory.
2318
- Permitted values : ["jsons", "docs"]
2319
- Types: str
2320
-
2321
- func_type
2322
- Optional Argument.
2323
- Specifies the type of function for which jsons or docs directory is required.
2324
- Types: TeradataAnalyticFunctionInfo
2325
-
2326
- version:
2327
- Optional Argument.
2328
- Specifies the version of directory for which jsons or docs directory is required.
2329
- Types: str
2330
-
2331
- RETURNS:
2332
- path to desired directory.
2333
-
2334
- EXAMPLES:
2335
- >>> json_dir = UtilFuncs._get_data_directory(dir_name="jsons",
2336
- ... func_type=TeradataAnalyticFunctionInfo.FASTPATH,
2337
- ... version="17.10")
2338
-
2339
- """
2340
- if func_type:
2341
- func_type = func_type.value["func_type"]
2342
- dir_path = os.path.join(UtilFuncs._get_tdml_directory(), "data")
2343
- levels = [dir_name, func_type, version]
2344
- for level in levels:
2345
- if level:
2346
- dir_path = os.path.join(dir_path, level)
2347
- else:
2348
- break
2349
- if os.path.exists(dir_path):
2350
- return dir_path
2351
-
2352
- @staticmethod
2353
- def _replace_special_chars(str_value, replace_char="_", addon=None):
2354
- """
2355
- DESCRIPTION:
2356
- Function to replace any special character with a underscore(_).
2357
-
2358
- PARAMETERS:
2359
- str_value:
2360
- Required Argument.
2361
- Specifies the value of string which has special characters.
2362
- Types: str
2363
-
2364
- replace_char:
2365
- Optional Argument.
2366
- Specifies the value to be replaced for any special character.
2367
- Types: str
2368
-
2369
- addon
2370
- Optional Argument.
2371
- Specifies a dictionary with key as value to be checked in "s" and value
2372
- to be replaced in "s".
2373
- Types: dict
2374
-
2375
- RETURNS:
2376
- str
2377
-
2378
- EXAMPLES:
2379
- >>> json_dir = UtilFuncs._replace_special_chars("123$%.", addon={"$": "#"})
2380
- """
2381
- char_dict = {'A': 'A',
2382
- 'B': 'B',
2383
- 'C': 'C',
2384
- 'D': 'D',
2385
- 'E': 'E',
2386
- 'F': 'F',
2387
- 'G': 'G',
2388
- 'H': 'H',
2389
- 'I': 'I',
2390
- 'J': 'J',
2391
- 'K': 'K',
2392
- 'L': 'L',
2393
- 'M': 'M',
2394
- 'N': 'N',
2395
- 'O': 'O',
2396
- 'P': 'P',
2397
- 'Q': 'Q',
2398
- 'R': 'R',
2399
- 'S': 'S',
2400
- 'T': 'T',
2401
- 'U': 'U',
2402
- 'V': 'V',
2403
- 'W': 'W',
2404
- 'X': 'X',
2405
- 'Y': 'Y',
2406
- 'Z': 'Z',
2407
- 'a': 'a',
2408
- 'b': 'b',
2409
- 'c': 'c',
2410
- 'd': 'd',
2411
- 'e': 'e',
2412
- 'f': 'f',
2413
- 'g': 'g',
2414
- 'h': 'h',
2415
- 'i': 'i',
2416
- 'j': 'j',
2417
- 'k': 'k',
2418
- 'l': 'l',
2419
- 'm': 'm',
2420
- 'n': 'n',
2421
- 'o': 'o',
2422
- 'p': 'p',
2423
- 'q': 'q',
2424
- 'r': 'r',
2425
- 's': 's',
2426
- 't': 't',
2427
- 'u': 'u',
2428
- 'v': 'v',
2429
- 'w': 'w',
2430
- 'x': 'x',
2431
- 'y': 'y',
2432
- 'z': 'z',
2433
- '0': '0',
2434
- '1': '1',
2435
- '2': '2',
2436
- '3': '3',
2437
- '4': '4',
2438
- '5': '5',
2439
- '6': '6',
2440
- '7': '7',
2441
- '8': '8',
2442
- '9': '9'}
2443
- char_dict.update({" ": "", "_": "_", "\"": ""})
2444
- if addon:
2445
- char_dict.update(addon)
2446
- return reduce(lambda x,y: x+y, (char_dict.get(c, replace_char) for c in str_value))
2447
-
2448
- @staticmethod
2449
- def _get_dict_from_libs(lib_name):
2450
- """
2451
- DESCRIPTION:
2452
- Function to format the list of library version string to a dictionary,
2453
- on the basis of regex.
2454
-
2455
- PARAMETERS:
2456
- lib_name:
2457
- Required Argument.
2458
- Specifies the libs the user wants to format to a dictionary with
2459
- key as lib_name and value as lib_version.
2460
- Types: str, list of str
2461
-
2462
- RETURNS:
2463
- dict
2464
- """
2465
- result = {}
2466
- if isinstance(lib_name, str):
2467
- lib_name = UtilFuncs._as_list(lib_name)
2468
- for lib in lib_name:
2469
- matches = re.findall(r'([^<>=]+)([<>=].*)', lib)
2470
- if matches:
2471
- for key, value in matches:
2472
- result[key] = value
2473
- else:
2474
- result[lib] = ''
2475
- return result
2476
-
2477
- @staticmethod
2478
- def _is_valid_td_type(type_):
2479
- """
2480
- DESCRIPTION:
2481
- Function to check whether it is valid teradatasqlalchemy type or not.
2482
-
2483
- PARAMETERS:
2484
- type_:
2485
- Required Argument.
2486
- Specifies any value which needs to be validated for teradatasqlalchemy type.
2487
- Types: Any python object
2488
-
2489
- RETURNS:
2490
- bool
2491
- """
2492
- if isinstance(type_, _TDType):
2493
- return True
2494
- if isinstance(type_, type) and issubclass(type_, _TDType):
2495
- return True
2496
- return False
2497
-
2498
-
2499
- from teradataml.common.aed_utils import AedUtils
2500
- from teradataml.dbutils.filemgr import remove_file
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 uuid
17
+ from math import floor
18
+ import os, itertools
19
+ import time
20
+ import re, requests
21
+ import sqlalchemy
22
+ from pathlib import Path
23
+ from numpy import number
24
+ from sqlalchemy import Column, MetaData, Table
25
+ from teradataml.context.context import get_connection
26
+
27
+ from teradataml import _version
28
+ from teradataml.context import context as tdmlctx
29
+ from teradataml.common.exceptions import TeradataMlException
30
+ from teradataml.common.messages import Messages
31
+ from teradataml.common.messagecodes import MessageCodes
32
+ from teradataml.common.sqlbundle import SQLBundle
33
+ from teradataml.common import td_coltype_code_to_tdtype
34
+ from teradataml.common.constants import PythonTypes
35
+ from teradataml.common.constants import TeradataTypes
36
+ from teradataml.common.garbagecollector import GarbageCollector
37
+ from teradataml.common.constants import TeradataConstants, PTITableConstants, \
38
+ TableOperatorConstants, HTTPRequest
39
+ from teradataml.common.warnings import VantageRuntimeWarning
40
+ from teradataml.options.configure import configure
41
+ from teradataml.options.display import display
42
+ from teradataml.common.constants import TeradataReservedKeywords, TeradataConstants
43
+
44
+ from teradatasqlalchemy.types import _TDType
45
+ from teradatasqlalchemy.types import (INTEGER, SMALLINT, BIGINT, BYTEINT,
46
+ DECIMAL, FLOAT, NUMBER)
47
+ from teradatasqlalchemy.types import (DATE, TIME, TIMESTAMP)
48
+ from teradatasqlalchemy.types import (BYTE, VARBYTE, BLOB)
49
+ from teradatasqlalchemy.types import (CHAR, VARCHAR, CLOB)
50
+ from functools import reduce
51
+ import warnings
52
+ from teradatasqlalchemy.telemetry.queryband import set_queryband, collect_queryband, get_qb_query
53
+ from teradataml.utils.utils import execute_sql
54
+ from teradataml.utils.validators import _Validators
55
+ from sqlalchemy.exc import OperationalError as sqlachemyOperationalError
56
+
57
+
58
+ class UtilFuncs():
59
+ def _get_numeric_datatypes(self):
60
+ """
61
+ Returns the numeric data types used in Teradata Vantage
62
+ **From : https://www.info.teradata.com/HTMLPubs/DB_TTU_16_00/
63
+ index.html#page/General_Reference/B035-1091-160K/psa1472241434371.html
64
+
65
+ PARAMETERS:
66
+ None
67
+
68
+ RAISES:
69
+ None
70
+
71
+ RETURNS:
72
+ List of numeric data types used in Teradata Vantage
73
+ """
74
+ return [BYTEINT, SMALLINT, INTEGER, BIGINT, DECIMAL, FLOAT, NUMBER]
75
+
76
+ def _get_timedate_datatypes(self):
77
+ """
78
+ Returns a list of TimeDate data types.
79
+
80
+ PARAMETERS:
81
+ None
82
+
83
+ RAISES:
84
+ None
85
+
86
+ RETURNS:
87
+ List of TimeDate data types used in Teradata Vantage
88
+ """
89
+ return [TIMESTAMP, DATE, TIME]
90
+
91
+ def _get_character_datatypes(self):
92
+ """
93
+ Returns a list of Character data types.
94
+
95
+ PARAMETERS:
96
+ None
97
+
98
+ RAISES:
99
+ None
100
+
101
+ RETURNS:
102
+ List of Character data types used in Teradata Vantage
103
+ """
104
+ return [CHAR, VARCHAR, CLOB]
105
+
106
+ def _get_byte_datatypes(self):
107
+ """
108
+ Returns a list of byte like data types.
109
+
110
+ PARAMETERS:
111
+ None
112
+
113
+ RAISES:
114
+ None
115
+
116
+ RETURNS:
117
+ List of Byte data types used in Teradata Vantage
118
+ """
119
+ return [BYTE, VARBYTE, BLOB]
120
+
121
+ def _get_categorical_datatypes(self):
122
+ """
123
+ Returns a list of containing Character and TimeDate data types.
124
+
125
+ PARAMETERS:
126
+ None
127
+
128
+ RAISES:
129
+ None
130
+
131
+ RETURNS:
132
+ List of Character and TimeDate data types used in Teradata Vantage
133
+ """
134
+ return list.__add__(self._get_character_datatypes(), self._get_timedate_datatypes())
135
+
136
+ def _get_all_datatypes(self):
137
+ """
138
+ Returns a list of Character, Numeric and TimeDate data types.
139
+
140
+ PARAMETERS:
141
+ None
142
+
143
+ RAISES:
144
+ None
145
+
146
+ RETURNS:
147
+ List of Character, Numeric and TimeDate data types used in Teradata Vantage
148
+ """
149
+ return list.__add__(self._get_categorical_datatypes(), self._get_numeric_datatypes())
150
+
151
+ def _get_db_name_from_dataframe(self, df):
152
+ """
153
+ DESCRIPTION:
154
+ Function to get database name from teradataml DataFrame.
155
+
156
+ PARAMETERS:
157
+ df:
158
+ Required Argument.
159
+ Specifies the input teradataml DataFrame.
160
+ Types: teradataml DataFrame
161
+
162
+ RETURNS:
163
+ Database name.
164
+
165
+ RAISES:
166
+ None.
167
+
168
+ EXAMPLES:
169
+ UtilFuncs()._get_db_name_from_dataframe(df)
170
+ """
171
+ if df._table_name is None:
172
+ from teradataml.dataframe.dataframe_utils import DataFrameUtils
173
+ df._table_name = DataFrameUtils()._execute_node_return_db_object_name(df._nodeid,
174
+ df._metaexpr)
175
+
176
+ db_name = self._extract_db_name(df._table_name)
177
+ if db_name is None or db_name == "":
178
+ # Extract db_name from SQLAlchemy Engine URL.
179
+ if 'DATABASE' in tdmlctx.get_context().url.query:
180
+ db_name = tdmlctx.get_context().url.query['DATABASE']
181
+ else:
182
+ db_name = tdmlctx._get_current_databasename()
183
+ else:
184
+ db_name = db_name.replace("\"", "")
185
+
186
+ return db_name
187
+
188
+ @staticmethod
189
+ def _get_valid_aggregate_operations():
190
+ """
191
+ Returns the list of valid aggregate operations on Teradata Vantage
192
+
193
+ PARAMETERS:
194
+ None
195
+
196
+ RAISES:
197
+ None
198
+
199
+ RETURNS:
200
+ List of valid aggregate operations possible on Teradata Vantage
201
+ """
202
+ return ['count', 'kurtosis', 'max', 'mean', 'median', 'min', 'percentile', 'skew', 'std',
203
+ 'sum', 'unique', 'var']
204
+
205
+ @staticmethod
206
+ def _get_valid_time_series_aggregate_operations():
207
+ """
208
+ Returns the list of valid aggregate operations on Teradata Vantage
209
+
210
+ PARAMETERS:
211
+ None
212
+
213
+ RAISES:
214
+ None
215
+
216
+ RETURNS:
217
+ List of valid aggregate operations possible on Teradata Vantage
218
+ """
219
+ return ['bottom', 'bottom with ties', 'delta_t', 'first', 'last', 'mad', 'mode', 'top',
220
+ 'top with ties']
221
+
222
+ @staticmethod
223
+ def _generate_temp_table_name(databasename=None, user=None, prefix=None,
224
+ use_default_database=False, gc_on_quit=True, quote=True,
225
+ table_type=TeradataConstants.TERADATA_VIEW):
226
+ """
227
+ DESCRIPTION:
228
+ Function to return the random string for temporary table names.
229
+
230
+ PARAMETERS:
231
+ databasename:
232
+ Optional Argument.
233
+ Specifies the database name to use while generating the script.
234
+ Types: str
235
+
236
+ user:
237
+ Optional Argument.
238
+ Specifies the current username or database name on which user logged on to Teradata Vantage.
239
+ Types: str
240
+
241
+ prefix:
242
+ Optional Argument.
243
+ Specifies the prefix of the module from which table/view name is requested.
244
+ Types: str
245
+
246
+ use_default_database:
247
+ Optional Argument.
248
+ Specifies whether to create a table or view in the default database when
249
+ "databasename" is not provided.
250
+ Default value: False
251
+ Types: str
252
+
253
+ gc_on_quit:
254
+ Optional Argument.
255
+ Specifies whether to garbage collect the table/view with the generated name
256
+ at the end of the session.
257
+ When 'True', the objects created with the generated name will be garbage
258
+ collected at the end of the session.
259
+ Default value: True
260
+ Types: bool
261
+
262
+ quote:
263
+ Optional Argument.
264
+ Specifies whether to quote the database name and table/view name.
265
+ When 'True', quotes are added around the database name and the table/view name.
266
+ Default value: True
267
+ Types: bool
268
+
269
+ table_type:
270
+ Optional Argument.
271
+ Specifies the type of objects - table or view.
272
+ Default value: TeradataConstants.TERADATA_VIEW
273
+ Types: TeradataConstant
274
+
275
+ RETURNS:
276
+ Temporary table name.
277
+
278
+ RAISES:
279
+
280
+ EXAMPLES:
281
+ new_table_name = UtilFuncs._generate_temp_table_name(user='tdqg', prefix="from_pandas")
282
+ new_table_name = UtilFuncs._generate_temp_table_name(user='tdqg', prefix="from_pandas",
283
+ table_type = TeradataConstants.TERADATA_VIEW)
284
+ new_table_name = UtilFuncs._generate_temp_table_name(user='tdqg', prefix="from_pandas",
285
+ table_type = TeradataConstants.TERADATA_TABLE)
286
+
287
+ Output:
288
+ tdml_temp_table__1517501990393350 (or)
289
+ tdqg.tdml_temp_table__1517501990393350 (or)
290
+ tdml_temp_table__from_pandas_1517501990393350 (or)
291
+ tdqg.tdml_temp_table__from_pandas_1517501990393350
292
+ """
293
+ # Number of seconds since Jan 1, 1970 00:00:00
294
+ timestamp = time.time()
295
+ tabname = "ml_"
296
+ random_string = "{}{}".format(floor(timestamp / 1000000),
297
+ floor(timestamp % 1000000 * 1000000 +
298
+ int(str(uuid.uuid4().fields[-1])[:10])))
299
+ if prefix is not None:
300
+ tabname = "{}_{}".format(tabname, prefix)
301
+
302
+ tabname = "{}_{}".format(tabname, random_string)
303
+
304
+ if use_default_database and databasename is None:
305
+ tabname = "\"{}\".\"{}\"".format(tdmlctx._get_context_temp_databasename(
306
+ table_type=table_type), tabname)
307
+
308
+ if user is not None:
309
+ tabname = "\"{}\".\"{}\"".format(user, tabname)
310
+
311
+ if databasename is not None:
312
+ tabname = "\"{}\".\"{}\"".format(databasename, tabname)
313
+
314
+ # Enable garbage collection for the temporary view & table created while transformations.
315
+ if gc_on_quit:
316
+ GarbageCollector._add_to_garbagecollector(tabname, table_type)
317
+
318
+ return tabname
319
+
320
+ @staticmethod
321
+ def _generate_temp_script_name(database_name=None, prefix=None, use_default_database=True,
322
+ gc_on_quit=True, quote=True,
323
+ script_type=TeradataConstants.TERADATA_SCRIPT,
324
+ extension=None):
325
+ """
326
+ DESCRIPTION:
327
+ Function to return the random string for temporary script names.
328
+
329
+ PARAMETERS:
330
+ database_name:
331
+ Optional Argument:
332
+ Specifies the database name on which user logged on to Teradata Vantage.
333
+ Types: str
334
+
335
+ prefix:
336
+ Optional Argument.
337
+ Specifies the prefix of the module or function from which script name is requested.
338
+ Types: str
339
+
340
+ use_default_database:
341
+ Optional Argument.
342
+ Specifies whether the script will be installed in the default/connected database.
343
+ When 'True', the current/default database name will be used for generating the name.
344
+ Default value: True
345
+ Types: bool
346
+
347
+ gc_on_quit:
348
+ Optional Argument.
349
+ Specifies whether to garbage collect the object with the generated name
350
+ at the end of the session.
351
+ When 'True', the objects created with the generated name will be garbage
352
+ collected at the end of the session.
353
+ Default value: True
354
+ Types: bool
355
+
356
+ quote:
357
+ Optional Argument.
358
+ Specifies whether to quote the database name and script name.
359
+ When 'True', quotes are added around the database name and the script name.
360
+ Default value: True
361
+ Types: bool
362
+
363
+ script_type:
364
+ Optional Argument.
365
+ Specifies the type of script.
366
+ Default value: TeradataConstants.TERADATA_SCRIPT
367
+ Types: TeradataConstant
368
+
369
+ extension:
370
+ Optional Argument.
371
+ Specifies the extension of the script.
372
+ Default value: None
373
+ Types: str
374
+
375
+ RETURNS:
376
+ Temporary script name.
377
+
378
+ RAISES:
379
+ None.
380
+
381
+ EXAMPLES:
382
+ new_script_name = UtilFuncs._generate_temp_script_name(use_default_database=True,
383
+ script_type = TeradataConstants.TERADATA_SCRIPT)
384
+ """
385
+ # NOTE:
386
+ # 1. There can be other types of scripts going forward which may require their own type (like for Apply).
387
+ # Hence, we have a 'script_type' argument which currently has only one possible value.
388
+ # 2. Currently map_row and map_partition use only default database, but going forward this can be changed
389
+ # to use other databases for installation of script, using 'database_name'.
390
+
391
+ timestamp = time.time()
392
+ script_name = "ml_"
393
+
394
+ random_string = "{}{}".format(floor(timestamp / 1000000),
395
+ floor(timestamp % 1000000 * 1000000 +
396
+ int(str(uuid.uuid4().fields[-1])[:10])))
397
+
398
+ if prefix is not None:
399
+ script_name = "{}_{}".format(script_name, prefix)
400
+
401
+ script_name = "{}_{}".format(script_name, random_string)
402
+
403
+ if extension is not None:
404
+ script_name = "{}.{}".format(script_name, extension)
405
+
406
+ dbname_to_use = tdmlctx._get_current_databasename()
407
+ if not use_default_database and database_name is not None:
408
+ dbname_to_use = database_name
409
+
410
+ script_name = "\"{}\".\"{}\"".format(dbname_to_use, script_name)
411
+
412
+ # Enable garbage collection for the temporary script created.
413
+ if gc_on_quit:
414
+ GarbageCollector._add_to_garbagecollector(script_name, script_type)
415
+
416
+ return script_name
417
+
418
+ @staticmethod
419
+ def _serialize_and_encode(obj):
420
+ """
421
+ DESCRIPTION:
422
+ Internal utility to serialize any Python object (including functions)
423
+ using dill and encode using base64.
424
+
425
+ PARAMETERS:
426
+ obj:
427
+ Specifies the Python object to serialize and encode.
428
+ Types: object
429
+
430
+ RAISES:
431
+ None.
432
+
433
+ RETURNS:
434
+ An encoded byte string representing the serialized object 'obj'.
435
+
436
+ EXAMPLES:
437
+ >>> # Serializing and encoding a literal value
438
+ >>> literal = UtilFuncs._serialize_and_encode('literal value')
439
+ >>> # Serializing and encoding a function
440
+ >>> def udf(a, b): return a + b
441
+ >>> func = UtilFuncs._serialize_and_encode(udf)
442
+ """
443
+ from dill import dumps as dill_dumps
444
+ from base64 import b64encode as base64_b64encode
445
+
446
+ return base64_b64encode(dill_dumps(obj, recurse=True))
447
+
448
+ @staticmethod
449
+ def _quote_table_names(table_name):
450
+ """
451
+ Quotes table names or view names.
452
+ If the table name is in the format schema.table_name, it will quote the
453
+ schema name and table name.
454
+
455
+ Example:
456
+ mytab -> "my.tab"
457
+ schema.mytable -> "schema"."my.tab"
458
+ myview -> "myview"
459
+
460
+ PARAMETERS:
461
+ table_name - The name of table or view. The name can include the schema (e.g. schema.table_name)
462
+
463
+ RETURNS:
464
+ returns the quoted table name.
465
+
466
+ RAISES:
467
+
468
+ EXAMPLES:
469
+ table_name = UtilFuncs._quote_table_names(table_name)
470
+
471
+ """
472
+ table_name_list = re.findall('".+?"', table_name)
473
+ if table_name_list:
474
+ for i in range(0, len(table_name_list)):
475
+ if not (table_name_list[i].startswith("\"") and table_name_list[i].endswith("\"")):
476
+ table_name_list[i] = UtilFuncs._teradata_quote_arg(table_name_list[i], "\"", False)
477
+
478
+ return ".".join(table_name_list)
479
+ else:
480
+ return "\"{}\"".format(table_name)
481
+
482
+ @staticmethod
483
+ def _execute_ddl_statement(ddl_statement):
484
+ """
485
+ Executes a DDL statment and commits transaction
486
+ This is an internal function.
487
+
488
+ PARAMETERS:
489
+ ddl_statement - Teradata DDL statement.
490
+
491
+ RETURNS:
492
+
493
+ RAISES:
494
+ Database error if an error occurred while executing the DDL statement.
495
+
496
+ EXAMPLES:
497
+ UtilFuncs._execute_ddl_statement('create table mytab (col1 int, col2 varchar(20))')
498
+
499
+ """
500
+ # Empty queryband buffer before SQL call.
501
+ UtilFuncs._set_queryband()
502
+ # Let's execute our DDL statement with escape function '{fn teradata_fake_result_sets}'
503
+ # offered by teradatasql driver. This function will allow us catch any warnings thrown
504
+ # from the Vantage. Hence, executing the DDL statement with this escape function.
505
+ ddl_statement = "{fn teradata_fake_result_sets} " + ddl_statement
506
+
507
+ if tdmlctx.td_connection is not None:
508
+ cursor = None
509
+ try:
510
+ conn = tdmlctx.td_connection.connection
511
+ cursor = conn.cursor()
512
+ cursor.execute(ddl_statement)
513
+
514
+ # Warnings are displayed when the "suppress_vantage_runtime_warnings" attribute is set to 'False'.
515
+ if not display.suppress_vantage_runtime_warnings:
516
+ # Fetch the result set just to check whether we have received any warnings or not.
517
+ warnRes = cursor.fetchone()
518
+ # Check for "display.suppress_vantage_runtime_warnings" set to 'True'.
519
+ # Check for warning code and warning message
520
+ # warnRes[5] contains the Warning Code
521
+ # warnRes[6] contains the actual Warning Message
522
+ if warnRes[5] != 0 and warnRes[6] != "":
523
+ # Raise warning raised from Vantage as is.
524
+ warnings.simplefilter("always")
525
+ msg_ = Messages.get_message(MessageCodes.VANTAGE_WARNING)
526
+ warnings.warn(msg_.format(warnRes[5], warnRes[6]), VantageRuntimeWarning)
527
+
528
+ conn.commit()
529
+ except:
530
+ # logger.debug("Got exception while executing ({0})".format(teradataSQL))
531
+ raise
532
+ finally:
533
+ if cursor:
534
+ cursor.close()
535
+ else:
536
+ raise TeradataMlException(Messages.get_message(MessageCodes.CONNECTION_FAILURE),
537
+ MessageCodes.CONNECTION_FAILURE)
538
+
539
+ @staticmethod
540
+ def _execute_query(query, fetchWarnings=False, expect_none_result=False):
541
+ """
542
+ Retrieves result set data from query.
543
+
544
+ PARAMETERS:
545
+ query:
546
+ Required Argument.
547
+ Specifies the SQL query to execute.
548
+ Types: str
549
+
550
+ fetchWarnings:
551
+ Optional Argument.
552
+ Specifies a flag that decides whether to raise warnings thrown from Vanatge or not.
553
+ Default Values: False
554
+ Types: bool
555
+
556
+ expect_none_result:
557
+ Optional Argument.
558
+ When set to True, warnings will not be fetched and only result set is fetched.
559
+ Returns None if no result set is received from the backend.
560
+ When fetchWarnings is set to True this option is ignored.
561
+ Default Values: False
562
+ Types: bool
563
+
564
+ RETURNS:
565
+ Returns only result set from query if 'fetchWarnings' is False. If set to True, then
566
+ return result set and columns for the result set.
567
+
568
+ RAISES:
569
+ Database error if an error occurred while executing query.
570
+
571
+ EXAMPLES:
572
+ result = UtilFuncs._execute_query('select col1, col2 from mytab')
573
+ result = UtilFuncs._execute_query('help column mytab.*')
574
+
575
+ result = UtilFuncs._execute_query('help column mytab.*')
576
+
577
+ # Execute the stored procedure using fetchWarnings.
578
+ UtilFuncs._execute_query("call SYSUIF.INSTALL_FILE('myfile',
579
+ 'filename.py',
580
+ 'cb!/Documents/filename.py')",
581
+ True, False)
582
+
583
+ # Execute the stored procedure without fetchWarnings but still needs resultsets.
584
+ UtilFuncs._execute_query("call SYSUIF.list_base_environments()", False, True)
585
+
586
+ """
587
+ # Empty queryband buffer before SQL call.
588
+ UtilFuncs._set_queryband()
589
+
590
+ if fetchWarnings:
591
+ # Let's execute our DDL statement with escape function '{fn teradata_fake_result_sets}'
592
+ # offered by teradatasql driver. This function will allow us catch any warnings thrown
593
+ # from the Vantage. Hence, executing the DDL statement with this escape function.
594
+ query = "{fn teradata_fake_result_sets} " + query
595
+
596
+ if tdmlctx.td_connection is not None:
597
+ cursor = None
598
+ try:
599
+ conn = tdmlctx.td_connection.connection
600
+ cursor = conn.cursor()
601
+ cursor.execute(query)
602
+
603
+ if fetchWarnings:
604
+ # Fetch the result set just to check whether we have received any warnings or not.
605
+ warnRes = cursor.fetchone()
606
+ # Check for warning code and warning message
607
+ # warnRes[5] contains the Warning Code
608
+ # warnRes[6] contains the actual Warning Message
609
+ if (warnRes[5] != 0 and warnRes[6] != "") and not display.suppress_vantage_runtime_warnings:
610
+ # Raise warning raised from Vantage as is.
611
+ warnings.simplefilter("always")
612
+ msg_ = Messages.get_message(MessageCodes.VANTAGE_WARNING)
613
+ warnings.warn(msg_.format(warnRes[5], warnRes[6]), VantageRuntimeWarning)
614
+
615
+ cursor.nextset()
616
+
617
+ return cursor.fetchall(), [col_desc[0] for col_desc in cursor.description]
618
+
619
+ # This check may be removed if DBS side stored procedure are fixed to return empty
620
+ # result sets with columns in cursor.description
621
+ elif expect_none_result:
622
+ cursor.nextset()
623
+ # Some stored procedure returns None if result set has no rows.
624
+ # cannot use fetchall call in such cases. If SPs are fixed to support result sets with zero
625
+ # rows then below call may be removed in the future.
626
+ if cursor.rowcount <= 0:
627
+ return None, None
628
+ return cursor.fetchall(), [col_desc[0] for col_desc in cursor.description]
629
+
630
+ else:
631
+ return cursor.fetchall()
632
+ except:
633
+ raise
634
+ finally:
635
+ if cursor:
636
+ cursor.close()
637
+ else:
638
+ raise TeradataMlException(Messages.get_message(MessageCodes.CONNECTION_FAILURE),
639
+ MessageCodes.CONNECTION_FAILURE)
640
+
641
+ @staticmethod
642
+ @collect_queryband(queryband='CreateView')
643
+ def _create_view(view_name, query):
644
+ """
645
+ Create a view from the given query.
646
+
647
+ PARAMETERS:
648
+ view_name - View name
649
+ query - SQL query
650
+
651
+ RAISES
652
+
653
+ RETURNS:
654
+ True if success.
655
+
656
+ EXAMPLES:
657
+ UtilFuncs._create_view(view_name, "select * from table_name")
658
+ """
659
+ crt_view = SQLBundle._build_create_view(view_name, query)
660
+ try:
661
+ UtilFuncs._execute_ddl_statement(crt_view)
662
+ return True
663
+ except:
664
+ raise
665
+
666
+ @staticmethod
667
+ @collect_queryband(queryband='CreateTbl')
668
+ def _create_table(table_name, query, volatile=False):
669
+ """
670
+ Create a table from the given query.
671
+
672
+ PARAMETERS:
673
+ table_name - Fully qualified quoted table name.
674
+ query - SQL query
675
+ volatile - Specifies whether to create volatile table or not.
676
+ When set to True, volatile table is created, otherwise
677
+ permanent table is created.
678
+
679
+ RAISES
680
+
681
+ RETURNS:
682
+ True if success, false if fails
683
+
684
+ EXAMPLES:
685
+ UtilFuncs._create_table('"dbname"."table_name"', "select * from table_name")
686
+ """
687
+ crt_table = SQLBundle._build_create_table_with_data(table_name, query)
688
+ if volatile:
689
+ crt_table = SQLBundle._build_create_volatile_table_with_data(table_name, query)
690
+
691
+ UtilFuncs._execute_ddl_statement(crt_table)
692
+ return True
693
+
694
+ @staticmethod
695
+ def _get_non_null_counts(col_names, table_name):
696
+ """
697
+ Returns a list of non-null count for each column in col_names from table table_name.
698
+
699
+ PARAMETERS:
700
+ col_names - list of column names for table table_name.
701
+ table_name - table name.
702
+
703
+ RETURNS:
704
+ returns a list of non-null counts for each column.
705
+
706
+ RAISES:
707
+
708
+ EXAMPLES:
709
+ UtilFuncs._get_non_null_counts(col_names, 'mytab')
710
+
711
+ """
712
+ count_col_names = ["count(\"{0}\")".format(name) for name in col_names]
713
+ select_count = "select {0} from {1}".format(", ".join(count_col_names), table_name)
714
+ result = UtilFuncs._execute_query(select_count)
715
+ return [str(i) for i in result[0]]
716
+
717
+ @staticmethod
718
+ @collect_queryband(queryband='CreateVolaTbl')
719
+ def _get_volatile_table(query, with_data=False):
720
+ """
721
+ Creates a volatile table as query.
722
+ If with_data is True, creates the volatile table with data.
723
+ Else, creates the volatile table without data.
724
+
725
+ PARAMETERS:
726
+ query - The query used to create the volatile table.
727
+ with_data(optional) - True, creates table with data.
728
+ False, creates table without data. Default is False
729
+
730
+ RETURNS:
731
+ returns the temporary name of the volatile table.
732
+
733
+ RAISES:
734
+ Database error if an error occurred while creating the volatile table.
735
+
736
+ EXAMPLES:
737
+ UtilFuncs._get_volatile_table('select col1, col2, from mytab')
738
+ UtilFuncs._get_volatile_table('select col1, col2, from mytab', with_data=True)
739
+
740
+ """
741
+ vtab_name = UtilFuncs._generate_temp_table_name()
742
+ if with_data:
743
+ create_vtab_ddl = SQLBundle._build_create_volatile_table_with_data(vtab_name, query)
744
+ else:
745
+ create_vtab_ddl = SQLBundle._build_create_volatile_table_without_data(vtab_name, query)
746
+ UtilFuncs._execute_ddl_statement(create_vtab_ddl)
747
+ return vtab_name
748
+
749
+ @staticmethod
750
+ def _drop_table(table_name, check_table_exist=True):
751
+ """
752
+ Drops a table.
753
+
754
+ PARAMETERS:
755
+ table_name - The table to drop.
756
+ check_table_exist - Checks if the table exist before dropping the table.
757
+
758
+ RETURNS:
759
+ True - if the table is dropped.
760
+
761
+ RAISES:
762
+ Database error if an error occurred while dropping the table.
763
+
764
+ EXAMPLES:
765
+ UtilFuncs._drop_table('mytab')
766
+ UtilFuncs._drop_table('mytab', check_table_exist = False)
767
+ UtilFuncs._drop_table('mydb.mytab', check_table_exist = False)
768
+ UtilFuncs._drop_table("mydb"."mytab", check_table_exist = True)
769
+
770
+ """
771
+ drop_tab = SQLBundle._build_drop_table(table_name)
772
+ if check_table_exist is True:
773
+ helptable = UtilFuncs._get_help_tablename(table_name)
774
+ if helptable:
775
+ UtilFuncs._execute_ddl_statement(drop_tab)
776
+ return True
777
+ else:
778
+ UtilFuncs._execute_ddl_statement(drop_tab)
779
+ return True
780
+
781
+ return False
782
+
783
+ @staticmethod
784
+ def _drop_view(view_name, check_view_exist=True):
785
+ """
786
+ Drops a view.
787
+
788
+ PARAMETERS:
789
+ view_name - The view to drop.
790
+ check_view_exist - Checks if the view exist before dropping the view.
791
+
792
+ RETURNS:
793
+ True - if the view is dropped.
794
+
795
+ RAISES:
796
+ Database error if an error occurred while dropping the view.
797
+
798
+ EXAMPLES:
799
+ UtilFuncs._drop_view('myview')
800
+ UtilFuncs._drop_view('myview', check_view_exist = False)
801
+ UtilFuncs._drop_view('mydb.myview', check_view_exist = False)
802
+ UtilFuncs._drop_view("mydb"."myview", check_view_exist = True)
803
+ """
804
+ drop_view = SQLBundle._build_drop_view(view_name)
805
+ if check_view_exist is True:
806
+ viewdetails = UtilFuncs._get_help_viewname(view_name)
807
+ if viewdetails:
808
+ UtilFuncs._execute_ddl_statement(drop_view)
809
+ return True
810
+ else:
811
+ UtilFuncs._execute_ddl_statement(drop_view)
812
+ return True
813
+
814
+ return False
815
+
816
+ @staticmethod
817
+ def _delete_script(script_name, file_type=TeradataConstants.TERADATA_SCRIPT,
818
+ check_script_exist=True):
819
+ """
820
+ DESCRIPTION:
821
+ Function to remove a user-installed file/script.
822
+
823
+ PARAMETERS:
824
+ script_name:
825
+ Required Argument.
826
+ Specifies the name of the script to remove.
827
+ Types: str
828
+
829
+ file_type:
830
+ Optional Argument.
831
+ Specifies the type of the file to remove, whether it is from
832
+ Enterpise (TeradataConstants.TERADATA_SCRIPT) or from Lake
833
+ (TeradataConstants.TERADATA_APPLY).
834
+ Default value: TeradataConstants.TERADATA_SCRIPT
835
+ Permitted Values: TeradataConstants.TERADATA_SCRIPT, TeradataConstants.TERADATA_APPLY
836
+ Types: TeradataConstants
837
+
838
+ check_script_exist:
839
+ Required Argument. Applicable only when "file_type" is
840
+ TeradataConstants.TERADATA_SCRIPT. Ignored otherwise.
841
+ Specifies whether to check if the script exists or not before removing it.
842
+ When 'True', the presence of the script will be check for.
843
+ Default value: True
844
+ Types: bool
845
+
846
+ RETURNS:
847
+ True - if the script is removed.
848
+
849
+ RAISES:
850
+ Database error if an error occurred while dropping the view.
851
+
852
+ EXAMPLES:
853
+ UtilFuncs._delete_script('myview')
854
+ UtilFuncs._delete_script('myview', check_script_exist = False)
855
+ UtilFuncs._delete_script('mydb.myview', check_script_exist = False)
856
+ UtilFuncs._delete_script("mydb"."myview", check_script_exist = True)
857
+ """
858
+ dbname = UtilFuncs._teradata_unquote_arg(UtilFuncs._extract_db_name(script_name),
859
+ quote='"')
860
+ script_alias = UtilFuncs._teradata_unquote_arg(UtilFuncs._extract_table_name(script_name),
861
+ quote='"')
862
+ current_db = tdmlctx._get_current_databasename()
863
+
864
+ if file_type == TeradataConstants.TERADATA_SCRIPT:
865
+ script_exists = False
866
+ if check_script_exist:
867
+ query = "select count(*) from dbc.tablesV " \
868
+ "where databasename = '{}' and tablename = '{}' " \
869
+ "and tablekind = 'Z'".format(dbname, script_alias)
870
+
871
+ script_exists = True if UtilFuncs._execute_query(query)[0][0] == 1 else False
872
+
873
+ if script_exists or not check_script_exist:
874
+ try:
875
+ # If the database is not the current/default database, we need to
876
+ # set that as the session database to be able to remove the file.
877
+ if dbname and dbname.lower() != current_db.lower():
878
+ execute_sql('database {}'.format(dbname))
879
+
880
+ # Strip off the file extension and extract the base name.
881
+ from pathlib import Path
882
+ script_base_name = Path(script_alias).stem
883
+
884
+ # Remove the file.
885
+ remove_file(script_base_name, force_remove=True, suppress_output=True)
886
+ return True
887
+ except:
888
+ raise
889
+ finally:
890
+ # Reset the database if it was set to something else.
891
+ if dbname and dbname.lower() != current_db.lower():
892
+ execute_sql('database {}'.format(current_db))
893
+ else:
894
+ # environment name and file name are separated by '::'
895
+ # like <user_env_name(str)>::<apply_script_name>
896
+ env_name, script_alias = script_alias.split('::')
897
+
898
+ from teradataml.scriptmgmt.lls_utils import get_env
899
+ env = get_env(env_name)
900
+ env.remove_file(script_alias, suppress_output=True)
901
+ return True
902
+
903
+ @staticmethod
904
+ def _get_help_vtablenames():
905
+ """
906
+ Function to get list of volatile tables.
907
+
908
+ RETURNS:
909
+ List of volatile tablenames.
910
+
911
+ EXAMPLES:
912
+ UtilFuncs._get_help_vtablenames()
913
+ """
914
+ vtables = UtilFuncs._execute_query(SQLBundle._build_help_volatile_table())
915
+ if vtables:
916
+ return list(map(str.strip, filter(None, vtables[0])))
917
+ return []
918
+
919
+ @staticmethod
920
+ def _get_help_viewname(view_name):
921
+ """
922
+ Function to get help of the view.
923
+
924
+ PARAMETERS:
925
+ view_name - The name of the view.
926
+
927
+ RETURNS:
928
+ The help information of the view specified by view_name.
929
+
930
+ EXAMPLES:
931
+ UtilFuncs._get_help_viewname(myview)
932
+ """
933
+ return UtilFuncs._execute_query(SQLBundle._build_help_view(view_name))
934
+
935
+ @staticmethod
936
+ def _get_help_tablename(table_name):
937
+ """
938
+ Function to get help of the table.
939
+
940
+ PARAMETERS:
941
+ table_name - The name of the table.
942
+
943
+ RETURNS:
944
+ The help information of the table specified by table_name.
945
+
946
+ EXAMPLES:
947
+ UtilFuncs._get_help_tablename(mytable)
948
+ """
949
+ return UtilFuncs._execute_query(SQLBundle._build_help_table(table_name))
950
+
951
+ @staticmethod
952
+ def _get_select_table(table_name):
953
+ """
954
+ Function to get a table if exists.
955
+
956
+ PARAMETERS:
957
+ table_name - Table name to check if exists in the database.
958
+
959
+ RETURNS:
960
+ Table name in a list.
961
+
962
+ EXAMPLES:
963
+ UtilFuncs._get_select_table('mytab')
964
+
965
+ """
966
+ table = UtilFuncs._execute_query(SQLBundle._build_select_table_name(table_name))
967
+ if table:
968
+ return table[0]
969
+ return []
970
+
971
+ @staticmethod
972
+ def _describe_column(metadata, to_type=None):
973
+ """
974
+ This is an internal function to retrieve
975
+ column names and column types for the table or view.
976
+
977
+ PARAMETERS:
978
+ metadata:
979
+ The result set from the HELP COLUMN command.
980
+
981
+ RETURNS:
982
+ A list of tuples (column_names, column_types).
983
+
984
+ RAISES:
985
+ Database errors if a problem occurs while trying to retrieve the column information.
986
+
987
+ EXAMPLES:
988
+ column_names_and_types = UtilFuncs._describe_column()
989
+
990
+ """
991
+ column_names_and_types = []
992
+ for row in metadata:
993
+ # logger.debug("Retrieving Teradata type for {0}".format(row[31]))
994
+ # row[31] corresponds to 'Column Dictionary Name' column in the result of 'HELP COLUMN' SQL commands result.
995
+ column_name = row[31]
996
+ # We also need to check if the column is a TD_TIMEBUCKET column, in which case we can ignore it.
997
+ # We do so by checking the column name, and row[48] which corresponds to the 'Time Series Column Type'
998
+ # column in the 'HELP COLUMN' command to make sure it is indeed the TD_TIMEBUCKET column in the PTI table,
999
+ # and not just a column with the same name in a PTI/non-PTI table.
1000
+ # TD_TIMEBUCKET column is ignored since it is not functionally available to any user.
1001
+ if column_name == PTITableConstants.TD_TIMEBUCKET.value and \
1002
+ len(row) > 48 and row[48] is not None and \
1003
+ row[48].strip() == PTITableConstants.TSCOLTYPE_TIMEBUCKET.value:
1004
+ continue
1005
+ if to_type == "TD":
1006
+ # row[18] corresponds to the 'UDT Name' in the 'HELP COLUMN' SQL commands result.
1007
+ # row[1] corresponds to the 'Type' in the 'HELP COLUMN' commands result.
1008
+ column_names_and_types.append((column_name,
1009
+ UtilFuncs._help_col_to_td_type(row[1].strip(),
1010
+ row[18],
1011
+ row[44])))
1012
+ else:
1013
+ column_names_and_types.append((column_name,
1014
+ UtilFuncs._help_col_to_python_type(row[1].strip(),
1015
+ row[44])))
1016
+
1017
+ return column_names_and_types
1018
+
1019
+ @staticmethod
1020
+ def _get_pandas_converters(col_types):
1021
+ """
1022
+ DESCRIPTION:
1023
+ Internal util function to get a dictionary of Python type names of columns
1024
+ in a teradataml DataFrame mapped to lambda functions to process the
1025
+ data to convert it to the type, which can be readily used with pandas'
1026
+ read_csv() function's 'converters' argument.
1027
+
1028
+ Note: This utility provides converter functions only for values of type
1029
+ int, float, and decimal.Decimal.
1030
+ For types that don't expect empty strings in input
1031
+ i.e. for 'datetime.datetime', 'datetime.date' and 'datetime.time',
1032
+ the converter function returns None for empty string input.
1033
+
1034
+ PARAMETERS:
1035
+ col_types:
1036
+ Required Argument.
1037
+ The list of Python types names corresponding to the columns in the input data.
1038
+ Types: list
1039
+
1040
+ RAISES:
1041
+ None
1042
+
1043
+ RETURNS:
1044
+ dict
1045
+
1046
+ EXAMPLES:
1047
+ >>> pandas_converters = UtilFuncs._get_pandas_converters(["int", "str"])
1048
+ """
1049
+ pandas_converters = dict()
1050
+ for i, type_ in enumerate(col_types):
1051
+ # Add a functions that converts the string values to float or int when
1052
+ # the value is not empty string, else return None.
1053
+ if type_ in (PythonTypes.PY_FLOAT_TYPE.value,
1054
+ PythonTypes.PY_DECIMAL_TYPE.value):
1055
+ pandas_converters[i] = lambda x: float(x) \
1056
+ if isinstance(x, (bytes, number, int, float)) \
1057
+ else float("".join(x.split())) if len(x.strip()) > 0 else None
1058
+
1059
+ elif type_ == PythonTypes.PY_INT_TYPE.value:
1060
+ pandas_converters[i] = lambda x: int(x) \
1061
+ if isinstance(x, (bytes, number, int, float)) \
1062
+ else int(float("".join(x.split()))) if len(x.strip()) > 0 else None
1063
+
1064
+ elif type_ in (PythonTypes.PY_DATETIME_TYPE.value,
1065
+ PythonTypes.PY_DATE_TYPE.value,
1066
+ PythonTypes.PY_TIME_TYPE.value):
1067
+ # For types that do not expect empty strings, add function to
1068
+ # set them to None when value received is empty string.
1069
+ pandas_converters[i] = lambda x: x if len(x.strip()) > 0 else None
1070
+
1071
+ else:
1072
+ # For 'str' and 'bytes' types, add function that returns value as is.
1073
+ pandas_converters[i] = lambda x: x
1074
+
1075
+ return pandas_converters
1076
+
1077
+ @staticmethod
1078
+ def _teradata_type_to_python_type(td_type):
1079
+ """
1080
+ Translate the Teradata type from metaexpr to Python types.
1081
+ PARAMETERS:
1082
+ td_type - The Teradata type from metaexpr.
1083
+
1084
+ RETURNS:
1085
+ The Python type for the given td_type.
1086
+
1087
+ RAISES:
1088
+
1089
+ EXAMPLES:
1090
+ # o is an instance of INTEGER
1091
+ pytype = UtilFuncs._teradata_type_to_python_type(o)
1092
+
1093
+ """
1094
+
1095
+ # loggerlogger.debug("_help_col_to_python_type td_type = {0} ".format(td_type))
1096
+ if type(td_type) in TeradataTypes.TD_INTEGER_TYPES.value:
1097
+ return PythonTypes.PY_INT_TYPE.value
1098
+ elif type(td_type) in TeradataTypes.TD_FLOAT_TYPES.value:
1099
+ return PythonTypes.PY_FLOAT_TYPE.value
1100
+ elif type(td_type) in TeradataTypes.TD_DECIMAL_TYPES.value:
1101
+ return PythonTypes.PY_DECIMAL_TYPE.value
1102
+ elif type(td_type) in TeradataTypes.TD_BYTE_TYPES.value:
1103
+ return PythonTypes.PY_BYTES_TYPE.value
1104
+ elif type(td_type) in TeradataTypes.TD_DATETIME_TYPES.value:
1105
+ return PythonTypes.PY_DATETIME_TYPE.value
1106
+ elif type(td_type) in TeradataTypes.TD_TIME_TYPES.value:
1107
+ return PythonTypes.PY_TIME_TYPE.value
1108
+ elif type(td_type) in TeradataTypes.TD_DATE_TYPES.value:
1109
+ return PythonTypes.PY_DATE_TYPE.value
1110
+
1111
+ return PythonTypes.PY_STRING_TYPE.value
1112
+
1113
+ @staticmethod
1114
+ def _help_col_to_python_type(col_type, storage_format):
1115
+ """
1116
+ Translate the 1 or 2 character TD type codes from HELP COLUMN to Python types.
1117
+ PARAMETERS:
1118
+ col_type - The 1 or 2 character type code from HELP COLUMN command.
1119
+ storage_format - The storage format from HELP COLUMN command.
1120
+
1121
+ RETURNS:
1122
+ The Python type for the given col_type.
1123
+
1124
+ RAISES:
1125
+
1126
+ EXAMPLES:
1127
+ pytype = UtilFuncs._help_col_to_python_type('CV', None)
1128
+ pytype = UtilFuncs._help_col_to_python_type('DT', 'CSV')
1129
+
1130
+ """
1131
+ if col_type in TeradataTypes.TD_INTEGER_CODES.value:
1132
+ return PythonTypes.PY_INT_TYPE.value
1133
+ elif col_type in TeradataTypes.TD_FLOAT_CODES.value:
1134
+ return PythonTypes.PY_FLOAT_TYPE.value
1135
+ elif col_type in TeradataTypes.TD_DECIMAL_CODES.value:
1136
+ return PythonTypes.PY_DECIMAL_TYPE.value
1137
+ elif col_type in TeradataTypes.TD_BYTE_CODES.value:
1138
+ return PythonTypes.PY_BYTES_TYPE.value
1139
+ elif col_type in TeradataTypes.TD_DATETIME_CODES.value:
1140
+ return PythonTypes.PY_DATETIME_TYPE.value
1141
+ elif col_type in TeradataTypes.TD_TIME_CODES.value:
1142
+ return PythonTypes.PY_TIME_TYPE.value
1143
+ elif col_type in TeradataTypes.TD_DATE_CODES.value:
1144
+ return PythonTypes.PY_DATE_TYPE.value
1145
+ elif col_type == "DT":
1146
+ sfmt = storage_format.strip()
1147
+ if sfmt == "CSV":
1148
+ return PythonTypes.PY_STRING_TYPE.value
1149
+ elif sfmt == "AVRO":
1150
+ return PythonTypes.PY_BYTES_TYPE.value
1151
+
1152
+ return PythonTypes.PY_STRING_TYPE.value
1153
+
1154
+ @staticmethod
1155
+ def _help_col_to_td_type(col_type, udt_name, storage_format):
1156
+ """
1157
+ Translate the 2 character TD type codes from HELP COLUMN to Teradata types.
1158
+ PARAMETERS:
1159
+ col_type - The 2 character type code from HELP COLUMN command.
1160
+ udt_name - The UDT name from the HELP COLUMN command.
1161
+ storage_format - The storage format from HELP COLUMN command.
1162
+
1163
+ RETURNS:
1164
+ The Teradata type for the given colType.
1165
+
1166
+ RAISES:
1167
+
1168
+ EXAMPLES:
1169
+ tdtype = UtilFuncs._help_col_to_td_type('CV', None, None)
1170
+
1171
+ """
1172
+ # logger.debug("helpColumnToTeradataTypeName colType = {0} udtName = {1}
1173
+ # storageFormat {2}".format(colType, udtName, storageFormat))
1174
+ if col_type in td_coltype_code_to_tdtype.HELP_COL_TYPE_TO_TDTYPE:
1175
+ return td_coltype_code_to_tdtype.HELP_COL_TYPE_TO_TDTYPE[col_type]
1176
+
1177
+ if col_type == "DT":
1178
+ return "DATASET STORAGE FORMAT {0}".format(storage_format.strip())
1179
+
1180
+ if col_type in ["UD", "US", "UT", "A1", "AN"]:
1181
+ if udt_name:
1182
+ return udt_name
1183
+
1184
+ return col_type
1185
+
1186
+ @staticmethod
1187
+ def _convert_date_to_string(date_obj):
1188
+ """
1189
+ Converts the date from datetime.date object to String type in the format "DATE 1987-06-09".
1190
+ PARAMETERS:
1191
+ date_obj:
1192
+ Required Argument.
1193
+ Specifies the date object to convert to string type.
1194
+ Types: datetime.date
1195
+
1196
+ RETURNS:
1197
+ The String reresentation for the given datetime.date object in the format "DATE 1987-06-09"
1198
+
1199
+ RAISES:
1200
+ None
1201
+
1202
+ Examples:
1203
+ date_str = UtilFuncs._convert_date_to_string(date_obj)
1204
+
1205
+ """
1206
+ date_str = 'DATE {}'.format(date_obj.strftime('%Y-%m-%d'))
1207
+ return date_str
1208
+
1209
+ @staticmethod
1210
+ def _process_for_teradata_keyword(keyword):
1211
+ """
1212
+ Processing the Teradata Reserved keywords.
1213
+ If keyword is in list of Teradata Reserved keywords, then it'll be quoted in double quotes "keyword".
1214
+
1215
+ PARAMETERS:
1216
+ keyword - A string or a list of strings to check whether it belongs to Teradata Reserved
1217
+ Keywords or not.
1218
+
1219
+ RETURNS:
1220
+ A quoted string or list of quoted strings, if keyword is one of the Teradata Reserved Keyword,
1221
+ else same object as is.
1222
+
1223
+ RAISES:
1224
+ None.
1225
+
1226
+ EXAMPLES:
1227
+ # Passing non-reserved returns "xyz" as is.
1228
+ keyword = self.__process_for_teradata_keyword("xyz")
1229
+ print(keyword)
1230
+ # Passing reserved str returns double-quoted str, i.e., "\"threshold\"".
1231
+ keyword = self.__process_for_teradata_keyword("threshold")
1232
+ print(keyword)
1233
+ """
1234
+ # If the input keyword is a list, then call the same function again for every
1235
+ # element in the list.
1236
+ if isinstance(keyword, list):
1237
+ return [UtilFuncs._process_for_teradata_keyword(col) for col in keyword]
1238
+
1239
+ if isinstance(keyword, str) and keyword.upper() in \
1240
+ TeradataReservedKeywords.TERADATA_RESERVED_WORDS.value:
1241
+ return UtilFuncs._teradata_quote_arg(keyword, "\"", False)
1242
+
1243
+ return keyword
1244
+
1245
+ @staticmethod
1246
+ def _in_schema(schema_name, table_name):
1247
+ """
1248
+ Function takes a schema name and a table name and creates a database
1249
+ object name in the format "schema"."table_name".
1250
+ Note:
1251
+ teradataml recommends to use this function to access table(s)/view(s),
1252
+ from the database other than the default database.
1253
+
1254
+ PARAMETERS:
1255
+ schema_name:
1256
+ Required Argument
1257
+ Specifies the schema where the table resides in.
1258
+ Types: str
1259
+
1260
+ table_name:
1261
+ Required Argument
1262
+ Specifies the table name or view name in Vantage.
1263
+ Types: str
1264
+
1265
+ EXAMPLES:
1266
+ from teradataml.dataframe.dataframe import in_schema, DataFrame
1267
+
1268
+ # Example 1: The following example creates a DataFrame from the
1269
+ # existing Vantage table "dbcinfo" in the non-default
1270
+ # database "dbc" using the in_schema() function.
1271
+ df = DataFrame(in_schema("dbc", "dbcinfo"))
1272
+
1273
+ # Example 2: The following example uses from_table() function, existing
1274
+ # Vantage table "dbcinfo" and non-default database "dbc" to
1275
+ # create a teradataml DataFrame.
1276
+ df = DataFrame.from_table(in_schema("dbc","dbcinfo"))
1277
+
1278
+ """
1279
+ return "{0}.{1}".format(UtilFuncs._teradata_quote_arg(schema_name, "\"", False),
1280
+ UtilFuncs._teradata_quote_arg(table_name, "\"", False))
1281
+
1282
+ @staticmethod
1283
+ def _extract_db_name(full_qualified_name):
1284
+ """
1285
+ Takes in fully qualified name of the table/view (db.table), and returns
1286
+ a database name from the same.
1287
+
1288
+ PARAMETERS:
1289
+ full_qualified_name - Name of the table/view
1290
+
1291
+ EXAMPLES:
1292
+ UtilFuncs._extract_db_name("db1"."tablename")
1293
+
1294
+ RETURNS:
1295
+ Database name from the provided name.
1296
+
1297
+ """
1298
+ # Extract the double quoted strings.
1299
+ names = re.findall(r'["](.*?)["]', full_qualified_name)
1300
+ # Remove quotes around the string.
1301
+ names = [i.replace('"', '') for i in names]
1302
+ if names:
1303
+ if len(names) == 2:
1304
+ return names[0]
1305
+ else:
1306
+ return None
1307
+
1308
+ @staticmethod
1309
+ def _extract_table_name(full_qualified_name):
1310
+ """
1311
+ Takes in fully qualified name of the table/view (db.table), and returns
1312
+ a table/view name from the same.
1313
+
1314
+ PARAMETERS:
1315
+ full_qualified_name - Name of the table/view
1316
+
1317
+ EXAMPLES:
1318
+ UtilFuncs._extract_db_name("db1"."tablename")
1319
+
1320
+ RETURNS:
1321
+ Table/View name from the provided name.
1322
+
1323
+ """
1324
+ # Extract the double quoted strings.
1325
+ names = re.findall(r'["](.*?)["]', full_qualified_name)
1326
+ # Remove quotes around the string.
1327
+ names = [i.replace('"', '') for i in names]
1328
+ if names:
1329
+ if len(names) == 2:
1330
+ return names[1]
1331
+ else:
1332
+ return names[0]
1333
+ return full_qualified_name
1334
+
1335
+ @staticmethod
1336
+ def _teradata_quote_arg(args, quote="'", call_from_wrapper=True):
1337
+ """
1338
+ Function to quote argument value.
1339
+ PARAMETERS:
1340
+ args : Argument to be quoted.
1341
+ quote : Type of quote to be used for quoting. Default is
1342
+ single quote (').
1343
+ RETURNS:
1344
+ Argument with quotes as a string.
1345
+
1346
+ EXAMPLES:
1347
+ When a call is being made from wrapper:
1348
+ UtilFuncs._teradata_quote_arg(family, "'")
1349
+ When a call is being made from non-wrapper function.
1350
+ UtilFuncs._teradata_quote_arg(family, "'", False)
1351
+ """
1352
+ if call_from_wrapper and not configure.column_casesensitive_handler:
1353
+ quote = ""
1354
+ return args
1355
+
1356
+ # Returning same string if it already quoted. Applicable only for strings.
1357
+ if isinstance(args, str) and args.startswith(quote) and args.endswith(quote):
1358
+ return args
1359
+ if args is None:
1360
+ return None
1361
+ if isinstance(args, list):
1362
+ return ["{0}{1}{0}".format(quote, arg) for arg in args]
1363
+
1364
+ return "{0}{1}{0}".format(quote, args)
1365
+
1366
+ @staticmethod
1367
+ def _teradata_unquote_arg(quoted_string, quote="'"):
1368
+ """
1369
+ Function to unquote argument value.
1370
+ PARAMETERS:
1371
+ quoted_string : String to be unquoted.
1372
+ quote : Type of quote to be used for unquoting. Default is
1373
+ single quote (').
1374
+ RETURNS:
1375
+ None if 'quoted_string' is not a string,
1376
+ else Argument without quotes as a string.
1377
+
1378
+ EXAMPLES:
1379
+ UtilFuncs._teradata_unquote_arg(family, "'")
1380
+ """
1381
+
1382
+ if not isinstance(quoted_string, str):
1383
+ return None
1384
+
1385
+ # Returning same string if it already unquoted.
1386
+ if not quoted_string.startswith(quote) and not quoted_string.endswith(quote):
1387
+ return quoted_string
1388
+
1389
+ return quoted_string[1:-1]
1390
+
1391
+ @staticmethod
1392
+ def _teradata_collapse_arglist(args_list, quote="'"):
1393
+ """
1394
+ Given a list as an argument this will single quote all the
1395
+ list elements and combine them into a single string separated by
1396
+ commas.
1397
+
1398
+ PARAMETERS:
1399
+ args_list: List containing string/s to be quoted.
1400
+ quote: Type of quote to be used for quoting. Default is single quote (').
1401
+
1402
+ RETURNS:
1403
+ Single string separated by commas.
1404
+
1405
+ EXAMPLES:
1406
+ UtilFuncs._teradata_collapse_arglist(family, "'")
1407
+
1408
+ """
1409
+ expr = r"([\"'][\d.\d\w]+\s*[\"'][,]*\s*)+([\"']\s*[\d.\d\w]+[\"']$)"
1410
+
1411
+ # # return None if list is empty
1412
+ # if not args_list and not isinstance(args_list, bool):
1413
+ # return args_list
1414
+
1415
+ # if args_list is a list quote all values of the list
1416
+ if isinstance(args_list, list):
1417
+ '''
1418
+ EXAMPLE:
1419
+ arg = ['admitted', 'masters', 'gpa', 'stats', 'programming']
1420
+ UtilFuncs._teradata_collapse_arglist(arg, "\"")
1421
+ RETURNS:
1422
+ '"admitted","masters","gpa","stats","programming"'
1423
+
1424
+ '''
1425
+ return ",".join("{0}{1}{0}".format(quote, arg) for arg in args_list)
1426
+ elif (isinstance(args_list, str)) and (bool(re.match(expr, args_list)) is True):
1427
+ '''
1428
+ Quotes the arguments which is string of strings with the provided quote variable
1429
+ value.
1430
+ The expr should be strings separeted by commas. The string values can be digits or
1431
+ alphabets.
1432
+ For example:
1433
+ args_list = '"masters","gpa","stats"'
1434
+ quote = "'"
1435
+ The args_list is quoted as below based on the quote argument provided:
1436
+ strQuotes = '"masters"','"gpa"','"stats"'
1437
+ RETURNS:
1438
+ quoted string
1439
+
1440
+ The quoted value is added to list in the functions with other arguments as:
1441
+ funcOtherArgs = ["'2.0'", "'POISSON'", "'IDENTITY'", "'0.05'", "'10'", "'False'", "'True'",
1442
+ '\'"masters"\',\'"gpa"\',\'"stats"\',\'"programming"\',\'"admitted"\'',
1443
+ '\'"masters"\',\'"stats"\',\'"programming"\'']
1444
+
1445
+ '''
1446
+ str_val = re.sub(r"\s+", "", args_list)
1447
+ args_list = str_val.split(",")
1448
+ return ",".join("{0}{1}{0}".format(quote, arg) for arg in args_list)
1449
+ # if argVector is any value of int/str/bool type, quote the value
1450
+ else:
1451
+ return UtilFuncs._teradata_quote_arg(args_list, quote, False)
1452
+
1453
+ @staticmethod
1454
+ def _get_metaexpr_using_columns(nodeid, column_info, with_engine=False, is_persist=False):
1455
+ """
1456
+ This internal function takes in input node ID and column information in zipped lists format
1457
+ to return metaexpr with or without engine.
1458
+
1459
+ PARAMETERS:
1460
+ nodeid - AED DAG node id for which a metaexpr is to be generated.
1461
+ column_info - This contains zipped lists of column names and corresponding column types.
1462
+ with_engine - A bool parameter, deciding whether to generate metaexpr with engine or not.
1463
+ Default is False.
1464
+ is_persist - A bool parameter, deciding whether to persist the result or not.
1465
+ Default is False.
1466
+
1467
+ RAISES:
1468
+
1469
+ RETURNS:
1470
+ metaexpr for the provided node ID and with column inforamtion.
1471
+
1472
+ EXAMPLES:
1473
+ node_id_list = self.__aed_utils._aed_ml_query(self.__input_nodeids, self.sqlmr_query, self.__func_output_args, "NaiveBayesMap")
1474
+ stdout_column_info = zip(stdout_column_names, stdout_column_types)
1475
+ UtilFuncs._get_metaexpr_using_columns(node_id_list[0], stdout_column_info)
1476
+ """
1477
+ from teradataml.dataframe.sql import _MetaExpression
1478
+ if with_engine:
1479
+ eng = tdmlctx.get_context()
1480
+ meta = sqlalchemy.MetaData(eng)
1481
+ else:
1482
+ meta = sqlalchemy.MetaData()
1483
+
1484
+ # Get the output table name for node_id from AED
1485
+ aed_utils = AedUtils()
1486
+
1487
+ table_name = aed_utils._aed_get_tablename(nodeid)
1488
+ db_schema = UtilFuncs._extract_db_name(table_name)
1489
+ db_table_name = UtilFuncs._extract_table_name(table_name)
1490
+
1491
+ # Constructing new Metadata (_metaexpr) without DB; _MetaExpression
1492
+ ouptut_table = Table(db_table_name, meta,
1493
+ *(Column(col_name, col_type) for col_name, col_type in column_info),
1494
+ schema=db_schema)
1495
+ return _MetaExpression(ouptut_table, is_persist=is_persist)
1496
+
1497
+ @staticmethod
1498
+ def _get_metaexpr_using_parent_metaexpr(nodeid, metaexpr):
1499
+ """
1500
+ This internal function takes in input node ID and metaexpr (parents)
1501
+ to return metaexpr with or without engine.
1502
+
1503
+ PARAMETERS:
1504
+ nodeid:
1505
+ Required Argument.
1506
+ Specifies AED DAG node id for which a metaexpr is to be generated.
1507
+
1508
+ metaexpr:
1509
+ Required Argument.
1510
+ _MetaExpression() of a DataFrame objects which is to be used to extract and
1511
+ create a new _MetaExpression.
1512
+
1513
+ RAISES:
1514
+ None.
1515
+
1516
+ RETURNS:
1517
+ metaexpr for the provided node ID and with metaexpr inforamtion.
1518
+
1519
+ EXAMPLES:
1520
+ node_id_list = self.__aed_utils._aed_ml_query(self.__input_nodeids, self.sqlmr_query, self.__func_output_args, "NaiveBayesMap")
1521
+ UtilFuncs._get_metaexpr_using_parent_metaexpr(node_id_list[0], parent_metaexpr)
1522
+ """
1523
+ meta_cols = metaexpr.t.c
1524
+ meta_columns = [c.name for c in meta_cols]
1525
+ col_names = []
1526
+ col_types = []
1527
+
1528
+ # When column list to retrieve is not provided, return meta-data for all columns.
1529
+ for col_name in meta_columns:
1530
+ col_names.append(meta_cols[col_name].name)
1531
+ col_types.append(meta_cols[col_name].type)
1532
+
1533
+ return UtilFuncs._get_metaexpr_using_columns(nodeid, zip(col_names, col_types))
1534
+
1535
+ @staticmethod
1536
+ def _create_table_using_columns(table_name, columns_datatypes, pti_clause=None, storage=None):
1537
+ """
1538
+ Create a table with columns.
1539
+
1540
+ PARAMETERS:
1541
+ table_name - Fully qualified quoted table name.
1542
+ columns_datatypes - Column names and dattypes for the table
1543
+ pti_clause - Specifies the string for the primary time index.
1544
+ storage - Specifies the storage for the table.
1545
+
1546
+ RAISES
1547
+
1548
+ RETURNS:
1549
+ True if success, false if fails
1550
+
1551
+ EXAMPLES:
1552
+ UtilFuncs._create_table_using_columns('"dbname"."table_name"',
1553
+ "col1 varchar(10), col2 integer, col3 timestamp")
1554
+ """
1555
+ # If storage option is specified, add the storage clause in the create table statement.
1556
+ if storage:
1557
+ table_name = "{}, STORAGE={}".format(table_name, storage)
1558
+
1559
+ crt_table = SQLBundle._build_create_table_using_columns(table_name, columns_datatypes)
1560
+
1561
+ if pti_clause is not None:
1562
+ crt_table = "{} PRIMARY TIME INDEX {}".format(crt_table, pti_clause)
1563
+
1564
+ try:
1565
+ UtilFuncs._execute_ddl_statement(crt_table)
1566
+ return True
1567
+ except Exception:
1568
+ raise
1569
+
1570
+ @staticmethod
1571
+ def _get_engine_name(engine):
1572
+ """
1573
+ Function to return the name of the engine mapped to the
1574
+ argument 'engine' in function mapped dictionary.
1575
+
1576
+ PARAMETERS:
1577
+ engine:
1578
+ Required Argument.
1579
+ Specifies the type of the engine.
1580
+
1581
+ RETURNS:
1582
+ Name of the engine.
1583
+
1584
+ RAISES:
1585
+ TeradataMLException
1586
+
1587
+ EXAMPLES:
1588
+ UtilFuncs._get_engine_name("ENGINE_SQL")
1589
+
1590
+ """
1591
+ _Validators._validate_engine(engine)
1592
+ supported_engines = TeradataConstants.SUPPORTED_ENGINES.value
1593
+ return supported_engines[engine]['name']
1594
+
1595
+ @staticmethod
1596
+ def _as_list(obj):
1597
+ """
1598
+ Function to convert an object to list, i.e., just enclose the value passed to the
1599
+ function in a list and return the same, if it is not of list type.
1600
+ PARAMETERS:
1601
+ obj:
1602
+ Required Argument.
1603
+ Specifies the object to be enclosed in a list.
1604
+ Types: Any type except list.
1605
+ RETURNS:
1606
+ list
1607
+ RAISES:
1608
+ None.
1609
+ EXAMPLES:
1610
+ obj = UtilFuncs._as_list("vantage1.0")
1611
+ """
1612
+ return obj if isinstance(obj, list) else [obj]
1613
+
1614
+ @staticmethod
1615
+ def _get_all_columns(object, is_object_type_tdml_column):
1616
+ """
1617
+ Function to get all columns from a given teradataml DataFrame
1618
+ or teradataml DataFrame column.
1619
+
1620
+ PARAMETERS:
1621
+ object:
1622
+ Required Argument.
1623
+ Specifies either teradataml DataFrame or teradataml DataFrame
1624
+ Column.
1625
+ Types: teradataml DataFrame, _SQLColumnExpression
1626
+
1627
+ is_object_type_tdml_column:
1628
+ Required Argument.
1629
+ Specifies whether "object" is a teradataml DataFrame or
1630
+ teradataml DataFrame Column.
1631
+ If True, "object" treats as teradataml DataFrame Column.
1632
+ If False, "object" treats as teradataml DataFrame.
1633
+ Types: bool
1634
+
1635
+ RETURNS:
1636
+ An iterator and each element in the iterator represents a Column
1637
+
1638
+ RAISES:
1639
+ None.
1640
+
1641
+ EXAMPLES:
1642
+ obj = UtilFuncs._get_all_columns(df.col, True)
1643
+ obj = UtilFuncs._get_all_columns(df, False)
1644
+ """
1645
+ if is_object_type_tdml_column:
1646
+ return UtilFuncs._all_df_column_expressions(object)
1647
+ # object._metaexpr.c extracts the data to a list. And, the caller of
1648
+ # this function will again iterate through the list, to process the
1649
+ # list i.e. object._metaexpr.c is being iterated twice. To avoid this,
1650
+ # a generator object is being constructed and returned.
1651
+ return (c for c in object._metaexpr.c)
1652
+
1653
+ @staticmethod
1654
+ def _get_file_contents(file_path, read_in_binary_mode=False):
1655
+ """
1656
+ Description:
1657
+ Function to get the file content from a file, given absolute
1658
+ file path.
1659
+
1660
+ PARAMETERS:
1661
+ file_path:
1662
+ Required Argument.
1663
+ Specifies absolute file path of the file.
1664
+ Types: str
1665
+
1666
+ read_in_binary_mode:
1667
+ Optional Argument.
1668
+ Specifies whether to read the file in binary format or not.
1669
+ If True, read the file in binary mode.
1670
+ If False, read the file in ASCII mode.
1671
+ Default value: False
1672
+ Types: bool
1673
+
1674
+ RETURNS:
1675
+ str OR bytes
1676
+
1677
+ RAISES:
1678
+ TeradataMlException
1679
+
1680
+ EXAMPLES:
1681
+ obj = UtilFuncs._get_file_contents("/abc/xyz.txt")
1682
+ obj = UtilFuncs._get_file_contents("/abc/xyz.txt", True)
1683
+ """
1684
+ try:
1685
+ mode = 'r'
1686
+ if read_in_binary_mode:
1687
+ mode = 'rb'
1688
+ with open(file_path, mode) as file_data:
1689
+ _Validators._check_empty_file(file_path)
1690
+ return file_data.read()
1691
+ except TeradataMlException:
1692
+ raise
1693
+ except FileNotFoundError:
1694
+ raise
1695
+ except Exception as err:
1696
+ msg_code = MessageCodes.EXECUTION_FAILED
1697
+ raise TeradataMlException(
1698
+ Messages.get_message(msg_code, "read contents of file '{}'".format(file_path), str(err)), msg_code)
1699
+
1700
+ @staticmethod
1701
+ def _create_table_using_table_object(table_obj):
1702
+ """
1703
+ DESCRIPTION:
1704
+ This function creates the table in Vantage using table object.
1705
+
1706
+ PARAMETERS:
1707
+ table_obj:
1708
+ Specifies the table object.
1709
+ Types: sqlalchemy.sql.schema.Table
1710
+
1711
+ RETURNS:
1712
+ None.
1713
+
1714
+ RAISES:
1715
+ TeradataMlException
1716
+
1717
+ EXAMPLES:
1718
+ from sqlalchemy import Table, MetaData, Column
1719
+
1720
+ meta = MetaData()
1721
+ # Create default Table construct with parameter dictionary
1722
+ table_obj = Table(table_name, meta,
1723
+ *(Column(col_name, col_type)
1724
+ for col_name, col_type in
1725
+ zip(col_names, col_types)),
1726
+ teradatasql_post_create=pti,
1727
+ prefixes=prefix,
1728
+ schema=schema_name
1729
+ )
1730
+
1731
+ _create_table_using_table_object(table_obj)
1732
+ """
1733
+ if table_obj is not None:
1734
+ try:
1735
+ table_obj.create(bind=tdmlctx.get_context())
1736
+ except sqlachemyOperationalError as err:
1737
+ raise TeradataMlException(Messages.get_message(MessageCodes.TABLE_OBJECT_CREATION_FAILED) +
1738
+ '\n' + str(err),
1739
+ MessageCodes.TABLE_OBJECT_CREATION_FAILED)
1740
+ else:
1741
+ raise TeradataMlException(Messages.get_message(MessageCodes.TABLE_OBJECT_CREATION_FAILED),
1742
+ MessageCodes.TABLE_OBJECT_CREATION_FAILED)
1743
+
1744
+ @staticmethod
1745
+ def _extract_table_object_column_info(table_obj):
1746
+ """
1747
+ Internal function to extract the column name and column types from
1748
+ table object.
1749
+
1750
+ PARAMETERS:
1751
+ table_obj:
1752
+ Required Argument.
1753
+ Specifies the table object.
1754
+ Types: sqlalchemy.sql
1755
+
1756
+ RETURNS:
1757
+ Tuple
1758
+
1759
+ RAISES:
1760
+ None
1761
+
1762
+ EXAMPLE:
1763
+ meta = MetaData()
1764
+ table = Table(table_name, meta, schema=schema_name, autoload_with=eng)
1765
+ _extract_table_object_column_info(table.c)
1766
+ """
1767
+ col_names = []
1768
+ col_types = []
1769
+
1770
+ for col in table_obj:
1771
+ col_names.append(col.name)
1772
+ col_types.append(col.type)
1773
+
1774
+ return col_names, col_types
1775
+
1776
+ @staticmethod
1777
+ def _get_warnings(argument_name, argument_value, specified_argument_name, specified_argument_value):
1778
+ """
1779
+ Internal function to print the warning.
1780
+
1781
+ PARAMETERS:
1782
+ argument_name:
1783
+ Required Argument.
1784
+ Specifies the argument name to check.
1785
+ Types: str
1786
+
1787
+ argument_value:
1788
+ Required Argument.
1789
+ Specifies the argument value to check.
1790
+ Types: bool
1791
+
1792
+ specified_argument_name:
1793
+ Required Argument.
1794
+ Specifies the argument name to use in warning message.
1795
+ Types: str
1796
+
1797
+ specified_argument_value:
1798
+ Required Argument.
1799
+ Specifies the argument value to use in warning message.
1800
+ Types: str
1801
+
1802
+ RETURNS:
1803
+ None
1804
+
1805
+ RAISES:
1806
+ None
1807
+
1808
+ EXAMPLE:
1809
+ _get_warnings(argument_name, argument_value, specified_argument_name, specified_argument_value)
1810
+ """
1811
+ if argument_value:
1812
+ warnings.warn(Messages.get_message(MessageCodes.IGNORE_ARGS_WARN,
1813
+ '{0}',
1814
+ "{1}='{2}'",
1815
+ 'specified').format(argument_name,
1816
+ specified_argument_name,
1817
+ specified_argument_value))
1818
+
1819
+ @staticmethod
1820
+ def _get_sqlalchemy_table(table_name, schema_name=None, check_table_exists=False):
1821
+ """
1822
+ Internal function returns the SQLAlchemy table object for a table.
1823
+ If check_table_exists specified, function also checks for table existence.
1824
+
1825
+ PARAMETERS:
1826
+ table_name:
1827
+ Required Argument.
1828
+ Specifies the table name.
1829
+ Types: str
1830
+
1831
+ schema_name:
1832
+ Optional Argument.
1833
+ Specifies schema name.
1834
+ Types: str
1835
+
1836
+ check_table_exists:
1837
+ Optional Argument.
1838
+ Specifies whether to check table exists or not.
1839
+ Default Value: False
1840
+ Types: bool
1841
+
1842
+ RETURNS:
1843
+ sqlalchemy.sql.schema.Table
1844
+
1845
+ RAISES:
1846
+ None
1847
+
1848
+ EXAMPLE:
1849
+ _get_sqlalchemy_table(table_name='my_table')
1850
+ """
1851
+ con = tdmlctx.get_connection()
1852
+
1853
+ if check_table_exists:
1854
+ table_exists = con.dialect.has_table(con, table_name, schema_name)
1855
+
1856
+ if not table_exists:
1857
+ raise TeradataMlException(Messages.get_message(MessageCodes.TABLE_DOES_NOT_EXIST, table_name),
1858
+ MessageCodes.TABLE_DOES_NOT_EXIST)
1859
+
1860
+ meta = MetaData()
1861
+ return Table(table_name, meta,
1862
+ schema=schema_name,
1863
+ autoload_with=tdmlctx.get_context())
1864
+
1865
+ @staticmethod
1866
+ def _extract_table_object_index_info(table_obj):
1867
+ """
1868
+ Internal function to extract primary index information of existing table.
1869
+
1870
+ PARAMETERS:
1871
+ table_obj:
1872
+ Required Argument.
1873
+ Specifies the sqlalchemy table object.
1874
+ Types: sqlalchemy.sql.schema.Table.
1875
+
1876
+ RETURNS:
1877
+ list.
1878
+
1879
+ RAISES:
1880
+ None.
1881
+
1882
+ EXAMPLE:
1883
+ _extract_table_object_index_info(table_object)
1884
+ """
1885
+ sqlalchemy_table_primary_index = table_obj.indexes
1886
+ primary_index_list = []
1887
+ for index in sqlalchemy_table_primary_index:
1888
+ primary_index_list = index.columns.keys()
1889
+ return primary_index_list
1890
+
1891
+ @staticmethod
1892
+ def _get_positive_infinity():
1893
+ """
1894
+ Description:
1895
+ Function to get the positive infinity.
1896
+
1897
+ RETURNS:
1898
+ float
1899
+
1900
+ RAISES:
1901
+ None
1902
+
1903
+ EXAMPLES:
1904
+ inf = UtilFuncs._get_positive_infinity()
1905
+ """
1906
+ return float("inf")
1907
+
1908
+ @staticmethod
1909
+ def _get_negative_infinity():
1910
+ """
1911
+ Description:
1912
+ Function to get the negative infinity.
1913
+
1914
+ RETURNS:
1915
+ float
1916
+
1917
+ RAISES:
1918
+ None
1919
+
1920
+ EXAMPLES:
1921
+ inf = UtilFuncs._get_negative_infinity()
1922
+ """
1923
+ return -1 * UtilFuncs._get_positive_infinity()
1924
+
1925
+ @staticmethod
1926
+ def _get_class(class_name, supress_isinstance_check=False):
1927
+ """
1928
+ Description:
1929
+ Function to get the class dynamically with the name as 'class_name'.
1930
+
1931
+ PARAMETERS:
1932
+ class_name:
1933
+ Required Parameter.
1934
+ Specifies the name of the class generated to be.
1935
+ Types: str
1936
+
1937
+ supress_isinstance_check:
1938
+ Optional Parameter.
1939
+ Specifies whether the dynamically created class should overwrite the
1940
+ isinstance method or not. When set to True, if the class generated from
1941
+ this function is passed to isinstance method, instead of verifying the
1942
+ actual type, it tries to match the name of object's class with 'class_name'.
1943
+ Default value: False
1944
+ Types: bool
1945
+
1946
+ RETURNS:
1947
+ type
1948
+
1949
+ RAISES:
1950
+ None
1951
+
1952
+ EXAMPLES:
1953
+ inf = UtilFuncs._get_class("test")
1954
+ """
1955
+ parent_object = object
1956
+ if supress_isinstance_check:
1957
+
1958
+ # isinstance function is governed by the dunder method __instancecheck__.
1959
+ # However, unlike other dunder method's, __instancecheck__ should be overwritten
1960
+ # for a class, instead of object ,i.e., while creating the class itself, __instancecheck__
1961
+ # should be overwritten.
1962
+ # Note that, python's type accepts either object or any other class as a parent class.
1963
+ # Since, other than object, one should pass only a class to a python type, creating a
1964
+ # dummy class and specifying the metaclass as SupressInstanceCheck so that the dummy class
1965
+ # has updated __instancecheck__ dunder method.
1966
+ class SupressInstanceCheck(type):
1967
+ def __instancecheck__(self, instance):
1968
+ try:
1969
+ return self.__name__ == instance.__class__.__name__
1970
+ except Exception:
1971
+ return False
1972
+
1973
+ class temp(metaclass=SupressInstanceCheck):
1974
+ pass
1975
+
1976
+ parent_object = temp
1977
+
1978
+ return type(class_name, (parent_object, ), {})
1979
+
1980
+ @staticmethod
1981
+ def _get_file_size(file_path, in_mb=True):
1982
+ """
1983
+ Description:
1984
+ Function to get the size of file, given absolute file path.
1985
+
1986
+ PARAMETERS:
1987
+ file_path:
1988
+ Required Argument.
1989
+ Specifies absolute file path of the file.
1990
+ Types: str
1991
+
1992
+ in_mb:
1993
+ Optional Argument.
1994
+ Specifies whether to get the file size in mega bytes or not.
1995
+ If True, size of the file returns in MB's. Otherwise, returns
1996
+ in bytes.
1997
+ Default value: True
1998
+ Types: bool
1999
+
2000
+ RETURNS:
2001
+ int OR float
2002
+
2003
+ RAISES:
2004
+ TeradataMlException
2005
+
2006
+ EXAMPLES:
2007
+ file_size = UtilFuncs._get_file_size("/abc/xyz.txt")
2008
+ """
2009
+ size_in_bytes = os.path.getsize(file_path)
2010
+
2011
+ return size_in_bytes/(1024*1024.0) if in_mb else size_in_bytes
2012
+
2013
+ @staticmethod
2014
+ def _http_request(url, method_type=HTTPRequest.GET, **kwargs):
2015
+ """
2016
+ Description:
2017
+ Function to initiate HTTP(S) request.
2018
+
2019
+ PARAMETERS:
2020
+ url:
2021
+ Required Argument.
2022
+ Specifies the url to initiate http request.
2023
+ Types: str
2024
+
2025
+ method_type:
2026
+ Optional Argument.
2027
+ Specifies the type of HTTP request.
2028
+ Default value: HTTPREquest.GET
2029
+ Types: HTTPRequest enum
2030
+
2031
+ **kwargs:
2032
+ Specifies the keyword arguments required for HTTP Request.
2033
+ Below are the expected arguments as a part of kwargs:
2034
+ json:
2035
+ Optional Argument.
2036
+ Specifies the payload for HTTP request in a dictionary.
2037
+ Types: dict
2038
+
2039
+ data:
2040
+ Optional Argument.
2041
+ Specifies the payload for HTTP request in a string format.
2042
+ Types: str
2043
+
2044
+ headers:
2045
+ Optional Argument.
2046
+ Specifies the headers for HTTP request.
2047
+ Types: dict
2048
+
2049
+ verify:
2050
+ Optional Argument.
2051
+ Specifies whether to verify the certificate or not in a HTTPS request.
2052
+ One can specify either False to suppress the certificate verification or
2053
+ path to certificate to verify the certificate.
2054
+ Types: str OR bool
2055
+
2056
+ files:
2057
+ Optional Argument.
2058
+ Specifies the file to be uploaded with a HTTP Request.
2059
+ Types: tuple
2060
+
2061
+ RETURNS:
2062
+ Response object.
2063
+
2064
+ RAISES:
2065
+ None
2066
+
2067
+ EXAMPLES:
2068
+ resp = UtilFuncs._http_request("http://abc/xyz.teradata")
2069
+ """
2070
+ kwargs["verify"] = configure.certificate_file
2071
+
2072
+ if not configure.certificate_file:
2073
+ warnings.filterwarnings("ignore", message="Unverified HTTPS request is being made to host[ a-zA-Z0-9'-.]*")
2074
+
2075
+ return getattr(requests, method_type.value)(url=url, **kwargs)
2076
+
2077
+ @staticmethod
2078
+ def _get_tdml_directory():
2079
+ """
2080
+ DESCRIPTION:
2081
+ Function to get the directory of teradataml module.
2082
+
2083
+ PARAMETERS:
2084
+ None.
2085
+
2086
+ RETURNS:
2087
+ str.
2088
+
2089
+ EXAMPLES:
2090
+ >>> tdml_path = UtilFuncs._get_tdml_directory()
2091
+ """
2092
+ # Get the directory of teradataml module.
2093
+ return os.path.dirname(_version.__file__)
2094
+
2095
+ @staticmethod
2096
+ def _get_data_directory(dir_name=None, func_type=None, version=None):
2097
+ """
2098
+ DESCRIPTION:
2099
+ Function to get the directory for jsons or docs from teradataml/data.
2100
+
2101
+ PARAMETERS:
2102
+ dir_name:
2103
+ Optional Argument.
2104
+ Specifies the name of directory required from teradataml/data directory.
2105
+ Permitted values : ["jsons", "docs"]
2106
+ Types: str
2107
+
2108
+ func_type
2109
+ Optional Argument.
2110
+ Specifies the type of function for which jsons or docs directory is required.
2111
+ Types: TeradataAnalyticFunctionInfo
2112
+
2113
+ version:
2114
+ Optional Argument.
2115
+ Specifies the version of directory for which jsons or docs directory is required.
2116
+ Types: str
2117
+
2118
+ RETURNS:
2119
+ path to desired directory.
2120
+
2121
+ EXAMPLES:
2122
+ >>> json_dir = UtilFuncs._get_data_directory(dir_name="jsons",
2123
+ ... func_type=TeradataAnalyticFunctionInfo.FASTPATH,
2124
+ ... version="17.10")
2125
+
2126
+ """
2127
+ if func_type:
2128
+ func_type = func_type.value["func_type"]
2129
+ dir_path = os.path.join(UtilFuncs._get_tdml_directory(), "data")
2130
+ levels = [dir_name, func_type, version]
2131
+ for level in levels:
2132
+ if level:
2133
+ dir_path = os.path.join(dir_path, level)
2134
+ else:
2135
+ break
2136
+ if os.path.exists(dir_path):
2137
+ return dir_path
2138
+
2139
+ @staticmethod
2140
+ def _replace_special_chars(str_value, replace_char="_", addon=None):
2141
+ """
2142
+ DESCRIPTION:
2143
+ Function to replace any special character with a underscore(_).
2144
+
2145
+ PARAMETERS:
2146
+ str_value:
2147
+ Required Argument.
2148
+ Specifies the value of string which has special characters.
2149
+ Types: str
2150
+
2151
+ replace_char:
2152
+ Optional Argument.
2153
+ Specifies the value to be replaced for any special character.
2154
+ Types: str
2155
+
2156
+ addon
2157
+ Optional Argument.
2158
+ Specifies a dictionary with key as value to be checked in "s" and value
2159
+ to be replaced in "s".
2160
+ Types: dict
2161
+
2162
+ RETURNS:
2163
+ str
2164
+
2165
+ EXAMPLES:
2166
+ >>> json_dir = UtilFuncs._replace_special_chars("123$%.", addon={"$": "#"})
2167
+ """
2168
+ char_dict = {'A': 'A',
2169
+ 'B': 'B',
2170
+ 'C': 'C',
2171
+ 'D': 'D',
2172
+ 'E': 'E',
2173
+ 'F': 'F',
2174
+ 'G': 'G',
2175
+ 'H': 'H',
2176
+ 'I': 'I',
2177
+ 'J': 'J',
2178
+ 'K': 'K',
2179
+ 'L': 'L',
2180
+ 'M': 'M',
2181
+ 'N': 'N',
2182
+ 'O': 'O',
2183
+ 'P': 'P',
2184
+ 'Q': 'Q',
2185
+ 'R': 'R',
2186
+ 'S': 'S',
2187
+ 'T': 'T',
2188
+ 'U': 'U',
2189
+ 'V': 'V',
2190
+ 'W': 'W',
2191
+ 'X': 'X',
2192
+ 'Y': 'Y',
2193
+ 'Z': 'Z',
2194
+ 'a': 'a',
2195
+ 'b': 'b',
2196
+ 'c': 'c',
2197
+ 'd': 'd',
2198
+ 'e': 'e',
2199
+ 'f': 'f',
2200
+ 'g': 'g',
2201
+ 'h': 'h',
2202
+ 'i': 'i',
2203
+ 'j': 'j',
2204
+ 'k': 'k',
2205
+ 'l': 'l',
2206
+ 'm': 'm',
2207
+ 'n': 'n',
2208
+ 'o': 'o',
2209
+ 'p': 'p',
2210
+ 'q': 'q',
2211
+ 'r': 'r',
2212
+ 's': 's',
2213
+ 't': 't',
2214
+ 'u': 'u',
2215
+ 'v': 'v',
2216
+ 'w': 'w',
2217
+ 'x': 'x',
2218
+ 'y': 'y',
2219
+ 'z': 'z',
2220
+ '0': '0',
2221
+ '1': '1',
2222
+ '2': '2',
2223
+ '3': '3',
2224
+ '4': '4',
2225
+ '5': '5',
2226
+ '6': '6',
2227
+ '7': '7',
2228
+ '8': '8',
2229
+ '9': '9'}
2230
+ char_dict.update({" ": "", "_": "_", "\"": ""})
2231
+ if addon:
2232
+ char_dict.update(addon)
2233
+ return reduce(lambda x,y: x+y, (char_dict.get(c, replace_char) for c in str_value))
2234
+
2235
+ @staticmethod
2236
+ def _get_dict_from_libs(lib_name):
2237
+ """
2238
+ DESCRIPTION:
2239
+ Function to format the list of library version string to a dictionary,
2240
+ on the basis of regex.
2241
+
2242
+ PARAMETERS:
2243
+ lib_name:
2244
+ Required Argument.
2245
+ Specifies the libs the user wants to format to a dictionary with
2246
+ key as lib_name and value as lib_version.
2247
+ Types: str, list of str
2248
+
2249
+ RETURNS:
2250
+ dict
2251
+ """
2252
+ result = {}
2253
+ if isinstance(lib_name, str):
2254
+ lib_name = UtilFuncs._as_list(lib_name)
2255
+ for lib in lib_name:
2256
+ matches = re.findall(r'([^<>=]+)([<>=].*)', lib)
2257
+ if matches:
2258
+ for key, value in matches:
2259
+ result[key] = value
2260
+ else:
2261
+ result[lib] = ''
2262
+ return result
2263
+
2264
+ @staticmethod
2265
+ def _is_valid_td_type(type_):
2266
+ """
2267
+ DESCRIPTION:
2268
+ Function to check whether it is valid teradatasqlalchemy type or not.
2269
+
2270
+ PARAMETERS:
2271
+ type_:
2272
+ Required Argument.
2273
+ Specifies any value which needs to be validated for teradatasqlalchemy type.
2274
+ Types: Any python object
2275
+
2276
+ RETURNS:
2277
+ bool
2278
+ """
2279
+ if isinstance(type_, _TDType):
2280
+ return True
2281
+ if isinstance(type_, type) and issubclass(type_, _TDType):
2282
+ return True
2283
+ return False
2284
+
2285
+ @staticmethod
2286
+ def _all_df_column_expressions(df_column):
2287
+ """
2288
+ DESCRIPTION:
2289
+ A method to get all the SQLALchemy Columns involved in corresponding DataFrame.
2290
+
2291
+ PARAMETERS:
2292
+ df_column:
2293
+ Required Argument.
2294
+ Specifies teradataml DataFrame ColumnExpression.
2295
+ Types: teradataml DataFrame ColumnExpression
2296
+
2297
+ RAISES:
2298
+ None
2299
+
2300
+ RETURNS:
2301
+ list
2302
+
2303
+ EXAMPLES:
2304
+ >>> self._all_df_column_expressions
2305
+ """
2306
+ cols = []
2307
+ for table_ in df_column._get_sqlalchemy_tables(df_column.expression):
2308
+ cols = cols + list(table_.columns)
2309
+ return cols
2310
+
2311
+ @staticmethod
2312
+ def _all_df_columns(df_column):
2313
+ """
2314
+ DESCRIPTION:
2315
+ A method to get all the column names involved in corresponding DataFrame.
2316
+
2317
+ PARAMETERS:
2318
+ df_column:
2319
+ Required Argument.
2320
+ Specifies teradataml DataFrame ColumnExpression.
2321
+ Types: teradataml DataFrame ColumnExpression
2322
+
2323
+ RAISES:
2324
+ None
2325
+
2326
+ RETURNS:
2327
+ list
2328
+
2329
+ EXAMPLES:
2330
+ >>> self._all_df_columns
2331
+ """
2332
+ return [col.name for col in UtilFuncs._all_df_column_expressions(df_column)]
2333
+
2334
+ @staticmethod
2335
+ def _is_lake():
2336
+ """
2337
+ DESCRIPTION:
2338
+ An internal function to check whether system is Lake or enterprise.
2339
+
2340
+ PARAMETERS:
2341
+ None.
2342
+
2343
+ RAISES:
2344
+ None
2345
+
2346
+ RETURNS:
2347
+ bool
2348
+
2349
+ EXAMPLES:
2350
+ >>> self._is_lake()
2351
+ """
2352
+
2353
+ from teradataml.context.context import _get_database_version
2354
+ return int(_get_database_version().split(".")[0]) >= 20
2355
+
2356
+ @staticmethod
2357
+ def _get_python_execution_path():
2358
+ """
2359
+ DESCRIPTION:
2360
+ An internal function to get the python execution path.
2361
+
2362
+ PARAMETERS:
2363
+ None.
2364
+
2365
+ RAISES:
2366
+ None
2367
+
2368
+ RETURNS:
2369
+ bool
2370
+
2371
+ EXAMPLES:
2372
+ >>> self._get_python_execution_path()
2373
+ """
2374
+
2375
+ if UtilFuncs._is_lake():
2376
+ return "python"
2377
+ else:
2378
+ if configure.indb_install_location == "/var/opt/teradata/languages/sles12sp3/Python/":
2379
+ return '{}bin/python3'.format(configure.indb_install_location)
2380
+ else:
2381
+ return configure.indb_install_location
2382
+
2383
+ def _is_view(tablename):
2384
+ """
2385
+ DESCRIPTION:
2386
+ Internal function to check whether the object is view or not.
2387
+ PARAMETERS:
2388
+ tablename:
2389
+ Required Argument.
2390
+ Table name or view name to be checked.
2391
+ Types: str
2392
+ RAISES:
2393
+ None.
2394
+ RETURNS:
2395
+ True when the tablename is view, else false.
2396
+ EXAMPLES:
2397
+ >>> _is_view('"dbname"."tablename"')
2398
+ """
2399
+ db_name = UtilFuncs._teradata_unquote_arg(UtilFuncs._extract_db_name(tablename), "\"")
2400
+ table_view_name = UtilFuncs._teradata_unquote_arg(UtilFuncs._extract_table_name(tablename), "\"")
2401
+ query = SQLBundle._build_select_table_kind(db_name, "{0}".format(table_view_name), "'V'")
2402
+
2403
+ df = UtilFuncs._execute_query(query)
2404
+ if len(df) > 0:
2405
+ return True
2406
+ else:
2407
+ return False
2408
+ @staticmethod
2409
+ def _set_queryband():
2410
+ try:
2411
+ qb_query = get_qb_query()
2412
+ execute_sql(qb_query)
2413
+ except Exception:
2414
+ pass
2415
+
2416
+
2417
+ from teradataml.common.aed_utils import AedUtils
2418
+ from teradataml.dbutils.filemgr import remove_file