install_file | Script Method | 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 method to install or replace script on Vantage.

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_name specifies the name of the file user wants to install.
Optional arguments:
  • is_binary specifies if the file to be installed is a binary file.
  • force_replace specifies if system should check for the file being used before replacing it:
    • If set to True, then the file is replaced even if it is being executed.
    • If set to False, then an error is thrown if it is being executed.
File can be on client or remote server. The file location should be specified accordingly.

Example 1: Install a file found at the relative path using default text mode

To run this example, "mapper.py" is required on client at the path specified by argument file_local_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))
  • Set the search path to the database where the file is installed.
    >>> get_context().execute("SET SESSION SEARCHUIFDBPATH = <database name>;")
  • Import required packages.
    >>> from collections import OrderedDict
    >>> from teradatasqlalchemy import (VARCHAR)
  • Create a Script object that allows user to run script on Vantage.
    >>> sto = Script(data=barrierdf,
                script_name='mapper.py',
                files_local_path= 'data/scripts',
                script_command='python3 ./<database name>/mapper.py',
                data_order_column="Id",
                is_local_order=False
                delimiter=',',
                nulls_first=False,
                sort_ascending=False,
                charset='latin', returns=OrderedDict([("word", VARCHAR(15)), ("count_input", VARCHAR(2))])
                )
  • Install the file on Vantage.
    >>> sto.install_file(file_identifier='mapper', file_name='mapper.py', is_binary=False)
    File mapper.py installed in Vantage
  • After making changes to the file "mapper.py", user can use the install_file method with "replace=True" to replace the existing file with the new file.
    >>> sto.install_file(file_identifier='mapper', file_name='mapper.py', is_binary=False, replace=True, force_replace=True)
    File mapper.py replaced in Vantage

Example 2: Install a file found at the relative path using binary mode

>>> sto.install_file (file_identifier='binaryfile', file_name='binary_file.dms', is_binary = True)
File binary_file.dms installed in Vantage