{ "docs": [ { "location": "/", "text": "!\n\n\n! expr - Logical not.\n\n\n\n\n%\n\n\nexpr1 % expr2 - Returns the remainder after \nexpr1\n/\nexpr2\n.\n\n\nExamples:\n\n\n> SELECT 2 % 1.8;\n 0.2\n> SELECT MOD(2, 1.8);\n 0.2\n\n\n\n\n\n\n&\n\n\nexpr1 & expr2 - Returns the result of bitwise AND of \nexpr1\n and \nexpr2\n.\n\n\nExamples:\n\n\n> SELECT 3 & 5;\n 1\n\n\n\n\n\n\n*\n\n\nexpr1 * expr2 - Returns \nexpr1\n*\nexpr2\n.\n\n\nExamples:\n\n\n> SELECT 2 * 3;\n 6\n\n\n\n\n\n\n+\n\n\nexpr1 + expr2 - Returns \nexpr1\n+\nexpr2\n.\n\n\nExamples:\n\n\n> SELECT 1 + 2;\n 3\n\n\n\n\n\n\n-\n\n\nexpr1 - expr2 - Returns \nexpr1\n-\nexpr2\n.\n\n\nExamples:\n\n\n> SELECT 2 - 1;\n 1\n\n\n\n\n\n\n/\n\n\nexpr1 / expr2 - Returns \nexpr1\n/\nexpr2\n. It always performs floating point division.\n\n\nExamples:\n\n\n> SELECT 3 / 2;\n 1.5\n> SELECT 2L / 2L;\n 1.0\n\n\n\n\n\n\n<\n\n\nexpr1 < expr2 - Returns true if \nexpr1\n is less than \nexpr2\n.\n\n\nArguments:\n\n\n\n\nexpr1, expr2 - the two expressions must be same type or can be casted to a common type,\n and must be a type that can be ordered. For example, map type is not orderable, so it\n is not supported. For complex types such array/struct, the data types of fields must\n be orderable.\n\n\n\n\nExamples:\n\n\n> SELECT 1 < 2;\n true\n> SELECT 1.1 < '1';\n false\n> SELECT to_date('2009-07-30 04:17:52') < to_date('2009-07-30 04:17:52');\n false\n> SELECT to_date('2009-07-30 04:17:52') < to_date('2009-08-01 04:17:52');\n true\n> SELECT 1 < NULL;\n NULL\n\n\n\n\n\n\n<=\n\n\nexpr1 <= expr2 - Returns true if \nexpr1\n is less than or equal to \nexpr2\n.\n\n\nArguments:\n\n\n\n\nexpr1, expr2 - the two expressions must be same type or can be casted to a common type,\n and must be a type that can be ordered. For example, map type is not orderable, so it\n is not supported. For complex types such array/struct, the data types of fields must\n be orderable.\n\n\n\n\nExamples:\n\n\n> SELECT 2 <= 2;\n true\n> SELECT 1.0 <= '1';\n true\n> SELECT to_date('2009-07-30 04:17:52') <= to_date('2009-07-30 04:17:52');\n true\n> SELECT to_date('2009-07-30 04:17:52') <= to_date('2009-08-01 04:17:52');\n true\n> SELECT 1 <= NULL;\n NULL\n\n\n\n\n\n\n<=>\n\n\nexpr1 <=> expr2 - Returns same result as the EQUAL(=) operator for non-null operands,\nbut returns true if both are null, false if one of the them is null.\n\n\nArguments:\n\n\n\n\nexpr1, expr2 - the two expressions must be same type or can be casted to a common type,\n and must be a type that can be used in equality comparison. Map type is not supported.\n For complex types such array/struct, the data types of fields must be orderable.\n\n\n\n\nExamples:\n\n\n> SELECT 2 <=> 2;\n true\n> SELECT 1 <=> '1';\n true\n> SELECT true <=> NULL;\n false\n> SELECT NULL <=> NULL;\n true\n\n\n\n\n\n\n=\n\n\nexpr1 = expr2 - Returns true if \nexpr1\n equals \nexpr2\n, or false otherwise.\n\n\nArguments:\n\n\n\n\nexpr1, expr2 - the two expressions must be same type or can be casted to a common type,\n and must be a type that can be used in equality comparison. Map type is not supported.\n For complex types such array/struct, the data types of fields must be orderable.\n\n\n\n\nExamples:\n\n\n> SELECT 2 = 2;\n true\n> SELECT 1 = '1';\n true\n> SELECT true = NULL;\n NULL\n> SELECT NULL = NULL;\n NULL\n\n\n\n\n\n\n==\n\n\nexpr1 == expr2 - Returns true if \nexpr1\n equals \nexpr2\n, or false otherwise.\n\n\nArguments:\n\n\n\n\nexpr1, expr2 - the two expressions must be same type or can be casted to a common type,\n and must be a type that can be used in equality comparison. Map type is not supported.\n For complex types such array/struct, the data types of fields must be orderable.\n\n\n\n\nExamples:\n\n\n> SELECT 2 == 2;\n true\n> SELECT 1 == '1';\n true\n> SELECT true == NULL;\n NULL\n> SELECT NULL == NULL;\n NULL\n\n\n\n\n\n\n>\n\n\nexpr1 > expr2 - Returns true if \nexpr1\n is greater than \nexpr2\n.\n\n\nArguments:\n\n\n\n\nexpr1, expr2 - the two expressions must be same type or can be casted to a common type,\n and must be a type that can be ordered. For example, map type is not orderable, so it\n is not supported. For complex types such array/struct, the data types of fields must\n be orderable.\n\n\n\n\nExamples:\n\n\n> SELECT 2 > 1;\n true\n> SELECT 2 > '1.1';\n true\n> SELECT to_date('2009-07-30 04:17:52') > to_date('2009-07-30 04:17:52');\n false\n> SELECT to_date('2009-07-30 04:17:52') > to_date('2009-08-01 04:17:52');\n false\n> SELECT 1 > NULL;\n NULL\n\n\n\n\n\n\n>=\n\n\nexpr1 >= expr2 - Returns true if \nexpr1\n is greater than or equal to \nexpr2\n.\n\n\nArguments:\n\n\n\n\nexpr1, expr2 - the two expressions must be same type or can be casted to a common type,\n and must be a type that can be ordered. For example, map type is not orderable, so it\n is not supported. For complex types such array/struct, the data types of fields must\n be orderable.\n\n\n\n\nExamples:\n\n\n> SELECT 2 >= 1;\n true\n> SELECT 2.0 >= '2.1';\n false\n> SELECT to_date('2009-07-30 04:17:52') >= to_date('2009-07-30 04:17:52');\n true\n> SELECT to_date('2009-07-30 04:17:52') >= to_date('2009-08-01 04:17:52');\n false\n> SELECT 1 >= NULL;\n NULL\n\n\n\n\n\n\n^\n\n\nexpr1 ^ expr2 - Returns the result of bitwise exclusive OR of \nexpr1\n and \nexpr2\n.\n\n\nExamples:\n\n\n> SELECT 3 ^ 5;\n 6\n\n\n\n\n\n\nabs\n\n\nabs(expr) - Returns the absolute value of the numeric value.\n\n\nExamples:\n\n\n> SELECT abs(-1);\n 1\n\n\n\n\n\n\nacos\n\n\nacos(expr) - Returns the inverse cosine (a.k.a. arc cosine) of \nexpr\n, as if computed by\n\njava.lang.Math.acos\n.\n\n\nExamples:\n\n\n> SELECT acos(1);\n 0.0\n> SELECT acos(2);\n NaN\n\n\n\n\n\n\nadd_months\n\n\nadd_months(start_date, num_months) - Returns the date that is \nnum_months\n after \nstart_date\n.\n\n\nExamples:\n\n\n> SELECT add_months('2016-08-31', 1);\n 2016-09-30\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\naggregate\n\n\naggregate(expr, start, merge, finish) - Applies a binary operator to an initial state and all\nelements in the array, and reduces this to a single state. The final state is converted\ninto the final result by applying a finish function.\n\n\nExamples:\n\n\n> SELECT aggregate(array(1, 2, 3), 0, (acc, x) -> acc + x);\n 6\n> SELECT aggregate(array(1, 2, 3), 0, (acc, x) -> acc + x, acc -> acc * 10);\n 60\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\nand\n\n\nexpr1 and expr2 - Logical AND.\n\n\n\n\napprox_count_distinct\n\n\napprox_count_distinct(expr[, relativeSD]) - Returns the estimated cardinality by HyperLogLog++.\n\nrelativeSD\n defines the maximum estimation error allowed.\n\n\n\n\napprox_percentile\n\n\napprox_percentile(col, percentage [, accuracy]) - Returns the approximate percentile value of numeric\ncolumn \ncol\n at the given percentage. The value of percentage must be between 0.0\nand 1.0. The \naccuracy\n parameter (default: 10000) is a positive numeric literal which\ncontrols approximation accuracy at the cost of memory. Higher value of \naccuracy\n yields\nbetter accuracy, \n1.0/accuracy\n is the relative error of the approximation.\nWhen \npercentage\n is an array, each value of the percentage array must be between 0.0 and 1.0.\nIn this case, returns the approximate percentile array of column \ncol\n at the given\npercentage array.\n\n\nExamples:\n\n\n> SELECT approx_percentile(10.0, array(0.5, 0.4, 0.1), 100);\n [10.0,10.0,10.0]\n> SELECT approx_percentile(10.0, 0.5, 100);\n 10.0\n\n\n\n\n\n\narray\n\n\narray(expr, ...) - Returns an array with the given elements.\n\n\nExamples:\n\n\n> SELECT array(1, 2, 3);\n [1,2,3]\n\n\n\n\n\n\narray_contains\n\n\narray_contains(array, value) - Returns true if the array contains the value.\n\n\nExamples:\n\n\n> SELECT array_contains(array(1, 2, 3), 2);\n true\n\n\n\n\n\n\narray_distinct\n\n\narray_distinct(array) - Removes duplicate values from the array.\n\n\nExamples:\n\n\n> SELECT array_distinct(array(1, 2, 3, null, 3));\n [1,2,3,null]\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\narray_except\n\n\narray_except(array1, array2) - Returns an array of the elements in array1 but not in array2,\nwithout duplicates.\n\n\nExamples:\n\n\n> SELECT array_except(array(1, 2, 3), array(1, 3, 5));\n [2]\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\narray_intersect\n\n\narray_intersect(array1, array2) - Returns an array of the elements in the intersection of array1 and\narray2, without duplicates.\n\n\nExamples:\n\n\n> SELECT array_intersect(array(1, 2, 3), array(1, 3, 5));\n [1,3]\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\narray_join\n\n\narray_join(array, delimiter[, nullReplacement]) - Concatenates the elements of the given array\nusing the delimiter and an optional string to replace nulls. If no value is set for\nnullReplacement, any null value is filtered.\n\n\nExamples:\n\n\n> SELECT array_join(array('hello', 'world'), ' ');\n hello world\n> SELECT array_join(array('hello', null ,'world'), ' ');\n hello world\n> SELECT array_join(array('hello', null ,'world'), ' ', ',');\n hello , world\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\narray_max\n\n\narray_max(array) - Returns the maximum value in the array. NULL elements are skipped.\n\n\nExamples:\n\n\n> SELECT array_max(array(1, 20, null, 3));\n 20\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\narray_min\n\n\narray_min(array) - Returns the minimum value in the array. NULL elements are skipped.\n\n\nExamples:\n\n\n> SELECT array_min(array(1, 20, null, 3));\n 1\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\narray_position\n\n\narray_position(array, element) - Returns the (1-based) index of the first element of the array as long.\n\n\nExamples:\n\n\n> SELECT array_position(array(3, 2, 1), 1);\n 3\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\narray_remove\n\n\narray_remove(array, element) - Remove all elements that equal to element from array.\n\n\nExamples:\n\n\n> SELECT array_remove(array(1, 2, 3, null, 3), 3);\n [1,2,null]\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\narray_repeat\n\n\narray_repeat(element, count) - Returns the array containing element count times.\n\n\nExamples:\n\n\n> SELECT array_repeat('123', 2);\n [\"123\",\"123\"]\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\narray_sort\n\n\narray_sort(array) - Sorts the input array in ascending order. The elements of the input array must\nbe orderable. Null elements will be placed at the end of the returned array.\n\n\nExamples:\n\n\n> SELECT array_sort(array('b', 'd', null, 'c', 'a'));\n [\"a\",\"b\",\"c\",\"d\",null]\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\narray_union\n\n\narray_union(array1, array2) - Returns an array of the elements in the union of array1 and array2,\nwithout duplicates.\n\n\nExamples:\n\n\n> SELECT array_union(array(1, 2, 3), array(1, 3, 5));\n [1,2,3,5]\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\narrays_overlap\n\n\narrays_overlap(a1, a2) - Returns true if a1 contains at least a non-null element present also in a2. If the arrays have no common element and they are both non-empty and either of them contains a null element null is returned, false otherwise.\n\n\nExamples:\n\n\n> SELECT arrays_overlap(array(1, 2, 3), array(3, 4, 5));\n true\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\narrays_zip\n\n\narrays_zip(a1, a2, ...) - Returns a merged array of structs in which the N-th struct contains all\nN-th values of input arrays.\n\n\nExamples:\n\n\n> SELECT arrays_zip(array(1, 2, 3), array(2, 3, 4));\n [{\"0\":1,\"1\":2},{\"0\":2,\"1\":3},{\"0\":3,\"1\":4}]\n> SELECT arrays_zip(array(1, 2), array(2, 3), array(3, 4));\n [{\"0\":1,\"1\":2,\"2\":3},{\"0\":2,\"1\":3,\"2\":4}]\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\nascii\n\n\nascii(str) - Returns the numeric value of the first character of \nstr\n.\n\n\nExamples:\n\n\n> SELECT ascii('222');\n 50\n> SELECT ascii(2);\n 50\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nasin\n\n\nasin(expr) - Returns the inverse sine (a.k.a. arc sine) the arc sin of \nexpr\n,\nas if computed by \njava.lang.Math.asin\n.\n\n\nExamples:\n\n\n> SELECT asin(0);\n 0.0\n> SELECT asin(2);\n NaN\n\n\n\n\n\n\nassert_true\n\n\nassert_true(expr) - Throws an exception if \nexpr\n is not true.\n\n\nExamples:\n\n\n> SELECT assert_true(0 < 1);\n NULL\n\n\n\n\n\n\natan\n\n\natan(expr) - Returns the inverse tangent (a.k.a. arc tangent) of \nexpr\n, as if computed by\n\njava.lang.Math.atan\n\n\nExamples:\n\n\n> SELECT atan(0);\n 0.0\n\n\n\n\n\n\natan2\n\n\natan2(exprY, exprX) - Returns the angle in radians between the positive x-axis of a plane\nand the point given by the coordinates (\nexprX\n, \nexprY\n), as if computed by\n\njava.lang.Math.atan2\n.\n\n\nArguments:\n\n\n\n\nexprY - coordinate on y-axis\n\n\nexprX - coordinate on x-axis\n\n\n\n\nExamples:\n\n\n> SELECT atan2(0, 0);\n 0.0\n\n\n\n\n\n\navg\n\n\navg(expr) - Returns the mean calculated from values of a group.\n\n\n\n\nbase64\n\n\nbase64(bin) - Converts the argument from a binary \nbin\n to a base 64 string.\n\n\nExamples:\n\n\n> SELECT base64('Spark SQL');\n U3BhcmsgU1FM\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nbigint\n\n\nbigint(expr) - Casts the value \nexpr\n to the target data type \nbigint\n.\n\n\n\n\nbin\n\n\nbin(expr) - Returns the string representation of the long value \nexpr\n represented in binary.\n\n\nExamples:\n\n\n> SELECT bin(13);\n 1101\n> SELECT bin(-13);\n 1111111111111111111111111111111111111111111111111111111111110011\n> SELECT bin(13.3);\n 1101\n\n\n\n\n\n\nbinary\n\n\nbinary(expr) - Casts the value \nexpr\n to the target data type \nbinary\n.\n\n\n\n\nbit_length\n\n\nbit_length(expr) - Returns the bit length of string data or number of bits of binary data.\n\n\nExamples:\n\n\n> SELECT bit_length('Spark SQL');\n 72\n\n\n\n\nSince:\n 2.3.0\n\n\n\n\nboolean\n\n\nboolean(expr) - Casts the value \nexpr\n to the target data type \nboolean\n.\n\n\n\n\nbround\n\n\nbround(expr, d) - Returns \nexpr\n rounded to \nd\n decimal places using HALF_EVEN rounding mode.\n\n\nExamples:\n\n\n> SELECT bround(2.5, 0);\n 2.0\n\n\n\n\n\n\ncardinality\n\n\ncardinality(expr) - Returns the size of an array or a map.\nThe function returns -1 if its input is null and spark.sql.legacy.sizeOfNull is set to true.\nIf spark.sql.legacy.sizeOfNull is set to false, the function returns null for null input.\nBy default, the spark.sql.legacy.sizeOfNull parameter is set to true.\n\n\nExamples:\n\n\n> SELECT cardinality(array('b', 'd', 'c', 'a'));\n 4\n> SELECT cardinality(map('a', 1, 'b', 2));\n 2\n> SELECT cardinality(NULL);\n -1\n\n\n\n\n\n\ncast\n\n\ncast(expr AS type) - Casts the value \nexpr\n to the target data type \ntype\n.\n\n\nExamples:\n\n\n> SELECT cast('10' as int);\n 10\n\n\n\n\n\n\ncbrt\n\n\ncbrt(expr) - Returns the cube root of \nexpr\n.\n\n\nExamples:\n\n\n> SELECT cbrt(27.0);\n 3.0\n\n\n\n\n\n\nceil\n\n\nceil(expr) - Returns the smallest integer not smaller than \nexpr\n.\n\n\nExamples:\n\n\n> SELECT ceil(-0.1);\n 0\n> SELECT ceil(5);\n 5\n\n\n\n\n\n\nceiling\n\n\nceiling(expr) - Returns the smallest integer not smaller than \nexpr\n.\n\n\nExamples:\n\n\n> SELECT ceiling(-0.1);\n 0\n> SELECT ceiling(5);\n 5\n\n\n\n\n\n\nchar\n\n\nchar(expr) - Returns the ASCII character having the binary equivalent to \nexpr\n. If n is larger than 256 the result is equivalent to chr(n % 256)\n\n\nExamples:\n\n\n> SELECT char(65);\n A\n\n\n\n\nSince:\n 2.3.0\n\n\n\n\nchar_length\n\n\nchar_length(expr) - Returns the character length of string data or number of bytes of binary data. The length of string data includes the trailing spaces. The length of binary data includes binary zeros.\n\n\nExamples:\n\n\n> SELECT char_length('Spark SQL ');\n 10\n> SELECT CHAR_LENGTH('Spark SQL ');\n 10\n> SELECT CHARACTER_LENGTH('Spark SQL ');\n 10\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\ncharacter_length\n\n\ncharacter_length(expr) - Returns the character length of string data or number of bytes of binary data. The length of string data includes the trailing spaces. The length of binary data includes binary zeros.\n\n\nExamples:\n\n\n> SELECT character_length('Spark SQL ');\n 10\n> SELECT CHAR_LENGTH('Spark SQL ');\n 10\n> SELECT CHARACTER_LENGTH('Spark SQL ');\n 10\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nchr\n\n\nchr(expr) - Returns the ASCII character having the binary equivalent to \nexpr\n. If n is larger than 256 the result is equivalent to chr(n % 256)\n\n\nExamples:\n\n\n> SELECT chr(65);\n A\n\n\n\n\nSince:\n 2.3.0\n\n\n\n\ncoalesce\n\n\ncoalesce(expr1, expr2, ...) - Returns the first non-null argument if exists. Otherwise, null.\n\n\nExamples:\n\n\n> SELECT coalesce(NULL, 1, NULL);\n 1\n\n\n\n\nSince:\n 1.0.0\n\n\n\n\ncollect_list\n\n\ncollect_list(expr) - Collects and returns a list of non-unique elements.\n\n\n\n\ncollect_set\n\n\ncollect_set(expr) - Collects and returns a set of unique elements.\n\n\n\n\nconcat\n\n\nconcat(col1, col2, ..., colN) - Returns the concatenation of col1, col2, ..., colN.\n\n\nExamples:\n\n\n> SELECT concat('Spark', 'SQL');\n SparkSQL\n> SELECT concat(array(1, 2, 3), array(4, 5), array(6));\n [1,2,3,4,5,6]\n\n\n\n\nNote:\n\nat logic for arrays is available since 2.4.0.\n\n\n\nconcat_ws\n\n\nconcat_ws(sep, [str | array(str)]+) - Returns the concatenation of the strings separated by \nsep\n.\n\n\nExamples:\n\n\n> SELECT concat_ws(' ', 'Spark', 'SQL');\n Spark SQL\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nconv\n\n\nconv(num, from_base, to_base) - Convert \nnum\n from \nfrom_base\n to \nto_base\n.\n\n\nExamples:\n\n\n> SELECT conv('100', 2, 10);\n 4\n> SELECT conv(-10, 16, -10);\n -16\n\n\n\n\n\n\ncorr\n\n\ncorr(expr1, expr2) - Returns Pearson coefficient of correlation between a set of number pairs.\n\n\n\n\ncos\n\n\ncos(expr) - Returns the cosine of \nexpr\n, as if computed by\n\njava.lang.Math.cos\n.\n\n\nArguments:\n\n\n\n\nexpr - angle in radians\n\n\n\n\nExamples:\n\n\n> SELECT cos(0);\n 1.0\n\n\n\n\n\n\ncosh\n\n\ncosh(expr) - Returns the hyperbolic cosine of \nexpr\n, as if computed by\n\njava.lang.Math.cosh\n.\n\n\nArguments:\n\n\n\n\nexpr - hyperbolic angle\n\n\n\n\nExamples:\n\n\n> SELECT cosh(0);\n 1.0\n\n\n\n\n\n\ncot\n\n\ncot(expr) - Returns the cotangent of \nexpr\n, as if computed by \n1/java.lang.Math.cot\n.\n\n\nArguments:\n\n\n\n\nexpr - angle in radians\n\n\n\n\nExamples:\n\n\n> SELECT cot(1);\n 0.6420926159343306\n\n\n\n\n\n\ncount\n\n\ncount(*) - Returns the total number of retrieved rows, including rows containing null.\n\n\ncount(expr[, expr...]) - Returns the number of rows for which the supplied expression(s) are all non-null.\n\n\ncount(DISTINCT expr[, expr...]) - Returns the number of rows for which the supplied expression(s) are unique and non-null.\n\n\n\n\ncount_min_sketch\n\n\ncount_min_sketch(col, eps, confidence, seed) - Returns a count-min sketch of a column with the given esp,\nconfidence and seed. The result is an array of bytes, which can be deserialized to a\n\nCountMinSketch\n before usage. Count-min sketch is a probabilistic data structure used for\ncardinality estimation using sub-linear space.\n\n\n\n\ncovar_pop\n\n\ncovar_pop(expr1, expr2) - Returns the population covariance of a set of number pairs.\n\n\n\n\ncovar_samp\n\n\ncovar_samp(expr1, expr2) - Returns the sample covariance of a set of number pairs.\n\n\n\n\ncrc32\n\n\ncrc32(expr) - Returns a cyclic redundancy check value of the \nexpr\n as a bigint.\n\n\nExamples:\n\n\n> SELECT crc32('Spark');\n 1557323817\n\n\n\n\n\n\ncube\n\n\ncube([col1[, col2 ..]]) - create a multi-dimensional cube using the specified columns\nso that we can run aggregation on them.\n\n\nExamples:\n\n\n> SELECT name, age, count(*) FROM VALUES (2, 'Alice'), (5, 'Bob') people(age, name) GROUP BY cube(name, age);\n NULL 2 1\n NULL NULL 2\n Alice 2 1\n Bob 5 1\n NULL 5 1\n Bob NULL 1\n Alice NULL 1\n\n\n\n\nSince:\n 2.0.0\n\n\n\n\ncume_dist\n\n\ncume_dist() - Computes the position of a value relative to all values in the partition.\n\n\n\n\ncurrent_database\n\n\ncurrent_database() - Returns the current database.\n\n\nExamples:\n\n\n> SELECT current_database();\n default\n\n\n\n\n\n\ncurrent_date\n\n\ncurrent_date() - Returns the current date at the start of query evaluation.\n\n\nSince:\n 1.5.0\n\n\n\n\ncurrent_timestamp\n\n\ncurrent_timestamp() - Returns the current timestamp at the start of query evaluation.\n\n\nSince:\n 1.5.0\n\n\n\n\ndate\n\n\ndate(expr) - Casts the value \nexpr\n to the target data type \ndate\n.\n\n\n\n\ndate_add\n\n\ndate_add(start_date, num_days) - Returns the date that is \nnum_days\n after \nstart_date\n.\n\n\nExamples:\n\n\n> SELECT date_add('2016-07-30', 1);\n 2016-07-31\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\ndate_format\n\n\ndate_format(timestamp, fmt) - Converts \ntimestamp\n to a value of string in the format specified by the date format \nfmt\n.\n\n\nExamples:\n\n\n> SELECT date_format('2016-04-08', 'y');\n 2016\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\ndate_sub\n\n\ndate_sub(start_date, num_days) - Returns the date that is \nnum_days\n before \nstart_date\n.\n\n\nExamples:\n\n\n> SELECT date_sub('2016-07-30', 1);\n 2016-07-29\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\ndate_trunc\n\n\ndate_trunc(fmt, ts) - Returns timestamp \nts\n truncated to the unit specified by the format model \nfmt\n.\n\nfmt\n should be one of [\"YEAR\", \"YYYY\", \"YY\", \"MON\", \"MONTH\", \"MM\", \"DAY\", \"DD\", \"HOUR\", \"MINUTE\", \"SECOND\", \"WEEK\", \"QUARTER\"]\n\n\nExamples:\n\n\n> SELECT date_trunc('YEAR', '2015-03-05T09:32:05.359');\n 2015-01-01 00:00:00\n> SELECT date_trunc('MM', '2015-03-05T09:32:05.359');\n 2015-03-01 00:00:00\n> SELECT date_trunc('DD', '2015-03-05T09:32:05.359');\n 2015-03-05 00:00:00\n> SELECT date_trunc('HOUR', '2015-03-05T09:32:05.359');\n 2015-03-05 09:00:00\n\n\n\n\nSince:\n 2.3.0\n\n\n\n\ndatediff\n\n\ndatediff(endDate, startDate) - Returns the number of days from \nstartDate\n to \nendDate\n.\n\n\nExamples:\n\n\n> SELECT datediff('2009-07-31', '2009-07-30');\n 1\n\n> SELECT datediff('2009-07-30', '2009-07-31');\n -1\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nday\n\n\nday(date) - Returns the day of month of the date/timestamp.\n\n\nExamples:\n\n\n> SELECT day('2009-07-30');\n 30\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\ndayofmonth\n\n\ndayofmonth(date) - Returns the day of month of the date/timestamp.\n\n\nExamples:\n\n\n> SELECT dayofmonth('2009-07-30');\n 30\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\ndayofweek\n\n\ndayofweek(date) - Returns the day of the week for date/timestamp (1 = Sunday, 2 = Monday, ..., 7 = Saturday).\n\n\nExamples:\n\n\n> SELECT dayofweek('2009-07-30');\n 5\n\n\n\n\nSince:\n 2.3.0\n\n\n\n\ndayofyear\n\n\ndayofyear(date) - Returns the day of year of the date/timestamp.\n\n\nExamples:\n\n\n> SELECT dayofyear('2016-04-09');\n 100\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\ndecimal\n\n\ndecimal(expr) - Casts the value \nexpr\n to the target data type \ndecimal\n.\n\n\n\n\ndecode\n\n\ndecode(bin, charset) - Decodes the first argument using the second argument character set.\n\n\nExamples:\n\n\n> SELECT decode(encode('abc', 'utf-8'), 'utf-8');\n abc\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\ndegrees\n\n\ndegrees(expr) - Converts radians to degrees.\n\n\nArguments:\n\n\n\n\nexpr - angle in radians\n\n\n\n\nExamples:\n\n\n> SELECT degrees(3.141592653589793);\n 180.0\n\n\n\n\n\n\ndense_rank\n\n\ndense_rank() - Computes the rank of a value in a group of values. The result is one plus the\npreviously assigned rank value. Unlike the function rank, dense_rank will not produce gaps\nin the ranking sequence.\n\n\n\n\ndouble\n\n\ndouble(expr) - Casts the value \nexpr\n to the target data type \ndouble\n.\n\n\n\n\ne\n\n\ne() - Returns Euler's number, e.\n\n\nExamples:\n\n\n> SELECT e();\n 2.718281828459045\n\n\n\n\n\n\nelement_at\n\n\nelement_at(array, index) - Returns element of array at given (1-based) index. If index < 0,\naccesses elements from the last to the first. Returns NULL if the index exceeds the length\nof the array.\n\n\nelement_at(map, key) - Returns value for given key, or NULL if the key is not contained in the map\n\n\nExamples:\n\n\n> SELECT element_at(array(1, 2, 3), 2);\n 2\n> SELECT element_at(map(1, 'a', 2, 'b'), 2);\n b\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\nelt\n\n\nelt(n, input1, input2, ...) - Returns the \nn\n-th input, e.g., returns \ninput2\n when \nn\n is 2.\n\n\nExamples:\n\n\n> SELECT elt(1, 'scala', 'java');\n scala\n\n\n\n\nSince:\n 2.0.0\n\n\n\n\nencode\n\n\nencode(str, charset) - Encodes the first argument using the second argument character set.\n\n\nExamples:\n\n\n> SELECT encode('abc', 'utf-8');\n abc\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nexists\n\n\nexists(expr, pred) - Tests whether a predicate holds for one or more elements in the array.\n\n\nExamples:\n\n\n> SELECT exists(array(1, 2, 3), x -> x % 2 == 0);\n true\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\nexp\n\n\nexp(expr) - Returns e to the power of \nexpr\n.\n\n\nExamples:\n\n\n> SELECT exp(0);\n 1.0\n\n\n\n\n\n\nexplode\n\n\nexplode(expr) - Separates the elements of array \nexpr\n into multiple rows, or the elements of map \nexpr\n into multiple rows and columns.\n\n\nExamples:\n\n\n> SELECT explode(array(10, 20));\n 10\n 20\n\n\n\n\n\n\nexplode_outer\n\n\nexplode_outer(expr) - Separates the elements of array \nexpr\n into multiple rows, or the elements of map \nexpr\n into multiple rows and columns.\n\n\nExamples:\n\n\n> SELECT explode_outer(array(10, 20));\n 10\n 20\n\n\n\n\n\n\nexpm1\n\n\nexpm1(expr) - Returns exp(\nexpr\n) - 1.\n\n\nExamples:\n\n\n> SELECT expm1(0);\n 0.0\n\n\n\n\n\n\nfactorial\n\n\nfactorial(expr) - Returns the factorial of \nexpr\n. \nexpr\n is [0..20]. Otherwise, null.\n\n\nExamples:\n\n\n> SELECT factorial(5);\n 120\n\n\n\n\n\n\nfilter\n\n\nfilter(expr, func) - Filters the input array using the given predicate.\n\n\nExamples:\n\n\n> SELECT filter(array(1, 2, 3), x -> x % 2 == 1);\n [1,3]\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\nfind_in_set\n\n\nfind_in_set(str, str_array) - Returns the index (1-based) of the given string (\nstr\n) in the comma-delimited list (\nstr_array\n).\nReturns 0, if the string was not found or if the given string (\nstr\n) contains a comma.\n\n\nExamples:\n\n\n> SELECT find_in_set('ab','abc,b,ab,c,def');\n 3\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nfirst\n\n\nfirst(expr[, isIgnoreNull]) - Returns the first value of \nexpr\n for a group of rows.\nIf \nisIgnoreNull\n is true, returns only non-null values.\n\n\n\n\nfirst_value\n\n\nfirst_value(expr[, isIgnoreNull]) - Returns the first value of \nexpr\n for a group of rows.\nIf \nisIgnoreNull\n is true, returns only non-null values.\n\n\n\n\nflatten\n\n\nflatten(arrayOfArrays) - Transforms an array of arrays into a single array.\n\n\nExamples:\n\n\n> SELECT flatten(array(array(1, 2), array(3, 4)));\n [1,2,3,4]\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\nfloat\n\n\nfloat(expr) - Casts the value \nexpr\n to the target data type \nfloat\n.\n\n\n\n\nfloor\n\n\nfloor(expr) - Returns the largest integer not greater than \nexpr\n.\n\n\nExamples:\n\n\n> SELECT floor(-0.1);\n -1\n> SELECT floor(5);\n 5\n\n\n\n\n\n\nformat_number\n\n\nformat_number(expr1, expr2) - Formats the number \nexpr1\n like '#,###,###.##', rounded to \nexpr2\n\ndecimal places. If \nexpr2\n is 0, the result has no decimal point or fractional part.\n\nexpr2\n also accept a user specified format.\nThis is supposed to function like MySQL's FORMAT.\n\n\nExamples:\n\n\n> SELECT format_number(12332.123456, 4);\n 12,332.1235\n> SELECT format_number(12332.123456, '##################.###');\n 12332.123\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nformat_string\n\n\nformat_string(strfmt, obj, ...) - Returns a formatted string from printf-style format strings.\n\n\nExamples:\n\n\n> SELECT format_string(\"Hello World %d %s\", 100, \"days\");\n Hello World 100 days\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nfrom_json\n\n\nfrom_json(jsonStr, schema[, options]) - Returns a struct value with the given \njsonStr\n and \nschema\n.\n\n\nExamples:\n\n\n> SELECT from_json('{\"a\":1, \"b\":0.8}', 'a INT, b DOUBLE');\n {\"a\":1, \"b\":0.8}\n> SELECT from_json('{\"time\":\"26/08/2015\"}', 'time Timestamp', map('timestampFormat', 'dd/MM/yyyy'));\n {\"time\":\"2015-08-26 00:00:00.0\"}\n\n\n\n\nSince:\n 2.2.0\n\n\n\n\nfrom_unixtime\n\n\nfrom_unixtime(unix_time, format) - Returns \nunix_time\n in the specified \nformat\n.\n\n\nExamples:\n\n\n> SELECT from_unixtime(0, 'yyyy-MM-dd HH:mm:ss');\n 1970-01-01 00:00:00\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nfrom_utc_timestamp\n\n\nfrom_utc_timestamp(timestamp, timezone) - 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'.\n\n\nExamples:\n\n\n> SELECT from_utc_timestamp('2016-08-31', 'Asia/Seoul');\n 2016-08-31 09:00:00\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nget_json_object\n\n\nget_json_object(json_txt, path) - Extracts a json object from \npath\n.\n\n\nExamples:\n\n\n> SELECT get_json_object('{\"a\":\"b\"}', '$.a');\n b\n\n\n\n\n\n\ngreatest\n\n\ngreatest(expr, ...) - Returns the greatest value of all parameters, skipping null values.\n\n\nExamples:\n\n\n> SELECT greatest(10, 9, 2, 4, 3);\n 10\n\n\n\n\n\n\ngrouping\n\n\ngrouping(col) - indicates whether a specified column in a GROUP BY is aggregated or\nnot, returns 1 for aggregated or 0 for not aggregated in the result set.\",\n\n\nExamples:\n\n\n> SELECT name, grouping(name), sum(age) FROM VALUES (2, 'Alice'), (5, 'Bob') people(age, name) GROUP BY cube(name);\n Alice 0 2\n NULL 1 7\n Bob 0 5\n\n\n\n\nSince:\n 2.0.0\n\n\n\n\ngrouping_id\n\n\ngrouping_id([col1[, col2 ..]]) - returns the level of grouping, equals to\n\n(grouping(c1) << (n-1)) + (grouping(c2) << (n-2)) + ... + grouping(cn)\n\n\nExamples:\n\n\n> SELECT name, grouping_id(), sum(age), avg(height) FROM VALUES (2, 'Alice', 165), (5, 'Bob', 180) people(age, name, height) GROUP BY cube(name, height);\n NULL 2 2 165.0\n Alice 0 2 165.0\n NULL 2 5 180.0\n NULL 3 7 172.5\n Bob 0 5 180.0\n Bob 1 5 180.0\n Alice 1 2 165.0\n\n\n\n\nNote:\n\n\nInput columns should match with grouping columns exactly, or empty (means all the grouping\ncolumns).\n\n\nSince:\n 2.0.0\n\n\n\n\nhash\n\n\nhash(expr1, expr2, ...) - Returns a hash value of the arguments.\n\n\nExamples:\n\n\n> SELECT hash('Spark', array(123), 2);\n -1321691492\n\n\n\n\n\n\nhex\n\n\nhex(expr) - Converts \nexpr\n to hexadecimal.\n\n\nExamples:\n\n\n> SELECT hex(17);\n 11\n> SELECT hex('Spark SQL');\n 537061726B2053514C\n\n\n\n\n\n\nhour\n\n\nhour(timestamp) - Returns the hour component of the string/timestamp.\n\n\nExamples:\n\n\n> SELECT hour('2009-07-30 12:58:59');\n 12\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nhypot\n\n\nhypot(expr1, expr2) - Returns sqrt(\nexpr1\n2 + \nexpr2\n2).\n\n\nExamples:\n\n\n> SELECT hypot(3, 4);\n 5.0\n\n\n\n\n\n\nif\n\n\nif(expr1, expr2, expr3) - If \nexpr1\n evaluates to true, then returns \nexpr2\n; otherwise returns \nexpr3\n.\n\n\nExamples:\n\n\n> SELECT if(1 < 2, 'a', 'b');\n a\n\n\n\n\n\n\nifnull\n\n\nifnull(expr1, expr2) - Returns \nexpr2\n if \nexpr1\n is null, or \nexpr1\n otherwise.\n\n\nExamples:\n\n\n> SELECT ifnull(NULL, array('2'));\n [\"2\"]\n\n\n\n\nSince:\n 2.0.0\n\n\n\n\nin\n\n\nexpr1 in(expr2, expr3, ...) - Returns true if \nexpr\n equals to any valN.\n\n\nArguments:\n\n\n\n\nexpr1, expr2, expr3, ... - the arguments must be same type.\n\n\n\n\nExamples:\n\n\n> SELECT 1 in(1, 2, 3);\n true\n> SELECT 1 in(2, 3, 4);\n false\n> SELECT named_struct('a', 1, 'b', 2) in(named_struct('a', 1, 'b', 1), named_struct('a', 1, 'b', 3));\n false\n> SELECT named_struct('a', 1, 'b', 2) in(named_struct('a', 1, 'b', 2), named_struct('a', 1, 'b', 3));\n true\n\n\n\n\n\n\ninitcap\n\n\ninitcap(str) - Returns \nstr\n with the first letter of each word in uppercase.\nAll other letters are in lowercase. Words are delimited by white space.\n\n\nExamples:\n\n\n> SELECT initcap('sPark sql');\n Spark Sql\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\ninline\n\n\ninline(expr) - Explodes an array of structs into a table.\n\n\nExamples:\n\n\n> SELECT inline(array(struct(1, 'a'), struct(2, 'b')));\n 1 a\n 2 b\n\n\n\n\n\n\ninline_outer\n\n\ninline_outer(expr) - Explodes an array of structs into a table.\n\n\nExamples:\n\n\n> SELECT inline_outer(array(struct(1, 'a'), struct(2, 'b')));\n 1 a\n 2 b\n\n\n\n\n\n\ninput_file_block_length\n\n\ninput_file_block_length() - Returns the length of the block being read, or -1 if not available.\n\n\n\n\ninput_file_block_start\n\n\ninput_file_block_start() - Returns the start offset of the block being read, or -1 if not available.\n\n\n\n\ninput_file_name\n\n\ninput_file_name() - Returns the name of the file being read, or empty string if not available.\n\n\n\n\ninstr\n\n\ninstr(str, substr) - Returns the (1-based) index of the first occurrence of \nsubstr\n in \nstr\n.\n\n\nExamples:\n\n\n> SELECT instr('SparkSQL', 'SQL');\n 6\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nint\n\n\nint(expr) - Casts the value \nexpr\n to the target data type \nint\n.\n\n\n\n\nisnan\n\n\nisnan(expr) - Returns true if \nexpr\n is NaN, or false otherwise.\n\n\nExamples:\n\n\n> SELECT isnan(cast('NaN' as double));\n true\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nisnotnull\n\n\nisnotnull(expr) - Returns true if \nexpr\n is not null, or false otherwise.\n\n\nExamples:\n\n\n> SELECT isnotnull(1);\n true\n\n\n\n\nSince:\n 1.0.0\n\n\n\n\nisnull\n\n\nisnull(expr) - Returns true if \nexpr\n is null, or false otherwise.\n\n\nExamples:\n\n\n> SELECT isnull(1);\n false\n\n\n\n\nSince:\n 1.0.0\n\n\n\n\njava_method\n\n\njava_method(class, method[, arg1[, arg2 ..]]) - Calls a method with reflection.\n\n\nExamples:\n\n\n> SELECT java_method('java.util.UUID', 'randomUUID');\n c33fb387-8500-4bfa-81d2-6e0e3e930df2\n> SELECT java_method('java.util.UUID', 'fromString', 'a5cf6c42-0c85-418f-af6c-3e4e5b1328f2');\n a5cf6c42-0c85-418f-af6c-3e4e5b1328f2\n\n\n\n\n\n\njson_tuple\n\n\njson_tuple(jsonStr, p1, p2, ..., pn) - Returns a tuple like the function get_json_object, but it takes multiple names. All the input parameters and output column types are string.\n\n\nExamples:\n\n\n> SELECT json_tuple('{\"a\":1, \"b\":2}', 'a', 'b');\n 1 2\n\n\n\n\n\n\nkurtosis\n\n\nkurtosis(expr) - Returns the kurtosis value calculated from values of a group.\n\n\n\n\nlag\n\n\nlag(input[, offset[, default]]) - Returns the value of \ninput\n at the \noffset\nth row\nbefore the current row in the window. The default value of \noffset\n is 1 and the default\nvalue of \ndefault\n is null. If the value of \ninput\n at the \noffset\nth row is null,\nnull is returned. If there is no such offset row (e.g., when the offset is 1, the first\nrow of the window does not have any previous row), \ndefault\n is returned.\n\n\n\n\nlast\n\n\nlast(expr[, isIgnoreNull]) - Returns the last value of \nexpr\n for a group of rows.\nIf \nisIgnoreNull\n is true, returns only non-null values.\n\n\n\n\nlast_day\n\n\nlast_day(date) - Returns the last day of the month which the date belongs to.\n\n\nExamples:\n\n\n> SELECT last_day('2009-01-12');\n 2009-01-31\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nlast_value\n\n\nlast_value(expr[, isIgnoreNull]) - Returns the last value of \nexpr\n for a group of rows.\nIf \nisIgnoreNull\n is true, returns only non-null values.\n\n\n\n\nlcase\n\n\nlcase(str) - Returns \nstr\n with all characters changed to lowercase.\n\n\nExamples:\n\n\n> SELECT lcase('SparkSql');\n sparksql\n\n\n\n\nSince:\n 1.0.1\n\n\n\n\nlead\n\n\nlead(input[, offset[, default]]) - Returns the value of \ninput\n at the \noffset\nth row\nafter the current row in the window. The default value of \noffset\n is 1 and the default\nvalue of \ndefault\n is null. If the value of \ninput\n at the \noffset\nth row is null,\nnull is returned. If there is no such an offset row (e.g., when the offset is 1, the last\nrow of the window does not have any subsequent row), \ndefault\n is returned.\n\n\n\n\nleast\n\n\nleast(expr, ...) - Returns the least value of all parameters, skipping null values.\n\n\nExamples:\n\n\n> SELECT least(10, 9, 2, 4, 3);\n 2\n\n\n\n\n\n\nleft\n\n\nleft(str, len) - Returns the leftmost \nlen\n(\nlen\n can be string type) characters from the string \nstr\n,if \nlen\n is less or equal than 0 the result is an empty string.\n\n\nExamples:\n\n\n> SELECT left('Spark SQL', 3);\n Spa\n\n\n\n\nSince:\n 2.3.0\n\n\n\n\nlength\n\n\nlength(expr) - Returns the character length of string data or number of bytes of binary data. The length of string data includes the trailing spaces. The length of binary data includes binary zeros.\n\n\nExamples:\n\n\n> SELECT length('Spark SQL ');\n 10\n> SELECT CHAR_LENGTH('Spark SQL ');\n 10\n> SELECT CHARACTER_LENGTH('Spark SQL ');\n 10\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nlevenshtein\n\n\nlevenshtein(str1, str2) - Returns the Levenshtein distance between the two given strings.\n\n\nExamples:\n\n\n> SELECT levenshtein('kitten', 'sitting');\n 3\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nlike\n\n\nstr like pattern - Returns true if str matches pattern, null if any arguments are null, false otherwise.\n\n\nArguments:\n\n\n\n\nstr - a string expression\n\n\n\n\npattern - a string expression. The pattern is a string which is matched literally, with\n exception to the following special symbols:\n\n\n_ matches any one character in the input (similar to . in posix regular expressions)\n\n\n% matches zero or more characters in the input (similar to .* in posix regular\nexpressions)\n\n\nThe escape character is '\\'. If an escape character precedes a special symbol or another\nescape character, the following character is matched literally. It is invalid to escape\nany other character.\n\n\nSince Spark 2.0, string literals are unescaped in our SQL parser. For example, in order\nto match \"\\abc\", the pattern should be \"\\abc\".\n\n\nWhen SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, it fallbacks\nto Spark 1.6 behavior regarding string literal parsing. For example, if the config is\nenabled, the pattern to match \"\\abc\" should be \"\\abc\".\n\n\n\n\n\n\nExamples:\n\n\n> SELECT '%SystemDrive%\\Users\\John' like '\\%SystemDrive\\%\\\\Users%'\ntrue\n\n\n\n\nNote:\n\n\nUse RLIKE to match with standard regular expressions.\n\n\nSince:\n 1.0.0\n\n\n\n\nln\n\n\nln(expr) - Returns the natural logarithm (base e) of \nexpr\n.\n\n\nExamples:\n\n\n> SELECT ln(1);\n 0.0\n\n\n\n\n\n\nlocate\n\n\nlocate(substr, str[, pos]) - Returns the position of the first occurrence of \nsubstr\n in \nstr\n after position \npos\n.\nThe given \npos\n and return value are 1-based.\n\n\nExamples:\n\n\n> SELECT locate('bar', 'foobarbar');\n 4\n> SELECT locate('bar', 'foobarbar', 5);\n 7\n> SELECT POSITION('bar' IN 'foobarbar');\n 4\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nlog\n\n\nlog(base, expr) - Returns the logarithm of \nexpr\n with \nbase\n.\n\n\nExamples:\n\n\n> SELECT log(10, 100);\n 2.0\n\n\n\n\n\n\nlog10\n\n\nlog10(expr) - Returns the logarithm of \nexpr\n with base 10.\n\n\nExamples:\n\n\n> SELECT log10(10);\n 1.0\n\n\n\n\n\n\nlog1p\n\n\nlog1p(expr) - Returns log(1 + \nexpr\n).\n\n\nExamples:\n\n\n> SELECT log1p(0);\n 0.0\n\n\n\n\n\n\nlog2\n\n\nlog2(expr) - Returns the logarithm of \nexpr\n with base 2.\n\n\nExamples:\n\n\n> SELECT log2(2);\n 1.0\n\n\n\n\n\n\nlower\n\n\nlower(str) - Returns \nstr\n with all characters changed to lowercase.\n\n\nExamples:\n\n\n> SELECT lower('SparkSql');\n sparksql\n\n\n\n\nSince:\n 1.0.1\n\n\n\n\nlpad\n\n\nlpad(str, len, pad) - Returns \nstr\n, left-padded with \npad\n to a length of \nlen\n.\nIf \nstr\n is longer than \nlen\n, the return value is shortened to \nlen\n characters.\n\n\nExamples:\n\n\n> SELECT lpad('hi', 5, '??');\n ???hi\n> SELECT lpad('hi', 1, '??');\n h\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nltrim\n\n\nltrim(str) - Removes the leading space characters from \nstr\n.\n\n\nltrim(trimStr, str) - Removes the leading string contains the characters from the trim string\n\n\nArguments:\n\n\n\n\nstr - a string expression\n\n\ntrimStr - the trim string characters to trim, the default value is a single space\n\n\n\n\nExamples:\n\n\n> SELECT ltrim(' SparkSQL ');\n SparkSQL\n> SELECT ltrim('Sp', 'SSparkSQLS');\n arkSQLS\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nmap\n\n\nmap(key0, value0, key1, value1, ...) - Creates a map with the given key/value pairs.\n\n\nExamples:\n\n\n> SELECT map(1.0, '2', 3.0, '4');\n {1.0:\"2\",3.0:\"4\"}\n\n\n\n\n\n\nmap_concat\n\n\nmap_concat(map, ...) - Returns the union of all the given maps\n\n\nExamples:\n\n\n> SELECT map_concat(map(1, 'a', 2, 'b'), map(2, 'c', 3, 'd'));\n {1:\"a\",2:\"c\",3:\"d\"}\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\nmap_from_arrays\n\n\nmap_from_arrays(keys, values) - Creates a map with a pair of the given key/value arrays. All elements\nin keys should not be null\n\n\nExamples:\n\n\n> SELECT map_from_arrays(array(1.0, 3.0), array('2', '4'));\n {1.0:\"2\",3.0:\"4\"}\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\nmap_from_entries\n\n\nmap_from_entries(arrayOfEntries) - Returns a map created from the given array of entries.\n\n\nExamples:\n\n\n> SELECT map_from_entries(array(struct(1, 'a'), struct(2, 'b')));\n {1:\"a\",2:\"b\"}\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\nmap_keys\n\n\nmap_keys(map) - Returns an unordered array containing the keys of the map.\n\n\nExamples:\n\n\n> SELECT map_keys(map(1, 'a', 2, 'b'));\n [1,2]\n\n\n\n\n\n\nmap_values\n\n\nmap_values(map) - Returns an unordered array containing the values of the map.\n\n\nExamples:\n\n\n> SELECT map_values(map(1, 'a', 2, 'b'));\n [\"a\",\"b\"]\n\n\n\n\n\n\nmax\n\n\nmax(expr) - Returns the maximum value of \nexpr\n.\n\n\n\n\nmd5\n\n\nmd5(expr) - Returns an MD5 128-bit checksum as a hex string of \nexpr\n.\n\n\nExamples:\n\n\n> SELECT md5('Spark');\n 8cde774d6f7333752ed72cacddb05126\n\n\n\n\n\n\nmean\n\n\nmean(expr) - Returns the mean calculated from values of a group.\n\n\n\n\nmin\n\n\nmin(expr) - Returns the minimum value of \nexpr\n.\n\n\n\n\nminute\n\n\nminute(timestamp) - Returns the minute component of the string/timestamp.\n\n\nExamples:\n\n\n> SELECT minute('2009-07-30 12:58:59');\n 58\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nmod\n\n\nexpr1 mod expr2 - Returns the remainder after \nexpr1\n/\nexpr2\n.\n\n\nExamples:\n\n\n> SELECT 2 mod 1.8;\n 0.2\n> SELECT MOD(2, 1.8);\n 0.2\n\n\n\n\n\n\nmonotonically_increasing_id\n\n\nmonotonically_increasing_id() - Returns monotonically increasing 64-bit integers. The generated ID is guaranteed\nto be monotonically increasing and unique, but not consecutive. The current implementation\nputs the partition ID in the upper 31 bits, and the lower 33 bits represent the record number\nwithin each partition. The assumption is that the data frame has less than 1 billion\npartitions, and each partition has less than 8 billion records.\nThe function is non-deterministic because its result depends on partition IDs.\n\n\n\n\nmonth\n\n\nmonth(date) - Returns the month component of the date/timestamp.\n\n\nExamples:\n\n\n> SELECT month('2016-07-30');\n 7\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nmonths_between\n\n\nmonths_between(timestamp1, timestamp2[, roundOff]) - If \ntimestamp1\n is later than \ntimestamp2\n, then the result\nis positive. If \ntimestamp1\n and \ntimestamp2\n are on the same day of month, or both\nare the last day of month, time of day will be ignored. Otherwise, the difference is\ncalculated based on 31 days per month, and rounded to 8 digits unless roundOff=false.\n\n\nExamples:\n\n\n> SELECT months_between('1997-02-28 10:30:00', '1996-10-30');\n 3.94959677\n> SELECT months_between('1997-02-28 10:30:00', '1996-10-30', false);\n 3.9495967741935485\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nnamed_struct\n\n\nnamed_struct(name1, val1, name2, val2, ...) - Creates a struct with the given field names and values.\n\n\nExamples:\n\n\n> SELECT named_struct(\"a\", 1, \"b\", 2, \"c\", 3);\n {\"a\":1,\"b\":2,\"c\":3}\n\n\n\n\n\n\nnanvl\n\n\nnanvl(expr1, expr2) - Returns \nexpr1\n if it's not NaN, or \nexpr2\n otherwise.\n\n\nExamples:\n\n\n> SELECT nanvl(cast('NaN' as double), 123);\n 123.0\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nnegative\n\n\nnegative(expr) - Returns the negated value of \nexpr\n.\n\n\nExamples:\n\n\n> SELECT negative(1);\n -1\n\n\n\n\n\n\nnext_day\n\n\nnext_day(start_date, day_of_week) - Returns the first date which is later than \nstart_date\n and named as indicated.\n\n\nExamples:\n\n\n> SELECT next_day('2015-01-14', 'TU');\n 2015-01-20\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nnot\n\n\nnot expr - Logical not.\n\n\n\n\nnow\n\n\nnow() - Returns the current timestamp at the start of query evaluation.\n\n\nSince:\n 1.5.0\n\n\n\n\nntile\n\n\nntile(n) - Divides the rows for each window partition into \nn\n buckets ranging\nfrom 1 to at most \nn\n.\n\n\n\n\nnullif\n\n\nnullif(expr1, expr2) - Returns null if \nexpr1\n equals to \nexpr2\n, or \nexpr1\n otherwise.\n\n\nExamples:\n\n\n> SELECT nullif(2, 2);\n NULL\n\n\n\n\nSince:\n 2.0.0\n\n\n\n\nnvl\n\n\nnvl(expr1, expr2) - Returns \nexpr2\n if \nexpr1\n is null, or \nexpr1\n otherwise.\n\n\nExamples:\n\n\n> SELECT nvl(NULL, array('2'));\n [\"2\"]\n\n\n\n\nSince:\n 2.0.0\n\n\n\n\nnvl2\n\n\nnvl2(expr1, expr2, expr3) - Returns \nexpr2\n if \nexpr1\n is not null, or \nexpr3\n otherwise.\n\n\nExamples:\n\n\n> SELECT nvl2(NULL, 2, 1);\n 1\n\n\n\n\nSince:\n 2.0.0\n\n\n\n\noctet_length\n\n\noctet_length(expr) - Returns the byte length of string data or number of bytes of binary data.\n\n\nExamples:\n\n\n> SELECT octet_length('Spark SQL');\n 9\n\n\n\n\nSince:\n 2.3.0\n\n\n\n\nor\n\n\nexpr1 or expr2 - Logical OR.\n\n\n\n\nparse_url\n\n\nparse_url(url, partToExtract[, key]) - Extracts a part from a URL.\n\n\nExamples:\n\n\n> SELECT parse_url('http://spark.apache.org/path?query=1', 'HOST')\n spark.apache.org\n> SELECT parse_url('http://spark.apache.org/path?query=1', 'QUERY')\n query=1\n> SELECT parse_url('http://spark.apache.org/path?query=1', 'QUERY', 'query')\n 1\n\n\n\n\nSince:\n 2.0.0\n\n\n\n\npercent_rank\n\n\npercent_rank() - Computes the percentage ranking of a value in a group of values.\n\n\n\n\npercentile\n\n\npercentile(col, percentage [, frequency]) - Returns the exact percentile value of numeric column\n\ncol\n at the given percentage. The value of percentage must be between 0.0 and 1.0. The\nvalue of frequency should be positive integral\n\n\npercentile(col, array(percentage1 [, percentage2]...) [, frequency]) - Returns the exact\npercentile value array of numeric column \ncol\n at the given percentage(s). Each value\nof the percentage array must be between 0.0 and 1.0. The value of frequency should be\npositive integral\n\n\n\n\npercentile_approx\n\n\npercentile_approx(col, percentage [, accuracy]) - Returns the approximate percentile value of numeric\ncolumn \ncol\n at the given percentage. The value of percentage must be between 0.0\nand 1.0. The \naccuracy\n parameter (default: 10000) is a positive numeric literal which\ncontrols approximation accuracy at the cost of memory. Higher value of \naccuracy\n yields\nbetter accuracy, \n1.0/accuracy\n is the relative error of the approximation.\nWhen \npercentage\n is an array, each value of the percentage array must be between 0.0 and 1.0.\nIn this case, returns the approximate percentile array of column \ncol\n at the given\npercentage array.\n\n\nExamples:\n\n\n> SELECT percentile_approx(10.0, array(0.5, 0.4, 0.1), 100);\n [10.0,10.0,10.0]\n> SELECT percentile_approx(10.0, 0.5, 100);\n 10.0\n\n\n\n\n\n\npi\n\n\npi() - Returns pi.\n\n\nExamples:\n\n\n> SELECT pi();\n 3.141592653589793\n\n\n\n\n\n\npmod\n\n\npmod(expr1, expr2) - Returns the positive value of \nexpr1\n mod \nexpr2\n.\n\n\nExamples:\n\n\n> SELECT pmod(10, 3);\n 1\n> SELECT pmod(-10, 3);\n 2\n\n\n\n\n\n\nposexplode\n\n\nposexplode(expr) - Separates the elements of array \nexpr\n into multiple rows with positions, or the elements of map \nexpr\n into multiple rows and columns with positions.\n\n\nExamples:\n\n\n> SELECT posexplode(array(10,20));\n 0 10\n 1 20\n\n\n\n\n\n\nposexplode_outer\n\n\nposexplode_outer(expr) - Separates the elements of array \nexpr\n into multiple rows with positions, or the elements of map \nexpr\n into multiple rows and columns with positions.\n\n\nExamples:\n\n\n> SELECT posexplode_outer(array(10,20));\n 0 10\n 1 20\n\n\n\n\n\n\nposition\n\n\nposition(substr, str[, pos]) - Returns the position of the first occurrence of \nsubstr\n in \nstr\n after position \npos\n.\nThe given \npos\n and return value are 1-based.\n\n\nExamples:\n\n\n> SELECT position('bar', 'foobarbar');\n 4\n> SELECT position('bar', 'foobarbar', 5);\n 7\n> SELECT POSITION('bar' IN 'foobarbar');\n 4\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\npositive\n\n\npositive(expr) - Returns the value of \nexpr\n.\n\n\n\n\npow\n\n\npow(expr1, expr2) - Raises \nexpr1\n to the power of \nexpr2\n.\n\n\nExamples:\n\n\n> SELECT pow(2, 3);\n 8.0\n\n\n\n\n\n\npower\n\n\npower(expr1, expr2) - Raises \nexpr1\n to the power of \nexpr2\n.\n\n\nExamples:\n\n\n> SELECT power(2, 3);\n 8.0\n\n\n\n\n\n\nprintf\n\n\nprintf(strfmt, obj, ...) - Returns a formatted string from printf-style format strings.\n\n\nExamples:\n\n\n> SELECT printf(\"Hello World %d %s\", 100, \"days\");\n Hello World 100 days\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nquarter\n\n\nquarter(date) - Returns the quarter of the year for date, in the range 1 to 4.\n\n\nExamples:\n\n\n> SELECT quarter('2016-08-31');\n 3\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nradians\n\n\nradians(expr) - Converts degrees to radians.\n\n\nArguments:\n\n\n\n\nexpr - angle in degrees\n\n\n\n\nExamples:\n\n\n> SELECT radians(180);\n 3.141592653589793\n\n\n\n\n\n\nrand\n\n\nrand([seed]) - Returns a random value with independent and identically distributed (i.i.d.) uniformly distributed values in [0, 1).\n\n\nExamples:\n\n\n> SELECT rand();\n 0.9629742951434543\n> SELECT rand(0);\n 0.8446490682263027\n> SELECT rand(null);\n 0.8446490682263027\n\n\n\n\nNote:\n\nfunction is non-deterministic in general case.\n\nSince:\n 1.5.0\n\n\n\n\nrandn\n\n\nrandn([seed]) - Returns a random value with independent and identically distributed (i.i.d.) values drawn from the standard normal distribution.\n\n\nExamples:\n\n\n> SELECT randn();\n -0.3254147983080288\n> SELECT randn(0);\n 1.1164209726833079\n> SELECT randn(null);\n 1.1164209726833079\n\n\n\n\nNote:\n\nfunction is non-deterministic in general case.\n\nSince:\n 1.5.0\n\n\n\n\nrank\n\n\nrank() - Computes the rank of a value in a group of values. The result is one plus the number\nof rows preceding or equal to the current row in the ordering of the partition. The values\nwill produce gaps in the sequence.\n\n\n\n\nreflect\n\n\nreflect(class, method[, arg1[, arg2 ..]]) - Calls a method with reflection.\n\n\nExamples:\n\n\n> SELECT reflect('java.util.UUID', 'randomUUID');\n c33fb387-8500-4bfa-81d2-6e0e3e930df2\n> SELECT reflect('java.util.UUID', 'fromString', 'a5cf6c42-0c85-418f-af6c-3e4e5b1328f2');\n a5cf6c42-0c85-418f-af6c-3e4e5b1328f2\n\n\n\n\n\n\nregexp_extract\n\n\nregexp_extract(str, regexp[, idx]) - Extracts a group that matches \nregexp\n.\n\n\nExamples:\n\n\n> SELECT regexp_extract('100-200', '(\\\\d+)-(\\\\d+)', 1);\n 100\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nregexp_replace\n\n\nregexp_replace(str, regexp, rep) - Replaces all substrings of \nstr\n that match \nregexp\n with \nrep\n.\n\n\nExamples:\n\n\n> SELECT regexp_replace('100-200', '(\\\\d+)', 'num');\n num-num\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nrepeat\n\n\nrepeat(str, n) - Returns the string which repeats the given string value n times.\n\n\nExamples:\n\n\n> SELECT repeat('123', 2);\n 123123\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nreplace\n\n\nreplace(str, search[, replace]) - Replaces all occurrences of \nsearch\n with \nreplace\n.\n\n\nArguments:\n\n\n\n\nstr - a string expression\n\n\nsearch - a string expression. If \nsearch\n is not found in \nstr\n, \nstr\n is returned unchanged.\n\n\nreplace - a string expression. If \nreplace\n is not specified or is an empty string, nothing replaces\n the string that is removed from \nstr\n.\n\n\n\n\nExamples:\n\n\n> SELECT replace('ABCabc', 'abc', 'DEF');\n ABCDEF\n\n\n\n\nSince:\n 2.3.0\n\n\n\n\nreverse\n\n\nreverse(array) - Returns a reversed string or an array with reverse order of elements.\n\n\nExamples:\n\n\n> SELECT reverse('Spark SQL');\n LQS krapS\n> SELECT reverse(array(2, 1, 4, 3));\n [3,4,1,2]\n\n\n\n\nNote:\n\nrse logic for arrays is available since 2.4.0.\n\nSince:\n 1.5.0\n\n\n\n\nright\n\n\nright(str, len) - Returns the rightmost \nlen\n(\nlen\n can be string type) characters from the string \nstr\n,if \nlen\n is less or equal than 0 the result is an empty string.\n\n\nExamples:\n\n\n> SELECT right('Spark SQL', 3);\n SQL\n\n\n\n\nSince:\n 2.3.0\n\n\n\n\nrint\n\n\nrint(expr) - Returns the double value that is closest in value to the argument and is equal to a mathematical integer.\n\n\nExamples:\n\n\n> SELECT rint(12.3456);\n 12.0\n\n\n\n\n\n\nrlike\n\n\nstr rlike regexp - Returns true if \nstr\n matches \nregexp\n, or false otherwise.\n\n\nArguments:\n\n\n\n\nstr - a string expression\n\n\n\n\nregexp - a string expression. The pattern string should be a Java regular expression.\n\n\nSince Spark 2.0, string literals (including regex patterns) are unescaped in our SQL\nparser. For example, to match \"\\abc\", a regular expression for \nregexp\n can be\n\"^\\abc$\".\n\n\nThere is a SQL config 'spark.sql.parser.escapedStringLiterals' that can be used to\nfallback to the Spark 1.6 behavior regarding string literal parsing. For example,\nif the config is enabled, the \nregexp\n that can match \"\\abc\" is \"^\\abc$\".\n\n\n\n\n\n\nExamples:\n\n\nWhen spark.sql.parser.escapedStringLiterals is disabled (default).\n> SELECT '%SystemDrive%\\Users\\John' rlike '%SystemDrive%\\\\Users.*'\ntrue\n\nWhen spark.sql.parser.escapedStringLiterals is enabled.\n> SELECT '%SystemDrive%\\Users\\John' rlike '%SystemDrive%\\Users.*'\ntrue\n\n\n\n\nNote:\n\n\nUse LIKE to match with simple string pattern.\n\n\nSince:\n 1.0.0\n\n\n\n\nrollup\n\n\nrollup([col1[, col2 ..]]) - create a multi-dimensional rollup using the specified columns\nso that we can run aggregation on them.\n\n\nExamples:\n\n\n> SELECT name, age, count(*) FROM VALUES (2, 'Alice'), (5, 'Bob') people(age, name) GROUP BY rollup(name, age);\n NULL NULL 2\n Alice 2 1\n Bob 5 1\n Bob NULL 1\n Alice NULL 1\n\n\n\n\nSince:\n 2.0.0\n\n\n\n\nround\n\n\nround(expr, d) - Returns \nexpr\n rounded to \nd\n decimal places using HALF_UP rounding mode.\n\n\nExamples:\n\n\n> SELECT round(2.5, 0);\n 3.0\n\n\n\n\n\n\nrow_number\n\n\nrow_number() - Assigns a unique, sequential number to each row, starting with one,\naccording to the ordering of rows within the window partition.\n\n\n\n\nrpad\n\n\nrpad(str, len, pad) - Returns \nstr\n, right-padded with \npad\n to a length of \nlen\n.\nIf \nstr\n is longer than \nlen\n, the return value is shortened to \nlen\n characters.\n\n\nExamples:\n\n\n> SELECT rpad('hi', 5, '??');\n hi???\n> SELECT rpad('hi', 1, '??');\n h\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nrtrim\n\n\nrtrim(str) - Removes the trailing space characters from \nstr\n.\n\n\nrtrim(trimStr, str) - Removes the trailing string which contains the characters from the trim string from the \nstr\n\n\nArguments:\n\n\n\n\nstr - a string expression\n\n\ntrimStr - the trim string characters to trim, the default value is a single space\n\n\n\n\nExamples:\n\n\n> SELECT rtrim(' SparkSQL ');\n SparkSQL\n> SELECT rtrim('LQSa', 'SSparkSQLS');\n SSpark\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nschema_of_json\n\n\nschema_of_json(json[, options]) - Returns schema in the DDL format of JSON string.\n\n\nExamples:\n\n\n> SELECT schema_of_json('[{\"col\":0}]');\n array>\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\nsecond\n\n\nsecond(timestamp) - Returns the second component of the string/timestamp.\n\n\nExamples:\n\n\n> SELECT second('2009-07-30 12:58:59');\n 59\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nsentences\n\n\nsentences(str[, lang, country]) - Splits \nstr\n into an array of array of words.\n\n\nExamples:\n\n\n> SELECT sentences('Hi there! Good morning.');\n [[\"Hi\",\"there\"],[\"Good\",\"morning\"]]\n\n\n\n\nSince:\n 2.0.0\n\n\n\n\nsequence\n\n\nsequence(start, stop, step) - Generates an array of elements from start to stop (inclusive),\nincrementing by step. The type of the returned elements is the same as the type of argument\nexpressions.\n\n\nSupported types are: byte, short, integer, long, date, timestamp.\n\n\nThe start and stop expressions must resolve to the same type.\nIf start and stop expressions resolve to the 'date' or 'timestamp' type\nthen the step expression must resolve to the 'interval' type, otherwise to the same type\nas the start and stop expressions.\n\n\nArguments:\n\n\n\n\nstart - an expression. The start of the range.\n\n\nstop - an expression. The end the range (inclusive).\n\n\nstep - an optional expression. The step of the range.\n By default step is 1 if start is less than or equal to stop, otherwise -1.\n For the temporal sequences it's 1 day and -1 day respectively.\n If start is greater than stop then the step must be negative, and vice versa.\n\n\n\n\nExamples:\n\n\n> SELECT sequence(1, 5);\n [1,2,3,4,5]\n> SELECT sequence(5, 1);\n [5,4,3,2,1]\n> SELECT sequence(to_date('2018-01-01'), to_date('2018-03-01'), interval 1 month);\n [2018-01-01,2018-02-01,2018-03-01]\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\nsha\n\n\nsha(expr) - Returns a sha1 hash value as a hex string of the \nexpr\n.\n\n\nExamples:\n\n\n> SELECT sha('Spark');\n 85f5955f4b27a9a4c2aab6ffe5d7189fc298b92c\n\n\n\n\n\n\nsha1\n\n\nsha1(expr) - Returns a sha1 hash value as a hex string of the \nexpr\n.\n\n\nExamples:\n\n\n> SELECT sha1('Spark');\n 85f5955f4b27a9a4c2aab6ffe5d7189fc298b92c\n\n\n\n\n\n\nsha2\n\n\nsha2(expr, bitLength) - Returns a checksum of SHA-2 family as a hex string of \nexpr\n.\nSHA-224, SHA-256, SHA-384, and SHA-512 are supported. Bit length of 0 is equivalent to 256.\n\n\nExamples:\n\n\n> SELECT sha2('Spark', 256);\n 529bc3b07127ecb7e53a4dcf1991d9152c24537d919178022b2c42657f79a26b\n\n\n\n\n\n\nshiftleft\n\n\nshiftleft(base, expr) - Bitwise left shift.\n\n\nExamples:\n\n\n> SELECT shiftleft(2, 1);\n 4\n\n\n\n\n\n\nshiftright\n\n\nshiftright(base, expr) - Bitwise (signed) right shift.\n\n\nExamples:\n\n\n> SELECT shiftright(4, 1);\n 2\n\n\n\n\n\n\nshiftrightunsigned\n\n\nshiftrightunsigned(base, expr) - Bitwise unsigned right shift.\n\n\nExamples:\n\n\n> SELECT shiftrightunsigned(4, 1);\n 2\n\n\n\n\n\n\nshuffle\n\n\nshuffle(array) - Returns a random permutation of the given array.\n\n\nExamples:\n\n\n> SELECT shuffle(array(1, 20, 3, 5));\n [3,1,5,20]\n> SELECT shuffle(array(1, 20, null, 3));\n [20,null,3,1]\n\n\n\n\nNote:\n\nfunction is non-deterministic.\n\nSince:\n 2.4.0\n\n\n\n\nsign\n\n\nsign(expr) - Returns -1.0, 0.0 or 1.0 as \nexpr\n is negative, 0 or positive.\n\n\nExamples:\n\n\n> SELECT sign(40);\n 1.0\n\n\n\n\n\n\nsignum\n\n\nsignum(expr) - Returns -1.0, 0.0 or 1.0 as \nexpr\n is negative, 0 or positive.\n\n\nExamples:\n\n\n> SELECT signum(40);\n 1.0\n\n\n\n\n\n\nsin\n\n\nsin(expr) - Returns the sine of \nexpr\n, as if computed by \njava.lang.Math.sin\n.\n\n\nArguments:\n\n\n\n\nexpr - angle in radians\n\n\n\n\nExamples:\n\n\n> SELECT sin(0);\n 0.0\n\n\n\n\n\n\nsinh\n\n\nsinh(expr) - Returns hyperbolic sine of \nexpr\n, as if computed by \njava.lang.Math.sinh\n.\n\n\nArguments:\n\n\n\n\nexpr - hyperbolic angle\n\n\n\n\nExamples:\n\n\n> SELECT sinh(0);\n 0.0\n\n\n\n\n\n\nsize\n\n\nsize(expr) - Returns the size of an array or a map.\nThe function returns -1 if its input is null and spark.sql.legacy.sizeOfNull is set to true.\nIf spark.sql.legacy.sizeOfNull is set to false, the function returns null for null input.\nBy default, the spark.sql.legacy.sizeOfNull parameter is set to true.\n\n\nExamples:\n\n\n> SELECT size(array('b', 'd', 'c', 'a'));\n 4\n> SELECT size(map('a', 1, 'b', 2));\n 2\n> SELECT size(NULL);\n -1\n\n\n\n\n\n\nskewness\n\n\nskewness(expr) - Returns the skewness value calculated from values of a group.\n\n\n\n\nslice\n\n\nslice(x, start, length) - Subsets array x starting from index start (or starting from the end if start is negative) with the specified length.\n\n\nExamples:\n\n\n> SELECT slice(array(1, 2, 3, 4), 2, 2);\n [2,3]\n> SELECT slice(array(1, 2, 3, 4), -2, 2);\n [3,4]\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\nsmallint\n\n\nsmallint(expr) - Casts the value \nexpr\n to the target data type \nsmallint\n.\n\n\n\n\nsort_array\n\n\nsort_array(array[, ascendingOrder]) - Sorts the input array in ascending or descending order\naccording to the natural ordering of the array elements. Null elements will be placed\nat the beginning of the returned array in ascending order or at the end of the returned\narray in descending order.\n\n\nExamples:\n\n\n> SELECT sort_array(array('b', 'd', null, 'c', 'a'), true);\n [null,\"a\",\"b\",\"c\",\"d\"]\n\n\n\n\n\n\nsoundex\n\n\nsoundex(str) - Returns Soundex code of the string.\n\n\nExamples:\n\n\n> SELECT soundex('Miller');\n M460\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nspace\n\n\nspace(n) - Returns a string consisting of \nn\n spaces.\n\n\nExamples:\n\n\n> SELECT concat(space(2), '1');\n 1\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nspark_partition_id\n\n\nspark_partition_id() - Returns the current partition id.\n\n\n\n\nsplit\n\n\nsplit(str, regex) - Splits \nstr\n around occurrences that match \nregex\n.\n\n\nExamples:\n\n\n> SELECT split('oneAtwoBthreeC', '[ABC]');\n [\"one\",\"two\",\"three\",\"\"]\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nsqrt\n\n\nsqrt(expr) - Returns the square root of \nexpr\n.\n\n\nExamples:\n\n\n> SELECT sqrt(4);\n 2.0\n\n\n\n\n\n\nstack\n\n\nstack(n, expr1, ..., exprk) - Separates \nexpr1\n, ..., \nexprk\n into \nn\n rows.\n\n\nExamples:\n\n\n> SELECT stack(2, 1, 2, 3);\n 1 2\n 3 NULL\n\n\n\n\n\n\nstd\n\n\nstd(expr) - Returns the sample standard deviation calculated from values of a group.\n\n\n\n\nstddev\n\n\nstddev(expr) - Returns the sample standard deviation calculated from values of a group.\n\n\n\n\nstddev_pop\n\n\nstddev_pop(expr) - Returns the population standard deviation calculated from values of a group.\n\n\n\n\nstddev_samp\n\n\nstddev_samp(expr) - Returns the sample standard deviation calculated from values of a group.\n\n\n\n\nstr_to_map\n\n\nstr_to_map(text[, pairDelim[, keyValueDelim]]) - Creates a map after splitting the text into key/value pairs using delimiters. Default delimiters are ',' for \npairDelim\n and ':' for \nkeyValueDelim\n.\n\n\nExamples:\n\n\n> SELECT str_to_map('a:1,b:2,c:3', ',', ':');\n map(\"a\":\"1\",\"b\":\"2\",\"c\":\"3\")\n> SELECT str_to_map('a');\n map(\"a\":null)\n\n\n\n\n\n\nstring\n\n\nstring(expr) - Casts the value \nexpr\n to the target data type \nstring\n.\n\n\n\n\nstruct\n\n\nstruct(col1, col2, col3, ...) - Creates a struct with the given field values.\n\n\n\n\nsubstr\n\n\nsubstr(str, pos[, len]) - Returns the substring of \nstr\n that starts at \npos\n and is of length \nlen\n, or the slice of byte array that starts at \npos\n and is of length \nlen\n.\n\n\nExamples:\n\n\n> SELECT substr('Spark SQL', 5);\n k SQL\n> SELECT substr('Spark SQL', -3);\n SQL\n> SELECT substr('Spark SQL', 5, 1);\n k\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nsubstring\n\n\nsubstring(str, pos[, len]) - Returns the substring of \nstr\n that starts at \npos\n and is of length \nlen\n, or the slice of byte array that starts at \npos\n and is of length \nlen\n.\n\n\nExamples:\n\n\n> SELECT substring('Spark SQL', 5);\n k SQL\n> SELECT substring('Spark SQL', -3);\n SQL\n> SELECT substring('Spark SQL', 5, 1);\n k\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nsubstring_index\n\n\nsubstring_index(str, delim, count) - Returns the substring from \nstr\n before \ncount\n occurrences of the delimiter \ndelim\n.\nIf \ncount\n is positive, everything to the left of the final delimiter (counting from the\nleft) is returned. If \ncount\n is negative, everything to the right of the final delimiter\n(counting from the right) is returned. The function substring_index performs a case-sensitive match\nwhen searching for \ndelim\n.\n\n\nExamples:\n\n\n> SELECT substring_index('www.apache.org', '.', 2);\n www.apache\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nsum\n\n\nsum(expr) - Returns the sum calculated from values of a group.\n\n\n\n\ntan\n\n\ntan(expr) - Returns the tangent of \nexpr\n, as if computed by \njava.lang.Math.tan\n.\n\n\nArguments:\n\n\n\n\nexpr - angle in radians\n\n\n\n\nExamples:\n\n\n> SELECT tan(0);\n 0.0\n\n\n\n\n\n\ntanh\n\n\ntanh(expr) - Returns the hyperbolic tangent of \nexpr\n, as if computed by\n\njava.lang.Math.tanh\n.\n\n\nArguments:\n\n\n\n\nexpr - hyperbolic angle\n\n\n\n\nExamples:\n\n\n> SELECT tanh(0);\n 0.0\n\n\n\n\n\n\ntimestamp\n\n\ntimestamp(expr) - Casts the value \nexpr\n to the target data type \ntimestamp\n.\n\n\n\n\ntinyint\n\n\ntinyint(expr) - Casts the value \nexpr\n to the target data type \ntinyint\n.\n\n\n\n\nto_date\n\n\nto_date(date_str[, fmt]) - Parses the \ndate_str\n expression with the \nfmt\n expression to\na date. Returns null with invalid input. By default, it follows casting rules to a date if\nthe \nfmt\n is omitted.\n\n\nExamples:\n\n\n> SELECT to_date('2009-07-30 04:17:52');\n 2009-07-30\n> SELECT to_date('2016-12-31', 'yyyy-MM-dd');\n 2016-12-31\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nto_json\n\n\nto_json(expr[, options]) - Returns a JSON string with a given struct value\n\n\nExamples:\n\n\n> SELECT to_json(named_struct('a', 1, 'b', 2));\n {\"a\":1,\"b\":2}\n> SELECT to_json(named_struct('time', to_timestamp('2015-08-26', 'yyyy-MM-dd')), map('timestampFormat', 'dd/MM/yyyy'));\n {\"time\":\"26/08/2015\"}\n> SELECT to_json(array(named_struct('a', 1, 'b', 2)));\n [{\"a\":1,\"b\":2}]\n> SELECT to_json(map('a', named_struct('b', 1)));\n {\"a\":{\"b\":1}}\n> SELECT to_json(map(named_struct('a', 1),named_struct('b', 2)));\n {\"[1]\":{\"b\":2}}\n> SELECT to_json(map('a', 1));\n {\"a\":1}\n> SELECT to_json(array((map('a', 1))));\n [{\"a\":1}]\n\n\n\n\nSince:\n 2.2.0\n\n\n\n\nto_timestamp\n\n\nto_timestamp(timestamp[, fmt]) - Parses the \ntimestamp\n expression with the \nfmt\n expression to\na timestamp. Returns null with invalid input. By default, it follows casting rules to\na timestamp if the \nfmt\n is omitted.\n\n\nExamples:\n\n\n> SELECT to_timestamp('2016-12-31 00:12:00');\n 2016-12-31 00:12:00\n> SELECT to_timestamp('2016-12-31', 'yyyy-MM-dd');\n 2016-12-31 00:00:00\n\n\n\n\nSince:\n 2.2.0\n\n\n\n\nto_unix_timestamp\n\n\nto_unix_timestamp(expr[, pattern]) - Returns the UNIX timestamp of the given time.\n\n\nExamples:\n\n\n> SELECT to_unix_timestamp('2016-04-08', 'yyyy-MM-dd');\n 1460041200\n\n\n\n\nSince:\n 1.6.0\n\n\n\n\nto_utc_timestamp\n\n\nto_utc_timestamp(timestamp, timezone) - 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'.\n\n\nExamples:\n\n\n> SELECT to_utc_timestamp('2016-08-31', 'Asia/Seoul');\n 2016-08-30 15:00:00\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\ntransform\n\n\ntransform(expr, func) - Transforms elements in an array using the function.\n\n\nExamples:\n\n\n> SELECT transform(array(1, 2, 3), x -> x + 1);\n [2,3,4]\n> SELECT transform(array(1, 2, 3), (x, i) -> x + i);\n [1,3,5]\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\ntranslate\n\n\ntranslate(input, from, to) - Translates the \ninput\n string by replacing the characters present in the \nfrom\n string with the corresponding characters in the \nto\n string.\n\n\nExamples:\n\n\n> SELECT translate('AaBbCc', 'abc', '123');\n A1B2C3\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\ntrim\n\n\ntrim(str) - Removes the leading and trailing space characters from \nstr\n.\n\n\ntrim(BOTH trimStr FROM str) - Remove the leading and trailing \ntrimStr\n characters from \nstr\n\n\ntrim(LEADING trimStr FROM str) - Remove the leading \ntrimStr\n characters from \nstr\n\n\ntrim(TRAILING trimStr FROM str) - Remove the trailing \ntrimStr\n characters from \nstr\n\n\nArguments:\n\n\n\n\nstr - a string expression\n\n\ntrimStr - the trim string characters to trim, the default value is a single space\n\n\nBOTH, FROM - these are keywords to specify trimming string characters from both ends of\n the string\n\n\nLEADING, FROM - these are keywords to specify trimming string characters from the left\n end of the string\n\n\nTRAILING, FROM - these are keywords to specify trimming string characters from the right\n end of the string\n\n\n\n\nExamples:\n\n\n> SELECT trim(' SparkSQL ');\n SparkSQL\n> SELECT trim('SL', 'SSparkSQLS');\n parkSQ\n> SELECT trim(BOTH 'SL' FROM 'SSparkSQLS');\n parkSQ\n> SELECT trim(LEADING 'SL' FROM 'SSparkSQLS');\n parkSQLS\n> SELECT trim(TRAILING 'SL' FROM 'SSparkSQLS');\n SSparkSQ\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\ntrunc\n\n\ntrunc(date, fmt) - Returns \ndate\n with the time portion of the day truncated to the unit specified by the format model \nfmt\n.\n\nfmt\n should be one of [\"year\", \"yyyy\", \"yy\", \"mon\", \"month\", \"mm\"]\n\n\nExamples:\n\n\n> SELECT trunc('2009-02-12', 'MM');\n 2009-02-01\n> SELECT trunc('2015-10-27', 'YEAR');\n 2015-01-01\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nucase\n\n\nucase(str) - Returns \nstr\n with all characters changed to uppercase.\n\n\nExamples:\n\n\n> SELECT ucase('SparkSql');\n SPARKSQL\n\n\n\n\nSince:\n 1.0.1\n\n\n\n\nunbase64\n\n\nunbase64(str) - Converts the argument from a base 64 string \nstr\n to a binary.\n\n\nExamples:\n\n\n> SELECT unbase64('U3BhcmsgU1FM');\n Spark SQL\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nunhex\n\n\nunhex(expr) - Converts hexadecimal \nexpr\n to binary.\n\n\nExamples:\n\n\n> SELECT decode(unhex('537061726B2053514C'), 'UTF-8');\n Spark SQL\n\n\n\n\n\n\nunix_timestamp\n\n\nunix_timestamp([expr[, pattern]]) - Returns the UNIX timestamp of current or specified time.\n\n\nExamples:\n\n\n> SELECT unix_timestamp();\n 1476884637\n> SELECT unix_timestamp('2016-04-08', 'yyyy-MM-dd');\n 1460041200\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nupper\n\n\nupper(str) - Returns \nstr\n with all characters changed to uppercase.\n\n\nExamples:\n\n\n> SELECT upper('SparkSql');\n SPARKSQL\n\n\n\n\nSince:\n 1.0.1\n\n\n\n\nuuid\n\n\nuuid() - Returns an universally unique identifier (UUID) string. The value is returned as a canonical UUID 36-character string.\n\n\nExamples:\n\n\n> SELECT uuid();\n 46707d92-02f4-4817-8116-a4c3b23e6266\n\n\n\n\nNote:\n\nfunction is non-deterministic.\n\n\n\nvar_pop\n\n\nvar_pop(expr) - Returns the population variance calculated from values of a group.\n\n\n\n\nvar_samp\n\n\nvar_samp(expr) - Returns the sample variance calculated from values of a group.\n\n\n\n\nvariance\n\n\nvariance(expr) - Returns the sample variance calculated from values of a group.\n\n\n\n\nweekday\n\n\nweekday(date) - Returns the day of the week for date/timestamp (0 = Monday, 1 = Tuesday, ..., 6 = Sunday).\n\n\nExamples:\n\n\n> SELECT weekday('2009-07-30');\n 3\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\nweekofyear\n\n\nweekofyear(date) - Returns the week of the year of the given date. A week is considered to start on a Monday and week 1 is the first week with >3 days.\n\n\nExamples:\n\n\n> SELECT weekofyear('2008-02-20');\n 8\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nwhen\n\n\nCASE WHEN expr1 THEN expr2 [WHEN expr3 THEN expr4]* [ELSE expr5] END - When \nexpr1\n = true, returns \nexpr2\n; else when \nexpr3\n = true, returns \nexpr4\n; else returns \nexpr5\n.\n\n\nArguments:\n\n\n\n\nexpr1, expr3 - the branch condition expressions should all be boolean type.\n\n\nexpr2, expr4, expr5 - the branch value expressions and else value expression should all be\n same type or coercible to a common type.\n\n\n\n\nExamples:\n\n\n> SELECT CASE WHEN 1 > 0 THEN 1 WHEN 2 > 0 THEN 2.0 ELSE 1.2 END;\n 1\n> SELECT CASE WHEN 1 < 0 THEN 1 WHEN 2 > 0 THEN 2.0 ELSE 1.2 END;\n 2\n> SELECT CASE WHEN 1 < 0 THEN 1 WHEN 2 < 0 THEN 2.0 END;\n NULL\n\n\n\n\n\n\nwindow\n\n\n\n\nxpath\n\n\nxpath(xml, xpath) - Returns a string array of values within the nodes of xml that match the XPath expression.\n\n\nExamples:\n\n\n> SELECT xpath('b1b2b3c1c2','a/b/text()');\n ['b1','b2','b3']\n\n\n\n\n\n\nxpath_boolean\n\n\nxpath_boolean(xml, xpath) - Returns true if the XPath expression evaluates to true, or if a matching node is found.\n\n\nExamples:\n\n\n> SELECT xpath_boolean('1','a/b');\n true\n\n\n\n\n\n\nxpath_double\n\n\nxpath_double(xml, xpath) - Returns a double value, the value zero if no match is found, or NaN if a match is found but the value is non-numeric.\n\n\nExamples:\n\n\n> SELECT xpath_double('12', 'sum(a/b)');\n 3.0\n\n\n\n\n\n\nxpath_float\n\n\nxpath_float(xml, xpath) - Returns a float value, the value zero if no match is found, or NaN if a match is found but the value is non-numeric.\n\n\nExamples:\n\n\n> SELECT xpath_float('12', 'sum(a/b)');\n 3.0\n\n\n\n\n\n\nxpath_int\n\n\nxpath_int(xml, xpath) - Returns an integer value, or the value zero if no match is found, or a match is found but the value is non-numeric.\n\n\nExamples:\n\n\n> SELECT xpath_int('12', 'sum(a/b)');\n 3\n\n\n\n\n\n\nxpath_long\n\n\nxpath_long(xml, xpath) - Returns a long integer value, or the value zero if no match is found, or a match is found but the value is non-numeric.\n\n\nExamples:\n\n\n> SELECT xpath_long('12', 'sum(a/b)');\n 3\n\n\n\n\n\n\nxpath_number\n\n\nxpath_number(xml, xpath) - Returns a double value, the value zero if no match is found, or NaN if a match is found but the value is non-numeric.\n\n\nExamples:\n\n\n> SELECT xpath_number('12', 'sum(a/b)');\n 3.0\n\n\n\n\n\n\nxpath_short\n\n\nxpath_short(xml, xpath) - Returns a short integer value, or the value zero if no match is found, or a match is found but the value is non-numeric.\n\n\nExamples:\n\n\n> SELECT xpath_short('12', 'sum(a/b)');\n 3\n\n\n\n\n\n\nxpath_string\n\n\nxpath_string(xml, xpath) - Returns the text contents of the first xml node that matches the XPath expression.\n\n\nExamples:\n\n\n> SELECT xpath_string('bcc','a/c');\n cc\n\n\n\n\n\n\nyear\n\n\nyear(date) - Returns the year component of the date/timestamp.\n\n\nExamples:\n\n\n> SELECT year('2016-07-30');\n 2016\n\n\n\n\nSince:\n 1.5.0\n\n\n\n\nzip_with\n\n\nzip_with(left, right, func) - Merges the two given arrays, element-wise, into a single array using function. If one array is shorter, nulls are appended at the end to match the length of the longer array, before applying function.\n\n\nExamples:\n\n\n> SELECT zip_with(array(1, 2, 3), array('a', 'b', 'c'), (x, y) -> (y, x));\n [{\"y\":\"a\",\"x\":1},{\"y\":\"b\",\"x\":2},{\"y\":\"c\",\"x\":3}]\n> SELECT zip_with(array(1, 2), array(3, 4), (x, y) -> x + y);\n [4,6]\n> SELECT zip_with(array('a', 'b', 'c'), array('d', 'e', 'f'), (x, y) -> concat(x, y));\n [\"ad\",\"be\",\"cf\"]\n\n\n\n\nSince:\n 2.4.0\n\n\n\n\n|\n\n\nexpr1 | expr2 - Returns the result of bitwise OR of \nexpr1\n and \nexpr2\n.\n\n\nExamples:\n\n\n> SELECT 3 | 5;\n 7\n\n\n\n\n\n\n~\n\n\n~ expr - Returns the result of bitwise NOT of \nexpr\n.\n\n\nExamples:\n\n\n> SELECT ~ 0;\n -1", "title": "Functions" } ] }