{"id":79720,"date":"2020-08-27T09:00:24","date_gmt":"2020-08-27T03:30:24","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=79720"},"modified":"2020-08-27T09:00:24","modified_gmt":"2020-08-27T03:30:24","slug":"apache-hive-built-in-functions","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/apache-hive-built-in-functions\/","title":{"rendered":"Hive Built-in Functions and their Return Type with Examples"},"content":{"rendered":"<p>In Apache Hive, there are various functions available for performing several tasks. These functions are known as Built-in functions. In this article, we will study Hive Built-in functions.<\/p>\n<p>The Hive Built-in functions are categorized as Mathematical function, Collection function, Type conversion function, Date function, Conditional function, and String function. We will study all of these Hive Built-in functions in detail.<\/p>\n<p>Let&#8217;s start!!!<\/p>\n<h3>Hive Built-in Functions<\/h3>\n<p>Hive was designed to perform SQL like queries on the huge datasets stored in HDFS. It supports different types of data types, as well as operators that are not supported by different databases.<\/p>\n<p>For performing some specific mathematical and arithmetic operations, Hive provides some built-in functions. These built-in functions extract data from tables in hive and process the calculations.<\/p>\n<p>For using Hive built-in functions in our applications, we have to first check the application requirement. It is possible to call these hive built-in functions directly in our application.<\/p>\n<p>There are several types of Hive Built-in Functions such as Mathematical function, Collection function, Type conversion function, Date function, Conditional function, and String function.<\/p>\n<p>Now, let us study each Hive Built-in Functions in detail.<\/p>\n<h4>1. Mathematical Functions<\/h4>\n<p>The Hive Built-in Mathematical functions are used for performing mathematical calculations. Most of the mathematical function returns NULL when the arguments(s) are NULL.<\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>Name<\/strong><\/td>\n<td><strong>Return Type<\/strong><\/td>\n<td><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td>abs(DOUBLE a)<\/td>\n<td><span style=\"font-weight: 400\">DOUBLE<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the absolute value of the number passed \u2018a\u2019.<\/span><\/td>\n<\/tr>\n<tr>\n<td>round(DOUBLE a)<\/td>\n<td><span style=\"font-weight: 400\">DOUBLE<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the rounded BIGINT value of the number passed \u2018a\u2019.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td>round(DOUBLE a, INT d)<\/td>\n<td><span style=\"font-weight: 400\">DOUBLE<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return a rounded value of \u2018a\u2019 to \u2018d\u2019 decimal places.<\/span><\/td>\n<\/tr>\n<tr>\n<td>bround(DOUBLE a)<\/td>\n<td><span style=\"font-weight: 400\">DOUBLE<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the rounded BIGINT value of the number passed \u2018a\u2019 by using HALF_EVEN rounding mode. It is also known as the Gaussian rounding or the bankers&#8217; rounding.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Example: bround(2.5) = 2, bround(3.5) = 4.<\/span><\/td>\n<\/tr>\n<tr>\n<td>bround(DOUBLE a, INT d)<\/td>\n<td><span style=\"font-weight: 400\">DOUBLE<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return a rounded value of \u2018a\u2019 to \u2018d\u2019 decimal places by using HALF_EVEN rounding mode.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Example: bround(8.25, 1) = 8.2, bround(8.35, 1) = 8.4.<\/span><\/td>\n<\/tr>\n<tr>\n<td>floor(DOUBLE a)<\/td>\n<td><span style=\"font-weight: 400\">BIGINT<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the maximum BIGINT value which is equal to or less than the number passed \u2018a\u2019.<\/span><\/td>\n<\/tr>\n<tr>\n<td>ceil(DOUBLE a), ceiling(DOUBLE a)<\/td>\n<td><span style=\"font-weight: 400\">BIGINT<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the minimum BIGINT value which is equal to or greater than the number passed \u2018a\u2019.<\/span><\/td>\n<\/tr>\n<tr>\n<td>rand(), rand(INT seed)<\/td>\n<td><span style=\"font-weight: 400\">DOUBLE<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return a random number, which changes from row to row, and that is uniformly distributed from 0 to 1. By specifying the <\/span>seed<span style=\"font-weight: 400\"> will ensure that the generated random number sequence is deterministic.<\/span><\/td>\n<\/tr>\n<tr>\n<td>log10(DOUBLE a), log10(DECIMAL a)<\/td>\n<td><span style=\"font-weight: 400\">DOUBLE<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the base-10 logarithm of the argument passed \u2018a\u2019.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td>log2(DOUBLE a), log2(DECIMAL a)<\/td>\n<td><span style=\"font-weight: 400\">DOUBLE<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the base-2 logarithm of the argument passed \u2018a\u2019.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td>log(DOUBLE base, DOUBLE a)<\/p>\n<p>log(DECIMAL base, DECIMAL a)<\/td>\n<td><span style=\"font-weight: 400\">DOUBLE<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the base-base logarithm of the argument passed \u2018a\u2019.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td>pow(DOUBLE a, DOUBLE p), power(DOUBLE a, DOUBLE p)<\/td>\n<td><span style=\"font-weight: 400\">DOUBLE<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return a<\/span><span style=\"font-weight: 400\">p<\/span><span style=\"font-weight: 400\">.<\/span><\/td>\n<\/tr>\n<tr>\n<td>sqrt(DOUBLE a), sqrt(DECIMAL a)<\/td>\n<td><span style=\"font-weight: 400\">DOUBLE<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the square root of argument a.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td>bin(BIGINT a)<\/td>\n<td><span style=\"font-weight: 400\">STRING<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the number in the binary format<\/span><\/td>\n<\/tr>\n<tr>\n<td>hex(BIGINT a) hex(STRING a) hex(BINARY a)<\/td>\n<td><span style=\"font-weight: 400\">STRING<\/span><\/td>\n<td><span style=\"font-weight: 400\">If the argument is an INT or binary, it will return the number as a STRING in the hexadecimal format. Otherwise, if the number is a STRING, then it converts each character into its hexadecimal representation and returns the resulting STRING.<\/span><\/td>\n<\/tr>\n<tr>\n<td>unhex(STRING a)<\/td>\n<td><span style=\"font-weight: 400\">BINARY<\/span><\/td>\n<td><span style=\"font-weight: 400\">It is the inverse of hex. It interprets each pair of characters as a hexadecimal number and converts them to the byte representation of the number.<\/span><\/td>\n<\/tr>\n<tr>\n<td>factorial(INT a)<\/td>\n<td><span style=\"font-weight: 400\">BIGINT<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the factorial of argument \u2018a\u2019. The Valid a is [0..20].<\/span><\/td>\n<\/tr>\n<tr>\n<td>cbrt(DOUBLE a)<\/td>\n<td><span style=\"font-weight: 400\">DOUBLE<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the cube root of double value passed.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>2. Collection Functions<\/h4>\n<p>Collection functions are used for the collections. Collections means the grouping of the elements and returning the single or array of elements on the basis of the return type mentioned in the function name.<\/p>\n<p>The following collection functions are supported in Hive:<\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>Name<\/strong><\/td>\n<td><strong>Return Type<\/strong><\/td>\n<td><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td>size(Map&lt;K.V&gt;)<\/td>\n<td><span style=\"font-weight: 400\">int<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the number of elements in the data type map.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td>size(Array&lt;T&gt;)<\/td>\n<td><span style=\"font-weight: 400\">int<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the number of elements in the data type array.<\/span><\/td>\n<\/tr>\n<tr>\n<td>map_keys(Map&lt;K.V&gt;)<\/td>\n<td><span style=\"font-weight: 400\">array&lt;K&gt;<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return an unordered array that contains the keys of the input map.<\/span><\/td>\n<\/tr>\n<tr>\n<td>map_values(Map&lt;K.V&gt;)<\/td>\n<td><span style=\"font-weight: 400\">array&lt;V&gt;<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return an unordered array that contains the values of the input map.<\/span><\/td>\n<\/tr>\n<tr>\n<td>array_contains(Array&lt;T&gt;, value)<\/td>\n<td><span style=\"font-weight: 400\">boolean<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return TRUE if an array contains value.<\/span><\/td>\n<\/tr>\n<tr>\n<td>sort_array(Array&lt;T&gt;)<\/td>\n<td><span style=\"font-weight: 400\">array&lt;t&gt;<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will sort the input array in ascending order and return it.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>3. Type Conversion Functions<\/h4>\n<p>The following Built-in Type Conversion functions are supported in Hive:<\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>Name<\/strong><\/td>\n<td><strong>Return Type<\/strong><\/td>\n<td><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td>binary(string|binary)<\/td>\n<td><span style=\"font-weight: 400\">binary<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will cast the parameter passed into a binary.<\/span><\/td>\n<\/tr>\n<tr>\n<td>cast(expr as &lt;type&gt;)<\/td>\n<td><span style=\"font-weight: 400\">Expected &#8220;=&#8221; to follow &#8220;type&#8221;<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will convert the results of the expression \u2018expr\u2019 to the\u00a0 &lt;type&gt;.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">For example, cast(&#8216;1&#8217; as BIGINT). It will convert the string &#8216;1&#8217; to its integral representation.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">If the conversion doesn\u2019t succeed then, NULL is returned.<\/span><\/p>\n<p><span style=\"font-weight: 400\">If cast(expr as boolean), then Hive returns true for the non-empty string.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>4. Date Functions<\/h4>\n<p>Date functions in Hive are used for performing Date Manipulations and Converting Date types from one type to another type.<\/p>\n<p>The following built-in date functions are supported in Hive:<\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>Name<\/strong><\/td>\n<td><strong>Return Type\u00a0<\/strong><\/td>\n<td><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td>unix_timestamp(string date)<\/td>\n<td><span style=\"font-weight: 400\">bigint<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will Convert the time string in the format <\/span>yyyy-MM-dd HH:mm:ss<span style=\"font-weight: 400\"> to Unix timestamp (in seconds), by using the default timezone and the default locale. It will return 0 if failed.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td>unix_timestamp(string date, string pattern)<\/td>\n<td><span style=\"font-weight: 400\">bigint<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will convert the time string with the given pattern to the Unix timestamp (in seconds). It returns 0 if failed.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td>year(string date)<\/td>\n<td><span style=\"font-weight: 400\">int<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the year part of a date or a timestamp string.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Example: year(&#8220;2020-05-11 00:00:00&#8221;) = 2020<\/span><\/td>\n<\/tr>\n<tr>\n<td>quarter(date\/timestamp\/string)<\/td>\n<td><span style=\"font-weight: 400\">int<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the quarter of the year for a date, timestamp, or string in the range 1 to 4.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Example: quarter(&#8216;2020-05-11&#8217;) = 2.<\/span><\/td>\n<\/tr>\n<tr>\n<td>month(string date)<\/td>\n<td><span style=\"font-weight: 400\">int<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the month part of a date or a timestamp string.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Example: month(&#8220;2020-05-11 00:00:00&#8221;) = 05.<\/span><\/td>\n<\/tr>\n<tr>\n<td>day(string date) dayofmonth(date)<\/td>\n<td><span style=\"font-weight: 400\">int<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the day part of a date or a timestamp string.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Example:<\/span><\/p>\n<p><span style=\"font-weight: 400\">day(&#8220;2020-05-11 00:00:00&#8221;) = 11.<\/span><\/td>\n<\/tr>\n<tr>\n<td>hour(string date)<\/td>\n<td><span style=\"font-weight: 400\">int<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the hour of the timestamp.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Example: hour(&#8216;2020-05-11 12:58:59&#8242;) = 12, hour(&#8217;12:58:59&#8217;) = 12.<\/span><\/td>\n<\/tr>\n<tr>\n<td>minute(string date)<\/td>\n<td><span style=\"font-weight: 400\">int<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the minute of the timestamp.<\/span><\/td>\n<\/tr>\n<tr>\n<td>second(string date)<\/td>\n<td><span style=\"font-weight: 400\">int<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the second of the timestamp.<\/span><\/td>\n<\/tr>\n<tr>\n<td>weekofyear(string date)<\/td>\n<td><span style=\"font-weight: 400\">int<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the week number of a timestamp string.<\/span><\/td>\n<\/tr>\n<tr>\n<td>extract(field FROM source)<\/td>\n<td><span style=\"font-weight: 400\">int<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will retrieve the fields such as days or hours from the source.\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">Source must be a timestamp, date, interval or a string that can be converted into either a date or timestamp.\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">The supported fields include: day, dayofweek, hour, minute, month, quarter, second, week and year.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Examples:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">select extract(month from &#8220;2020-05-11&#8221;) results in 05.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">select extract(hour from &#8220;2020-05-11 05:06:07&#8221;) results in 5.<\/span><\/li>\n<\/ol>\n<\/td>\n<\/tr>\n<tr>\n<td>current_date<\/td>\n<td><span style=\"font-weight: 400\">date<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the current date at the start of query evaluation. All the calls of the current_\u00a0 date function within the same query return the same value.<\/span><\/td>\n<\/tr>\n<tr>\n<td>current_timestamp<\/td>\n<td><span style=\"font-weight: 400\">timestamp<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the current timestamp at the start of query evaluation. All the\u00a0 calls of the current_timestamp function within the same query return the same value.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>5. Conditional Functions<\/h4>\n<p>We use Conditional function for conditional values checks. The following are the built-in conditional function supported by Hive:<\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>Name<\/strong><\/td>\n<td><strong>Return Type<\/strong><\/td>\n<td><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td>if(boolean testCondition, T valueTrue, T valueFalseOrNull)<\/td>\n<td><span style=\"font-weight: 400\">T<\/span><\/td>\n<td><span style=\"font-weight: 400\">It returns the valueTrue when testCondition is true. It returns valueFalse Or Null otherwise.<\/span><\/td>\n<\/tr>\n<tr>\n<td>isnull( a )<\/td>\n<td><span style=\"font-weight: 400\">boolean<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return true if argument \u2018a\u2019 is NULL and false otherwise.<\/span><\/td>\n<\/tr>\n<tr>\n<td>isnotnull ( a )<\/td>\n<td><span style=\"font-weight: 400\">boolean<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return true if argument \u2018a\u2019 is not NULL and false otherwise.<\/span><\/td>\n<\/tr>\n<tr>\n<td>nvl(T value, T default_value)<\/td>\n<td><span style=\"font-weight: 400\">T<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return default value if the value is null. Otherwise it\u00a0 returns value.<\/span><\/td>\n<\/tr>\n<tr>\n<td>COALESCE(T v1, T v2, &#8230;)<\/td>\n<td><span style=\"font-weight: 400\">T<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the first v that is not NULL, or NULL if all v&#8217;s are NULL.<\/span><\/td>\n<\/tr>\n<tr>\n<td>CASE a WHEN b THEN c [WHEN d THEN e]* [ELSE f] END<\/td>\n<td><span style=\"font-weight: 400\">T<\/span><\/td>\n<td><span style=\"font-weight: 400\">When a = b, it will return c.<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0when a = d, it will return e;<\/span><\/p>\n<p><span style=\"font-weight: 400\">else it will return f.<\/span><\/td>\n<\/tr>\n<tr>\n<td>CASE WHEN a THEN b [WHEN c THEN d]* [ELSE e] END<\/td>\n<td><span style=\"font-weight: 400\">T<\/span><\/td>\n<td><span style=\"font-weight: 400\">When a = true, it will return b;\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">when c = true, it will\u00a0 return d;\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">else it will return e.<\/span><\/td>\n<\/tr>\n<tr>\n<td>nullif( a, b )<\/td>\n<td><span style=\"font-weight: 400\">T<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return NULL if a=b; otherwise returns \u2018a\u2019.<\/span><\/td>\n<\/tr>\n<tr>\n<td>assert_true(boolean condition)<\/td>\n<td><span style=\"font-weight: 400\">void<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will throw an exception if\u00a0 the &#8216;condition&#8217; is not true.\u00a0 otherwise it will return NULL.\u00a0<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>6. STRING Functions<\/h4>\n<p>We use String functions for string manipulations and string operations. The following are the built-in Hive String functions:<\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>Name<\/strong><\/td>\n<td><strong>Return Type<\/strong><\/td>\n<td><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td>ascii(string str)<\/td>\n<td><span style=\"font-weight: 400\">int<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the numeric value of the first character of argument str.<\/span><\/td>\n<\/tr>\n<tr>\n<td>concat(string|binary A, string|binary B&#8230;)<\/td>\n<td><span style=\"font-weight: 400\">string<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the string or bytes resulting from the concatenation of\u00a0 the strings or bytes passed in as arguments in order.<\/span><\/p>\n<p><span style=\"font-weight: 400\">For example, concat(&#8216;teddy&#8217;, &#8216;bear&#8217;) results in &#8216;teddybear&#8217;. Note: It will take any number of input strings.<\/span><\/td>\n<\/tr>\n<tr>\n<td>character_length(string str)<\/td>\n<td><span style=\"font-weight: 400\">int<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the number of UTF-8 characters contained in argument str.<\/span><\/p>\n<p><span style=\"font-weight: 400\">The function char_length is shorthand for this function.<\/span><\/td>\n<\/tr>\n<tr>\n<td>decode(binary bin, string charset)<\/td>\n<td><span style=\"font-weight: 400\">string<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will decode the first argument into a String using the provided character set.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">If any of the arguments is null, the result will also be null. (As of Hive <\/span><span style=\"font-weight: 400\">0.12.0<\/span><span style=\"font-weight: 400\">.)<\/span><\/td>\n<\/tr>\n<tr>\n<td>encode(string src, string charset)<\/td>\n<td><span style=\"font-weight: 400\">binary<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will encode the first argument into the BINARY using the provided character set. If any of the arguments is null, then\u00a0 the result will also be null.<\/span><\/td>\n<\/tr>\n<tr>\n<td>field(val T,val1 T,val2 T,val3 T,&#8230;)<\/td>\n<td><span style=\"font-weight: 400\">int<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the index of val in the list of val1,val2,val3,&#8230; or 0 if not found.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Example:<\/span><\/p>\n<p><span style=\"font-weight: 400\">field(&#8216;Isha&#8217;,&#8217;Isha&#8217;,&#8217;says&#8217;,&#8217;hello&#8217;) returns 1.<\/span><\/p>\n<p><span style=\"font-weight: 400\">All primitive types are supported, arguments are compared using str.equals(x).\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">In case, if val is NULL, the return value is 0.<\/span><\/td>\n<\/tr>\n<tr>\n<td>find_in_set(string str, string strList)<\/td>\n<td><span style=\"font-weight: 400\">int<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the first occurrence of argument str in strList where strList is a comma-delimited string.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">This will return null if either argument is null.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">It will return 0 if the first argument contains any commas.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Example: find_in_set(&#8216;ab&#8217;, &#8216;abc,b,ab,c,def&#8217;) returns 3.<\/span><\/td>\n<\/tr>\n<tr>\n<td>instr(string str, string substr)<\/td>\n<td><span style=\"font-weight: 400\">int<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the position of the first occurrence of substr in str.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">This will return null if either of the arguments are null.<\/span><\/p>\n<p><span style=\"font-weight: 400\">It will return 0 if substr could not be found in str.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Note: This is not zero based. The first character in str has index 1.<\/span><\/td>\n<\/tr>\n<tr>\n<td>in_file(string str, string filename)<\/td>\n<td><span style=\"font-weight: 400\">boolean<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return true if the string str appears as the entire line in the file filename.<\/span><\/td>\n<\/tr>\n<tr>\n<td>length(string A)<\/td>\n<td><span style=\"font-weight: 400\">int<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the length of the string passed.<\/span><\/td>\n<\/tr>\n<tr>\n<td>locate(string substr, string str[, int pos])<\/td>\n<td><span style=\"font-weight: 400\">int<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the position of the first occurrence of the substr in str after position pos.<\/span><\/td>\n<\/tr>\n<tr>\n<td>lower(string A) lcase(string A)<\/td>\n<td><span style=\"font-weight: 400\">string<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the string by converting all characters of string A to lowercase.<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0Example, lower(&#8216;BaR&#8217;) results in &#8216;bar&#8217;.<\/span><\/td>\n<\/tr>\n<tr>\n<td>parse_url(string urlString, string partToExtract [, string keyToExtract])<\/td>\n<td><span style=\"font-weight: 400\">string<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the specified part from the URL.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">The valid values for the partToExtract include HOST, PATH, QUERY, REF, PROTOCOL, AUTHORITY, FILE, and USERINFO.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td>repeat(string str, int n)<\/td>\n<td><span style=\"font-weight: 400\">string<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will repeat str n times.<\/span><\/td>\n<\/tr>\n<tr>\n<td>regexp_extract(string subject, string pattern, int index)<\/td>\n<td><span style=\"font-weight: 400\">string<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the string extracted using the pattern.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td>regexp_replace(string INITIAL_STRING, string PATTERN, string REPLACEMENT)<\/td>\n<td><span style=\"font-weight: 400\">string<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the string resulting from replacing all the substrings in INITIAL_STRING that match the java regular expression syntax defined in PATTERN with instances of REPLACEMENT.<\/span><\/td>\n<\/tr>\n<tr>\n<td>replace(string A, string OLD, string NEW)<\/td>\n<td><span style=\"font-weight: 400\">string<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the string \u2018A\u2019 with all the non-overlapping occurrences of the OLD replaced with the NEW.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Example: select replace(&#8220;aabab&#8221;, &#8220;bab&#8221;, &#8220;Z&#8221;); returns &#8220;aaZ&#8221;.<\/span><\/td>\n<\/tr>\n<tr>\n<td>reverse(string A)<\/td>\n<td><span style=\"font-weight: 400\">string<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the reversed string.<\/span><\/td>\n<\/tr>\n<tr>\n<td>upper(string A) ucase(string A)<\/td>\n<td><span style=\"font-weight: 400\">string<\/span><\/td>\n<td><span style=\"font-weight: 400\">It will return the string resulting from converting all the characters of string \u2018A\u2019 to uppercase.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Example: upper(&#8216;BaR&#8217;) results in &#8216;BAR&#8217;<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Summary<\/h3>\n<p>This article had explained all the Hive Built-in functions in detail along with their return type. I hope after reading this article, you clearly understand Hive Built-in functions.<\/p>\n<p>The article had covered all types of Hive built-in functions such as mathematical function, collection function, type conversion function, date function, conditional function, and string function.<\/p>\n<p>If you still have any doubt in hive built-in function, then feel free to ask us in the comment section.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Apache Hive, there are various functions available for performing several tasks. These functions are known as Built-in functions. In this article, we will study Hive Built-in functions. The Hive Built-in functions are categorized&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":79737,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[544],"tags":[3241,3242],"class_list":["post-79720","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hadoop","tag-apache-hive-built-in-functions","tag-hive-built-in-functions"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Hive Built-in Functions and their Return Type with Examples - TechVidvan<\/title>\n<meta name=\"description\" content=\"Learn about Hive Built-in-Functions like mathematical, collection, type conversion, date, conditional, and string function with return types and details\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/apache-hive-built-in-functions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hive Built-in Functions and their Return Type with Examples - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Learn about Hive Built-in-Functions like mathematical, collection, type conversion, date, conditional, and string function with return types and details\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/apache-hive-built-in-functions\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-27T03:30:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/08\/Apache-Hive-Built-in-Functions.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Hive Built-in Functions and their Return Type with Examples - TechVidvan","description":"Learn about Hive Built-in-Functions like mathematical, collection, type conversion, date, conditional, and string function with return types and details","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/apache-hive-built-in-functions\/","og_locale":"en_US","og_type":"article","og_title":"Hive Built-in Functions and their Return Type with Examples - TechVidvan","og_description":"Learn about Hive Built-in-Functions like mathematical, collection, type conversion, date, conditional, and string function with return types and details","og_url":"https:\/\/techvidvan.com\/tutorials\/apache-hive-built-in-functions\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-08-27T03:30:24+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/08\/Apache-Hive-Built-in-Functions.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/apache-hive-built-in-functions\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/apache-hive-built-in-functions\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Hive Built-in Functions and their Return Type with Examples","datePublished":"2020-08-27T03:30:24+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/apache-hive-built-in-functions\/"},"wordCount":2194,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/apache-hive-built-in-functions\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/08\/Apache-Hive-Built-in-Functions.jpg","keywords":["Apache Hive Built-In Functions","Hive Built In Functions"],"articleSection":["Hadoop Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/apache-hive-built-in-functions\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/apache-hive-built-in-functions\/","url":"https:\/\/techvidvan.com\/tutorials\/apache-hive-built-in-functions\/","name":"Hive Built-in Functions and their Return Type with Examples - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/apache-hive-built-in-functions\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/apache-hive-built-in-functions\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/08\/Apache-Hive-Built-in-Functions.jpg","datePublished":"2020-08-27T03:30:24+00:00","description":"Learn about Hive Built-in-Functions like mathematical, collection, type conversion, date, conditional, and string function with return types and details","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/apache-hive-built-in-functions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/apache-hive-built-in-functions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/apache-hive-built-in-functions\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/08\/Apache-Hive-Built-in-Functions.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/08\/Apache-Hive-Built-in-Functions.jpg","width":1200,"height":628,"caption":"Apache Hive Built-in Functions"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/apache-hive-built-in-functions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Hive Built-in Functions and their Return Type with Examples"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/79720","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=79720"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/79720\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/79737"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=79720"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=79720"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=79720"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}