Table of Contents

Search

  1. Preface
  2. The Transformation Language
  3. Constants
  4. Operators
  5. Variables
  6. Dates
  7. Functions

Transformation Language Reference

Transformation Language Reference

Subscript Operator

Subscript Operator

Use a subscript operator to access elements in an array or a map. You can access a specific element or a range of elements in an array. You can access the value corresponding to a given key in a key-value pair of a map.

Syntax

To access a specific element in an array, use the following syntax:
array[ index ]
To access a range of elements in an array, use the following syntax:
array[ start_index , end_index ]
To access the value corresponding to a given key in a map, use the following syntax:
map[ key ]
The following table describes the arguments in the syntax:
Argument
Description
array
Array. The array from which you want to access one or more elements.
You can enter any valid transformation expression that evaluates to an array.
index
Integer. The position of the element that you want to access. For example, an index of 0 indicates the first element in an array.
start_index
Integer. The starting index in a range of elements that you want to access. The subscript operator includes the element that the starting index represents.
end_index
Integer. The ending index in a range of elements that you want to access. The subscript operator excludes the element that the ending index represents.
map
Map. The map from which you want to retrieve the value corresponding to a key.
key
Data type of the key. The key element for which you want to retrieve the value.
You can enter any valid transformation expression that evaluates to a key value of the map data.
You can use an expression for the index that returns an integer value. If the expression returns a negative value, the index is considered to be 0.
If the specified index is greater than the size of the array minus 1, the index accesses the final element in the array.

Return Value

If you specify an index, the expression returns the element in the array. The return type is the same as the data type of the element in the specified array.
If you specify two indices separated by a comma, such as
[i,j]
, the expression returns an array of the elements from
i
to
j-1
. If
i
is greater than
j
or the size of the array, the expression returns an empty array. The type configuration of the subarray that the expression returns is the same as the type configuration of the specified array.
If you specify a key, the expression returns the value associated with the key in the map. The return type is the same as the data type of the value in the specified map.

Nulls

If the index in the subscript is greater than the size of the array, the subscript operator returns a NULL value.
If the index is NULL, the subscript operator returns a NULL value. If you specify multiple indices such as
[i,j]
and either
i
or
j
is NULL, the expression returns NULL.
If the array is NULL, the subscript operator returns a NULL value.
If the key does not exist in the map, the subscript operator returns a NULL value.

Examples

You have the following array with string elements:
drinks = [‘milk’, ‘coffee’, ‘tea’, ‘chai’]
The following expressions use a subscript operator to access string elements from the array:
Input Value
RETURN VALUE
drinks[0]
'milk'
drinks[2]
'tea'
drinks[NULL]
NULL
drinks[1,3]
['coffee','tea']
drinks[2,NULL]
NULL
drinks[3,1]
[ ]
You have the following map with key-value elements of type string-string:
country_currency = [‘England’ -> ‘Pound’, ‘France’ -> ‘Euro’, ‘Japan’ -> ‘Yen’>, ‘USA’ -> ‘Dollar’]
Input Value
RETURN VALUE
country_currency [‘Japan’]
‘Yen’
country_currency [‘India’]
NULL
country_currency [‘England’]
‘Pound’

0 COMMENTS

We’d like to hear from you!