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