install_file() | Database Utilities | Teradata Python Package - install_file() - Teradata Package for Python

Teradata® Package for Python User Guide

Product
Teradata Package for Python
Release Number
17.00
Published
November 2021
Language
English (United States)
Last Update
2022-01-14
dita:mapPath
bol1585763678431.ditamap
dita:ditavalPath
ayr1485454803741.ditaval
dita:id
B700-4006
lifecycle
previous
Product Category
Teradata Vantage

Use the install_file() function to install or replace external language script or model files in Vantage. On success, it prints a message confirming that file is installed or replaced.

Installed language script can be executed using execute_script method in Script.

Required arguments:
  • file_identifier specifies the name associated with the user-installed file. It cannot have a database name associated with it, as the file is always installed in the current database. The name should be unique within the database. It can be any valid Teradata identifier.
  • file_path specifies the absolute or relative path of the file (including file name) to be installed. This file is identified in Vantage by file_identifier.
    File can be on client or remote server. The file location should be specified accordingly.
Optional arguments:
  • file_on_client specifies whether the file is present on client or at remote location on Vantage. The default value is True, which means on client. Set to False if the file to be installed is present at remote location on Vantage.
  • is_binary specifies if the file to be installed is a binary file.
  • replace specifies if the file is to be installed or replaced.
    • If set to True: the file is replaced based on value of force_replace;
    • If set to False: the file is installed.
  • force_replace specifies if system should check for the file being used before replacing it:
    • If set to True: the file is replaced even if it is being executed.
    • If set to False: an error is thrown if it is being executed.
    This argument is ignored if replace is set to False.

Example 1: Install a file using default text mode

To run this example, "mapper.py" is required on client at the path specified by argument file_path.
  • Create the "mapper.py" file:
    #!/usr/bin/python
    import sys
    for line in sys.stdin:
        line = line.strip()
        words = line.split()
        for word in words:
            print ('%s\t%s' % (word, 1))
  • Install the file:
    >>> install_file (file_identifier='mapper', file_path='data/scripts/mapper.py')
    File mapper.py installed in Vantage

Example 2: Install a file using binary mode

>>> install_file (file_identifier='binaryfile', file_path='data/scripts/binary_file.dms', file_on_client = True, is_binary = True)
File binary_file.dms installed in Vantage

Example 3: Replace a file with another one using default text mode

This example replaces the file 'mapper.py' with 'mapper_replace.py' found at the relative path using the default text mode.

To run this example, "mapper_replace.py" is required on client at the path specified by argument file_path.
  • Create the "mapper_replace.py" file:
    #!/usr/bin/python
    import sys
    for line in sys.stdin:
        line = line.strip()
        words = line.split()
        for newword in words:
            print ('%s,%s' % (newword, 1))
  • Replace the existing file with the new file:
    >>> install_file (file_identifier='mapper', file_path='data/scripts/mapper_replace.py', file_on_client=True, is_binary= False, replace=True, force_replace=True)
    File mapper_replace.py replaced in Vantage