Functions Library

Mathematical Functions

The following built-in mathematical functions are supported in Transformation; most return NULL when the argument(s) are NULL:

Mathematical Functions

Return Type

Name (Signature)

Description

DOUBLE

round(DOUBLE a)

Returns the rounded BIGINT value of a.

DOUBLE

round(DOUBLE a, INT d)

Returns a rounded to d decimal places.

DOUBLE

bround(DOUBLE a)

Returns the rounded BIGINT value of a using HALF_EVEN rounding mode. Also known as Gaussian rounding or bankers' rounding. Example: bround(2.5) = 2, bround(3.5) = 4.

DOUBLE

bround(DOUBLE a, INT d)

Returns a rounded to d decimal places using HALF_EVEN rounding mode. Example: bround(8.25, 1) = 8.2, bround(8.35, 1) = 8.4.

BIGINT

floor(DOUBLE a)

Returns the maximum BIGINT value that is equal to or less than a.

BIGINT

ceil(DOUBLE a), ceiling(DOUBLE a)

Returns the minimum BIGINT value that is equal to or greater than a.

DOUBLE

rand(), rand(INT seed)

Returns a random number (that changes from row to row) that is distributed uniformly from 0 to - Specifying the seed will make sure the generated random number sequence is deterministic.

DOUBLE

exp(DOUBLE a), exp(DECIMAL a)

Returns e^a where e is the base of the natural logarithm.

DOUBLE

ln(DOUBLE a), ln(DECIMAL a)

Returns the natural logarithm of the argument a.

DOUBLE

log10(DOUBLE a), log10(DECIMAL a)

Returns the base-10 logarithm of the argument a.

DOUBLE

log2(DOUBLE a), log2(DECIMAL a)

Returns the base-2 logarithm of the argument a.

DOUBLE

log(DOUBLE base, DOUBLE a) log(DECIMAL base, DECIMAL a)

Returns the base-base logarithm of the argument a.

DOUBLE

pow(DOUBLE a, DOUBLE p), power(DOUBLE a, DOUBLE p)

Returns a^p.

DOUBLE

sqrt(DOUBLE a), sqrt(DECIMAL a)

Returns the square root of a.

STRING

bin(BIGINT a)

Returns the number in binary format

STRING

hex(BIGINT a) hex(STRING a) hex(BINARY a)

If the argument is an INT or binary, hex returns the number as a STRING in hexadecimal format. Otherwise if the number is a STRING, it converts each character into its hexadecimal representation and returns the resulting STRING.

BINARY

unhex(STRING a)

Inverse of hex. Interprets each pair of characters as a hexadecimal number and converts to the byte representation of the number.

STRING

conv(BIGINT num, INT from<i>base, INT to</i>base), conv(STRING num, INT from<i>base, INT to</i>base)

Converts a number from a given base to another

DOUBLE

abs(DOUBLE a)

Returns the absolute value.

INT or DOUBLE

pmod(INT a, INT b), pmod(DOUBLE a, DOUBLE b)

Returns the positive value of a mod b.

DOUBLE

sin(DOUBLE a), sin(DECIMAL a)

Returns the sine of a (a is in radians).

DOUBLE

asin(DOUBLE a), asin(DECIMAL a)

Returns the arc sin of a if -1<=a<=1 or NULL otherwise.

DOUBLE

cos(DOUBLE a), cos(DECIMAL a)

Returns the cosine of a (a is in radians).

DOUBLE

acos(DOUBLE a), acos(DECIMAL a)

Returns the arccosine of a if -1<=a<=1 or NULL otherwise.

DOUBLE

tan(DOUBLE a), tan(DECIMAL a)

Returns the tangent of a (a is in radians).

DOUBLE

atan(DOUBLE a), atan(DECIMAL a)

Returns the arctangent of a.

DOUBLE

degrees(DOUBLE a), degrees(DECIMAL a)

Converts value of a from radians to degrees.

DOUBLE

radians(DOUBLE a), radians(DOUBLE a)

Converts value of a from degrees to radians.

INT or DOUBLE

positive(INT a), positive(DOUBLE a)

Returns a.

INT or DOUBLE

negative(INT a), negative(DOUBLE a)

Returns -a.

DOUBLE or INT

sign(DOUBLE a), sign(DECIMAL a)

Returns the sign of a as '1.0' (if a is positive) or '-1.0' (if a is negative), '0.0' otherwise. The decimal version returns INT instead of DOUBLE.

