setup_sto_env | Script Method | Teradata Python Package - setup_sto_env - 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 setup_sto_env method to load already downloaded sandbox image. See Script for details about sandbox environment.

Teradata recommends using setup_sandbox_env() function available from teradataml 17.00.00.02, instead of this setup_sto_env method from previous release.

The setup_sto_env method features only one argument: docker_image_location. This required argument specifies the location of the sandbox image on user's system.

Example

To run this example, "mapper.py" and "barrier.csv" are required and must be present under the same location specified by the argument files_local_path.
  • "barrier.csv" is present under <teradataml_install_location>/teradataml/data directory.
  • "mapper.py" can be created as follows:
    #!/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))
  • Load example data.
    >>> load_example_data("Script", ["barrier"])
  • Import required packages.
    >>> from collections import OrderedDict
    >>> from teradatasqlalchemy import (VARCHAR)
  • Create teradataml DataFrame.
    >>> barrierdf = DataFrame.from_table("barrier")
  • Create a Script object 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))])
                )
  • Run the script locally within Docker container using data from csv.

    This helps users to fix script level issues outside Vantage.

    >>> sto.setup_sto_env(docker_image_location='/tmp/sto_sandbox_docker_image.tar'))
    Loading image from /tmp/sto_sandbox_docker_image.tar. It may take few minutes.
    Image loaded successfully.
    Starting a container for stosandbox:1.0 image.
    Container c1dd4d4b722cc54b643ab2bdc57540a3a3e6db98c299defc672227de97d2c345 started successfully.