Description
The function enables the user to run script in docker container environment
outside Vantage.
Note:
It is the responsibility of the user to make sure the docker environment is present in the client machine.
Input data for user script is read from file or Vantage.
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
.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. |
files.local.path |
Required Argument. |
script.name |
Required Argument. |
input.data.file |
Optional Argument. |
supporting.files |
Optional Arguument. |
script.args |
Optional Argument. |
exec.mode |
Optional Argument. |
... |
Specifies the arguments used for reading data from all AMPs and
arguments to specify different types of logon mechanisms.
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
)