DOUBLE

e()

Returns the value of e.

DOUBLE

pi()

Returns the value of pi.

BIGINT

factorial(INT a)

Returns the factorial of a. Valid a is [0..20].

DOUBLE

cbrt(DOUBLE a)

Returns the cube root of a double value.

INT BIGINT

shiftleft(TINYINT'SMALLINT'INT a, INT b) shiftleft(BIGINT a, INT b)

Bitwise left shift . Shifts a b positions to the left. Returns int for tinyint, smallint and int a. Returns bigint for bigint a.

INT BIGINT

shiftright(TINYINT'SMALLINT'INT a, INT b) shiftright(BIGINT a, INT b)

Bitwise right shift . Shifts a b positions to the right. Returns int for tinyint, smallint and int a. Returns bigint for bigint a.

INT BIGINT

shiftrightunsigned(TINYINT'SMALLINT'INTa, INT b), shiftrightunsigned(BIGINT a, INT b)

Bitwise unsigned right shift . Shifts a b positions to the right. Returns int for tinyint, smallint and int a. Returns bigint for bigint a.

T

greatest(T v1, T v2, ...)

Returns the greatest value of the list of values . Fixed to return NULL when one or more arguments are NULL, and strict type restriction relaxed, consistent with ">" operator .

T

least(T v1, T v2, ...)

Returns the least value of the list of values . Fixed to return NULL when one or more arguments are NULL, and strict type restriction relaxed, consistent with "<" operator .

INT

width_bucket(NUMERIC expr, NUMERIC min_value, NUMERIC max_value, INT num_buckets)<br>

Returns an integer between 0 and num_buckets+1 by mapping expr into the ith equally sized bucket. Buckets are made by dividing [min_value, max_value] into equally sized regions. If expr < min_value, return 1, if expr > max_value return num_buckets+1.<br>

Collection Functions

The following built-in collection functions are supported in Transformation:

Collection Fuctions

Return Type

Name (Signature)

Description

binary

