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

SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-24
dita:mapPath
qwr1571437338192.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1147
lifecycle
previous
Product Category
Teradata Vantage™

Purpose

Retrieves an individual attribute from the current input stream row.

Syntax

tdr.GetAttributeByNdx(  handle,  index,  coldef)
handle
Parameter type: raw vector

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

index
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.

coldef
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.

Return Value

This function returns one of the following results:
  • 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.

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.
library(tdr);
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:

$length
[1] 4
$value
[1] 11
$nullIndicator
[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);
}