Teradata R Package Function Reference | 17.00 - 17.00 - td_test_script - Teradata R Package

Teradata® R Package Function Reference

prodname
Teradata R Package
vrm_release
17.00
created_date
September 2020
category
Programming Reference
featnum
B700-4007-090K

Description

This function enables the user to run script in docker container environment outside Vantage. Input data for user script is read from file or Vantage.

Usage

## S3 method for class 'ScriptTableOperator'
td_test_script(
  object = NULL,
  files.local.path = NULL,
  script.name = NULL,
  input.data.file = NULL,
  supporting.files = NULL,
  script.args = NULL,
  ...
)

Arguments

object

Required Argument.
Specifies the ScriptTableOperator object containing the details that are needed for testing user script.

files.local.path

Required Argument.
Specifies the absolute local path where user script (specified in the argument "script.name"), all supporting files like model files (specified in the argument "supporting.files"), and input data file (specified in the argument "input.data.file") reside.
Types: character

script.name

Required Argument.
Specifies the name of the user script.
It should have a path relative to the location specified in "files.local.path" argument.
Types: character

input.data.file

Optional Argument.
Specifies the name of the input data file.
It should have a path relative to the location specified in "files.local.path" argument.
If this argument is not provided, data is read from AMP in the database. The data is taken from the "data" argument of ScriptTableOperator object.
Default Value: NULL
Types: character

supporting.files

Optional Arguument.
Specifies one or more supporting files like model files to be copied to the container. These files should have a path relative to the location specified in "files.local.path" argument.
Default Value: NULL
Types: character OR vector of characters

script.args

Optional Argument.
Specifies command line arguments required by the user script.
Default Value: NULL
Types: character

...

Specifies the arguments used for reading data from all AMPs.
The following are the valid argument names:

  1. data.row.limit: Specifies the number of rows to be taken from all AMPs when reading from a table or view on Vantage.
    Default Value: 1000
    Types: integer

  2. password: Specifies the password to connect to Vantage where the data resides.
    Types: character

Any other arguments, if provided, are ignored.

Value

A R data.frame containing the output of user script.

See Also

td_setup_test_env, Script

Examples

# Replace "<tdplyr_install_location>" with the absolute path of the install location of the
# tdplyr library. One can get this location using '.libPaths()'.
# Make sure to include 'tdplyr' in the path. For example, <r_pkg_install_location>/tdplyr.
tdplyr_install_location <- "<tdplyr_install_location>"

# Replace "<schema_name>" with the name of the schema to search the file for.
schema_name <- "<schema_name>"

# Replace "<path_to_docker_image>" with the local path to the downloaded docker image file.
docker_image_location <- "<path_to_docker_image>"

# Replace "<password>" with the password of the user to fetch data from Vantage.
password <- "<password>"

script_command <- gettextf("Rscript ./%s/mapper.R", schema_name)

# Get remote data source connection.
con <- td_get_context()$connection

# Load example data.
loadExampleData("script_example", "barrier")

# Create object(s) of class "tbl_teradata".
barrier <- tbl(con, "barrier")

# Create a ScriptTableOperator object that allows us to execute user script in Vantage.
script_obj <- Script(data = barrier %>% select(Name),
                     script.command = script_command,
                     returns = list("word"= "VARCHAR(15)", "count_input"= "VARCHAR(2)")
                     )

## Run the user script locally within docker container using data from csv file.

# Setup the environment by providing path to the docker image file.
td_setup_test_env(docker.image.location = docker_image_location)


# Example 1: Test user script mentioned in the argument "script.name" using the data
# provided in the argument "input.data.file".
td_test_script(object = script_obj,
               files.local.path = file.path(tdplyr_install_location, "scripts"),
               script.name = "mapper.R",
               input.data.file = "barrier.csv"
               )

# Example 2: Test user script mentioned in the argument "script.name" using the data
# from AMPs in the database.
td_test_script(object = script_obj,
               files.local.path = file.path(tdplyr_install_location, "scripts"),
               script.name = "mapper.R",
               password = password
               )