Teradata Package for R Function Reference | 17.00 - td_set_data - 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
Set data

Description

This function enables the user to set data and data related arguments without having to re-create ScriptTableOperator object.
Note:

  • All data related arguments that are not specified in this function are reset to default values.

Usage

## S3 method for class 'ScriptTableOperator'
td_set_data(
  object = NULL,
  data = NULL,
  data.hash.column = NULL,
  data.partition.column = NULL,
  data.order.column = NULL,
  is.local.order = FALSE,
  sort.ascending = TRUE,
  nulls.first = TRUE,
  ...
)

Arguments

object

Required Argument.
Specifies the ScriptTableOperator object containing the details.

data

Required Argument.
Specifies the tbl_teradata containing the input for the script.
Default Value: NULL
Types: tbl_teradata

data.hash.column

Optional Argument.
Specifies the input tbl_teradata column to be used for hashing.
The rows in the data are redistributed to AMPs based on the hash value of the column specified. The user-installed script file then runs once on each AMP.
Note:

  • This argument cannot be specified along with the arguments "data.partition.column" and "data.order.column".

Default Value: NULL
Types: character

data.partition.column

Optional Argument.
Specifies Partition By columns for "data".
Values to this argument can be provided as a vector, if multiple columns are used for partition.
Note:

  1. This argument cannot be specified along with "data.hash.column" argument.

  2. This argument cannot be specified when the argument "is.local.order" is set to TRUE.

  3. If this argument is not specified, then the entire result set, delivered by the function, constitutes a single group or partition.

Permitted Values: "ANY" OR one or more columns in "data" tbl_teradata.
Default Value: NULL
Types: character OR vector of characters

data.order.column

Optional Argument.
Specifies Order By columns for "data".
Values to this argument can be provided as a vector, if multiple columns are used for ordering.
The column(s) mentioned in the argument is/are used in ordering irrespective of whether the argument "is.local.order" is set to TRUE or not.
Note:

  • This argument cannot be specified along with the argument "data.hash.column".

Default Value: NULL
Types: character OR vector of characters

is.local.order

Optional Argument.
Specifies whether the input data is to be ordered locally or not. When set to TRUE, the data is ordered locally.
Order by (Vs) Local Order by:

  • Order by: Specifies the order in which the values in a group, or partition, are sorted.

  • Local Order by: Orders qualified rows on each AMP in preparation to be input to a table function.

Note:

  1. This argument is ignored if the argument "data.order.column" is not specified or NULL.

  2. When this argument is specified, the argument "data.order.column" should be specified and the column(s) specified in "data.order.column" is/are used for local ordering.

Default Value: FALSE
Types: logical

sort.ascending

Optional Argument.
Specifies whether to sort the result set in ascending or descending order using columns specified in "data.order.column" argument.
The sorting is ascending when this argument is set to TRUE, descending otherwise.
Note:

  • This argument is ignored if the argument "data.order.column" is not specified.

Default Value: TRUE
Types: logical

nulls.first

Optional Argument.
Specifies whether the result set containing NULL values are to be listed first during ordering.
NULLs are listed first when this argument is set to TRUE, otherwise NULLs are listed last.
Default Value: TRUE
Types: logical

...

Any other optional arguments, if required.

Value

A named list of "ScriptTableOperator" class.

See Also

td_setup_sandbox_env, td_test_script, td_execute_script

Examples


# Note: Refer to Teradata Package for R User Guide for setting search path
#       and required permissions.

# 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>"

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(script.command = script_command,
                     charset = "LATIN",
                     returns = list("word"= "VARCHAR(15)",
                                    "count_input"= "VARCHAR(2)")
                     )

# 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,
               script.name = "mapper.R",
               files.local.path = file.path(tdplyr_install_location,
                                            "scripts"),
               input.data.file = "barrier.csv"
               )

# Now in order to test/run script using actual data on Vantage user can set
# data and related arguments without recreating ScriptTableOperator object.
script_obj <- td_set_data(object = script_obj,
                          data = barrier %>% select(Name)
                          )

# Run the td_execute_script() function to execute the script on Vantage or
# td_test_script() to test the script in the sandbox.