# Functions Class

## Definition

Functions available for DataFrame operations.

public static class Functions
type Functions = class
Public Class Functions
Inheritance
Functions

## Methods

 Computes the absolute value. Inverse cosine of column in radians, as if computed by java.lang.Math.acos. Inverse cosine of columnName in radians, as if computed by java.lang.Math.acos. Returns the date that is numMonths after startDate. Returns the date that is numMonths after startDate. Returns the approximate number of distinct items in a group. Returns the approximate number of distinct items in a group. Returns the approximate number of distinct items in a group. Returns the approximate number of distinct items in a group. Creates a new array column. The input columns must all have the same data type. Creates a new array column. The input columns must all have the same data type. Returns null if the array is null, true if the array contains value, and false otherwise. Removes duplicate values from the array. Returns an array of the elements in the col1 but not in the col2, without duplicates. The order of elements in the result is nondeterministic. Returns an array of the elements in the intersection of the given two arrays, without duplicates. Concatenates the elements of column using the delimiter. Concatenates the elements of column using the delimiter. Null values are replaced with nullReplacement. Returns the maximum value in the array. Returns the minimum value in the array. Locates the position of the first occurrence of the value in the given array as long. Returns null if either of the arguments are null. Remove all elements that equal to element from the given array. Creates an array containing the left argument repeated the number of times given by the right argument. Creates an array containing the left argument repeated the count number of times. Sorts the input array in ascending order. The elements of the input array must be sortable. Null elements will be placed at the end of the returned array. Returns true if a1 and a2 have at least one non-null element in common. If not and both arrays are non-empty and any of them contains a null, it returns null. It returns false otherwise. Returns a merged array of structs in which the N-th struct contains all N-th values of input arrays. Returns an array of the elements in the union of the given two arrays, without duplicates. Returns a sort expression based on the ascending order of the column. Computes the numeric value of the first character of the string column, and returns the result as an int column. Returns a sort expression based on the ascending order of the column, and null values return before non-null values. Returns a sort expression based on the ascending order of the column, and null values appear after non-null values. Inverse sine of column in radians, as if computed by java.lang.Math.asin. Inverse sine of columnName in radians, as if computed by java.lang.Math.asin. Inverse tangent of column in radians, as if computed by java.lang.Math.atan. Inverse tangent of columnName in radians, as if computed by java.lang.Math.atan. Computes atan2 for the given x and y. Computes atan2 for the given x and y. Computes atan2 for the given x and y. Computes atan2 for the given x and y. Computes atan2 for the given x and y. Computes atan2 for the given x and y. Computes atan2 for the given x and y. Computes atan2 for the given x and y. Returns the average of the values in a group. Returns the average of the values in a group. Computes the BASE64 encoding of a binary column and returns it as a string column. An expression that returns the string representation of the binary value of the given long column. For example, bin("12") returns "1100". An expression that returns the string representation of the binary value of the given long column. For example, bin("12") returns "1100". Computes bitwise NOT. Marks a DataFrame as small enough for use in broadcast joins. Returns the value of the column rounded to 0 decimal places with HALF_EVEN round mode. Returns the value of the column rounded to scale decimal places with HALF_EVEN round mode. A transform for any type that partitions by a hash of the input column. A transform for any type that partitions by a hash of the input column. Call an user-defined function registered via SparkSession.Udf().Register(). Computes the cube-root of the given column. Computes the cube-root of the given column. Computes the ceiling of the given value. Computes the ceiling of the given value. Returns the first column that is not null, or null if all inputs are null. Returns a Column based on the given column name. Alias for Column(). Returns a list of objects with duplicates. Returns a list of objects with duplicates. Returns a set of objects with duplicate elements eliminated. Returns a set of objects with duplicate elements eliminated. Returns a Column based on the given column name. Concatenates multiple input columns together into a single column. Concatenates multiple input string columns together into a single string column, using the given separator. Convert a number in a string column from one base to another. Returns the Pearson Correlation Coefficient for two columns. Returns the Pearson Correlation Coefficient for two columns. Computes cosine of the angle, as if computed by java.lang.Math.cos Computes cosine of the angle, as if computed by java.lang.Math.cos Computes hyperbolic cosine of the angle, as if computed by java.lang.Math.cosh Computes hyperbolic cosine of the angle, as if computed by java.lang.Math.cosh Returns the number of items in a group. Returns the number of items in a group. Returns the number of distinct items in a group. Returns the number of distinct items in a group. Returns the population covariance for two columns. Returns the population covariance for two columns. Returns the sample covariance for two columns. Returns the sample covariance for two columns. Calculates the cyclic redundancy check value (CRC32) of a binary column and returns the value as a bigint. Window function: returns the cumulative distribution of values within a window partition, i.e. the fraction of rows that are below the current row. Returns the current date as a date column. Window function: returns the special frame boundary that represents the current row in the window partition. Returns the current timestamp as a timestamp column. Returns the date that is days days after start. Returns the date that is days days after start. Returns the number of days from start to end. Converts a date/timestamp/string to a value of string in the format specified by the date format given by the second argument. Returns the date that is days days before start. Returns the date that is days days before start. Returns timestamp truncated to the unit specified by the format. Extracts the day of the month as an integer from a given date/timestamp/string. Extracts the day of the week as an integer from a given date/timestamp/string. Extracts the day of the year as an integer from a given date/timestamp/string. A transform for timestamps and dates to partition data into days. Computes the first argument into a string from a binary using the provided character set (one of 'US-ASCII', 'ISO-8859-1', 'UTF-8', 'UTF-16BE', 'UTF-16LE', 'UTF-16') Converts an angle measured in radians to an approximately equivalent angle measured in degrees. Converts an angle measured in radians to an approximately equivalent angle measured in degrees. Window function: returns the rank of rows within a window partition, without any gaps. Returns a sort expression based on the descending order of the column. Returns a sort expression based on the descending order of the column, and null values return before non-null values. Returns a sort expression based on the descending order of the column, and null values appear after non-null values. Returns element of array at given index in value if column is array. Returns value for the given key in value if column is map. Computes the first argument into a binary from a string using the provided character set (one of 'US-ASCII', 'ISO-8859-1', 'UTF-8', 'UTF-16BE', 'UTF-16LE', 'UTF-16') Computes the exponential of the given value. Computes the exponential of the given value. Creates a new row for each element in the given array or map column. Creates a new row for each element in the given array or map column. Unlike Explode(), if the array/map is null or empty then null is produced. Computes the exponential of the given value minus one. Computes the exponential of the given value minus one. Parses the expression string into the column that it represents. Computes the factorial of the given value. Returns the first value of a column in a group. Returns the first value of a column in a group. Creates a single array from an array of arrays. If a structure of nested arrays is deeper than two levels, only one level of nesting is removed. Computes the floor of the given value. Computes the floor of the given value. Formats the given numeric column to a format like '#,###,###.##', rounded to the given d decimal places with HALF_EVEN round mode, and returns the result as a string column. Formats the arguments in printf-style and returns the result as a string column. Parses a column containing a CSV string into a StructType with the specified schema. Parses a column containing a CSV string into a StructType with the specified schema. Parses a column containing a JSON string into a StructType or ArrayType of StructTypes with the specified schema. Parses a column containing a JSON string into a StructType or ArrayType of StructTypes with the specified schema. 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 with a default format "yyyy-MM-dd HH:mm:ss". 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 with the given format. Given a timestamp like '2017-07-14 02:40:00.0', interprets it as a time in UTC, and renders that time as a timestamp in the given time zone. For example, 'GMT+1' would yield '2017-07-14 03:40:00.0'. Given a timestamp like '2017-07-14 02:40:00.0', interprets it as a time in UTC, and renders that time as a timestamp in the given time zone. For example, 'GMT+1' would yield '2017-07-14 03:40:00.0'. Extracts JSON object from a JSON string based on path specified, and returns JSON string of the extracted JSON object. Returns the greatest value of the list of values, skipping null values. Returns the greatest value of the list of column names, skipping null values. Indicates whether a specified column in a GROUP BY list is aggregated or not, returning 1 for aggregated or 0 for not aggregated in the result set. Indicates whether a specified column in a GROUP BY list is aggregated or not, returning 1 for aggregated or 0 for not aggregated in the result set. Returns the number of distinct items in a group. Returns the number of distinct items in a group. Calculates the hash code of given columns, and returns the result as an int column. Computes hex value of the given column. Extracts the hours as an integer from a given date/timestamp/string. A transform for timestamps to partition data into hours. Computes sqrt(a^2^ + b^2^) without intermediate overflow or underflow. Computes sqrt(a^2^ + b^2^) without intermediate overflow or underflow. Computes sqrt(a^2^ + b^2^) without intermediate overflow or underflow. Computes sqrt(a^2^ + b^2^) without intermediate overflow or underflow. Computes sqrt(a^2^ + b^2^) without intermediate overflow or underflow. Computes sqrt(a^2^ + b^2^) without intermediate overflow or underflow. Computes sqrt(a^2^ + b^2^) without intermediate overflow or underflow. Computes sqrt(a^2^ + b^2^) without intermediate overflow or underflow. Returns a new string column by converting the first letter of each word to uppercase. Words are delimited by whitespace. Creates a string column for the file name of the current Spark task. Locate the position of the first occurrence of the given substring. Return true iff the column is NaN. Return true iff the column is null. Creates a new row for a JSON column according to the given field names. Returns the kurtosis of the values in a group. Returns the kurtosis of the values in a group. Window function: returns the value that is 'offset' rows before the current row, and null if there is less than 'offset' rows before the current row. For example, an 'offset' of one will return the previous row at any given point in the window partition. Window function: returns the value that is 'offset' rows before the current row, and null if there is less than 'offset' rows before the current row. For example, an 'offset' of one will return the previous row at any given point in the window partition. Returns the last value of a column in a group. Returns the last value of a column in a group. Returns the last day of the month which the given date belongs to. Window function: returns the value that is 'offset' rows after the current row, and null if there is less than 'offset' rows after the current row. For example, an 'offset' of one will return the next row at any given point in the window partition. Window function: returns the value that is 'offset' rows after the current row, and null if there is less than 'offset' rows after the current row. For example, an 'offset' of one will return the next row at any given point in the window partition. Returns the least value of the list of values, skipping null values. Returns the least value of the list of values, skipping null values. Computes the character length of a given string or number of bytes of a binary string. Computes the Levenshtein distance of the two given string columns. Creates a Column of literal value. Locate the position of the first occurrence of the given substring. Locate the position of the first occurrence of the given substring starting from the given position offset. Computes the natural logarithm of the given value. Computes the first argument-base logarithm of the second argument. Computes the first argument-base logarithm of the second argument. Computes the natural logarithm of the given value. Computes the logarithm of the given value in base 10. Computes the logarithm of the given value in base 10. Computes the natural logarithm of the given value plus one. Computes the natural logarithm of the given value plus one. Computes the logarithm of the given column in base 2. Computes the logarithm of the given column in base 2. Converts a string column to lower case. Left-pad the string column with pad to the given length len. If the string column is longer than len, the return value is shortened to len characters. Trim the spaces from left end for the given string column. Trim the specified character string from left end for the given string column. Creates a new map column. Returns the union of all the given maps. Returns an unordered array of all entries in the given map. Creates a new map column. The array in the first column is used for keys. The array in the second column is used for values. All elements in the array for key should not be null. Returns a map created from the given array of entries. Returns an unordered array containing the keys of the map. Returns an unordered array containing the values of the map. Returns the maximum value of the column in a group. Returns the maximum value of the column in a group. Calculates the MD5 digest of a binary column and returns the value as a 32 character hex string. Returns the average value of the column in a group. Returns the average value of the column in a group. Returns the minimum value of the column in a group. Returns the minimum value of the column in a group. Extracts the minutes as an integer from a given date/timestamp/string. A column expression that generates monotonically increasing 64-bit integers. Extracts the month as an integer from a given date/timestamp/string. A transform for timestamps and dates to partition data into months. Returns number of months between dates end and stasrt. Returns number of months between dates end and start. If roundOff is set to true, the result is rounded off to 8 digits; it is not rounded otherwise. Returns col1 if it is not NaN, or col2 if col1 is NaN. Unary minus, i.e. negate the expression. Given a date column, returns the first date which is later than the value of the date column that is on the specified day of the week. Inversion of boolean expression, i.e. NOT. Window function: returns the ntile group id (from 1 to n inclusive) in an ordered window partition. For example, if n is 4, the first quarter of the rows will get value 1, the second quarter will get 2, the third quarter will get 3, and the last quarter will get 4. Overlay the specified portion of src with replace, starting from byte position pos of src. Overlay the specified portion of src with replace, starting from byte position pos of src and proceeding for len bytes. Window function: returns the relative rank (i.e. percentile) of rows within a window partition. Returns the positive value of dividend mod divisor. Creates a new row for each element with position in the given array or map column. Creates a new row for each element with position in the given array or map column. Unlike Posexplode(), if the array/map is null or empty then the row(null, null) is produced. Returns the value of the first argument raised to the power of the second argument. Returns the value of the first argument raised to the power of the second argument. Returns the value of the first argument raised to the power of the second argument. Returns the value of the first argument raised to the power of the second argument. Returns the value of the first argument raised to the power of the second argument. Returns the value of the first argument raised to the power of the second argument. Returns the value of the first argument raised to the power of the second argument. Returns the value of the first argument raised to the power of the second argument. Extracts the quarter as an integer from a given date/timestamp/string. Converts an angle measured in degrees to an approximately equivalent angle measured in radians. Converts an angle measured in degrees to an approximately equivalent angle measured in radians. Generate a random column with independent and identically distributed (i.i.d.) samples from U[0.0, 1.0]. Generate a random column with independent and identically distributed (i.i.d.) samples from U[0.0, 1.0]. Generate a random column with independent and identically distributed (i.i.d.) samples from the standard normal distribution. Generate a random column with independent and identically distributed (i.i.d.) samples from the standard normal distribution. Window function: returns the rank of rows within a window partition. Extract a specific group matched by a Java regex, from the specified string column. Replace all substrings of the specified string value that match the pattern with the given replacement string. Replace all substrings of the specified string value that match the pattern with the given replacement string. Repeats a string column n times, and returns it as a new string column. Reverses the string column and returns it as a new string column. Returns the double value that is closest in value to the argument and is equal to a mathematical integer. Returns the double value that is closest in value to the argument and is equal to a mathematical integer. Returns the value of the column rounded to 0 decimal places with HALF_UP round mode. Returns the value of the column rounded to scale decimal places with HALF_UP round mode. Window function: returns a sequential number starting at 1 within a window partition. Right-pad the string column with pad to the given length len. If the string column is longer than len, the return value is shortened to len characters. Trim the spaces from right end for the specified string value. Trim the specified character string from right end for the given string column. Parses a CSV string and infers its schema in DDL format. Parses a CSV string and infers its schema in DDL format. Parses a CSV string and infers its schema in DDL format. Parses a JSON string and infers its schema in DDL format. Parses a JSON string and infers its schema in DDL format. Parses a JSON string and infers its schema in DDL format. Extracts the seconds as an integer from a given date/timestamp/string. Generate a sequence of integers from start to stop, incrementing by 1 if start is less than or equal to stop, otherwise -1. Generate a sequence of integers from start to stop, incrementing by step. Calculates the SHA-1 digest of a binary column and returns the value as a 40 character hex string. Calculates the SHA-2 family of hash functions of a binary column and returns the value as a hex string. Shift the given value numBits left. (Signed) shift the given value numBits right. Unsigned shift the given value numBits right. Returns a random permutation of the given array. Computes the signum of the given value. Computes the signum of the given value. Computes sine of the angle, as if computed by java.lang.Math.sin. Computes sine of the angle, as if computed by java.lang.Math.sin. Computes hyperbolic sine of the angle, as if computed by java.lang.Math.sin. Computes hyperbolic sine of the angle, as if computed by java.lang.Math.sin. Returns length of array or map. Returns the skewness of the values in a group. Returns the skewness of the values in a group. Returns an array containing all the elements in column from index start (or starting from the end if start is negative) with the specified length. Sorts the input array for the given column in ascending (default) or descending order, the natural ordering of the array elements. Returns the soundex code for the specified expression. Partition ID. Splits string with a regular expression pattern. Splits str around matches of the given pattern. Computes the square root of the specified float value. Computes the square root of the specified float value. Alias for StddevSamp(). Alias for StddevSamp(). Returns the population standard deviation of the expression in a group. Returns the population standard deviation of the expression in a group. Returns the sample standard deviation of the expression in a group. Returns the sample standard deviation of the expression in a group. Creates a new struct column that composes multiple input columns. Creates a new struct column that composes multiple input columns. Returns the substring (or slice of byte array) starting from the given position for the given length. Returns the substring from the given string before count occurrences of the given delimiter. Returns the sum of all values in the expression. Returns the sum of all values in the expression. Returns the sum of distinct values in the expression. Returns the sum of distinct values in the expression. Computes tangent of the given value, as if computed by java.lang.Math.tan. Computes tangent of the given value, as if computed by java.lang.Math.tan. Computes hyperbolic tangent of the given value, as if computed by java.lang.Math.tanh. Computes hyperbolic tangent of the given value, as if computed by java.lang.Math.tanh. Converts a column containing a StructType into a CSV string with the specified schema. Converts a column containing a StructType into a CSV string with the specified schema. Converts the column into DateType by casting rules to DateType. Converts the column into a DateType with a specified format. Converts a column containing a StructType, ArrayType of StructTypes, a MapType or ArrayType of MapTypes into a JSON string. Convert time string to a Unix timestamp (in seconds) by casting rules to TimestampType. Convert time string to a Unix timestamp (in seconds) with specified format. Given a timestamp like '2017-07-14 02:40:00.0', interprets it as a time in the given time zone, and renders that time as a timestamp in UTC. For example, 'GMT+1' would yield '2017-07-14 01:40:00.0'. Given a timestamp like '2017-07-14 02:40:00.0', interprets it as a time in the given time zone, and renders that time as a timestamp in UTC. For example, 'GMT+1' would yield '2017-07-14 01:40:00.0'. Translate any characters that match with the given matchingString in the column by the given replaceString. Trim the spaces from both ends for the specified string column. Trim the specified character from both ends for the specified string column. Returns date truncated to the unit specified by the format. Creates a UDF from the specified delegate. Creates a UDF from the specified delegate. Creates a UDF from the specified delegate. Creates a UDF from the specified delegate. Creates a UDF from the specified delegate. Creates a UDF from the specified delegate. Creates a UDF from the specified delegate. Creates a UDF from the specified delegate. Creates a UDF from the specified delegate. Creates a UDF from the specified delegate. Creates a UDF from the specified delegate. Creates a UDF from the specified delegate. Creates a UDF from the specified delegate. Creates a UDF from the specified delegate. Creates a UDF from the specified delegate. Creates a UDF from the specified delegate. Creates a UDF from the specified delegate. Creates a UDF from the specified delegate. Creates a UDF from the specified delegate. Creates a UDF from the specified delegate. Creates a UDF from the specified delegate. Creates a UDF from the specified delegate. Decodes a BASE64 encoded string column and returns it as a binary column. Window function: returns the special frame boundary that represents the last row in the window partition. Window function: returns the special frame boundary that represents the first row in the window partition. Inverse of hex. Interprets each pair of characters as a hexadecimal number and converts to the byte representation of number. Returns the current Unix timestamp (in seconds). Converts time string in format yyyy-MM-dd HH:mm:ss to Unix timestamp (in seconds), using the default timezone and the default locale. Converts time string with given format to Unix timestamp (in seconds). Converts a string column to upper case. Alias for VarSamp(). Alias for VarSamp(). Returns the population variance of the values in a group. Returns the population variance of the values in a group. Returns the unbiased variance of the values in a group. Returns the unbiased variance of the values in a group. Extracts the week number as an integer from a given date/timestamp/string. Evaluates a condition and returns one of multiple possible result expressions. If otherwise is not defined at the end, null is returned for unmatched conditions. Generates tumbling time windows given a timestamp specifying column. Bucketize rows into one or more time windows given a timestamp column. Bucketize rows into one or more time windows given a timestamp column. Calculates the hash code of given columns using the 64-bit variant of the xxHash algorithm, and returns the result as a long column. Extracts the year as an integer from a given date/timestamp/string. A transform for timestamps and dates to partition data into years.