Teradata Package for Python Function Reference on VantageCloud Lake - install_file - 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 on VantageCloud Lake
- Deployment
- VantageCloud
- Edition
- Lake
- 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_Lake_2000
- Product Category
- Teradata Vantage
- teradataml.table_operators.Apply.install_file = install_file(self, file_name, replace=False)
- DESCRIPTION:
Function to install script in remote user environment specified in env_name
argument of an Apply class object.
On success, prints a message that file is installed or replaced.
This language script can be executed via execute_script() function.
PARAMETERS:
file_name:
Required Argument:
Specifies the name of the file including file extension to be installed
or replaced.
Note:
File names are case sensitive.
Types: str
replace:
Optional Argument.
Specifies if the file is to be installed or replaced.
Default Value: False
Types: bool
RETURNS:
True, if successful.
RAISES:
TeradataMLException, SqlOperationalError
EXAMPLES:
# Example 1: Install the file mapper.py found at the relative path data/scripts/ using
# the default text mode.
# In order to run example 1, "mapper.py" is required to be present on client.
# Provide the path of "mapper.py" in "file_path" argument.
# Create a file named "mapper.py" with content as follows:
-----------------------------------------------------------
#!/usr/bin/python
import sys
for line in sys.stdin:
line = line.strip()
words = line.split()
for word in words:
print ('%s %s' % (word, 1))
------------------------------------------------------------
# Create teradataml DataFrame objects.
>>> barrierdf = DataFrame.from_table("barrier")
# Create remote user environment.
>>> from teradataml import create_env
>>> test_env = create_env('test_env', 'python_3.7.9', 'Demo environment')
User environment testenv created.
>>> import teradataml, os
>>> teradataml_dir = os.path.dirname(teradataml.__file__)
# Create an Apply object that allows user to execute script using Open Analytics Framework.
>>> apply_obj = Apply(data=barrierdf,
files_local_path='data/scripts/',
script_name='mapper.py',
apply_command='python3 mapper.py',
data_order_column="Id",
env_name=test_env,
returns={"word": VARCHAR(15), "count_input": VARCHAR(2)}
)
# Install file in remote user environment.
>>> apply_obj.install_file(file_name='mapper.py')
File 'mapper.py' installed successfully in the remote user environment 'test_env'.
# Replace file in remote user environment.
>>> apply_obj.install_file(file_name='mapper.py', replace=True)
File 'mapper.py' replaced successfully in the remote user environment 'test_env'.