17
Utility functions The following table lists the functions available in the Utility category (square brackets indicate an argument is optional): Name Description Arguments Output GetEnvironme nt Returns the value of the given environment variable environment variable (string) result (strin g) NextSKChain Returns the value of the surrogate key column for the next record in the chain, or value for the newest record value (number) result (int64 ) NextSurrogat eKey Returns the value of the next surrogate key None result (int64 ) PrevSKChain Returns the value of the surrogate key column for the previous record in the chain, or value for the first record value (number) result (int64 ) Type "casting" functions There is a special class of type conversion function to help you when performing mathematical calculations using numeric fields. For example, if you have a calculation using an output column of type float derived from an input column of type integer in a Parallel Transformer stage the result will be derived as an integer regardless of its float type. If you want a non-integral result for a calculation using integral operands, you can use the following functions (which act in a similar way as casting in C) to cast the integer operands into non-integral operands:

Transformer Functions

Embed Size (px)

Citation preview

Page 1: Transformer Functions

Utility functionsThe following table lists the functions available in the Utility category (square brackets indicate an argument is optional):

Name Description Arguments Output

GetEnvironment Returns the value of the given environment variable

environment variable (string)

result (string)

NextSKChain Returns the value of the surrogate key column for the next record in the chain, or value for the newest record

value (number) result (int64)

NextSurrogateKey Returns the value of the next surrogate key None result (int64)

PrevSKChain Returns the value of the surrogate key column for the previous record in the chain, or value for the first record

value (number) result (int64)

Type "casting" functionsThere is a special class of type conversion function to help you when performing mathematical calculations using numeric fields. For example, if you have a calculation using an output column of type float derived from an input column of type integer in a Parallel Transformer stage the result will be derived as an integer regardless of its float type. If you want a non-integral result for a calculation using integral operands, you can use the following functions (which act in a similar way as casting in C) to cast the integer operands into non-integral operands:

Name Description Arguments Output

AsDouble Treat the given number as a double number (number) number (double)

AsFloat Treat the given number as a float number (number) number (float)

AsInteger Treat the given number as an integer number (number) number (int)

Type Conversion FunctionsThe following table lists the functions available in the Type Conversion category (square brackets indicate an argument is optional):

Name Description Arguments Output

DateToString Return the string representation of the date result

Page 2: Transformer Functions

Name Description Arguments Output

given date

[format (string)]

(string)

DecimalToDecimal Returns the given decimal in decimal representation with specified precision and scale

decimal (decimal) [rtype (string)] [packedflag (int8)]

result (decimal)

DecimalToDFloat Returns the given decimal in dfloat representation

number (decimal) ["fix_zero"]

result (dfloat)

DecimalToString Return the string representation of the given decimal

number (decimal) ["fix_zero"]

result (string)

DfloatToDecimal Returns the given dfloat in decimal representation

number (dfloat) [rtype (string)]

result (decimal)

DfloatToStringNoExp Returns the given dfloat in its string representation with no exponent, using the specified scale

number (dfloat) scale (string)

result (string)

IsValid Return whether the given string is valid for the given type. Valid types are "date", "decimal", "dfloat", "sfloat", "int8", "uint8", "int16", "uint16", "int32", "uint32", "int64", "uint64", "raw", "string", "time", "timestamp". "ustring"

type (string) format (string)

result (int8)

StringToDate Returns a date from the given string in the given format

date (string)

format (string)

date

StringToDecimal Returns the given string in decimal representation

string (string) [rtype (string)]

result (decimal)

StringToRaw Returns a string in raw representation string (string) result (raw)

StringToTime Returns a time representation of the given string

string (string) [format (string)]

time

StringToTimestamp Returns a timestamp representation of the given string

string (string) [format (string)]

timestamp

Page 3: Transformer Functions

Name Description Arguments Output

TimestampToDate Returns a date from the given timestamp timestamp date

TimestampToString Return the string representation of the given timestamp

timestamp [format (string)]

result (string)

TimestampToTime Returns the time from a given timestamp timestamp time

TimeToString Return the string representation of the given time

time [format (string)]

result (string)

StringToUstring Returns a ustring from the given string, optionally using the specified map (otherwise uses project default)

string (string) [,mapname (string)]

result (ustring)

UstringToString Returns a string from the given ustring, optionally using the specified map (otherwise uses project default)

string(ustring)

[,mapname (string)]

result (string)

Rtype. The rtype argument is a string, and should contain one of the following:

ceil. Round the source field toward positive infinity. E.g, 1.4 -> 2, -1.6 -> -1. floor. Round the source field toward negative infinity. E.g, 1.6 -> 1, -1.4 -> -2. round_inf. Round or truncate the source field toward the nearest representable value,

breaking ties by rounding positive values toward positive infinity and negative values toward negative infinity. E.g, 1.4 -> 1, 1.5 -> 2, -1.4 -> -1, -1.5 -> -2.