binary(string'binary)

Casts the parameter into a binary.

<code class="inline-code"><type></code>

cast(expr as <code class="inline-code"><type></code>)

Converts the results of the expression expr to . For example, cast('1' as BIGINT) will convert the string '1' to its integral representation. A null is returned if the conversion does not succeed. If cast(expr as boolean) Transformation returns true for a non-empty string.

Date Functions

The following built-in date functions are supported in Transformation:

Date Functions

Return Type

Name (Signature)

Description

string

from_unixtime(bigint unixtime[, string format])

Converts the number of seconds from unix epoch (1970-01-01 00:00:00 UTC) to a string representing the timestamp of that moment in the current system time zone in the format of "1970-01-01 00:00:00".

bigint

unix_timestamp()

Gets current Unix timestamp in seconds. This function is not deterministic and its value is not fixed for the scope of a query execution, therefore prevents proper optimization of queries - this has been deprecated since 2.0 in favour of CURRENT_TIMESTAMP constant.

bigint

unix_timestamp(string date)

Converts time string in format yyyy-MM-dd HH:mm:ss to Unix timestamp (in seconds), using the default timezone and the default locale, return 0 if fail: unix_timestamp('2009-03-20 11:30:01') = 1237573801

bigint

unix_timestamp(string date, string pattern)

Convert time string with given pattern to Unix time stamp (in seconds), return 0 if fail: unix_timestamp('2009-03-20', 'yyyy-MM-dd') = 1237532400.

string

to_date(string timestamp)

Returns the date part of a timestamp string: to_date("1970-01-01 00:00:00") = "1970-01-01".

int

year(string date)

Returns the year part of a date or a timestamp string: year("1970-01-01 00:00:00") = 1970, year("1970-01-01") = 1970.

int

quarter(date/timestamp/string)

Returns the quarter of the year for a date, timestamp, or string in the range 1 to 4 . Example: quarter('2015-04-08') = 2.

int

month(string date)

Returns the month part of a date or a timestamp string: month("1970-11-01 00:00:00") = 11, month("1970-11-01") = 11.

int

day(string date) dayofmonth(date)

Returns the day part of a date or a timestamp string: day("1970-11-01 00:00:00") = 1, day("1970-11-01") = 1.

int

hour(string date)

Returns the hour of the timestamp: hour('2009-07-30 12:58:59') = 12, hour('12:58:59') = 12.

int

minute(string date)

Returns the minute of the timestamp.

int

second(string date)

Returns the second of the timestamp.

int

weekofyear(string date)

Returns the week number of a timestamp string: weekofyear("1970-11-01 00:00:00") = 44, weekofyear("1970-11-01") = 44.

int

extract(field FROM source)

<p>Retrieve fields such as days or hours from source. Source must be a date, timestamp, interval or a string that can be converted into either a date or timestamp. Supported fields include: day, dayofweek, hour, minute, month, quarter, second, week and year.</p><p>Examples:</p><p>1. select extract(month from “2016-10-20”) results in 10.</p><p>2. select extract(hour from “2016-10-20 05:06:07”) results in 5.</p><p>3. select extract(dayofweek from “2016-10-20 05:06:07”) results in 5.</p><p>4. select extract(month from interval ‘1-3’ year to month) results in 3.</p><p>5. select extract(minute from interval ‘3 12:20:30’ day to second) results in 20.</p>

int

datediff(string enddate, string startdate)

Returns the number of days from startdate to enddate: datediff('2009-03-01', '2009-02-27') = 2.

string

date_add(date/timestamp/string startdate, tinyint/smallint/int days)

Adds a number of days to startdate: date_add('2008-12-31', 1) = '2009-01-01'.

<i></i>pre 2.1.0: <i></i>string <i></i>2.1.0 on: <i></i>date

date_sub(date/timestamp/string startdate, tinyint/smallint/int days)

Subtracts a number of days to startdate: date_sub('2008-12-31', 1) = '2008-12-30'.

timestamp

from_utc_timestamp({any primitive type}*, string timezone)<br>

Converts a timestamp* in UTC to a given timezone. * timestamp is a primitive type, including timestamp/date, tinyint/smallint/int/bigint, float/double and decimal. Fractional values are considered as seconds. Integer values are considered as milliseconds.. E.g from_utc_timestamp(2592000.0,’PST’), from_utc_timestamp(2592000000,’PST’) and from_utc_timestamp(timestamp ‘1970-01-30 16:00:00′,’PST’) all return the timestamp 1970-01-30 08:00:00<br>

timestamp

to_utc_timestamp({any primitive type} ts, string timezone)<br>

Converts a timestamp* in a given timezone to UTC. * timestamp is a primitive type, including timestamp/date, tinyint/smallint/int/bigint, float/double and decimal. Fractional values are considered as seconds. Integer values are considered as milliseconds.. E.g to_utc_timestamp(2592000.0,’PST’), to_utc_timestamp(2592000000,’PST’) and to_utc_timestamp(timestamp ‘1970-01-30 16:00:00′,’PST’) all return the timestamp 1970-01-31 00:00:00<br>

date

current_date

Returns the current date at the start of query evaluation. All calls of current_date within the same query return the same value.

timestamp

current_timestamp

Returns the current timestamp at the start of query evaluation. All calls of current_timestamp within the same query return the same value.

string

add_months(string start_date, int num_months)<br>

Returns the date that is num_months after start_date. start_date is a string, date or timestamp. num_months is an integer. The time part of start_date is ignored. If start_date is the last day of the month or if the resulting month has fewer days than the day component of start_date, then the result is the last day of the resulting month. Otherwise, the result has the same day component as start_date.<br>

string

last_day(string date)

Returns the last day of the month which the date belongs to. date is a string in the format ‘yyyy-MM-dd HH:mm:ss’ or ‘yyyy-MM-dd’. The time part of date is ignored.

string

next_day(string start_date, string day_of_week)<br>

Returns the first date which is later than start_date and named as day_of_week. start_date is a string/date/timestamp. day_of_week is 2 letters, 3 letters or full name of the day of the week (e.g. Mo, tue, FRIDAY). The time part of start_date is ignored. Example: next_day(‘2015-01-14’, ‘TU’) = 2015-01-20.<br>

string

trunc(string date, string format)

Returns date truncated to the unit specified by the format. Supported formats: MONTH/MON/MM, YEAR/YYYY/YY. Example: trunc('2015-03-17', 'MM') = 2015-03-01.

double

months_between(date1, date2)

Returns number of months between dates date1 and date- If date1 is later than date2, then the result is positive. If date1 is earlier than date2, then the result is negative. If date1 and date2 are either the same days of the month or both last days of months, then the result is always an integer. Otherwise the UDF calculates the fractional portion of the result based on a 31-day month and considers the difference in time components date1 and date- date1 and date2 type can be date, timestamp or string in the format 'yyyy-MM-dd' or 'yyyy-MM-dd HH:mm:ss'. The result is rounded to 8 decimal places. Example: months_between('1997-02-28 10:30:00', '1996-10-30') = 3.94959677

string

date_format(date/timestamp/string ts, string fmt)

<p>Converts a date/timestamp/string to a value of string in the format specified by the date format fmt. Supported formats are Java SimpleDateFormat formats. The second argument fmt should be constant. Example: date_format(‘2015-04-08’, ‘y’) = ‘2015’.</p><p>date_format can be used to implement other UDFs, for example,</p><p>· dayname(date) is date_format(date, ‘EEEE’)</p><p>· dayofyear(date) is date_format(date, ‘D’)</p>

Conditional Functions

The following built-in date functions are supported in Transformation:

Conditional Functions

Return Type

Name (Signature)

Description

T

if(boolean testCondition, T valueTrue, T valueFalseOrNull)

Returns valueTrue when testCondition is true, returns valueFalseOrNull otherwise.

boolean

isnull( a )

Returns true if a is NULL and false otherwise.

boolean

isnotnull ( a )

Returns true if a is not NULL and false otherwise.

T

nvl(T value, T default_value)

Returns default value if value is null else returns value.

T

COALESCE(T v1, T v2, ...)

Returns the first v that is not NULL, or NULL if all v's are NULL.

T

CASE a WHEN b THEN c [WHEN d THEN e]* [ELSE f] END

When a = b, returns c; when a = d, returns e; else returns f.

T

CASE WHEN a THEN b [WHEN c THEN d]* [ELSE e] END

When a = true, returns b; when c = true, returns d; else returns e.

T

nullif( a, b )

Returns NULL if a=b; otherwise returns a. Shorthand for: CASE WHEN a = b then NULL else a

void

assert_true(boolean condition)

Throw an exception if 'condition' is not true, otherwise return null. For example, select assert_true (2<1).

String Functions

The following built-in String functions are supported in Transformation:

String Functions

Return Type

Name (Signature)

Description

int

ascii(string str)

Returns the numeric value of the first character of str.

string

base64(binary bin)

Converts the argument from binary to a base 64 string.

int

character_length(string str)

Returns the number of UTF-8 characters contained in str. The function char_length is shorthand for this function.

string

chr(bigint'double A)

Returns the ASCII character having the binary equivalent to A. If A is larger than 256 the result is equivalent to chr(A % 256). Example: select chr(88); returns "X".

string

concat(string'binary A, string'binary B...)

Returns the string or bytes resulting from concatenating the strings or bytes passed in as parameters in order. For example, concat('foo', 'bar') results in 'foobar'. Note that this function can take any number of input strings.

array>

context_ngrams(array>, array, int K, int pf)

Returns the top-k contextual N-grams from a set of tokenized sentences, given a string of “context”. For more details, see <a href="https://cwiki.apache.org/confluence/display/Hive/StatisticsAndDataMining">StatisticsAndDataMining</a>.<br>

string

concat_ws(string SEP, string A, string B...)

Like concat() above, but with custom separator SEP.

string

concat_ws(string SEP, array)

Like concat_ws() above, but taking an array of strings.

string

concat_ws(string SEP, string A, string B...)

Like concat() above, but with custom separator SEP.

string

concat_ws(string SEP, array)

Like concat_ws() above, but taking an array of strings.

string

decode(binary bin, string charset)

Decodes the first argument into a String using the provided character set (one of 'US-ASCII', 'ISO-8859-1', 'UTF-8', 'UTF-16BE', 'UTF-16LE', 'UTF-16'). If either argument is null, the result will also be null.

string

elt(N int,str1 string,str2 string,str3 string,...)

Return string at index number. For example elt(2,'hello','world') returns 'world'. Returns NULL if N is less than 1 or greater than the number of arguments.

binary

encode(string src, string charset)

Encodes the first argument into a BINARY using the provided character set (one of 'US-ASCII', 'ISO-8859-1', 'UTF-8', 'UTF-16BE', 'UTF-16LE', 'UTF-16'). If either argument is null, the result will also be null.

int

field(val T,val1 T,val2 T,val3 T,...)

Returns the index of val in the val1,val2,val3,... list or 0 if not found. For example field('world','say','hello','world') returns - All primitive types are supported, arguments are compared using str.equals(x). If val is NULL, the return value is 0.

int

find_in_set(string str, string strList)<br>

Returns the first occurance of str in strList where strList is a comma-delimited string. Returns null if either argument is null. Returns 0 if the first argument contains any commas. For example, find<i>in</i>set('ab', 'abc,b,ab,c,def') returns 3.

string

format_number(number x, int d)

Formats the number X to a format like '#,###,###.##', rounded to D decimal places, and returns the result as a string. If D is 0, the result has no decimal point or fractional part.

string

get_json_object(string json_string, string path)<br>

Extracts json object from a json string based on json path specified, and returns json string of the extracted json object. It will return null if the input json string is invalid. NOTE: The json path can only have the characters [0-9a-z_], i.e., no upper-case or special characters. Also, the keys <i>cannot start with numbers.</i>

boolean

in_file(string str, string filename)

Returns true if the string str appears as an entire line in filename.

int

instr(string str, string substr)

Returns the position of the first occurrence of substr in str. Returns null if either of the arguments are nulland returns 0 if substr could not be found in str. Be aware that this is not zero based. The first character in str has index 1.

int

length(string A)

Returns the length of the string.

int

locate(string substr, string str[, int pos])

Returns the position of the first occurrence of substr in str after position pos.

string

lower(string A) lcase(string A)

Returns the string resulting from converting all characters of B to lower case. For example, lower('fOoBaR') results in 'foobar'.

string

lpad(string str, int len, string pad)

Returns str, left-padded with pad to a length of len. If str is longer than len, the return value is shortened to len characters. In case of empty pad string, the return value is null.

string

ltrim(string A)

Returns the string resulting from trimming spaces from the beginning(left hand side) of A. For example, ltrim(' foobar ') results in 'foobar '.

<code class="inline-code">array<struct<string,double>></code>

ngrams(array>, int N, int K, int pf)

Returns the top-k N-grams from a set of tokenized sentences, such as those returned by the sentences() UDAF. See <a href="https://cwiki.apache.org/confluence/display/Hive/StatisticsAndDataMining">Statistics And Data Mining</a> for more information.

int

octet_length(string str)

Returns the number of octets required to hold the string str in UTF-8 encoding . Note that octet<i>length(str) can be larger than character</i>length(str).

string

parse_url(string urlString, string partToExtract [, string keyToExtract])

Returns the specified part from the URL. Valid values for partToExtract include HOST, PATH, QUERY, REF, PROTOCOL, AUTHORITY, FILE, and USERINFO. For example, parse_url(‘http://facebook.com/path1/p.php?k1=v1&k2=v2#Ref1’, ‘HOST’) returns ‘facebook.com’. Also a value of a particular key in QUERY can be extracted by providing the key as the third argument, for example, parse_url(‘http://facebook.com/path1/p.php?k1=v1&k2=v2#Ref1’, ‘QUERY’, ‘k1’) returns ‘v1’.<br>

string

printf(String format, Obj... args)

Returns the input formatted according do printf-style format strings .

string

regexp_extract(string subject, string pattern, int index)

Returns the string extracted using the pattern. For example, regexp_extract('foothebar', 'foo(.*?)(bar)', 2) returns 'bar.' Note that some care is necessary in using predefined character classes: using '\s' as the second argument will match the letter s; '\s' is necessary to match whitespace, etc. The 'index' parameter is the Java regex Matcher group() method index. See docs/api/java/util/regex/Matcher.html for more information on the 'index' or Java regex group() method.

string

regexp_replace(string INITIAL_STRING, string PATTERN, string REPLACEMENT)<br>

Returns the string resulting from replacing all substrings in INITIAL_STRING that match the java regular expression syntax defined in PATTERN with instances of REPLACEMENT. For example, regexp_replace(“foobar”, “oo|ar”, “”) returns ‘fb.’ Note that some care is necessary in using predefined character classes: using ‘\s’ as the second argument will match the letter s; ‘\s’ is necessary to match whitespace, etc.<br>

string

repeat(string str, int n)

Repeats str n times.

string

replace(string A, string OLD, string NEW)

Returns the string A with all non-overlapping occurrences of OLD replaced with NEW . Example: select replace("ababab", "abab", "Z"); returns "Zab".

string

reverse(string A)

Returns the reversed string.

string

rpad(string str, int len, string pad)

Returns str, right-padded with pad to a length of len. If str is longer than len, the return value is shortened to len characters. In case of empty pad string, the return value is null.

string

rtrim(string A)

Returns the string resulting from trimming spaces from the end(right hand side) of A. For example, rtrim(' foobar ') results in ' foobar'.

<code class="inline-code">array<array<string>></code>

sentences(string str, string lang, string locale)

Tokenizes a string of natural language text into words and sentences, where each sentence is broken at the appropriate sentence boundary and returned as an array of words. The 'lang' and 'locale' are optional arguments. For example, sentences('Hello there! How are you?') returns ( ("Hello", "there"), ("How", "are", "you") ).

string

space(int n)

Returns a string of n spaces.

array

split(string str, string pat)

Splits str around pat (pat is a regular expression).

<code class="inline-code">map<string,string></code>

str_to_map(text[, delimiter1, delimiter2])<br>

Splits text into key-value pairs using two delimiters. Delimiter1 separates text into K-V pairs, and Delimiter2 splits each K-V pair. Default delimiters are ',' for delimiter1 and ':' for delimiter2.

string

substr(string'binary A, int start) substring(string'binary A, int start)

Returns the substring or slice of the byte array of A starting from start position till the end of string A. For example, substr('foobar', 4) results in 'bar' (see <a href="http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substr">here</a>).

string

substr(string'binary A, int start, int len) substring(string'binary A, int start, int len)

Returns the substring or slice of the byte array of A starting from start position with length len. For example, substr('foobar', 4, 1) results in 'b' (see <a href="http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substr">here</a>).

string

substring_index(string A, string delim, int count)

Returns the substring from string A before count occurrences of the delimiter delim . If count is positive, everything to the left of the final delimiter (counting from the left) is returned. If count is negative, everything to the right of the final delimiter (counting from the right) is returned. Substring_index performs a case-sensitive match when searching for delim. Example: substring_index(‘www.apache.org’, ‘.’, 2) = ‘www.apache’.

string

translate(string'char'varchar input, string'char'varchar from, string'char'varchar to)

Translates the input string by replacing the characters present in the from string with the corresponding characters in the to string. This is similar to the translate function in PostgreSQL. If any of the parameters to this UDF are NULL, the result is NULL as well.

string

trim(string A)

Returns the string resulting from trimming spaces from both ends of A. For example, trim(' foobar ') results in 'foobar'

binary

unbase64(string str)

Converts the argument from a base 64 string to BINARY.

string

upper(string A) ucase(string A)

Returns the string resulting from converting all characters of A to upper case. For example, upper('fOoBaR') results in 'FOOBAR'.

string

initcap(string A)

Returns string, with the first letter of each word in uppercase, all other letters in lowercase. Words are delimited by whitespace.

int

levenshtein(string A, string B)

Returns the Levenshtein distance between two strings. For example, levenshtein('kitten', 'sitting') results in 3.

string

soundex(string A)

Returns soundex code of the string . For example, soundex('Miller') results in M460.

Data Masking Functions

The following built-in data masking functions are supported in Transformation:

Data Masking Functions

Return Type

Name (Signature)

Description

string

mask(string str[, string upper[, string lower[, string number]]])

Returns a masked version of str. By default, upper case letters are converted to "X", lower case letters are converted to "x" and numbers are converted to "n". For example mask("abcd-EFGH-8765-4321") results in xxxx-XXXX-nnnn-nnnn. You can override the characters used in the mask by supplying additional arguments: the second argument controls the mask character for upper case letters, the third argument for lower case letters and the fourth argument for numbers. For example, mask("abcd-EFGH-8765-4321", "U", "l", "#") results in llll-UUUU-###-###.

string

mask_first_n(string str[, int n])<br>

Returns a masked version of str with the first n values masked. Upper case letters are converted to "X", lower case letters are converted to "x" and numbers are converted to "n". For example, mask<i>first</i>n("1234-5678-8765-4321", 4) results in nnnn-5678-8765-4321.

string

mask_last_n(string str[, int n])<br>

Returns a masked version of str with the last n values masked . Upper case letters are converted to "X", lower case letters are converted to "x" and numbers are converted to "n". For example, mask<i>last</i>n("1234-5678-8765-4321", 4) results in 1234-5678-8765-nnnn.

string

mask_show_first_n(string str[, int n])<br>

Returns a masked version of str, showing the first n characters unmasked . Upper case letters are converted to "X", lower case letters are converted to "x" and numbers are converted to "n". For example, mask<i>show</i>first_n("1234-5678-8765-4321", 4) results in 1234-nnnn-nnnn-nnnn.

string

mask_show_last_n(string str[, int n])<br>

Returns a masked version of str, showing the last n characters unmasked . Upper case letters are converted to "X", lower case letters are converted to "x" and numbers are converted to "n". For example, mask<i>show</i>last_n("1234-5678-8765-4321", 4) results in nnnn-nnnn-nnnn-4321.

string

mask_hash(string|char|varchar str)

Returns a hashed value based on str . The hash is consistent and can be used to join masked values together across tables. This function returns null for non-string types.

Miscellaneous Functions

The following built-in data masking functions are supported in Transformation:

Miscellaneous Functions

Return Type

Name (Signature)

Description

varies

java_method(class, method[, arg1[, arg2..]])

Synonym for reflect.

varies

reflect(class, method[, arg1[, arg2..]])

Calls a Java method by matching the argument signature, using reflection. See <a href="https://cwiki.apache.org/confluence/display/Hive/ReflectUDF">Reflect (Generic) UDF</a> for examples.<br>

int

hash(a1[, a2...])

Returns a hash value of the arguments.

string

current_user()

Returns current user name from the configured authenticator manager . Could be the same as the user provided when connecting, but with some authentication managers (for example HadoopDefaultAuthenticator) it could be different.

string

md5(string/binary)

Calculates an MD5 128-bit checksum for the string or binary . The value is returned as a string of 32 hex digits, or NULL if the argument was NULL. Example: md5('ABC') = '902fbdd2b1df0c4f70b4a5d23525e932'.

string

sha1(string/binary) sha(string/binary)

Calculates the SHA-1 digest for string or binary and returns the value as a hex string . Example: sha1('ABC') = '3c01bdbb26f358bab27f267924aa2c9a03fcfdb8'.

bigint

crc32(string/binary)

Computes a cyclic redundancy check value for string or binary argument and returns bigint value . Example: crc32('ABC') = 2743272264.

string

sha2(string/binary, int)

Calculates the SHA-2 family of hash functions . The first argument is the string or binary to be hashed. The second argument indicates the desired bit length of the result, which must have a value of 224, 256, 384, 512, or 0 (which is equivalent to 256). SHA-224 is supported starting from Java 8. If either argument is NULL or the hash length is not one of the permitted values, the return value is NULL. Example: sha2('ABC', 256) = 'b5d4045c3f466fa91fe2cc6abe79232a1a57cdf104f7a26e716e0a1e2789df78'.

binary

aes_encrypt(input string/binary, key string/binary)

Encrypt input using AES . Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed. If either argument is NULL or the key length is not one of the permitted values, the return value is NULL. Example: base64(aes_encrypt('ABC', '1234567890123456')) = 'y6Ss+zCYObpCbgfWfyNWTw=='.

binary

aes_decrypt(input binary, key string/binary)

Decrypt input using AES. Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed. If either argument is NULL or the key length is not one of the permitted values, the return value is NULL. Example: aes_decrypt(unbase64('y6Ss+zCYObpCbgfWfyNWTw=='), '1234567890123456') = 'ABC'.

Infoworks UDF

Return Type

Name (Signature)

Description

string

iwuuid()

Generate random UUID

string

<code class="inline-code">iwrowid(<column-name>[,<column-name>,…)</code>

Generate unique uuid based on column values

string

<code class="inline-code">iwltrim(<column-name>)</code>

Generate ltrim of the column

string

<code class="inline-code">iwrtrim(<column-name>)</code>

Generate rtrim of the column

array<string>

<code class="inline-code">iwsplit(<column-name>,int)</code>

Split column based on substring length into values and returns array of strings

<code class="inline-code"><multiple-rows></code>

<code class="inline-code">iwdateloop(<start-date>,<end-date>,int,string)</code>

Takes start date and end date, increment number and unit to increment("year","month","week","day") and return multiple rows from start date to end date with increment number increased date per row. This is will duplicate all records in the node into multiple rows

<code class="inline-code"><multiple-rows></code>

<code class="inline-code">iwgenrows(<integer column-name>,<integer column-name>,int)</code>

This is will duplicate all records in the node into multiple rows based on low and high value in the column provided based on increment factor