Teradata Package for Python Function Reference | 20.00 - deploy - Teradata Package for Python - Look here for syntax, methods and examples for the functions included in the Teradata Package for Python.
Teradata® Package for Python Function Reference - 20.00
- Deployment
- VantageCloud
- VantageCore
- Edition
- Enterprise
- IntelliFlex
- VMware
- Product
- Teradata Package for Python
- Release Number
- 20.00.00.03
- Published
- December 2024
- ft:locale
- en-US
- ft:lastEdition
- 2024-12-19
- dita:id
- TeradataPython_FxRef_Enterprise_2000
- lifecycle
- latest
- Product Category
- Teradata Vantage
- teradataml.table_operators.Script.deploy = deploy(self, model_column, partition_columns=None, model_file_prefix=None, retry=3, retry_timeout=30)
- DESCRIPTION:
Function deploys the models generated after running `execute_script()` in database in
VantageCloud Enterprise or in user environment in VantageCloud Lake.
If deployed files are not needed, these files can be removed using `remove_file()` in
database or `UserEnv.remove_file()` in lake.
Note:
If the models (one or many) fail to get deployed in Vantage even after retries,
try deploying them again using `install_file()` function or remove installed
files using `remove_file()` function.
PARAMETERS:
model_column:
Required Argument.
Specifies the column name in which models are present.
Supported types of model in this column are CLOB and BLOB.
Note:
The column mentioned in this argument should be present in
<apply_obj/script_obj>.result.
Types: str
partition_columns:
Optional Argument.
Specifies the columns on which data is partitioned.
Note:
The columns mentioned in this argument should be present in
<apply_obj/script_obj>.result.
Types: str OR list of str
model_file_prefix:
Optional Argument.
Specifies the prefix to be used to the generated model file.
If this argument is None, prefix is auto-generated.
If the argument "model_column" contains multiple models and
* "partition_columns" is None - model file prefix is appended with
underscore(_) and numbers starting from one(1) to get model file
names.
* "partition_columns" is NOT None - model file prefix is appended
with underscore(_) and unique values in partition_columns are joined
with underscore(_) to generate model file names.
Types: str
retry:
Optional Argument.
Specifies the maximum number of retries to be made to deploy the models.
This argument helps in retrying the deployment of models in case of network issues.
This argument should be a positive integer.
Default Value: 3
Types: int
retry_timeout:
Optional Argument. Used along with retry argument. Ignored otherwise.
Specifies the time interval in seconds between each retry.
This argument should be a positive integer.
Default Value: 30
Types: int
RETURNS:
List of generated file identifiers in database or file names in lake.
RAISES:
- TeradatamlException
- Throws warning when models failed to deploy even after retries.
EXAMPLES:
>>> import teradataml
>>> from teradataml import load_example_data
>>> load_example_data("openml", "multi_model_classification")
>>> df = DataFrame("multi_model_classification")
>>> df
col2 col3 col4 label group_column partition_column_1 partition_column_2
col1
-1.013454 0.855765 -0.256920 -0.085301 1 9 0 10
-3.146552 -1.805530 -0.071515 -2.093998 0 10 0 10
-1.175097 -0.950745 0.018280 -0.895335 1 10 0 11
0.218497 -0.968924 0.183037 -0.303142 0 11 0 11
-1.471908 -0.029195 -0.166141 -0.645309 1 11 1 10
1.082336 0.846357 -0.012063 0.812633 1 11 1 11
-1.132068 -1.209750 0.065422 -0.982986 0 10 1 10
-0.440339 2.290676 -0.423878 0.749467 1 8 1 10
-0.615226 -0.546472 0.017496 -0.488720 0 12 0 10
0.579671 -0.573365 0.160603 0.014404 0 9 1 10
## Run in VantageCloud Enterprise using Script object.
# Install Script file.
>>> file_location = os.path.join(os.path.dirname(teradataml.__file__), "data", "scripts", "deploy_script.py")
>>> install_file("deploy_script", file_location, replace=True)
>>> execute_sql("SET SESSION SEARCHUIFDBPATH = <db_name>;")
# Variables needed for Script execution.
>>> from teradataml import configure
>>> script_command = f'{configure.indb_install_location} ./<db_name>/deploy_script.py enterprise'
>>> partition_columns = ["partition_column_1", "partition_column_2"]
>>> columns = ["col1", "col2", "col3", "col4", "label",
"partition_column_1", "partition_column_2"]
>>> returns = OrderedDict([("partition_column_1", INTEGER()),
("partition_column_2", INTEGER()),
("model", CLOB())])
# Script execution.
>>> obj = Script(data=df.select(columns),
script_command=script_command,
data_partition_column=partition_columns,
returns=returns
)
>>> opt = obj.execute_script()
>>> opt
partition_column_1 partition_column_2 model model
0 10 b'gAejc1.....drIr'
0 11 b'gANjcw.....qWIu'
1 10 b'abdwcd.....dWIz'
1 11 b'gA4jc4.....agfu'
# Example 1: Provide only "partition_columns" argument. Here, "model_file_prefix"
# is auto generated.
>>> obj.deploy(model_column="model",
partition_columns=["partition_column_1", "partition_column_2"])
['model_file_1710436227163427__0_10',
'model_file_1710436227163427__1_10',
'model_file_1710436227163427__0_11',
'model_file_1710436227163427__1_11']
# Example 2: Provide only "model_file_prefix" argument. Here, filenames are suffixed
# with 1, 2, 3, ... for multiple models.
>>> obj.deploy(model_column="model", model_file_prefix="my_prefix_new_")
['my_prefix_new__1',
'my_prefix_new__2',
'my_prefix_new__3',
'my_prefix_new__4']
# Example 3: Without both "partition_columns" and "model_file_prefix" arguments.
>>> obj.deploy(model_column="model")
['model_file_1710438346528596__1',
'model_file_1710438346528596__2',
'model_file_1710438346528596__3',
'model_file_1710438346528596__4']
# Example 4: Provide both "partition_columns" and "model_file_prefix" arguments.
>>> obj.deploy(model_column="model", model_file_prefix="my_prefix_new_",
partition_columns=["partition_column_1", "partition_column_2"])
['my_prefix_new__0_10',
'my_prefix_new__0_11',
'my_prefix_new__1_10',
'my_prefix_new__1_11']
# Example 5: Assuming that 2 model files fail to get installed due to network issues,
# the function retries installing the failed files twice with timeout between
# retries of 10 secs.
>>> opt = obj.deploy(model_column="model", model_file_prefix="my_prefix_",
partition_columns=["partition_column_1", "partition_column_2"],
retry=2, retry_timeout=10)
RuntimeWarning: The following model files failed to get installed in Vantage:
['my_prefix__1_10', 'my_prefix__1_11'].
Try manually deploying them from the path '<temp_path>' using:
- `install_file()` when connected to Enterprise/On-Prem system or
- `UserEnv.install_file()` when connected to Lake system.
OR
Remove the returned installed files manually using `remove_file()` or `UserEnv.remove_file()`.
>>> opt
['my_prefix__0_10',
'my_prefix__0_11']
## Run in VantageCloud Lake using Apply object.
# Let's assume an user environment named "user_env" already exists in VantageCloud Lake,
# which will be used for the examples below.
# ApplyTableOperator returns BLOB type for model column as per deploy_script.py.
>>> returns = OrderedDict([("partition_column_1", INTEGER()),
("partition_column_2", INTEGER()),
("model", BLOB())])
# Install the script file which returns model and partition columns.
>>> user_env.install_file(file_location)
>>> script_command = 'python3 deploy_script.py lake'
>>> obj = Apply(data=df.select(columns),
script_command=script_command,
data_partition_column=partition_columns,
returns=returns,
env_name="user_env"
)
>>> opt = obj.execute_script()
>>> opt
partition_column_1 partition_column_2 model model
0 10 b'gAejc1.....drIr'
0 11 b'gANjcw.....qWIu'
1 10 b'abdwcd.....dWIz'
1 11 b'gA4jc4.....agfu'
# Example 6: Provide both "partition_columns" and "model_file_prefix" arguments.
>>> obj.deploy(model_column="model", model_file_prefix="my_prefix_",
partition_columns=["partition_column_1", "partition_column_2"])
['my_prefix__0_10',
'my_prefix__0_11',
'my_prefix__1_10',
'my_prefix__1_11']
# Other examples are similar to the examples provided for VantageCloud Enterprise.