trunc_zero. Discard any fractional digits to the right of the rightmost fractional digit supported in the destination, regardless of sign. For example, if the destination is an integer, all fractional digits are truncated. If the destination is another decimal with a smaller scale, round or truncate to the scale size of the destination decimal. E.g, 1.6 -> 1, -1.6 -> -1.

The default is trunc_zero.

Format string. Date, Time, and Timestamp functions that take a format string (e.g., timetostring(time, stringformat)) need to have the date format specified. The format strings are described in Date and time formats.

Where your dates, times, or timestamps convert to or from ustrings, WebSphere DataStage will pick this up automatically. In these cases the separators in your format string (for example, `:' or `-') can themselves be Unicode characters.

fix_zero. By default decimal numbers comprising all zeros are treated as invalid. If the string fix_zero is specified as a second argument, then all zero decimal values are regarded as valid.

Page 4: Transformer Functions

String functionsThe following table lists the functions available in the String category (square brackets indicate an argument is optional):

Name Description Arguments Output

AlNum Return whether the given string consists of alphanumeric characters

string (string) true/false (int8)

Alpha Returns 1 if string is purely alphabetic

string (string) result (int8)

CompactWhiteSpace Return the string after reducing all consective whitespace to a single space

string (string) result (string)

Compare Compares two strings for sorting string1 (string)

string2 (string)

[justification (L or R)]

result (int8)

ComparNoCase Case insensitive comparison of two strings

string1 (string) string2 (string)

result (int8)

ComparNum Compare the first n characters of the two strings

string1 (string) string2 (string)

length (int16)

result (int8)

CompareNumNoCase Caseless comparison of the first n characters of the two strings

string1 (string) string2 (string)

length (int16)

result (int8)

Convert Converts specified characters in a string to designated replacement characters

fromlist (string)

tolist (string)

expression (string)

result (string)

Count Count number of times a substring occurs in a string

string (string)

substring (string)

result (int32)

Dcount Count number of delimited fields in a string

string (string)

delimiter (string)

result (int32)

DownCase Change all uppercase letters in a string to lowercase

string (string) result (string)

Page 5: Transformer Functions

Name Description Arguments Output

DQuote Enclose a string in double quotation marks

string (string) result (string)

Field Return 1 or more delimited substrings

string (string) delimiter (string)

occurrence (int32) [number (int32)]

result (string)

Index Find starting character position of substring

string (string) substring (string) occurrence (int32)

result (int32)

Left Leftmost n characters of string string (string)

number (int32)

result (string)

Len Length of string in characters string (string) result (int32)

Num Return 1 if string can be converted to a number

string (string) result (int8)

PadString Return the string padded with the optional pad character and optional length

string (string)

padlength (int32)

result (string)

Right Rightmost n characters of string string (string)

number (int32)

result (string)

Soundex Returns a string which identifies a set of words that are (roughly) phonetically alike based on the standard, open algorithm for SOUNDEX evaluation

string (string) result (string)

Space Return a string of N space characters length (int32) result (string)

Squote Enclose a string in single quotation marks

string (string) result (string)

Str Repeat a string string (string)

repeats (int32)

result (string)

StripWhiteSpace Return the string after stripping all whitespace from it

string (string) result (string)

Trim Remove all leading and trailing spaces and tabs plus reduce internal occurrences to one

string (string) [stripchar (string)] [options (string)]

result (string)

Page 6: Transformer Functions

Name Description Arguments Output

TrimB Remove all trailing spaces and tabs string (string) result (string)

TrimF Remove all leading spaces and tabs string (string) result (string)

Trim Leading Trailing

Returns a string with leading and trailing whitespace removed

string (string) result (string)

Upcase Change all lowercase letters in a string to uppercase

string (string) result (string)

true = 1

false = 0

Possible options for the Trim function are:

L Removes leading occurrences of character. T Removes trailing occurrences of character. B Removes leading and trailing occurrences of character. R Removes leading and trailing occurrences of character, and reduces multiple

occurrences to a single occurrence. A Removes all occurrences of character. F Removes leading spaces and tabs. E Removes trailing spaces and tabs. D Removes leading and trailing spaces and tabs, and reduces multiple spaces and tabs

to single ones.

Date and time functionsThe following table lists the functions that are available in the Date and Time category (Square brackets indicate an argument is optional):

Name Description Arguments Output

DateFromDaysSince Returns a date by adding an integer to a baseline date

number (int32) [baseline date]

date

DateFromJulianDay Returns a date from the given julian date

juliandate (uint32) date

DaysSinceFromDate Returns the number of days from source date to the given date

source_date

given_date

days since (int32)

HoursFromTime Returns the hour time hours (int8)

Page 7: Transformer Functions

Name Description Arguments Output

portion of a time

JulianDayFromDate Returns julian day from the given date

date julian date (int32)

MicroSecondsFromTime Returns the microsecond portion from a time

time microseconds (int32)

MinutesFromTime Returns the minute portion from a time

time minutes (int8)

MonthDayFromDate Returns the day of the month given the date

date day (int8)

MonthFromDate Returns the month number given the date

date month number (int8)

NextWeekdayFromDate Returns the date of the specified day of the week soonest after the source date

source date

day of week (string)

date

PreviousWeekdayFromDate Returns the date of the specified day of the week most recent before the source date

source date

day of week (string)

date

SecondsFromTime Returns the second portion from a time

time seconds (dfloat)

SecondsSinceFromTimestamp Returns the number of seconds between two timestamps

timestamp base timestamp

seconds (dfloat)

TimeDate Returns the system time and date as a formatted string

- system time and date (string)

TimeFromMidnightSeconds Returns the time given the number of seconds since midnight

seconds (dfloat) time

TimestampFromDateTime Returns a timestamp form the given date and time

date time timestamp

TimestampFromSecondsSince Returns the timestamp from the number of seconds

seconds (dfloat)

[base timestamp]

timestamp

Page 8: Transformer Functions

Name Description Arguments Output

from the base timestamp

TimestampFromTimet Returns a timestamp from the given unix time_t value

timet (int32) timestamp

TimetFromTimestamp Returns a unix time_t value from the given timestamp

timestamp timet (int32)

WeekdayFromDate Returns the day number of the week from the given date. Origin day optionally specifies the day regarded as the first in the week and is Sunday by default

date [origin day] day (int8)

YeardayFromDate Returns the day number in the year from the given date

date day (int16)

YearFromDate Returns the year from the given date

date year (int16)

YearweekFromDate Returns the week number in the year from the given date

date week (int16)

Date, Time, and Timestamp functions that specify dates, times, or timestamps in the argument use strings with specific formats:

For a date, the format is %yyyy-%mm-%dd

For a time, the format is %hh:%nn:%ss, or, if extended to include microseconds, %hh:%nn:%ss.x where x gives the number of decimal places seconds is given to.

For a timestamp the format is %yyyy-%mm-%dd %hh:%nn:%ss, or, if extended to include microseconds, %yyyy-%mm-%dd %hh:%nn:%ss.x where x gives the number of decimal places seconds is given to.

This applies to the arguments date, baseline date, given date, time, timestamp, and base timestamp.

Functions that have days of week in the argument take a string specifying the day of the week, this applies to day of week and origin day.

Page 9: Transformer Functions

Date and time formats Parallel jobs provide flexible handling of date and time formats.

Logical FunctionsThe following table lists the functions available in the Logical category (square brackets indicate an argument is optional):

Name Description Arguments Output

Not Returns the complement of the logical value of an expression

expression Complement (int8)

BitAnd Returns the bitwise AND of the two integer arguments

number 1 (uint64) number 2 (uint64)

number (uint64)

BitOr Returns the bitwise OR of the two integer arguments

number 1 (uint64) number 2 (uint64)

number (uint64)

BitXOr Returns the bitwise Exclusive OR of the two integer arguments

number 1 (uint64) number 2 (uint64)

number (uint64)

BitExpand Returns a string containing the binary representation in "1"s and "0"s of the given integer

number (uint64) string

BitCompress Returns the integer made from the string argument, which contains a binary representation of "1"s and "0"s.

number (string) number (uint64)

SetBit Returns an integer with specific bits set to a specific state, where

origfield is the input value to perform the action on,

bitlist is a string containing a list of comma separated bit numbers to set the state of, and bitstate is either 1 or 0, indicating which state to set those bits.

origfield (uint64) bitlist (string)

bitstate (uint8)

number (uint64)

Page 10: Transformer Functions

Null handling functionsThe following table lists the functions available in the Null Handling category (square brackets indicate an argument is optional):

Name Description Arguments Output

IsNotNull Returns true when an expression does not evaluate to the null value

any true/false (int8)

IsNull Returns true when an expression evaluates to the null value

any true/false (int8)

MakeNull Change an in-band null to out of band null any (column)

string (string)

-

NullToEmpty Returns an empty string if input column is null, otherwise returns the input column value

input column input column value or empty string

NullToZero Returns zero if input column is null, otherwise returns the input column value

input column input column value or zero

NullToValue Returns specified value if input column is null, otherwise returns the input column value

input column, value

input column value or value

SetNull Assign a null value to the target column - -

true = 1

false = 0

Number functionsThe following table lists the functions available in the Number category (square brackets indicate an argument is optional):

Name Description Arguments Output

MantissaFromDecimal Returns the mantissa from the given decimal

number (decimal)

result (dfloat)

Page 11: Transformer Functions

Name Description Arguments Output

MantissaFromDFloat Returns the mantissa from the given dfloat number (dfloat) result (dfloat)

Raw functionsThe following table lists the functions available in the Raw category (square brackets indicate an argument is optional):

Name Description Arguments Output

RawLength Returns the length of a raw string input string (raw) Result (int32)

Vector functionThe following function can be used within expressions to access an element in a vector column. The vector index starts at 0.

Name Description Arguments Output

ElementAt Accesses an element of a vector input column index (int) element of vector

This can be used as part of, or the whole of an expression. For example, an expression to add 1 to the third element of an vector input column 'InLink.col1' would be:

ElementAt(InLink.col1, 2) + 1