tdr.GetAttributeByNdx Function | R Table Operators | Teradata Vantage - 17.10 - tdr.GetAttributeByNdx - Advanced SQL Engine - Teradata Database

Teradata Vantageā„¢ - SQL External Routine Programming

Advanced SQL Engine
Teradata Database
Release Number
Release Date
July 2021
Content Type
Programming Reference
Publication ID
English (United States)
Returns one of the following attributes from the current input stream row:
  • A list representing the selected attribute value. This list consists of the following three elements:
    • value
    • nullindicator
    • length

    If nullindicator has a value of -1, the attribute is NULL.

    The type of value depends on the attribute type. See Mapping Between Teradata Data Types and R Types for a mapping from Teradata attribute types into R types.

  • NULL if there is an error.
    Error conditions include the following:
    • The handle is associated with an output stream.
    • The input stream is not open.
    • The index is not valid.
    • The coldef list contains an invalid data type or an incomplete set of attributes for that data type.
    • The attribute is not of type list.
    • This function was called from the contract function.


tdr.GetAttributeByNdx(  handle,  index,  coldef)

Syntax Elements

Parameter type: raw vector

The handle of the input stream returned by the tdr.Open function.

Parameter type: integer

The index of an attribute. The valid range is from 0 to n-1, where n is the number of attributes in the stream. Index 0 indicates the first attribute.

Parameter type: list

The schema of a stream. This schema is a list with the number of columns and the definition of each column. Each definition includes the column information for the data type of that specific column. This is the return value of a call to the tdr.GetColDef function.

If coldef is NULL, the function will retrieve the coldef information.

Usage Notes

The coldef parameter can be used to improve performance. By passing the coldef information to the function, the function does not have to retrieve it on each call. However, you can optionally pass NULL instead and the function will retrieve the coldef information by itself.

Before you call this function, you must call the tdr.Open function to open the input stream. Then pass the handle returned from tdr.Open as an argument to this function.

This function is valid only if called from the table operator.

Example: Retrieve the First Attribute From Rows in the Input Stream

# Open the input stream.
stream <- 0;
options <- 0;
direction <- "R";
inHandle <- tdr.Open(direction, stream, options);

# A data frame is created with the retrieved attributes.

mydataframe <- data.frame();
while (tdr.Read(inHandle) == 0) {
  att <- tdr.GetAttributeByNdx(inHandle, 0, NULL);
  newrow <- data.frame(att$value);
  mydataframe <- rbind(mydataframe, newrow);

Consider an input stream with a row whose first attribute is of type INTEGER with a value of 11. Object att for this row would be the following list:

[1] 4
[1] 11
[1] 0

Attribute value is an integer.

The previous example can optionally be written to pass the coldef information to the tdr.GetAttributeByNdx function. This would improve performance.

mydataframe <- data.frame();
coldef <- tdr.GetColDef(streamno, direction);
while (tdr.Read(inHandle) == 0) {
  att <- tdr.GetAttributeByNdx(inHandle, 0, coldef);
  newrow <- data.frame(att$value);
  mydataframe <- rbind(mydataframe, newrow);