Teradata Package for R Function Reference | 17.00 - td_test_script - Teradata Package for R - Look here for syntax, methods and examples for the functions included in the Teradata Package for R.

Teradata® Package for R Function Reference

Product
Teradata Package for R
Release Number
17.00
Published
July 2021
Language
English (United States)
Last Update
2023-08-08
dita:id
B700-4007
NMT
no
Product Category
Teradata Vantage
Test user script

Description

The function enables the user to run script in docker container environment outside Vantage.

Note:

  1. It is the responsibility of the user to make sure the docker environment is present in the client machine.

  2. Input data for user script is read from file or Vantage.

  3. The function uses the container in the option 'sandbox.container'. If this option is NULL, either set this option or run the function td_setup_sandbox_env.

  4. quotechar functionality is not implemented in the function yet.

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,
  exec.mode = "sandbox",
  ...
)

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

exec.mode

Optional Argument.
Specifies the mode in which user wants to test the script. If set to 'sandbox', the user script will run within the sandbox environment, else it will run locally on user's system. Permitted Values: 'sandbox', 'local' Default Value: 'sandbox' Types: character

...

Specifies the arguments used for reading data from all AMPs and arguments to specify different types of logon mechanisms.
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

  3. data.file.delimiter: Specifies the delimiter used in the input data file. This argument can be specified when data is read from file.
    Default Value: ',' Types: character

  4. data.file.header: Specifies whether the input data file contains header. This argument can be specified when data is read from file.
    Default Value: TRUE
    Types: logical

  5. logmech: Specifies the type of logon mechanism to establish a connection to Teradata Vantage.
    Permitted Values: 'TD2', 'TDNEGO', 'LDAP', 'KRB5' & 'JWT'
    Default Value: TD2
    Types: character

    • TD2: The Teradata 2 (TD2) mechanism provides authentication using a Vantage username and password.

    • TDNEGO: A security mechanism that automatically determines the actual mechanism required, based on policy, without user's involvement. The actual mechanism is determined by the TDGSS server configuration and by the security policy's mechanism restrictions.

    • LDAP: A directory-based user logon to Vantage with a directory username and password and is authenticated by the directory.

    • KRB5 (Kerberos): A directory-based user logon to Vantage with a domain username and password and is authenticated by Kerberos.
      Note: User must have a valid ticket-granting ticket in order to use this logon mechanism.

    • JWT: The JSON Web Token (JWT) authentication mechanism enables single sign-on (SSO) to the Vantage after the user successfully authenticates to Teradata UDA User Service.
      Note: User must use logdata parameter when using 'JWT' as the logon mechanism.

    Note: tdplyr expects the client environments are already setup with appropriate security mechanisms and are in working conditions.
    For more information please refer Teradata Vantage™ - Advanced SQL Engine Security Administration at https://www.info.teradata.com/

  6. logdata: Specifies parameters to the LOGMECH command beyond those needed by the logon mechanism, such as user ID, password and tokens (in case of JWT) to successfully authenticate the user.
    Types: character

Any other arguments, if provided, are ignored.

Value

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

See Also

td_setup_sandbox_env, Script, td_cleanup_sandbox_env, td_copy_files_from_container

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_sandbox_env(docker.image.location = docker_image_location,
                     docker.image.name = "rstosandbox:1.0")


# 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
               )
# Example 3: Test user script mentioned in the argument "script.name" using 
# the data provided in the argument "input.data.file" in local environment.
td_test_script(object = script_obj,
               exec.mode = "local",
               files.local.path = file.path(tdplyr_install_location, 
                                            "scripts"),
               script.name = "mapper.R",
               input.data.file = "barrier.csv"
               )

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